import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); String[] sa = br.readLine().split(" "); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = Integer.parseInt(sa[i]); } int q = Integer.parseInt(br.readLine()); int[] t = new int[q]; int[] v = new int[q]; for (int i = 0; i < q; i++) { sa = br.readLine().split(" "); t[i] = Integer.parseInt(sa[0]) - 1; v[i] = Integer.parseInt(sa[1]); } br.close(); int[] b = new int[n]; int sum = 0; for (int i = 0; i < 24; i++) { sum += a[i]; } b[23] = sum; for (int i = 24; i < n; i++) { sum -= a[i - 24]; sum += a[i]; b[i] = sum; } int max = 0; for (int i = 23; i < n; i++) { max = Math.max(max, b[i]); } PrintWriter pw = new PrintWriter(System.out); for (int i = 0; i < q; i++) { int d = v[i] - a[t[i]]; a[t[i]] = v[i]; for (int j = Math.max(t[i] - 23, 0); j < Math.min(t[i] + 24, n); j++) { b[j] += d; max = Math.max(max, b[j]); } pw.println(max); } pw.flush(); } }