Latin Squares
문제
Chris is a fan of puzzles. Recently he learned about Sudoku puzzles, that are based on Latin squares. A table is called a Latin square if the number of distinct elements in the table is , and there are no two equal elements in the matrix that share the same row or the same column.
For example, [이미지 1], [이미지 2] and [이미지 3] are Latin squares, while [이미지 4], [이미지 5] and [이미지 6] are not.
Chris wants to make a new Latin square puzzle. However, he only has an old template, which is an table. Chris wants to cut a contiguous Latin square fragment from the template. In how many ways can he do this? Two ways to cut a square are considered different if there is a cell that is present in one square, but not present in the other.
입력
The first line contains two integers and --- dimensions of the template ().
The next lines contain strings that describe the template. Each string contains characters with ASCII codes between and . The cell in row and column of the template contains a pair of characters and (, ). Two cells of the template contain equal elements if their ordered character pairs are equal. See the Notes section for further explanation.
출력
Print a single integer --- the number of ways to cut a Latin square from the template.
힌트
In the first sample there are ways to cut a Latin square, as well as other ways:
| [이미지 7] | [이미지 8] | [이미지 9] |
| (a) Way 1 | (b) Way 2 | (c) Way 3 |
| [이미지 10] | [이미지 11] | [이미지 12] |
| (d) Way 4 | (e) Way 5 | (f) Way 6 |
예제
예제 1
4 5 AABBAAAACC BBAABBCCAA AABBCCAABB BBCCAABBCC
26
예제 2
5 10
!"#$%&'()*+,-./01234
56789:;<=>?@ABCDEFGH
IJKLMNOPQRSTUVWXYZ[\
]^_`abcdefghijklmnop
qrstuvwxyz{|}~!"#$%&50