#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 A(n + 1); for (int i = 0; i < n; i++) A[i + 1] = A[i] + a[i]; vector b(n - 24 + 1); for (int i = 0; i + 24 <= n; i++) { b[i] = A[i + 24] - A[i]; } int q; cin >> q; while (--q >= 0) { int t, v; cin >> t >> v; t--; int d = v - a[t]; for (int i = max(0, t - 23); i < min(n, (t + 24) / 24); i++) { b[i] += d; } cout << *max_element(b.begin(), b.end()) << endl; } return 0; }