using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray(); static int[] NMi => ReadLine().Split().Select(c => int.Parse(c) - 1).ToArray(); static int[][] NMap(int n) => Enumerable.Repeat(0, n).Select(_ => NMi).ToArray(); public static void Main() { Solve(); } static void Solve() { var n = NN; var a = NList; var q = NN; var map = NArr(q); var sum = new long[n]; for (var i = 0; i < n; ++i) sum[i] = a[i]; var uf = new UnionFindTree(n); for (var i = 0; i + 1 < n; ++i) { if (a[i] > 0 && a[i + 1] > 0) { var ar = uf.GetRoot(i); var br = uf.GetRoot(i + 1); uf.Unite(i, i + 1); var nr = uf.GetRoot(i); sum[nr] = sum[ar] + sum[br]; } } var ans = new long[q]; for (var i = 0; i < q; ++i) { var x = map[i][0] - 1; var b = map[i][1]; if (a[x] == 0) { ans[i] = b; if (x > 0) ans[i] += sum[uf.GetRoot(x - 1)]; if (x + 1 < n) ans[i] += sum[uf.GetRoot(x + 1)]; } else { ans[i] = sum[uf.GetRoot(x)] + b - a[x]; } } WriteLine(string.Join("\n", ans)); } class UnionFindTree { int[] roots; public UnionFindTree(int size) { roots = new int[size]; for (var i = 0; i < size; ++i) roots[i] = -1; } public int GetRoot(int a) { if (roots[a] < 0) return a; return roots[a] = GetRoot(roots[a]); } public bool IsSameTree(int a, int b) { return GetRoot(a) == GetRoot(b); } public bool Unite(int a, int b) { var x = GetRoot(a); var y = GetRoot(b); if (x == y) return false; if (-roots[x] < -roots[y]) { var tmp = x; x = y; y = tmp; } roots[x] += roots[y]; roots[y] = x; return true; } public int GetSize(int a) { return -roots[GetRoot(a)]; } } }