프로그램 명: coci_malcolm
제한시간: 1 초
[요약]
본인보다 K단계 위, 아래 사이에 있는 사람들과는 친구 관계 친구 관계인 사람들 중 이름의 길이가 같으면 친한 친구 관계입니다.
사람의 이름이 순서대로 주어졌을 때 얼마나 많은 친한 친구 관계가 만들어지는지 출력하세요.
(이름의 길이는 2자 이상 20자 이하입니다)
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.
입력
-
The first line of input contains two positive integers, N (3 ≤ N ≤ 300 000) and K (1 ≤ K ≤ 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.
출력
The first and only line of output must contain the required number of pairs.
입출력 예
input
4 2
IVA
IVO
ANA
TOM
output
5
input
6 3
CYNTHIA
LLOYD
STEVIE
KEVIN
MALCOLM
DABNEY
output
2
출처:coci/2012-2013/contest3/3 번
요약:ladow21
[질/답]
[제출 현황]
[푼 후(1)]