Task
Kida has found herself in the casino again! In front of her, there are roulettes, each having pins. Each of the 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 can be obtained from , but or cannot be obtained from .
Kida asks you to count the number of unordered pairs of similar roulettes.
Input
The first line contains two integers and ().
Each of the following lines contains a string of characters representing a roulette.
For tests worth points: , .
For tests worth more points: ,
For tests worth 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 pairs are , and .
In the second sample case, the only pair is .