LoFi Girl II


Submit solution

Points: 1
Time limit: 1.0s
Memory limit: 256M

Problem type
Allowed languages
C, C++, Java, Python

Inspired by the massive success of _Lofi Girl_, Giordan sees an exciting business opportunity. Why spend years learning music production when he can simply automate the process? He creates _Lofi Girl II_, an AI-powered music generator designed to mass-produce endless lo-fi tracks, maximise watch time, and farm ad revenue from students procrastinating at 2 AM.

Unfortunately, Giordan's model was trained almost entirely on 10-hour livestream archives and has developed a serious creativity problem. The generated songs keep repeating the same riff patterns over and over again, making the music sound less relaxing and more like soulless AI slop.

A riff is represented by a string of exactly m notes. A riff pattern is defined by the relative sequence of notes, independent of starting pitch. Two riffs are considered the same pattern if they differ only by a constant shift applied to all notes.

To improve the generator, Giordan applies a quality filter before publishing a track. As part of the filtering process, a riff pattern is considered overused if it appears at least k times in the song.

Given the generated list of riffs, determine how many distinct overused riff patterns exist.

Input

The first line consists of three integers n, m, and k (1 \leq n\leq 10^5, 1 \leq m\leq 10, 0 \leq k\leq n), where n represents the number of riffs in the song, m represents the number of notes in each riff, and k represents the threshold for overused riff patterns.

The next n lines each contain a single string s of length m, where s represents a riff. It is guaranteed that s consists only of lowercase English letters.

Output

Output a single integer representing the number of distinct riff patterns that appear at least k times.

Example

Input 1
3 5 2
abcde
vwxyz
tcyvg
Output 1
1

The three riffs are abcde, vwxyz, and tcyvg:

  • abcde and vwxyz are the same pattern, since they differ only by a constant shift of 21 applied to all notes.
  • tcyvg differs by irregular shifts and forms its own distinct pattern.

There are 2 distinct patterns in total:

  • The pattern abcde/vwxyz appears 2 times, which meets the threshold of k = 2, so it is overused.
  • The pattern tcyvg appears only 1 time, which does not meet the threshold of k = 2, so it is not overused.

Therefore there is 1 overused riff pattern.

Input 2
8 7 3
ycilpvy
ohpesqg
opjwcsl
mqwzdjm
fygvjhx
zdjmqwz
atbqecs
quadhnq
Output 2
2

The 8 riffs form 3 distinct patterns:

  • ycilpvy, mqwzdjm, zdjmqwz, and quadhnq are the same pattern, differing only by a constant shift applied to all notes. This pattern appears 4 times, exceeding the threshold of k = 3, so it is overused.
  • ohpesqg, fygvjhx, and atbqecs are the same pattern, differing only by a constant shift applied to all notes. This pattern appears 3 times, meeting the threshold of k = 3, so it is overused.
  • opjwcsl forms its own distinct pattern, appearing only 1 time, which does not meet the threshold of k = 3, so it is not overused.

Therefore there are 2 overused riff patterns.


Comments

There are no comments at the moment.