#!/usr/bin/env python3.8 import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import itertools N = int(readline()) A = list(map(int, readline().split())) Q = int(readline()) m = map(int, read().split()) TV = zip(m, m) Acum = list(itertools.accumulate(A)) A24 = Acum[23:] for i in range(1, len(A24)): A24[i] -= Acum[i - 1] best = max(A24) for t, v in TV: dx = v - A[t - 1] A[t - 1] = v L = max(t - 24, 0) for i in range(L, min(t, len(A24))): A24[i] += dx y = max(A24[L:t]) if best < y: best = y print(best)