Yesterday, Ignat heard about a staircase — an unusual structure in an array. It is constructed in a simple way:
-
The first element of the array always enters the staircase;
-
If there are no strictly greater elements to the right of the last element of the staircase in the original array, then this element is the last element of the staircase;
-
Otherwise, the first element is searched that it is located to the right of the last element of the staircase in the original array and is strictly greater than the last element of the staircase. This element is added to the end of the staircase.
For example, for the array [1, 2, 5, 1, 7], the staircase will be [1, 2, 5, 7].
Ignat learned to quickly find the staircase in the array a, but then Vadim came and decided to add a non-negative value xi to the element at the pi-th position for each of the next Q days. Now Ignat has to recalculate the staircase each time. Help him find the number of elements in the staircase after each change.
Input
The first line contains an integer N — the number of elements in the original array (1 ≤ N ≤ 105).
The second line contains N integers ai — values in the original array (0 ≤ ai ≤ 109).
The third line contains an integer Q — the number of days during which Vadim modifies the elements of the array (1 ≤ Q ≤ 105).
The next Q lines describe the changes with a pair of integers pi and xi — on the i-th day, Vadim increases api by xi (1 ≤ pi ≤ N, 0 ≤ xi ≤ 109).
Output
Output Q integers li — the number of elements in the staircase after the i-th change.
Sample
input | output |
---|
5
1 2 5 1 7
3
1 3
2 3
4 6
| 3
3
3
|
Notes
After the first change, the array will be [4, 2, 5, 1, 7], and its staircase will include the first, third, and fifth elements.
After the second change, the array will be [4, 5, 5, 1, 7], and its staircase will include the first, second, and fifth elements.
After the third change, the array will be [4, 5, 5, 7, 7], and its staircase will include the first, second, and fourth elements.
Problem Author: Ignat Nigmatullin
Problem Source: Ural School Programming Contest 2023