Sausage Slinger


Submit solution

Points: 1
Time limit: 1.5s
Memory limit: 256M

Author:
Problem type
Allowed languages
C, C++, Java, Python

Rory is an innovator... a prodigy... a trend-setter...

He is looking for the next big opportunity or gap in the market to make insane profits before he can sell all of his equity to run a goose farm in Mildura.

Rory has decided to try out sausage slinging (selling hotdogs) at orientation week this year.

Unfortunately for Rory, he doesn't have anyone to serve in his hotdog stand while he chefs up a storm. To compensate, Rory will hurl the sausages from his trailer window into the queue of first-year students keen for a feed!

Rory wants to know which student received each sausage. If he can throw them well enough he won't need any helpers to serve his hotdogs, allowing him to skyrocket his profits.

Input

The first line consists of an integer n (1 \leq n \leq 10^5), the number of career expo-goers currently in the sausage queue.

The second line consists of n space-separated integers, p_i\ (0 \leq p_i \leq 10^7), where each p_i represents the positions of each career expo-goer in the queue. The student positions are unique and sorted in ascending order.

p_i = 0 represents the front most position in the line, infront of the hotdog stall.

The third line consists of an integer m (1 \leq m \leq 10^5), denoting the number of hotdogs to be served.

The fourth line consists of m space-separated integers, q_j\ (0 \leq q_j \leq 10^7), where each q_j is the random service position for hotdog j.

Output

For each hotdog to be served, return the position of the customer who will receive the randomly allocated hotdog.

If the service position is larger than a customers position, the hotdog will go to the next person in the line. Formally, if q_j > p_i, then p_i cannot receive the hotdog; p_i will receive hotdog j when q_j > p_{i-1} and q_j \le p_{i}.

If the hotdog positon q_j has no customer to receive it, output -1.

Output each new receival position on a new line.

Example

Input 1
3
0 3 6
3
1 3 5
Output 1
3 
3 
6

Example 1

  • The first hotdog flew over the student at position 0 and was collected by the student at position 3, because there was no prior student with a position 3 \le p_i < 6
  • The second hotdog landed on the student at position 3.
  • The final hotdog flew over the student at position 3 but was collected by the student at position 6.
Input 2
1
1
2
1 3
Output 2
1 
-1

The first hotdog was received by the student at position 1, however, the second hotdog was thrown to a position with no student to collect it.


Comments

There are no comments at the moment.