In Croatian class, Jakov reads a poem consisting of $n$ lines and $n/4$ stanzas. Lines 1, 2, 3, and 4 make up the first stanza, lines 5, 6, 7, and 8 the second stanza, and so on. Each line in each stanza consists of exactly $m$ words. We say that two lines rhyme if the last $k$ letters of their last words match. If the last word in one of the lines consists of fewer than $k$ letters, then the lines do not rhyme. At the stanza level, we distinguish three types of rhyme schemes:
- AABB – lines 1 and 2 rhyme, and lines 3 and 4 rhyme
- ABAB – lines 1 and 3 rhyme, and lines 2 and 4 rhyme
- ABBA – lines 1 and 4 rhyme, and lines 2 and 3 rhyme The teacher asked Jakov to determine in how many stanzas of the poem each of these three types of rhyme schemes appears. Help Jakov answer the teacher correctly and get an A in Croatian class!
Input
The first line contains the natural numbers $n$, $m$ and $k$ ($1 \le n \le 500$ and $n$ is divisible by 4, $1 \le m$, $k \le 20$) from the text of the task. The next $n$ lines contain $m$ words each, with each word being made up of at most 20 lowercase letters of the English alphabet.
Output
In the first and only line, write three numbers: the number of stanzas in which AABB rhyme appears, the number of stanzas in which ABAB rhyme appears, and the number of stanzas in which ABBA rhyme appears.
Example 1
8 2 3 aa bb cc bb dd ee ff ee auu aaaaaahh auu wer asdf power lol kldahh
0 0 1
Example 2
8 2 2 ja programiram mjesec listopad ponekad chillam voda vodopad banana jabuka fiziku znam teska odluka njam njam
0 2 0
Example 3
4 4 2 pas konj zec macka trokut teziste poluravnina tocka nogomet tenis ragbi odbojka sir mlijeko kulen sunka
1 1 1
Clarification of the first example: In the first stanza, not a single pair of lines can rhyme, because each last word has only 2 letters, and k = 3. The second stanza follows an ABBA rhyme scheme because the 1st and 4th lines rhyme (aaaaaahh and kldahh), and the 2nd and 3rd lines also rhyme (wer and power). Thus, AABB and ABAB rhymes occur 0 times, while ABBA rhyme occurs once. Clarification of the third example: In the only stanza of this poem, the last two letters of the last word in each line are ka, so all lines rhyme with each other. It follows that all three types of rhyme schemes appear in this stanza: AABB, ABAB and ABBA.
Discussion
Threads about this problem. Spoilers are collapsed; wrap hints in
||double bars||.No discussion yet. Start a thread if something here needs explaining.