import sys input = sys.stdin.readline N = int(input()) lsA = list(map(int,input().split())) Q = int(input()) lsTV = [] for i in range(Q): t,v = map(int,input().split()) lsTV.append((t-1,v)) maxp = 0 for i in range(N-23): maxp = max(maxp,sum(lsA[i:i+24])) for i in range(Q): t,v = lsTV[i] l,r = max(0,t-24),t+24 lsA[t] = v for j in range(l,r): sm = sum(lsA[j:j+24]) if maxp < sm: maxp = sm print(maxp)