N=int(input()) A=list(map( int,input().split())) dp=[0]*(N+1) for i in range(1,N+1): for j in range(1,i-1): dp[i]=max(dp[i],dp[j]) dp[i]+=A[i-1] print(dp[-1])