Aether is travelling across Teyvat, which can be represented by a by
grid, where each cell
is either empty
.
or contains a teleporter x
. Due to terrain and weather reasons, he can only move down and to the right. Formally, if he is at the cell , he can go to
if
, and he can go to
if
.
Whenever he is at a cell containing a teleporter, he can choose to teleport to any other cell containing a teleporter. Each teleporter can be used an unlimited number of times.
Since Aether likes exploring new areas, he would like to know, what is the maximum number of unique cells that he can visit if he starts at the top-leftmost cell
?
Constraints
.
x
Subtask 1 [5%]
There are no teleporters. Formally,
x
.
Subtask 2 [45%]
Subtask 3 [50%]
No additional constraints.
Input Specification
The first line of input contains integer,
, representing the dimensions of the grid.
The next lines of input each contain
characters,
, representing the cells in each row.
Output Specification
Output integer, the maximum number of unique cells that Aether can visit.
Sample Input 1
3
...
..x
.x.
Sample Output 1
6
Explanation for Sample 1
The following path visits unique cells:
- Start at
- Go to
- Go to
- Go to
- Teleport to
- Go to
It can be proven that this is the maximum number of unique cells Aether can visit.
Sample Input 2
5
x....
.x...
...x.
.....
.x..x
Sample Output 2
25
Comments