n = int(input())
a = list(map(int, input().split()))
b = 1000
for i in range(n - 1):
    dp = [0] * 1000 * 200
    dp[0] = 0
    c = b
    for j in range(b + 1):
        dp[j + a[i]] = max(dp[j + a[i]], dp[j] + a[i + 1])
    for j in range(b + 1):
        c = max(c, dp[j] + b - j)
    b = c
print(b)