Dima's got a staircase that consists of n stairs. The first stair is at height a_1, the second one is at a_2, the last one is at a_{n} (1 ≤ a_1 ≤ a_2 ≤ ... ≤ a_{n}). 

Dima decided to play with the staircase, so he is throwing rectangular boxes at the staircase from above. The i-th box has width w_{i} and height h_{i}. Dima throws each box vertically down on the first w_{i} stairs of the staircase, that is, the box covers stairs with numbers 1, 2, ..., w_{i}. Each thrown box flies vertically down until at least one of the two following events happen:  the bottom of the box touches the top of a stair;  the bottom of the box touches the top of a box, thrown earlier. 

We only consider touching of the horizontal sides of stairs and boxes, at that touching with the corners isn't taken into consideration. Specifically, that implies that a box with width w_{i} cannot touch the stair number w_{i} + 1.

You are given the description of the staircase and the sequence in which Dima threw the boxes at it. For each box, determine how high the bottom of the box after landing will be. Consider a box to fall after the previous one lands.


-----Input-----

The first line contains integer n (1 ≤ n ≤ 10^5) — the number of stairs in the staircase. The second line contains a non-decreasing sequence, consisting of n integers, a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9; a_{i} ≤ a_{i} + 1).

The next line contains integer m (1 ≤ m ≤ 10^5) — the number of boxes. Each of the following m lines contains a pair of integers w_{i}, h_{i} (1 ≤ w_{i} ≤ n; 1 ≤ h_{i} ≤ 10^9) — the size of the i-th thrown box.

The numbers in the lines are separated by spaces.


-----Output-----

Print m integers — for each box the height, where the bottom of the box will be after landing. Print the answers for the boxes in the order, in which the boxes are given in the input.

Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.


-----Examples-----
Input
5
1 2 3 6 6
4
1 1
3 1
1 1
4 3

Output
1
3
4
6

Input
3
1 2 3
2
1 1
3 1

Output
1
3

Input
1
1
5
1 2
1 10
1 10
1 10
1 10

Output
1
3
13
23
33



-----Note-----

The first sample are shown on the picture. [Image]

Difficulty: interview

Starter code:

Solutions:
__author__ = "runekri3"

stairs_amount = int(input())
stair_heights = list(map(int, input().split()))
boxes_amount = int(input())
boxes = []
for _ in range(boxes_amount):
    boxes.append(list(map(int, input().split())))

for width, height in boxes:
    box_bottom = max(stair_heights[0], stair_heights[width - 1])
    print(box_bottom)
    stair_heights[0] = box_bottom + height


def main():
    n, res = int(input()), []
    l = list(map(int, input().split()))
    for _ in range(int(input())):
        w, h = list(map(int, input().split()))
        m = max(l[0], l[w - 1])
        res.append(m)
        l[0] = m + h
    print('\n'.join(map(str, res)))


def __starting_point():
    main()

__starting_point()

import sys

def main():
    n = int(sys.stdin.readline())
    a = list(map(int, sys.stdin.readline().split(' ')))
    m = int(sys.stdin.readline())
    (w1, h1) = (0, 0)
    H = 0
    for i in range(m):
        (w2, h2) = list(map(int, sys.stdin.readline().split(' ')))
        H = max(H + h1, a[w2 - 1])
        sys.stdout.write('{}\n'.format(str(H)))
        (w1, h1) = (w2, h2)

main()


n=int(input())
l=list(map(int,input().split()))
g=l[0]
m=int(input())
S=''
for i in range(m) :
    a,b=list(map(int,input().split()))
    t=max(l[0],l[a-1])
    S+=str(t)+'\n'
    l[0]=t+b
    l[a-1]=t+b
print(S)
    


n = int(input())
import sys
l = [0]+list(map(int,sys.stdin.readline().strip().split()))
x = 0
b = 0
m = int(input())
for _ in range(m):
    w,h = map(int,sys.stdin.readline().strip().split())
    x = max(x+b,l[w])
    b = h
    print(x)

n=int(input())
l=list(map(int,input().split()))
m=int(input())
s=[]
for i in range(m):
	s+=[list(map(int,input().split()))]
h=[]
a=0
for i in range(m):
	b=l[s[i][0]-1]
	t=max(b,a+1)
	h+=[t]
	a=t+s[i][1]-1

for i in h:
	print(i)

import sys
n=int(sys.stdin.readline())
l=list(map(int,sys.stdin.readline().split()))
m=int(sys.stdin.readline())
x=0
for i in range(m):
    w,h=map(int,sys.stdin.readline().split())
    x=max(x,l[w-1])
    sys.stdout.write(str(x)+'\n')
    x+=h

_ = input()
a = list(map(int, input().split(' ')))
m = input()

res = list()


for _ in range(int(m)):
    w, h = map(int, input().split(' '))
    #print(w, h)
    cmax = max(a[0], a[w-1])
    res.append(cmax)
    # for x in range(w):
    #     a[x] = cmax + h
    a[0] = cmax + h
    a[w-1] = cmax + h

    #print(a)

print('\n'.join(map(str, res)))

_ = input()
a = list(map(int, input().split(' ')))
m = input()

res = list()


for _ in range(int(m)):
    w, h = map(int, input().split(' '))
    #print(w, h)
    cmax = max(a[0], a[w-1])
    res.append(cmax)
    # for x in range(w):
    #     a[x] = cmax + h
    a[0] = cmax + h
    #a[w-1] = cmax + h

    #print(a)

print('\n'.join(map(str, res)))

n=int(input())
a=list(map(int, input().split()))
m=int(input())
b=[]
for _ in range(m):
	b.append(list(map(int, input().split())))

for x,y in b:
	m=max(a[0], a[x - 1])
	print(m)
	a[0]=m+y

n = int(input())

a = list(map(int, input().split()))

m = int(input())

b = {}

t = []
for i in range(m):
    w, h = list(map(int, input().split()))
    x = max(a[0],a[w-1])
    t.append(x)
    a[0] = x+h
    a[w-1] = x+h

for i in range(m):
    print(t[i])

n = int(input())
a = list(map(int,input().split()))
m = int(input())
l = [list(map(int,input().split())) for _ in range(m)]
ans = [a[l[0][0]-1]]
lasth = l[0][1]
for _,[w,h] in enumerate(l[1:]):
	ans.append(max(ans[-1] + lasth,a[w-1]))
	lasth = h
print(*ans,sep='\n')
	




def main():
    n = int(input())
    hts = list(map(int,input().split()))
    ans = []
    max_ht = 0
    m = int(input())
    for i in range(m):
        w,h = list(map(int,input().split()))
        curr_ht = hts[w-1]
        if max_ht == 0:
            ans.append(curr_ht)
            max_ht = curr_ht+h
        else:
            if curr_ht >= max_ht:
                max_ht = curr_ht+h
                ans.append(curr_ht)
            else:
                ans.append(max_ht)
                max_ht += h

    for i in range(m):
        print(ans[i])


main()


n  = int(input())
arr = list(map(int, input().split()))
idx, res = 0, []
m = int(input())
for _ in range(m):
    w, h = map(int, input().split())
    r = max(arr[w-1], idx)
    res.append(r)
    arr[w-1] = r + h
    idx = max(idx, arr[w-1])
print('\n'.join(map(str, res)))

from sys import stdin

input = stdin.readline

n = int(input())
s = [0] + [int(item) for item in input().split(' ')]
pre = s[0]

q = int(input())
x = {}
lowest = s[1]
while q:
    [w, h] = [int(item) for item in input().split(' ')]
    height = max(lowest, s[w])
    lowest = height + h
    print(height)
    q -= 1


__autor__ = 'Esfandiar'
import sys
input=sys.stdin.readline
n = int(input())
a = list(map(int,input().split()))
m = int(input())
M = -float('inf')
for i in range(m):
    w,h = list(map(int,input().split()))
    if a[w-1]<M:
        print(M)
        M+=h
    else:
        print(a[w-1])
        a[w-1]+=h
        M = max(M,a[w-1])

   
    





__autor__ = 'Esfandiar'
import sys
input=sys.stdin.readline
n = int(input())
a = list(map(int,input().split()))
m = int(input())
M = -float('inf')
for i in range(m):
    w,h = list(map(int,input().split()))
    if a[w-1]<M:
        print(M)
        M+=h
    else:
        print(a[w-1])
        a[w-1]+=h
        M = a[w-1]