import sequtils,strutils,math var N = stdin.readline.parseInt A = stdin.readline.split.map(parseInt) Q = stdin.readline.parseInt t,v : int M : int for i in 0 .. (A.high - 23): M = max(M, sum(A[i .. (i + 23)])) for q in 1..Q: (t, v) = stdin.readline.split.map(parseInt) var m ,c : int A[t - 1] = v var i = max(0, t - 24) var j = i + 23 m = sum(A[i .. j]) c = m while j < min(A.high, t + 23): j += 1 c += A[j] c -= A[i] i += 1 m = max(c, m) M = max(m,M) echo M