#include using namespace std; using ll = long long int; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n; cin >> n; vector a(n); for (auto &x : a) cin >> x; vector b(n); int ans = 0; int sum = 0; for (int i = 0; i < 24; i++) { sum += a[i]; } for (int i = 0; i < n; i++) { if (i >= 24) sum += a[i] - a[i - 24]; b[i] = sum; ans = max(ans, b[i]); } int q; cin >> q; while (--q >= 0) { int t, v; cin >> t >> v; t--; int d = v - a[t]; a[t] = v; for (int i = max(0, t - 23); i < min(n, t + 24); i++) { b[i] += d; ans = max(ans, b[i]); } cout << ans << endl; } return 0; }