n = int(input()) rain_list = [0] * 23 + list(map(int, input().split())) + [0] * 23 k = int(input()) correc_list = [] for i in range(k): x, y = map(int, input().split()) correc_list.append((x + 23 - 1, y)) rain_len = len(rain_list) rain_vol = sum(rain_list[:24]) ret = rain_vol for i in range(rain_len - 24): rain_vol = rain_vol - rain_list[i] + rain_list[i + 24] ret = max(ret, rain_vol) for j in range(len(correc_list)): rain_list[correc_list[j][0]] = correc_list[j][1] correc_rain_vol = sum(rain_list[correc_list[j][0] - 23: correc_list[j][0] + 1]) ret = max(ret, correc_rain_vol) for k in range(23): correc_rain_vol = correc_rain_vol - rain_list[correc_list[j][0] - 23 + k] + rain_list[correc_list[j][0] + 1 + k] ret = max(ret, correc_rain_vol) print(ret)