from collections import deque
n=int(input())
res=float("-inf")
que=deque([[0,-1]])
total=0
for i,num in enumerate([int(i) for i in input().split()]*2):
    total+=num
    while que and i-que[0][1]>n:
        que.popleft()
    if que:
        res=max(res,total-que[0][0])
    while que and que[-1][0]>=total:
        que.pop()
    que.append([total,i])
print(res)