The Peterson Problem -------------------- Oscar Peterson, one of the greatest jazz musicians of all time, recently passed away. He was an adjunct professor in York University's department of music and he was York's Chancellor from 1991 to 1994. He was known for dazzling fingerwork on the piano. In fact, Louis Armstrong called him "the man with four hands". In this problem, we will compute how much his fingers moved when playing songs. A standard piano keyboard has a linear arrangement of 88 keys. Musicians, being less logical than computer scientists, did not name the keys 1,2,3,...,88. Instead, the keys are grouped into octaves. Each octave has 12 keys in the following order (from left to right): C C# D D# E F F# G G# A A# B. To the right of the B key is the C key of the next octave. The keys are coloured black and white. The black keys have #'s in their names and the white keys do not. The octaves are numbered: at the left end of the piano is a partial octave of 3 keys labelled A0, A#0, B0. The next octave to the right is octave 1 (with keys labelled C1, C#1, D1, ..., B1). The next octave to the right is octave 2, and so on. The rightmost complete octave is octave 7. Then there is one key (C8) of the next octave. To add to the confusion, there are alternate names for each of the black keys: in any name, the following replacements are possible C# = Db, D# = Eb, F# = Gb, G# = Ab and A# = Bb. Suppose Mr Peterson's fingers are numbered 1 to 10 (1 = left pinky, 2 = left ring finger, ..., 5 = left thumb, 6 = right thumb, ..., 10 = right pinky). Then each keypress can be specified by a list as follows. First we specify a duration (in milliseconds). Then we specify how many keys are to be pressed simultaneously. This is followed by a list of pairs, where the first number in each pair gives the finger number and the second number gives the key name. For example, 100 3 6 C5 7 E5 9 G5 represents playing a C-major chord of duration 100 milliseconds with the right hand. (Three keys are pressed simultaneously for this). Similarly 200 3 2 D2 4 F#2 5 A2 represents playing a D-major chord of duration 200 milliseconds with the left hand. You may assume that, within each line, the fingers are listed in increasing order and the keys are also listed from left to right. (The latter condition means Mr Peterson will not cross his fingers or hands while playing.) A complete song can be expressed by a sequence of lines, where each line describes a keypress. The duration on each line indicates how long to wait after hitting the keys described by that line until hitting the keys described on the next line. Note: there may be some lines that contain only a duration followed by a 0. This means the list of keys to press is empty, indicating a "rest" during which no notes are sounded. Assume that any finger hitting a key does so in the exact centre of the key. Adjacent white keys have centres 1 inch apart. The centre of a white key is half an inch away from the centre of an adjacent black key. To complete a description of where all the fingers are, we have to know where the fingers that do not participate in a keypress go. If there are two fingers f1 and f2 on a hand that participate in the keypress, then the fingers between f1 and f2 move to locations that are equally spaced between the locations of f1 and f2. Fingers to the right of the rightmost finger that participates in a keypress move to locations that are spaced at half-inch intervals beyond the rightmost finger. Similarly for the fingers to the left of the leftmost finger. For example, if we have the following description of a keypress: 100 4 1 C2 2 E2 7 C5 10 G5 then - finger 3 will be half an inch to the right of finger 2 - finger 4 will be half an inch to the right of finger 3 - finger 5 will be half an inch to the right of finger 4 - finger 6 will be half an inch to the left of finger 7 - fingers 8 and 9 will be 1/3 and 2/3 of the way between fingers 7 and 10 (i.e. finger 8 will be 4/3 inches to the right of finger 7 and finger 9 will be 4/3 inches to the right of finger 8). Given a description of a song, you have to compute the total distance travelled by each finger. You may assume Mr Peterson's fingers start at the first position they will play so there is not travelling required to reach the first keypress. If one hand is not used during a keypress, then it just stays where it was. The input will consist of several instances (songs). The end of a song is indicated by a line that contains only 0. The end of the input is indicated by a line containing only -1. See the sample output for the format you should use. Distances should be accurate to the closest 1000th of an inch. Sample Input ------------ 100 1 1 C4 100 0 200 2 1 D4 4 F#4 0 100 2 2 C3 5 E3 150 1 3 C4 50 1 8 Eb7 120 2 4 D1 7 F7 100 2 6 C5 10 D#7 200 10 1 C1 2 F#1 3 G1 4 A#1 5 D#2 6 D5 7 F5 8 F#5 9 Bb5 10 C6 0 -1 Sample Output ------------- During song number 1: finger 1 travelled 1 inch. finger 2 travelled 1.333 inches. finger 3 travelled 1.667 inches. finger 4 travelled 2 inches. finger 5 travelled 2 inches. finger 6 travelled 0 inches. finger 7 travelled 0 inches. finger 8 travelled 0 inches. finger 9 travelled 0 inches. finger 10 travelled 0 inches. During song number 2: finger 1 travelled 27.5 inches. finger 2 travelled 30.5 inches. finger 3 travelled 30.333 inches. finger 4 travelled 31.167 inches. finger 5 travelled 33.5 inches. finger 6 travelled 19.5 inches. finger 7 travelled 16 inches. finger 8 travelled 16 inches. finger 9 travelled 14.5 inches. finger 10 travelled 13.5 inches.