#P7756. [COCI 2012/2013 #3] MALCOLM

[COCI 2012/2013 #3] MALCOLM

Description

According to Malcolm’s observations, there are nn students in the class. If the ranks of two students differ by at most kk, then they are friends. If two students are friends and their name lengths are the same, then they are good friends.

Now you are given the names and ranks of these nn students. Find how many pairs of good friends there are in the class.

Input Format

The input has n+1n+1 lines.

The first line contains two integers n,kn,k, representing the number of students in the class and the maximum rank difference allowed for being friends.
The next nn lines follow: the (i+1)(i+1)-th line contains a string, the name of the student ranked ii-th in the class.

Output Format

Output a single line with one integer, the number of pairs of good friends in the class.

4 2
IVA
IVO
ANA
TOM
5
6 3
CYNTHIA
LLOYD
STEVIE
KEVIN
MALCOLM
DABNEY
2

Hint

Constraints

For all testdata, 3n3×1053\leqslant n\leqslant 3\times 10^5, 1kn1\leqslant k\leqslant n. Each string has length in [2,20][2,20] and contains only uppercase English letters.

Source

This problem is from COCI 2012-2013 CONTEST 3 T3 MALCOLM. Using the original testdata settings, the full score is 100100 points.

Translated and organized by Eason_AC.

Translated by ChatGPT 5