Harmony
InterviewTime limit7sMemory limit1024 MB
Given K voices over N note rows, list every pair of consecutive rows and voice pair that forms a parallel fifth (both voices move and stay 7 semitones apart mod 12).
- Level
Easy3 of 10
- Topics
- Implementation, Brute force, Array, Math
- Solved
- No attempts yet
Problem
According to classical harmony theory, when writing a multi-voice arrangement you should avoid so-called parallel fifths. A parallel fifth is the following situation: the distance in semitones between two voices leaves a remainder of when divided by ; then the pitch changes in both voices, and afterwards the distance in semitones between them again leaves a remainder of when divided by .¹
Parallel fifths occur only when the pitch changes in both voices. That is, if for two consecutive notes the distance between two voices leaves a remainder of when divided by , but the pitch stays the same in one or both voices, then it is not a parallel fifth.
Write a program that detects parallel fifths in a -voice arrangement.
Pitches are given as integers. The value denotes the note C of the first octave; a positive integer denotes a pitch semitones higher, and a negative integer a pitch that many semitones lower. For example, corresponds to the note E of the first octave, and to the note A of the small octave.²
¹ A remark for readers more interested in music theory: sometimes not only two consecutive perfect fifths are counted as parallel fifths, but also, for example, a perfect fifth followed by a diminished fifth (seven and six semitones respectively). In this problem, only two consecutive perfect fifths count as parallel fifths.
² You do not need to understand the note names to solve this problem.
Input
The first line contains two space-separated integers and (, ) — the number of notes in each voice, , and the number of voices, .
Each of the next lines contains space-separated integers , where is the pitch of the -th note in the -th voice (, for ). The notes on one line sound simultaneously, and notes on consecutive lines sound one immediately after another.
Output
If the arrangement contains no parallel fifths, output the single word POLE.
Otherwise, output one line for each parallel fifth. If a parallel fifth occurs between note rows and in voices and (with ), output the three space-separated integers , , and .
List all parallel fifths in increasing order of . If two lines have the same , order them by increasing ; if two lines have the same and , order them by increasing .