Kaity is collecting statistics for the latest iteration of the Berkeley Math Tournament. In the last tournament, she had students numbered from to participating. Each student received a score that was a positive integer number of points.
One day, Sylvia, her archnemesis, wanted to collect statistics about how well students did in the tournament. Sylvia has questions. Each question takes the form: Among all students from to , what was the most frequent score among the given students?
Kaity is a nice person and wants the students to look as good as possible, so if multiple scores are tied for most frequent, she will tell Sylvia the largest mode.
Sylvia is impatient, so please answer her questions as quickly as possible!
Constraints
In tests worth 1 mark, .
In tests worth an additional 2 marks, .
In tests worth an additional 3 marks, .
In tests worth an additional 4 marks, .
Input Specification
The first line contains two integers, and .
The next line contains integers, the scores of the students from to in order.
The next lines contain two integers each, and , indicating the set of students Sylvia is asking about.
Output Specification
Output lines. On line , output the answer to Sylvia's th question.
Sample Input
5 3
2 1 2 1 1
1 2
1 4
1 5
Sample Output
2
2
1
Comments
Is it even possible to solve this problem in Python 3 or Pypy3? (not asking for the solution, but all the correct answers have been in C++)
The only languages where this problem is expected to be solvable are C and C++.