ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules

2175. Staircase

Time limit: 2.0 second
Memory limit: 256 MB
Yesterday, Ignat heard about a staircase — an unusual structure in an array. It is constructed in a simple way:
  1. The first element of the array always enters the staircase;
  2. 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;
  3. 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 ≤ piN, 0 ≤ xi ≤ 109).

Output

Output Q integers li — the number of elements in the staircase after the i-th change.

Sample

inputoutput
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