import collections
n = raw_input()
ais = map(int, raw_input().split())
#whats the max m that you get from 
def f(a,b):
	k = 0
	seen = set([])
	while(((k*a) + a-1) % b not in seen):
		seen.add((k*a + a-1) % b)
		k +=1
	return max(list(seen))

r = 0
for i,ai in enumerate(ais):
	current = 0

	for j, aj in enumerate(ais):
		if i == j or ai == aj:
			current += ai - 1
		else:
			current += f(ai,aj)
	r = max(current, r)
print r