casino

Time limit: 0.4s Memory limit: 64MB Input: Output:

Task

Kida has found herself in the casino again! In front of her, there are NN roulettes, each having MM pins. Each of the MM pins of a roulette wheel is coded by a lowercase letter of the English alphabet.

Kida considers two roulettes to be similar if the configuration of the pins of the first roulette can be obtained on the second roulette by shifting left or right all the pins of the second roulette an arbitrary number of times. Note that each shift is a cyclic shift.

For example abcaabca can be obtained from caabcaab, but abacabac or aacbaacb cannot be obtained from abcaabca.

Kida asks you to count the number of unordered pairs of similar roulettes.

Input

The first line contains two integers NN and MM (1NM1061 \le N * M \le 10^6).
Each of the following NN lines contains a string of MM characters representing a roulette.

For tests worth 2020 points: N100N \le 100, M100M \le 100.

For tests worth 2020 more points: N500N \le 500, M500M \le 500

For tests worth 6060 more points: No additional limitations.

Output

You need to write a single integer, representing the number of unordered pairs of similar roulettes.

Example 1

stdin

4 4
abcd
xbcd
cdab
dabc

stdout

3

Example 2

stdin

3 6
adaada
aaadda
aadaad

stdout

1

Notes

In the first sample case, the 33 pairs are (0,2)(0, 2), (0,3)(0, 3) and (2,3)(2, 3).

In the second sample case, the only pair is (0,2)(0, 2).

Log in or sign up to be able to send submissions!