#!/usr/bin/env python3
import os
from sys import stdin, stdout

n = 0
seq = []
dp = []

def getMaximum(idx, stock, money):
    if idx == n-1:
        return money + stock*seq[idx]

    if stock < 10000 and dp[idx][stock] >= 0:
        return dp[idx][stock]

    ret = getMaximum(idx+1, stock, money)

    # buying
    k = 1
    cost = seq[idx]
    while cost <= money:
        ret = max(ret, getMaximum(idx+1, stock+k, money-cost))
        k += 1
        cost += seq[idx]

    # do nothing or selling
    cost = seq[idx]
    for k in range(1,stock):
        ret = max(ret, getMaximum(idx+1, stock-k, money+cost))
        cost += seq[idx]

    if stock < 10000:
        dp[idx][stock] = max(ret, dp[idx][stock])

    return ret


def solve(tc):
    global n
    global seq
    global dp

    n = int(stdin.readline().strip())
    seq = list(map(int, stdin.readline().split()))
    dp = [[-1 for j in range(10000)] for i in range(n)]

    print(getMaximum(0, 0, 1000))


tcs = 1
tc = 1
while tc <= tcs:
    solve(tc)
    tc += 1
