Ski jumpers have a unique mentality. To make -meter jumps, they need iron willpower and a focused psychological state. Each has their own way to prepare: some listen to music, some visualize the jump, and some play the popular game Bubble Breaker.
The game board consists of cells, each containing a ball of one of four colors: blue, red, green, or yellow. On each move, a player must remove any group of two or more adjacent balls of the same color. Cells are adjacent if they share a side. For each move, the player scores P \times (P-1) points, where is the number of balls removed in that group. Points are summed for the entire game.
After removal, balls above the emptied spaces fall vertically down to fill any gaps, continuing until they land on another ball or the bottom. The game ends when there are no more removable groups.
One jumper improved the greedy approach to this game with the following strategy:
If there is a move that creates a favorable situation for the next move, perform both this and the next move. Such a move is called a first-type move.
If no such move exists, perform the optimal move. This move is called a second-type move.
A move at step creates a favorable situation for step k+1 if, from the resulting position at step k+1, one can score more points than any other move at step would have allowed at that step k+1. A move at step is optimal if it earns more points than any other possible move at step .
If there are several suitable second-type moves, choose the group that is further to the left. If there are still several optimal moves, choose the one located higher. The position is determined by the topmost cell among the leftmost cells in the group.
If there are multiple first-type moves, select the move that will bring the maximum possible points in the next move. If there are still multiple such moves, select the optimal one (and, if necessary, use the same left-to-right and top-to-bottom tie-breaking rule described above).
The athletes do not want to be distracted from their training for long, so you are to determine the maximum number of points that can be scored with this strategy.
The first line contains and (1 \le N, M \le 50), the dimensions of the game board. Then follow lines of characters, each from the set \{\textbf{Y}, \textbf{B}, \textbf{R}, \textbf{G}\}. The character represents the color of the ball: (yellow), (blue), (red), (green).
Output a single number: the total number of points.
Example 1