n = int(input())
a = list(map(int,input().split()))

dp = [-1]*1000
dp[0] = 1000


for i in range(n):
    ndp = [-1]*1000

    for j in range(999):
        if dp[j] >= a[i]:
            for k in range(j,999):
                ndp[k] = max(ndp[k],dp[j]-(k-j)*a[i]) 
        
    for j in range(999,0,-1):
        if dp[j] >= 0:
            
            for k in range(j,-1,-1):
                ndp[k] = max(ndp[k],dp[j]+(j-k)*a[i]) 
    
    dp = ndp
print(max(dp))
