import itertools
import math
poc = int(input())

cisla = set()
triv=0
for s in input().split():
	c = int(s)
	if c in cisla:
		triv+=c
	else:
		cisla.add(c)
	
prv1 = cisla & {1,11,13,17,19}
cisla = cisla - {1,11,13,17,19}
moc2 = list(cisla & {4,8,16})
moc2.sort()
cisla = cisla - {4,8,16}

def vyhodnot(zoznam):
	if len(zoznam)<2:
		return 0
	gcds = 0
	for i in range(1,len(zoznam)):
		gcds += math.gcd(zoznam[i],zoznam[i-1])
	return gcds

if vyhodnot(moc2):
	cisla.add(4)
	triv += vyhodnot(moc2)
else:
	cisla = cisla | set(moc2)

pred = list(prv1)
triv += len(pred)
pred = tuple(cisla & {7})
po = cisla - {7}
pred += tuple(po & {14})
po = po - {14}
if {18,9} <= po:
	po = po - {18,9} | {(18,9)}

#print(test)
maxvyh = 0
for p in itertools.permutations(po):
	zoznam = list(pred)
	for e in p:
		if e == (18,9):
			zoznam.extend(e)
		else:
			zoznam.append(e)
	vys=0
	if len(zoznam)<2:
		maxvyh=maxvyh
		#return 0
	else:
		gcds = 0
		for i in range(1,len(zoznam)):
			gcds += math.gcd(zoznam[i],zoznam[i-1])
		maxvyh = max(maxvyh,gcds)
		
		
	zoznam = list(pred)	
	for e in p:
		if e == (18,9):
			zoznam.extend((9,18))
		else:
			zoznam.append(e)
	vys=0
	if len(zoznam)<2:
		maxvyh=maxvyh
		#return 0
	else:
		gcds = 0
		for i in range(1,len(zoznam)):
			gcds += math.gcd(zoznam[i],zoznam[i-1])
		maxvyh = max(maxvyh,gcds)

print(triv + maxvyh)
