oj mrJudge
Toggle navigation
  • Login
    • Forget Password
      Login
User Image

Hello, Stranger

Guest
  • Analysis Mode
  • Problems
    • All Problems
    • Latest Problems
  • Join Us Now
  • Registration
  • Contact Us
  • Infomation
  • About
    • Terms of Use
    • Technical Specifications
    • Credits

wheel Batch , stdin/stdout

Registered Users Only

Please login to utilize this feature.

Do note that this website only supports submissions in C++.

wheel.html

Little Joseph has recently bought a wheel of fortune. He wrote an uppercase letter of English alphabet onto each wedge.

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

Little Joseph rotated the wheel K times, and each time he wrote down by how many wedges the pointer moved changed, and what letter was pointed to at the end of that spin.

Little Hubert found that paper, and would like to now what letters Little Joseph wrote onto the wedges of the wheel.

Help him determine this, if the total number of wedges is known.

Input

The first line of input contains integers N (2 ≤ N ≤ 25), the number of wedges on the wheel, and K (1 ≤ K ≤ 100), the number of spins.

The following K lines contain descriptions Little Joseph wrote down for each spin, in order.

Each line contains an integer S (1 ≤ S ≤ 100), the number of times the pointed letter changed during that spin, and an uppercase letter at which pointer stopped.

Output

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

wheel.jpg

Tags

Ad Hoc

Subtasks and Limits

Subtask Score #TC Time Memory Scoring
110051s32MBAverage
2031s32MBAverage

Judge Compile Command

g++-8 ans.cpp -o wheel -Wall -Wshadow -static -O2 -lm -m64 -s -w -std=gnu++17 -fmax-errors=512

Accepted Submissions

subIDUserTimeMax Time

Past Submissions

subIDUserTimeScore
mrJudge 09.05.20
Copyright © 2020 mrJudge. All rights reserved.