
N = int(input())
X = list(map(int, input().split()))

MAX = 10 ** 5
dp = [[-1] * MAX for _ in range(N + 1)]
dp[0][0] = 1000
for i in range(N):
    for j in range(MAX):
        dp[i + 1][0] = dp[i][0]

    for j in range(MAX - 1):
        dp[i + 1][j] = max(dp[i + 1][j],
                           dp[i + 1][j - 1] - X[i], dp[i][j - 1] - X[i])

    for j in reversed(range(MAX - 1)):
        if dp[i + 1][j + 1] >= 0:
            dp[i + 1][j] = max(dp[i + 1][j], dp[i + 1][j + 1] + X[i])
        if dp[i][j + 1] >= 0:
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j + 1] + X[i])

print(max(dp[-1]))
