import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] arr = new int[n + 1]; int[] sums = new int[n + 1]; int[] total24 = new int[n + 1 - 23]; for (int i = 1; i <= n; i++) { arr[i] = sc.nextInt(); sums[i] = sums[i - 1] + arr[i]; } int max = 0; for (int i = 24; i <= n; i++) { total24[i - 23] = sums[i] - sums[i - 24]; max = Math.max(total24[i - 23], max); } int q = sc.nextInt(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < q; i++) { int time = sc.nextInt(); int value = sc.nextInt(); int add = value - arr[time]; arr[time] = value; for (int j = Math.max(time - 23, 1); j <= time && j < total24.length; j++) { total24[j] += add; max = Math.max(max, total24[j]); } sb.append(max).append("\n"); } System.out.print(sb); } }