n = int(input())
A = list(map(int, input().split()))
M = 1000
for i in range(n-1):
    dp = list(range(M+1))
    a, b = A[i], A[i+1]
    for j in range(M+1):
        if j >= a:
            dp[j] = max(dp[j-a]+b, dp[j])
    M = dp[M]
ans = M
print(ans)