Beautiful rectangles#1440

Beautiful rectangles

0.5 seconds
64 megabytes
Medium

One fine day, first-grader Petya came home, did his homework, and started thinking about what to do next. Nothing interesting came to mind, so Petya took a rectangular grid sheet of paper of rows and columns and wrote an uppercase letter of the English alphabet in every cell. Petya has only just started learning English, so for now, he knows only the first letters of the alphabet. Thus, each cell of the sheet contains one of the letters 'A'..'E'.

Looking at the results of his work, Petya was dissatisfied—maybe the sheet turned out too big, or the letters were written in a poor order. "Perhaps the situation could be improved if I cut out a smaller rectangle from the original sheet," thought Petya. "And, of course, the cut-out rectangle should be beautiful!" But what is a beautiful rectangle? The thing is, Petya doesn't like rectangles with a lot of different letters in their cells ( or ), nor those with too few different letters ( or ). So he considers a rectangle to be beautiful if the number of different letters in its cells is exactly .

Help Petya count how many ways he can cut a beautiful rectangle from the original sheet of paper. Cuts can only be made along the borders of cells. If the original sheet is itself a beautiful rectangle, Petya might decide not to cut anything at all and keep the entire rectangle—that also counts as one of the ways.

Note that each way to cut can be uniquely specified by a quadruple of non-negative numbers (a, b, c, d), where is the number of rows cut off from the top, is the number of rows cut off from the bottom, is the number of columns cut off from the left, and is the number of columns cut off from the right. Two ways to cut, specified by quadruples (a, b, c, d) and (a', b', c', d'), are considered different if at least one of the inequalities a \ne a', b \ne b', c \ne c', or d \ne d' holds.

Input

The first line contains the number of rows (1 \le N \le 400) written by Petya. Then follow lines specifying the array of strings containing the content of the original sheet of paper. In line t_i, the characters listed from left to right are those written in the cells of the (i+1)-th row from the top of the sheet. The number of characters in a line does not exceed (1 \le M \le 400).

Output

Print an integer equal to the number of ways to cut a beautiful rectangle from the original sheet of paper.

Examples

Example 1

Loading
Loading