| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 12883 | Patrick and Spongebob in SAO |
|
| 12885 | Pekotrick and Spongebob run away |
|
Description
UPD(2020/10/12 14:42): We update the description (new part added are in red word) for more clearly. Sorry for the inconvenience.
Spongebob and Patrick finally find out the guy with the biggest nose. But unluckily the guy is not Squidward (actually he is Barnacle Boy).
Suddenly, they see some octopus flies over.

“Well, we know one thing: it sure isn’t that guy.” said Spongebob.
Anyway Patrick is very hungry so they go to the restaurant, SAO(Seafood Around Octopuses), for their dinner. After arrving SAO, they order one Ragout Rabbit first.

They quickly eat up the Ragout Rabbit. But now they're facing a problem: they don’t know what they should order next. Patrick suggests that they could order the dish which is ordered by other customers mostly. So it’s your turn again!
There are n customers in SAO (of course not include Spongebob, Patrick and you) and they are numbered from 1 to n. Each of them orders exactly one dish. The dish ordered by the i-th customer is represented by an integer ai(the dish's number on the menu). You need to tell Spongebob and Patrick which dish is ordered mostly between the l-th, the (l+1)-th, …, the r-th customers. And if there are not only one kind of dish ordered mostly, you just need to output the dish's number which is the smallest between all the dishes ordered mostly in the range.
You have to help Spongebob and Patrick q times.
Subtask
- for testcase 1~2: ai = 1
- for testcase 3~5: ai = 1 or ai = 2
- for testcase 6~10: no additional restriction
Input
The first line contains one integer n (1 ≤ n ≤ 500) – the number of customers in SAO.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 500) – the number of dish each customer order.
The third line contains one integer q (1 ≤ q ≤ 500) – the times you have to help Spongebob and Patrick.
Then q lines follow. Each line contains two integer l, r (1 ≤ l ≤ r ≤ n) – the range of customers you have to find out the dish ordered mostly.
Output
For each time you help Spogebob and Patrick, output the dish's number which is ordered mostly in the range of customers(if there are not only one kind of dish ordered mostly, you just need to output the dish's number which is the smallest between all the dishes ordered mostly in the range).
Remember to print a newline('\n') at the end of the last line.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
After finishing dinner in SAO, it's time to have the bill. But Spongebob only has bubble-money and Patrick only has rock-money.
Of course they can't pay in neither bubble-money nor in rock-money. So the cashier is so mad that he calls the police to catch them. Spongebob and Patrick feel scared and they run away immediately(please don’t imitate them). To prevent from being caught, Patrick decide to cosplay an usagi.

Assuredly Patrick needs to move like an usagi, too. Formally we call "moving like an usagi" is that the footprint he left will look like a rabbit jump↘jump↗jump↘jump↗. And you have to help Patrick to move like an usagi.
To simplify the problem, we consider Patrick is on a n x m grid where m is an even number. And he is at the upper-left cell (1,1) in the begining. When he starts to move, he will go down continuously until the next cell he will move to is out of bounds. Then he will move to the right cell and go up with the previous pattern(stops when the next cell is out of bounds). While the right cell isn't out of bounds, he will move to the right cell and then keep moving like how he has moved(i.e. keep going down, move to the right cell, keep going up, move the right cell, keep going down......) until he can't move anymore.
What you have to do is to offer a map. And there must be a n x m grid on the map and all the cells in the grid are noted the order Patrick should visit. In this way Patrick can move like an usagi by following your map(don’t worry about Patrick’s counting ability).
The following image shows the example of n = 5, m = 6

Subtask
- for testcase 1~2: n = 1
- for testcase 3~5: n = 2
- for testcase 6~10: no additional restriction
Input
The first line contains two integers n, m (1 ≤ n, m ≤ 500) – the size of the grid which Patrick moves on.
It is guaranteed that m must be an even number.
Output
Output a n x m grid which is the map Patrick will follow.
Please reference the format of sample output and do not output space at the end of any line.
Remember to print a newline('\n') at the end of the last line.