N = int(input()) A = list(map(int, input().split())) Q = int(input()) s = [0] * (N+1) for i in range(N): if N >= 24: s[i+1] = s[i] + A[i] - s[i-23] else: s[i+1] = s[i] + A[i] res = max(s) for q in range(Q): T, V = map(int, input().split()) diff = V - A[T-1] A[T-1] = V for i in range(24): if T+i <= N: s[T+i] += diff if res <= s[T+i]: res = s[T+i] print(res)