def main(): import sys input = sys.stdin.buffer.readline N = int(input()) A = list(map(int, input().split())) B = [0] * (N-24+1) B[0] = sum(A[:24]) for i in range(1, len(B)): B[i] = B[i-1] + A[i+24-1] - A[i-1] M = max(B) for _ in range(int(input())): t, v = map(int, input().split()) t -= 1 d = v - A[t] A[t] = v for i in range(max(0, t - 23), min(N-23, t+1)): B[i] += d M = max(M, B[i]) print(M) if __name__ == '__main__': main()