Under construction

Still being built. Things may change

Harmony

Interview

Time limit7sMemory limit1024 MB

Summary
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 77 when divided by 1212; then the pitch changes in both voices, and afterwards the distance in semitones between them again leaves a remainder of 77 when divided by 1212.¹

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 77 when divided by 1212, 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 KK-voice arrangement.

Pitches are given as integers. The value 00 denotes the note C of the first octave; a positive integer kk denotes a pitch kk semitones higher, and a negative integer a pitch that many semitones lower. For example, 44 corresponds to the note E of the first octave, and −3-3 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 NN and KK (0≤N≤1000000 \le N \le 100000, 2≤K≤102 \le K \le 10) — the number of notes in each voice, NN, and the number of voices, KK.

Each of the next NN lines contains KK space-separated integers A1,i … AK,iA_{1,i}\ \ldots\ A_{K,i}, where Aj,iA_{j,i} is the pitch of the ii-th note in the jj-th voice (−100≤AK,i≤…≤A1,i≤100-100 \le A_{K,i} \le \ldots \le A_{1,i} \le 100, for i∈1…Ni \in 1 \ldots N). 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 ii and i+1i+1 in voices ss and tt (with s<ts < t), output the three space-separated integers ii, ss, and tt.

List all parallel fifths in increasing order of ii. If two lines have the same ii, order them by increasing ss; if two lines have the same ii and ss, order them by increasing tt.

Examples4

  1. Example 1

    Input
    5 2
    7 0
    10 -2
    14 -5
    12 -7
    7 0
    
    Expected output
    3 1 2
    4 1 2
    
  2. Example 2

    Input
    0 10
    
    Expected output
    POLE
    
  3. Example 3

    Input
    3 3
    13 7 0
    13 6 -1
    10 3 -4
    
    Expected output
    1 2 3
    2 1 2
    2 2 3
    
  4. Example 4

    Input
    2 2
    7 0
    7 0
    
    Expected output
    POLE