405098: GYM101790 H Time difference

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

H. Time differencetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

There are N questions in the intellectual game. The correct answer for the i-th question is i. For each question, the deadline of answers reception Ti is known.

The player on the smartphone's screen in the game entered into the text field M numbers Bi. For each of them the time on the smartphone Si is known. Initially, the field is empty. Input new value doesn't not take time, replaces the previous value, and the field is never cleared anymore.

The system considers the player's answer to the i-th question only the number that was entered last by the time Ti, inclusive.

You are given Q queries consisting of one number Di, denoting the difference to add to the time of all the replies from the player when calculating its result.

For each query, determine how many correct answers the player gave.

Input

The first line contains one integer, denoting the number of questions N (1 ≤ N ≤ 105).

The second line contains N numbers Ti (1 ≤ Ti ≤ 109), denoting the deadline for receiving responses to questions, arranged in ascending order.

The third line contains one integer M (1 ≤ M ≤ 105), denoting the number of entered numbers.

The next M lines containing two integers Si (1 ≤ Si ≤ 109) and Bi (1 ≤ Bi ≤ 105), denoting the time on the smartphone at the moment of input and the entered number correspondingly. Si > Si - 1 for all i > 1.

The next line contains one integer, dinoting the number of queries Q (1 ≤ Q ≤ 105).

The last line contains Q integers, denoting the query with parameter Di ( - 109 ≤ Di ≤ 109).

Output

Display Q integers: answers to queries in the order of the queries in the input.

ExampleInput
3
10 13 20
6
7 5
8 1
11 2
12 3
13 2
15 3
5
0 -20 1 10 -1
Output
3 1 2 0 2 
Note

In the first query, time does not shift, and the correct answers are counted on all questions. In the second query, the player is only given the answer to the third question. In the third query, the player's answers to the 1st and 3rd questions are counted. In the fourth query, the player does not count any of the answers. In the fifth query the player counts the answers to the 2nd and 3rd questions.

加入题单

上一题 下一题 算法标签: