Since teacher Herkabe has started ranking his students, the number of friendships in his class has sharply fallen. The students near the bottom of the rankings list have become jealous of the top students, while the top students started looking down on their less successful colleagues.
According to Malcolm's observations, the following rule holds: two students are friends if their ranks are close enough, more precisely, if they differ by at most . For example, if , then only neighbouring students on the rankings list are friends. Furthermore, two students are good friends if they are friends and their names have the same length.
Write a program to calculate the number of pairs of good friends in this gifted class.
Input Specification
The first line of input contains two positive integers, and , from the problem statement.
Each of the following lines contains a single student's name. The names are given in the order they appear on the rankings list. They consist of between and (inclusive) uppercase English letters.
Output Specification
The first and only line of output must contain the required number of pairs.
Sample Input 1
4 2
IVA
IVO
ANA
TOM
Sample Output 1
5
Sample Input 2
6 3
CYNTHIA
LLOYD
STEVIE
KEVIN
MALCOLM
DABNEY
Sample Output 2
2
Comments