ROBOTGRI  Robots on a grid
You have recently made a grid traversing robot that can
nd its way from the top left corner of a grid to the
bottom right corner. However, you had forgotten all your
AI programming skills, so you only programmed your robot
to go rightwards and downwards (that's after all where the
goal is). You have placed your robot on a grid with some
obstacles, and you sit and observe. However, after a while
you get tired of observing it getting stuck, and ask yourself
\How many paths are there from the start position to the
goal position?", and \If there are none, could the robot have
made it to the goal if it could walk upwards and leftwards?"
So you decide to write a program that, given a grid of
size n x n with some obstacles marked on it where the robot
cannot walk, counts the dierent ways the robot could go
from the top left corner s to the bottom right t, and if none,
tests if it were possible if it could walk up and left as well.
However, your program does not handle very large numbers, so the answer should be
given modulo 2^31  1.
Input
On the rst line is one integer, 1 < n <= 1000. Then follows n lines, each with n characters,
where each character is one of '.' and '#', where '.' is to be interpreted as a walkable
tile and '#' as a nonwalkable tile. There will never be a wall at s, and there will never
be a wall at t.
Output
Output one line with the number of dierent paths starting in s and ending in t (modulo
2^31  1) or THE GAME IS A LIE if you cannot go from s to t going only rightwards and
downwards but you can if you are allowed to go left and up as well, or INCONCEIVABLE if
there simply is no path from s to t.
Example
Input: 5
.....
#..#.
#..#.
...#.
..... Output: 6
hide comments
vengatesh15:
20170325 09:23:46
dfs tle .. bfs AC.. 

m_alhussein_96:
20160823 00:06:20
finally AC , recursively for count the path topdown , then bfs 

Shubham Garg:
20151020 19:39:36
A very silly mistake costed me many wrong answers. Be careful what your function returns. 

Fz:
20151018 21:34:50
comments will help you, its enough if you are satisfied with small test cases (but exhaustive) of yours. 

Gaurav Kumar:
20150203 12:03:49
Lesson learnt no to recursive dfs. 

sahni:
20150125 13:42:32
Do it iteratively...recursely wrong answer..inbuilt stack overflow 

Mohit Mehta:
20140803 18:13:11
dont forget to watch ur submission testing till the end. I had to rerun them for that only. 

N0VICE:
20140803 14:43:13
finally AC:) 

Archit Jain:
20140725 13:52:16
iteratively AC


Mitch Schwartz:
20140709 00:26:25
@Andres Felipe Ruiz Cardozo: Judging does not halt on first failure, the way SPOJ is currently set up. (You can see for yourself by submitting infinite loop code.) 
Added by:  Krzysztof Lewko 
Date:  20111005 
Time limit:  0.126s0.632s 
Source limit:  50000B 
Memory limit:  1536MB 
Cluster:  Cube (Intel G860) 
Languages:  All except: ASM64 
Resource:  Nordic programming contest 