提示: 欢迎访问OurACM平台。
Problem 1508 Link-up Game

Accept: 107    Submit: 291
Time Limit: 1000 mSec    Memory Limit : 32768 KB

Problem Description

Everyone plays link-up games, especially girls.

Link-up is a game which eliminates two boxes with the same pattern within three straight lines. Its simple rules, fast tempo make it full of excitement. Playing with people over network, competitiveness has been strengthened. Random changes in game maps make players feel enthusiasm about the game all the time. The first player to eliminate all the boxes is the winner.

For simplicity, we here require only the two adjacent boxes with the same pattern can be eliminated. Adjacent boxes are up, down, left or right to each other.

Here comes your question. Can you write a program to calculate the maximum number of boxes, which can be removed from the given map?

Input

The input consists of several test cases. For each case, the first line has two integer M, N (1 <= M, N <= 100), which indicates the width and the height of the rectangular map. The next N lines describe the rectangular map, which contains N rows and M columns. For each line, there are M characters from A to Z, indicating the boxes.

Output

Output the maximum number of boxes that you can eliminate from the given map.

Sample Input

4 4 AAAA AAAB BBAB BBBB

Sample Output

16

Source

FOJ月赛-2007年6月

Submit  Back  Status  Discuss