#b589. 超級馬拉松賽
while True:
n = int(input())
if n == 0:
break
s = list(map(int,input().split()))
dp = [[0 for _ in range(3)] for _ in range(n)]#
#print(dp)
dp[0][0] = 0 #休息
dp[0][1] = s[0] #一般
dp[0][2] = s[0] * 2 #衝刺
#print(dp)
for i in range(1,n):
dp[i][0] = max(dp[i-1][1],dp[i-1][2])#休息
dp[i][1] = max(dp[i-1][0],dp[i-1][1]) + s[i]#正常跑
dp[i][2] = max(dp[i-1][0],dp[i-1][1]) + s[i] * 2#衝刺
#print(dp)
print(max(dp[-1]))