Guess the modulo
면접 대비시간 제한1초메모리 제한1024 MB
N과 N-1개의 초기 값이 주어질 때, 히든 블랙박스에 질의를 보내 2 이상 10^9 이하인 모듈로 M을 알아내는 문제입니다.
문제
Fimka Sobak, unlike Ellochka the Cannibal, was reputed to be a cultured girl. In addition to her favorite smart buzzword, the -ality, she learned a remarkably entertaining game, "Guess the modulo".
The game is played in the following way. There are two players: the leader and the player. The leader initially thinks of two numbers: --- the number of numbers to be summed and --- the modulo. The leader tells the player the number , and the player must guess the number . Moreover, the leader thinks of an array of numbers and tells it to the player.
During the game the player tells the leader numbers to get more information. Every time the player says a number, the leader:
- appends it to the end of his array,
- calculate --- the sum of the last numbers in the array by the modulo ,
- appends to the end of the array and
- tells to the player.
As soon as the player guesses the value of the modulo , he or she informs the leader.
It is known that the modulo lies within the range between and , inclusively.
입력
The first line of the input stream contains a single integer (). The following line contains space-separated integers ranging from to inclusively.
The following lines of the input stream contain answers to questions. Each answer is the sum of the last elements of its array by modulo .
출력
You should print the queries and the player's answer into the standard output.
Player query format: "? p", p --- the number added by the player to the array. The number must be integer and must lie within the range from to inclusively.
Player answer format: "! M", M --- the modulo in question.
Make sure that each query ends with a line break and that you flush the output stream buffer (the flush command of the language). Otherwise the solution may get the verdict Deadlock.