#pragma GCC optimize("Ofast") #pragma GCC target("avx2") char*mmap(); #define rd(v) int v=0;{int _c;while(_c=*rp++-48,_c>=0)v=v*10+_c;} long wbuf[1<<22]; #define rep(v,e) for(int v=0;v=b?a:b) #define chmin(v,a) (v=v<=a?v:a) #define chmax(v,a) (v=v>=a?v:a) int a[200000]; main(){ char*rp=mmap(0l,1l<<28,1,2,0,0ll); long*wp=wbuf; rd(n); int s=0; rep(i,24){ rd(ai); a[i]=ai; s+=ai; } int b=s; rep3(i,24,n){ rd(ai); a[i]=ai; s+=ai-a[i-24]; chmax(b,s); } rd(q); rep(i,q){ rd(t); rd(v); a[--t]=v; s=0; int x=max(24,t); int y=min(t+24,n); rep3(i,x-24,x){ s+=a[i]; } chmax(b,s); rep3(i,x,y){ s+=a[i]-a[i-24]; chmax(b,s); } { int _z=b; long _d=0x2020202020202020l; while(_d=_d<<8|0x30|_z%10,_z/=10); *wp++=_d^0x2al<<56; } } write(1,wbuf,(wp-wbuf)*sizeof*wbuf); _exit(0); }