In Reme, a consular election is being held. This election has N electors, each of which can vote with one of the different candidates. A candidate is considered a winner if she wins strictly more than one third of the vote (this happens because Reme elects two consuls each year). Now, you are an aspiring vote-rigger. In order to more effectively rig the vote, you need to know at least one prospective winner. Unfortunately, although each elector has cast their vote, it is not public — at least not without a price. Moreover, the old consuls, who have already counted votes, can tell you the number of votes a particular candidate won — again, at a price.
More formally, you are asked to consider a hidden sequence of integers , with values at least and less than . You can perform two types of queries on this sequence:
- you can find out the value of a particular element in the sequence
- you can see how many times a particular value appears in the sequence.
You are asked to find a value that appears strictly more than times in the sequence, while making the number of queries you perform small enough.
Task
Given , find out any winner of the election, using the given queries, or announce that no winner exists.
Interaction
This is an interactive task. Thus the contestant will interact with the following functions, after including the file grader.h
. The contestant must implement a function void solve(int N)
, where the parameter represents the from the problem statement, which must solve an instance of the task (note that in one run of the source code, this function may be called multiple times). In order to solve the task, the contestant may use the following functions:
int kth(int i)
— which will return the value ofint cnt(int x)
— which will return the frequency of in the arrayvoid say_answer(int a)
— which, if is at least and less than , signals that is winner of the election; and if is , that no winner exists. If there exists a winner, and is not equal to a winner of the election, or if there is no winner, but is not , or is neither a valid candidate nor , then the contestant’s solution will get verdict “Wrong Answer!”.
Restrictions
Subtask | Score | Restrictions |
---|---|---|
1 | 15 points | |
2 | another 20 points | |
3 | another 65 points |
Scoring
Let be the maximum number of queries made in any test case in a file (not including the call of say_answer).
Subtask 1:
- If , then you will receive of the points on the test case.
- If , then you will receive of the points on the test case.
Subtask 2:
- If , then you will receive of the points on the test case.
- If , then you will receive of the points on the test case.
- If , then you will receive of the points on the test case.
Subtask 3:
- If , then you will receive of the points on the test case.
- If then you will receive of the points on the test case.
NOTE: the number of test cases is at most