Problem list
Log in
#coci00246 · COCI 2012/2013 Contest 3

Malcolm

Gold IV 1.0 s 32 MB

Since teacher Herkabe has started ranking his N 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 K. For example, if $K = 1$, 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

The first line of input contains two positive integers, N ($3 \le N \le 300,000$) and K ($1 \le K \le N$), from the problem statement. Each of the following N lines contains a single student's name. The names are given in the order they appear on the rankings list. They consist of between 2 and 20 (inclusive) uppercase English letters.

Output

The first and only line of output must contain the required number of pairs.

Example 1

Input
4 2
IVA
IVO
ANA
TOM
Output
5

Example 2

Input
6 3
CYNTHIA
LLOYD
STEVIE
KEVIN
MALCOLM
DABNEY
Output
2
Source
COCI 2012/2013 Contest 3
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code