#000186

z-transformer

After seeing the Transformers movie, Little Z decided to make his own transformer.

For start, he wants to make only 2D transformer, that is made of steel parts, and joints that connect different parts.

The description of the transformer can be represented by a 2D matrix in the following form:
.aa0bb.
Where '.' represents a free space, the letters represent the steel parts (each letter represents the same part) and finally '0' (zero) represents a joint.

Each joint can move in 90 degrees increments. The transformer above can look transform to:
.aa0
...b
...b


or

...b
...b
.aa0


But the following transformer can not transform at all (because of the way the parts are connected)

0aa0
b..c
b..c
0dd0


Little Z wants to send the transformer to his friend, and wants to use the smallest box possible. So he wonders, what is the smallest (in terms of area) 2D box he can use, so that the whole transformer fits inside.



InputFrom the first line of the standard input read two integers m and n. (1 <= m, n <= 50). From the next m lines read n characters representing the transformer (as described above). The transformer will have at most 26 different parts, and at most 20 different joints. In the input, each joint will always touch (connect) exactly two different parts (two different letters)


OutputTo the standard output write one integer representing the area of the smallest box that the transformer can fit in


Input:
4 5
0a0..
b.d0e
0c0..
.....

Output:
12
Explanation: the transformers can have the following shape:
0a0e
b.d0
0c0.



Input:
3 8
a.......
a..bb...
aa0bb0cc

Output:
12
Explanation: the transformers can have the following shape:
cc0
abb
abb
aa0


Input:
1 17
.aaa0bb0cc0d0e0f.

Output:
15
Explanation: the transformers can have the following shape:
aaa0bb0cc0d0e0f

Submit solution

Coming later

The grading service will be connected in a later migration step. You can inspect the task and your previous results now.