407224: GYM102697 195 Dungeon
Description
Unfortunately, you find yourself trapped in a dungeon, which can be represented as a 2D grid. The dungeon contains some impassable walls, represented by X characters, and empty space, represented as single dots (".").
You start in the top left corner. You want to figure out how many cells are accessible from your starting space. You can move up, down, right, and left any number of times, but you cannot move diagonally, and you cannot move through walls. You also can't go off the board.
InputThe first line of input consists of a single positive integer $$$n$$$: the number of rows and columns of the dungeon (the dungeon is always square).
The next $$$n$$$ lines each contain $$$n$$$ characters: the grid representation of the dungeon. If a character is an "X", it represents an impassable wall, and if a character is a single dot, it represents empty space.
OutputOutput a single positive integer $$$k$$$: the number of spaces in the dungeon accessible from your starting space, according to the rules above.
ExamplesInput5 ...X. ..X.. ....X ..XXX .X...Output
15Input
5 ..X.. .XX.. X.... ..... .....Output
3