#: Author - Soumya Saurav
import sys,io,os,time
from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect,math,heapq
alphabet = "abcdefghijklmnopqrstuvwxyz"

input = sys.stdin.readline
import collections,sys,threading
sys.setrecursionlimit(10**9)
threading.stack_size(10**8)

########################################
def main():
	n = int(input())
	arr = list(map(int , input().split()))
	from functools import lru_cache
	@lru_cache(None)
	def f(j, p, s):
		#print(j,p,s)
		global ans
		if p < 0 or s < 0:
			return -float("inf")
		if j == n:
			return p
		i = 1
		t1 = 0
		t2 = 0
		while p - arr[j]*i >= 0:
			t1 = max(t1 , f(j+1,p - arr[j]*i,s+i))
			i+=1
		i = 1
		while s - i >= 0:
			t2 = max(f(j+1,p+arr[j]*i,s-i), t2)
			i+=1
		return max(t2,t1,f(j+1,p,s))
	print(f(0,1000,0))



threading.Thread(target=main).start()







