You were 9 episodes into Date a Live when you noticed that something was wrong. Who is this Kurumi character and how come she is licking the protagonist's face? That is when you realize you were watching Date a Live 2 the entire time. Now you need to go through the difficult ordeal of marathoning Date a Live through the night! Unfortunately, you cannot live without food through the entire night, and the anime streamer you are using still does not have a pause button. This means out of the total episodes, you need to skip some continuous episodes to go downstairs and eat something. Luckily, you have the overall ratings for the episodes, out of 10! The episode has a user rating of . In order to determine the best time to go make food, you have queries — each query asking the highest episode rating you can watch if you skip episodes to (inclusive) and how many episodes with this rating there are. It is guaranteed for any query, there will be at least one episode that you do not skip.
Line 1: two integers space separated, .
Line 2: spaced integers, holding the rating for each episode, from to .
The next lines will contain integers and .
For each query, output two integers space separated. The first integer should be the highest rated episode that isn't skipped, and the second integer should be the number of episodes with this rating.
30% of cases
100% of cases
7 2 5 4 5 2 3 1 5 2 4 1 6
5 2 5 1
Explanation of Output for Sample Input
For the first query, episodes 2 to 4 will be skipped, leaving you with episode ratings:
5 x x x 3 1 5. The highest rated episode is 5, and both episodes 1 and 7 have this rating.