n= int(input())
arr = [int(x) for x in input().strip().split()]

mem = {}
def helper(i, mon, stk):
    key = (i, mon, stk)
    if key in mem:
        return mem[key]
    
    if i==len(arr):
        return mon
    
    ans = helper(i+1, mon, stk)
    buy = 1
    while True:
        if arr[i]*buy<=mon:
            ans = max(ans, helper(i+1, mon - arr[i]*buy, stk+buy))
        else:
            break
        
        buy += 1
    
    for s in range(1, stk+1):
        ans = max(ans, helper(i+1, mon+arr[i]*s, stk-s))
    
    mem[key] = ans
    return ans

    
print(helper(0, 1000, 0))