# k番目の要素の値をxに変更 def update(k, x): k += N0-1 data[k] = x while k >= 0: k = (k - 1) // 2 data[k] = max(data[2*k+1], data[2*k+2]) # 区間[l, r)の最小値を求める def query(l, r): L = l + N0; R = r + N0 s = -INF # 区間を列挙しながら最小値を求める while L < R: if R & 1: R -= 1 s = max(s, data[R-1]) if L & 1: s = max(s, data[L-1]) L += 1 L >>= 1; R >>= 1 return s N = int(input()) A = list(map(int, input().split())) B = [sum(A[0:24])] for i in range(1, N-23): B.append(B[-1] + A[i+23] - A[i-1]) M = len(B) # Range Minimum Query N0 = 2**(M-1).bit_length() INF = 2**31-1 # 0-indexedで管理 data = [-INF]*(2*N0) for i in range(M): update(i, B[i]) Q = int(input()) for _ in range(Q): Ti, Vi = map(int, input().split()) Ti -= 1 for i in range(max(Ti-23, 0), min(Ti+1, M)): update(i, B[i]-A[Ti]+Vi) B[i] = B[i] - A[Ti] + Vi A[Ti] = Vi print(query(0, M))