LoFi Girl II
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 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 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 ,
, and
,
,
, where
represents the number of riffs in the song,
represents the number of notes in each riff, and
represents the threshold for overused riff patterns.
The next lines each contain a single string
of length
, where
represents a riff. It is guaranteed that
consists only of lowercase English letters.
Output
Output a single integer representing the number of distinct riff patterns that appear at least times.
Example
Input 1
3 5 2
abcde
vwxyz
tcyvg
Output 1
1
The three riffs are abcde, vwxyz, and tcyvg:
abcdeandvwxyzare the same pattern, since they differ only by a constant shift of 21 applied to all notes.tcyvgdiffers by irregular shifts and forms its own distinct pattern.
There are 2 distinct patterns in total:
- The pattern
abcde/vwxyzappears 2 times, which meets the threshold of, so it is overused.
- The pattern
tcyvgappears only 1 time, which does not meet the threshold of, 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, andquadhnqare the same pattern, differing only by a constant shift applied to all notes. This pattern appears 4 times, exceeding the threshold of, so it is overused.
ohpesqg,fygvjhx, andatbqecsare the same pattern, differing only by a constant shift applied to all notes. This pattern appears 3 times, meeting the threshold of, so it is overused.
opjwcslforms its own distinct pattern, appearing only 1 time, which does not meet the threshold of, so it is not overused.
Therefore there are 2 overused riff patterns.
Comments