import collections
n = raw_input()
ais = collections.Counter(map(int, raw_input().split()))
def f(a,b):
	
	seen = set([])
	temp = 0
	a1mb = (a - 1) % b
	t = -float('inf')
	while((temp + a1mb) % b not in seen):
		seen.add((temp + a1mb) % b)
		t = max(r, (temp + a1mb) % b)
		temp += a
		temp %= b
	return t

r = 0

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