eolymp
bolt
Try our new interface for solving problems
Problems

Beautyful squares

Beautyful squares

One day Peter came home first-grader, has made the lessons and started to think about what he would do. Nothing of interest had not occurred, so Peter took the checkered square sheet of paper the size of \textbf{N} rows by \textbf{M} columns and recorded in every cell of the capital letter of the alphabet. English Pete started to learn recently, and so long as he knows only the first \textbf{5} letters of the alphabet. Thus, each cell sheet was written the letter '\textbf{A}' .. '\textbf{E}'. Looking at the results of his work, Peter was not satisfied - whether the list was too large, whether the letters were written on it in a bad manner. "\textit{Perhaps the situation can be improved if the cut from the original sheet smaller rectangle}," - thought Petya. "\textit{And, of course, cut the rectangle should be beautiful!}" But what a nice box? The fact that Pete did not like how the rectangles in the cells of which there are many different letters (\textbf{4} or \textbf{5}), and rectangles, the cells are little different letters (\textbf{1} or \textbf{2}). Therefore, he believes nice rectangle, if the number of different letters in its cells is \textbf{3}. Help Pete count how many ways he can cut from the original sheet of paper a nice rectangle. Incisions can be made only on the boundaries of cells. If the source rectangle is a beautiful leaf, it is possible that Peter wants nothing to cut out and keep the original box entirely, and it is also considered one of the ways to cut. Note that each method of cutting can uniquely specify the Quartet non-negative integers (\textbf{a}, \textbf{b}, \textbf{c}, \textbf{d}), where \textbf{a} - number of lines, cut off from the original sheet on top, \textbf{b} - number of lines, cut off the bottom, \textbf{c} - number of columns, cut to the left and \textbf{d} - the number of columns, cut off on the right. Two ways to cut, asked quadruples (\textbf{a}, \textbf{b}, \textbf{c}, \textbf{d}) and (\textbf{a'}, \textbf{b'}, \textbf{c'}, \textbf{d'}), considered different if at least one of the inequalities \textbf{a} ≠ \textbf{a'}, \textbf{b} ≠ \textbf{b'}, \textbf{c} ≠ \textbf{c'} or \textbf{d} ≠ \textbf{d'}. \InputFile The first line specifies the number of rows \textbf{N} (\textbf{1} ≤ \textbf{N} ≤ \textbf{400}) written by Petya. Next \textbf{N} lines is given in the array of rows with the contents of the original sheet of paper. In the line \textbf{t\[i\]} are listed from left to right characters written in the cells (\textbf{i +1})-th row from the top of the sheet. Number of characters per line is less than \textbf{M} (\textbf{1} ≤ \textbf{M} ≤ \textbf{400}). \OutputFile Integer equal to the number of ways to cut a beautiful box of the original sheet of paper.
Time limit 0.5 seconds
Memory limit 64 MiB
Input example #1
2
AAB
CCB
Output example #1
2
Author Vladimir Minaylov