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