import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); long[] rui = new long[n]; long[] a = new long[n]; for(int i = 0; i < n; i++) { a[i] = sc.nextLong(); if(i == 0) { rui[i] = a[i]; } else { rui[i] = rui[i - 1] + a[i]; } } long[] kukan = new long[n - 23]; for(int i = 0; i < n - 23; i++) { if(i == 0) { kukan[i] = rui[i + 23]; } else { kukan[i] = rui[i + 23] - rui[i - 1]; } } long ans = 0; for(int i = 0; i < n - 23; i++) { ans = Math.max(ans, kukan[i]); } int q = sc.nextInt(); for(int i = 0; i < q; i++) { int t = sc.nextInt() - 1; long v = sc.nextLong(); long sa = v - a[t]; a[t] = v; for(int j = t - 23; j <= t; j++) { if((j >= 0) && (j < n - 23)) { kukan[j] = kukan[j] + sa; ans = Math.max(ans, kukan[j]); } } System.out.println(ans); } } }