N. N-Checkers
time limit per test
0.5 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Few people know this, but according to a local legend the Portuguese name 'damas' is actually a linguistic corruption of 'dez-amas', a subset of the legendary $$$n$$$-amas.

The $$$n$$$-checkers board is an $$$n \times n$$$ board with squares alternating between white and black, with the square in the top-left corner being white. A square may be empty or, if it is black, contain a piece.

On their turn, a player must choose one of their pieces to move. The chosen piece may capture an opponent's piece if that piece is on a diagonally adjacent square and the next square in the same diagonal direction is empty. In this case, the chosen piece "jumps" over the opponent's piece, moves to the immediately following empty square, and removes the opponent's piece from the board. After a capture, the player may continue the move with the same chosen piece.

In the official rules of $$$n$$$-checkers, there is a majority-capture rule: if on their turn a player has the opportunity to capture opponent pieces, they must perform a sequence of moves that results in the largest possible number of captured pieces.

During the final of the Minas Gerais $$$n$$$-checkers Tournament, a dispute arose between the finalists. Alice, playing with the black pieces, accused Bob, playing with the white pieces, of having made an illegal move. Bob claims he captured as much as he could, but Alice says there was a longer path. Write a program that determines the maximum number of pieces Bob can capture in one move sequence.

Input

The first line contains a single integer $$$n$$$ $$$(4 \leq n \leq 14)$$$, the dimension of the board.

Then $$$n$$$ lines follow, each with $$$n$$$ characters representing the board. Each line contains only the characters 'B', 'P', and '.', representing white pieces, black pieces, and empty squares, respectively. The letters come from Portuguese: 'B' for white pieces and 'P' for black pieces.

The board will contain at least one piece of each color, and no piece will be on a white square.

Output

Print the maximum number of pieces Bob can capture.

Examples
Input
8
.P.P.P.P
P.P.P.P.
.P.....P
..P.P...
.....B..
B.B...B.
.B.B.B.B
B.B.B.B.
Output
2
Input
8
........
..P.P.P.
........
..P.P.P.
.......B
....P...
...B....
........
Output
6
Input
14
.B.P.B.B.P.B.P
B...B...B...B.
.P.B.P.P.B.P.B
..B...B...B...
.B.P.B.B.P.B.P
B...B...B...B.
.P.B.P.P.B.P.B
..B...B...B...
.P.B.P.P.B.P.B
B...B.B.B...B.
.B.P.B.B.P.B.P
..B...B...B...
.P.B.P.P.B.P.B
B...B.B.B...B.
Output
12
Note

Explanation for example 1

The move to be made, in which one of Bob's pieces captures two of Alice's pieces.

Explanation for example 2

One of the possible moves that can be made, in which one of Bob's pieces captures six of Alice's pieces. XIII.