#P7756. Good Friends Counting

    ID: 20943 Type: Default 1000ms 256MiB

Good Friends Counting

Good Friends Counting

Malcolm observed that a class has n students, each having a rank based on their ordering (the first student has rank 1, the second rank 2, and so on). Two students are considered friends if the difference in their ranks is at most k, i.e. \(|i - j| \le k\). Furthermore, if two friends have names of the same length, they are termed good friends. Given the names of all n students (in the order of their ranks) and the value of k, your task is to determine the total number of pairs of good friends.

Note: Each pair should be counted only once. That is, if student i and student j form a good friend pair (with \(i < j\)), count it once.

The formulas above are given in \(\LaTeX\) format.

inputFormat

The first line contains two integers n and k separated by a space, where n is the number of students and k denotes the maximum allowed difference in their ranks for them to be considered friends.

The following n lines each contain a single string representing a student's name. The order of these names represents the students' ranks (first name has rank 1, second has rank 2, etc.).

outputFormat

Output a single integer representing the number of pairs of good friends.

sample

5 2
Amy
Bob
Catty
Ann
Eve
2