n = int(input()) l = list(map(int, input().split())) q = int(input()) Vmax=0 for i in range(q): t, b =map(int, input().split()) l[t-1]=b for j in range(n-23): V = sum(l[j:j+24]) if V>Vmax: Vmax=V print(Vmax)