// #include using namespace std; #define ll long long #define pii pair #define fi first #define se second #define rep(i, x, y) for (int i = (x); i <= (y); i ++ ) #define per(i, x, y) for (int i = (x); i >= (y); i -- ) const int N = 5e5 + 5, M = 1e6 + 5; const int inf = 1e9, mod = 998244353; const ll INF = 1e18, RMX = 2324814; mt19937 rd(time(0)); uniform_int_distribution dist(0, RMX); int n, a[N], q; signed main(){ ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> n; rep(i, 1, n) cin >> a[i]; ll mx = 0; rep(i, 24, n){ ll sum = 0; rep(j, i - 23, i) sum += a[j]; mx = max(mx, sum); } cin >> q; while (q -- ){ int pos, x; cin >> pos >> x; a[pos] = x; rep(i, max(pos, 24), min(pos + 23, n)){ ll sum = 0; rep(j, i - 23, i) sum += a[j]; mx = max(mx, sum); } cout << mx << "\n"; } }