Time limit
2s
Memory limit
128 MB
Assume the basic Western scale consists of the seven white-key notes C, D, E, F, G, A, and B. They correspond to do, re, mi, fa, sol, la, and si in that order. Only these seven named notes are valid in this problem.
On a piano, some adjacent white keys have a black key between them and some do not. A black key is one semitone away from each neighboring white key. The black key between C and D is one semitone from both C and D. By contrast, there is no black key between B and C or between E and F, so those adjacent white keys are one semitone apart.
We can use semitone distances to move from one note to another. Moving -1 semitone from F reaches E, and moving 4 semitones from F reaches A. Because only the seven white-key notes are valid, moving 1 semitone from F does not reach a valid note.
A score is a sequence of semitone moves. The score 2 2 1 2 2 2 1, if started at C, visits C, D, E, F, G, A, B, C, so both its first and last notes are C. It cannot start at D because some move would land on a black key. Given a score, find every possible pair of first and last notes. Assume the piano extends infinitely in both directions.
The first line contains an integer n (1 <= n <= 10,000), the number of moves in the score. Each of the next n lines contains one integer distance. The absolute value of each distance is at most 20.
Print one possible first-note and last-note pair per line. If multiple pairs are possible, print them in increasing alphabetical order of the first note. If no pair is possible, print nothing.