문제
The ill-fated result of watching too many "do it yourself" engineering videos on the web, Farmer John has accidentally released a self-replicating robot on his farm!
The farm can be represented by an
Farmer John initially places the robot at one of the possible starting positions. In every hour that follows, all copies of the robot move in one coordinated mass in the same direction, either north, south, east, or west. After every
If moving or replicating would cause any of the robots to move into a rock, then all robots shut down immediately. Note that this implies that the robots must eventually shut down, due to the border of the farm being rock.
Help the cows figure out the number of empty squares that could potentially at some point in time hold a robot.
입력
The first line contains two space-separated integers
All characters in the first and last row and first and last column are '#'.
출력
An integer counting the number of cells that could at some point in time hold a robot.
예제1
10 1
##########
#........#
#S.......#
#........#
##########
#S....S..#
##########
##########
##########
##########
15

예제2
10 2
##########
#.#......#
#.#......#
#S.......#
#.#......#
#.#......#
##########
##########
##########
##########
28
Locations that could be occupied by robots:
##########
#x#.xxx..#
#x#xxxxx.#
#xxxxxxxx#
#x#xxxxx.#
#x#.xxx..#
##########
##########
##########
##########
예제3
10 2
##########
#.S#.....#
#..#.....#
#S.......#
#..#.....#
#..#.....#
##########
##########
##########
##########
10
Locations that could be occupied by robots:
##########
#xx#.....#
#xx#.....#
#xxx.....#
#xx#.....#
#x.#.....#
##########
##########
##########
##########