#include "bits/stdc++.h" // Begin Header {{{ #define all(x) x.begin(), x.end() #define SIZE(x) static_cast(x.size()) #define rep(i, n) for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i) #define reps(i, s, t) for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i) #define repr(i, s, t) for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i) #define VAR(Type, ...) Type __VA_ARGS__; input(__VA_ARGS__) #define let const auto #ifdef DBG #define trace(...) _internal::_trace(#__VA_ARGS__, __VA_ARGS__); #else #define trace(...) #endif using namespace std; using i64 = int_fast64_t; using pii = pair; template using MaxHeap = priority_queue; template using MinHeap = priority_queue, greater>; templateinline bool chmax(T &a, const U &b){return b>a && (a=b, true);} templateinline bool chmin(T &a, const U &b){return b> 1; } inline i64 divup(i64 a, i64 b) { return (a + b - 1) / b; } inline bool inner(i64 a, i64 low, i64 high) { return (low <= a && a < high); } constexpr int INF = 0x3f3f3f3f; constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL; namespace _internal { // {{{ template struct _Uint{}; template ostream& _print_tuple(ostream &out, const Tuple &t, _Uint<1>) { return out << std::get< std::tuple_size::value - 1 >(t); } template ostream& _print_tuple(ostream &out, const Tuple &t, _Uint) { out << std::get< std::tuple_size::value - Index >(t) << ' '; return _print_tuple(out, t, _Uint()); } template void _trace(const char *s, T&& x) { clog << '{'; while(*s != '\0') clog << *(s++); clog << ":" << setw(3) << x << '}' << endl; } template void _trace(const char *s, Head&& head, Tail&&... tail) { clog << '{'; while(*s != ',') clog << *(s++); clog << ":" << setw(3) << head << "}, "; for (++s; !isgraph(*s); ++s); _trace(s, std::forward(tail)...); } } // }}} template inline void input(T &x) { cin >> x; } template inline void input(Head &head, Tail&... tail) { cin >> head; input(tail...); } template inline void outl(Args&&... args) { cout << make_tuple(std::forward(args)...) << "\n"; } ostream& operator<< (ostream &out, ostream&) { return out; } template ostream& operator<< (ostream &out, const vector &vec) { rep(i, vec.size()) out << vec[i] << " \n"[i+1 == vec.size()]; return out; } template ostream& operator<< (ostream &out, const pair &p) { return out << p.first << ' ' << p.second; } template ostream& operator<< (ostream &out, const tuple &t) { return out << _internal::_print_tuple(out, t, _internal::_Uint()); } template ostream& print(Itr begin, Itr end, const string &separator = " ", ostream &out = cout) { const auto rbegin = std::prev(end); for (; begin != rbegin; ++begin) out << *begin << separator; out << *rbegin; return out; } // }}} End Header signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N; i64 a[200100] {}; i64 sum[200100] {}; cin >> N; reps(i, 1, N) { cin >> a[i]; } { i64 s = 0; reps(i, 1, 23) s += a[i]; reps(i, 24, N) { s += a[i]; sum[i - 23] = s; s -= a[i - 23]; } } let K = N - 23; i64 maxv = 0; reps(i, 1, K) { chmax(maxv, sum[i]); } trace(K, maxv); int Q; cin >> Q; while(Q--) { VAR(i64, T, V); let add = V - a[T]; a[T] = V; reps(i, max(1, T - 23), T) { sum[i] += add; chmax(maxv, sum[i]); } // print(sum, sum + K+1) << endl; outl(maxv); } return 0; }