## COCI '10 Contest 7 #2 Kolo

View as PDF

Points: 5 (partial)
Time limit: 1.0s
Memory limit: 32M

Problem type

Mirko has recently bought a wheel of fortune. He wrote an uppercase letter of the English alphabet onto each wedge, like this ( example test case):

No letter appears twice in the wheel, and the wheel spins clockwise. There is a pointer that stays in the same place while the wheel is spinning (it is pointing to H in the picture above). When we spin the wheel, the letter to which the pointer is pointing to changes accordingly.

Mirko spun the wheel times in a row, and each time he wrote down how many times the pointed letter changed, and what letter was pointed to at the end of that spin.

Slavko found that paper, and would like to know what letters Mirko wrote onto the wedges of the wheel. Help him determine this, if the total number of wedges is known.

#### Input Specification

The first line of input contains integers , the number of wedges on the wheel, and , the number of spins.

The following lines contain descriptions Mirko wrote down for each spin, in order. Each line contains an integer , the number of times the pointed letter changed during that spin, and an uppercase letter at which the pointer stopped.

#### Output Specification

If there is no wheel that meets the requirements described, output !.

Otherwise, output sequence of letters written onto the wheel, starting from the pointed letter at the end of the last spin and proceeding clockwise. If some letter can't be determined, output ? instead.

#### Sample Input 1

3 3
1 A
2 B
3 C

#### Sample Output 1

!

#### Sample Input 2

5 6
1 A
2 B
5 B
1 C
2 A
2 B

#### Sample Output 2

B?A?C

#### Sample Input 3

8 8
4 V
3 I
7 T
7 A
6 R
5 N
1 O
9 H

#### Sample Output 3

HONITAVR