import sys rr = sys.stdin N = int(rr.readline()) A = list(map(int,rr.readline().split())) Q = int(rr.readline()) def calc(i): ans = 0 for j in range(max(0,i - 24 + 1),i + 1): if j + 23 >= N: break tmp = 0 for k in range(24): tmp += A[j + k] if tmp > ans: ans = tmp return ans ans = 0 for i in range(N): tmp = calc(i) if tmp > ans: ans = tmp for _ in range(Q): t,v = map(int,rr.readline().split()) A[t - 1] = v tmp = calc(t - 1) if tmp > ans: ans = tmp print(ans)