N = int(input())
A = [int(a) for a in input().split()]

def dfs(day, money, kab, prev_kab):
    ans = 0
    if day == N:
        money += A[-1]*kab
        return money
    else:
        if prev_kab != A[day-1]:
            # buy
            buy_kab = 1
            while money-A[day-1]*buy_kab >= 0:
                new_ans = dfs(day+1, money-A[day-1]*buy_kab, kab+buy_kab, prev_kab)
                ans = max(ans, new_ans)
                buy_kab += 1
            # sell or do nothing
            for sell_kab in range(0, kab+1):
                new_ans = dfs(day+1, money+A[day-1]*sell_kab, kab-sell_kab, prev_kab)
                ans = max(ans, new_ans)
        else:
            new_ans = dfs(day+1, money, kab, kab)
            ans = max(ans, new_ans)
    return ans

ans = dfs(1, 1000, 0, -1)
print(ans)