# -*- coding: utf-8 -*- from math import sqrt def inpl(): return list(map(int, input().split())) class SegmentTree: def __init__(self, N, init_node=None): self.size = 2**int.bit_length(N) self.node = [0]*(2*self.size-1) if not init_node is None: for i in range(N): self.node[i+self.size-1] = init_node[i] for i in range(self.size-2, -1, -1): self.node[i] = max(self.node[2*i+1], self.node[2*i+2]) def add(self, x, val): x += self.size - 1 self.node[x] += val while x: x = (x-1)//2 self.node[x] = max(self.node[2*x+1], self.node[2*x+2]) N = int(input()) A = [0] * 23 + inpl() + [0]*23 s = sum(A[:24]) X = [0]*(N + 46) for i in range(24): X[i] = A[23]*1 s = A[23]*1 for i in range(24, N+46): s += A[i] - A[i-24] X[i] = s seg = SegmentTree(len(X), X) for _ in range(int(input())): t, v = inpl() t += 22 d = v - A[t] A[t] = v for i in range(t-23, t+24): seg.add(i, d) print(seg.node[0])