Predictor Machine

Time limit: 1.35s Memory limit: 64MB Input: Output:

Seeing how many people wanted to know their future CF rating, Stefan decided to actually use his programming skills to actually find some important points in people’s CF rating graphs. Since he doesn’t have time to add all his charting techniques in the code, he will only deal with points of interest.

Namely, he is given an array of nn integers, indexed from 11, and a continuous function, such that vi=f(i)v_i = f(i), which represents someone’s CodeForces rating graph, described as a function. Since the function is continuous, for each line between two consecutive points, the graph of the function touches all the integer points between the values.

For example, if f(1)=3f(1) = 3 and f(2)=9f(2) = 9, the line will touch the integer points 33, 44, 55, 66, 77, 88 and 99.

We are also given qq queries, where at some query we will change the value of a given position in the array and after each query, we must print the point of interest of this array, which is the point touched the biggest amount of times by the graph of the function; Furthermore, you also have to print how many times it is touched.

If there are multiple such points, we will print the point with the smallest value among them.

It is also guaranteed that the nn values will be distinct both at the beginning and throughout the updates.

Input

On the first line you will get nn, the number of integers from the array (2n1052 \le n \le 10^5).

On the second line you will get nn distinct integers, representing the array vv (1vi21051 \le v_i \le 2 \cdot 10^5).

On the third line you will get qq, the number of queries we have to answer to (1q21051 \le q \le 2 \cdot 10^5).

On the next qq lines you will get two numbers, pospos and valval, representing that vposv_{pos} becomes valval.

For tests worth 3030 points, (1n;q10001 \le n; q \le 1000).

Output

The output will contain qq lines, each line containing the two integers asked by the problem, namely the leftmost point which is touched the most amount of times by the graph of the function and how many times it is touched after the first qq updates have been done.

Example

stdin

5
4 2 6 1 7
5
1 3
4 4
2 1
5 2
3 5

stdout

3 4
5 3
5 3
2 3
2 3

Explanation

After all the updates are done, the array will look like this: 3 1 5 4 2.

The integer 22 is touched 33 times, between positions 11 and 22, between positions 22 and 33 and between positions 44 and 55.

Log in or sign up to be able to send submissions!