def main():
    n = int(input())
    a = list(map(int, input().split(" ")))
    
    ys_set = set([(1000,0)])
    for i in range(n):
        if 1<i:
            if a[i-1]<a[i]:
                ys_set, max_y = cal_set_sell(a[i], ys_set)
            elif a[i]<a[i-1]:
                ys_set, max_y = cal_set_buy(a[i], ys_set)
            else:
                continue
        else: 
            ys_set, max_y = cal_set_buy(a[i], ys_set)
            ys_set, max_y = cal_set_sell(a[i], ys_set)
    
    print(max_y)

def cal_set_sell(a_i, ys_set):
    ys_candidsate_set = set([])
    max_y = 0
    for one in ys_set:
        #sell
        for num_stock in range(one[1]+1):
            new_y = one[0] + num_stock*a_i
            new_s = one[1] - num_stock
            ys_candidsate_set.add((new_y, new_s))
            if max_y < new_y:
                max_y = new_y

    return ys_candidsate_set, max_y

def cal_set_buy(a_i, ys_set):
    ys_candidsate_set = set([])
    max_y = 0
    for one in ys_set:
        #buy
        for num_stock in range(one[0]//a_i+1):
            new_y = one[0] - num_stock*a_i
            new_s = one[1] + num_stock
            ys_candidsate_set.add((new_y, new_s))
            if max_y < new_y:
                max_y = new_y

    return ys_candidsate_set, max_y


if __name__=="__main__":
    main()