N = gets.to_i A = gets.split.map(&:to_i) Q = gets.to_i sum = A.sum def f(idx) res = 0 -23.upto(0) do |d| from = idx + d to = from + 23 next if from < 0 next if to >= N sum = 0 from.upto(to) do |idx| sum += A[idx] end res = sum if res < sum end res end Q.times do t, v = gets.split.map(&:to_i) A[t - 1] = v puts f(t - 1) end