#include<bits/stdc++.h>
using namespace std;

//#define int long long
#define f(i,a,b) for(int i = (a); i < (b); ++i)
#define f(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i,a,b) for(int i = (a); i < (b); ++i)
typedef pair<int, int> pii;
typedef vector<int> vi;


int firsttwo = 0;
int lasttwo = 0;
int firstthree = 0;
int lastthree = 0;


int subsolve(vi vals) {
	int ret = 0;
	sort(vals.begin(), vals.end());
	do {
		int ans = 0;
		f(i,0,vals.size() - 1) {
			int fr = vals[i];
			int ba = vals[i+1];
			if (fr == 4) fr = firsttwo;
			if (fr == 3) fr = firstthree;
			if (ba == 4) ba = lasttwo;
			if (ba == 3) ba = lastthree;
			ans += __gcd(fr, ba);
			//cerr << ans << " ";
		}
		ret = max(ans, ret);
	} 
	while (next_permutation(vals.begin(), vals.end()));
	return ret;
}


int solve(vi vals) {
	int ret = subsolve(vals);
	swap(firsttwo, lasttwo);
	//cerr << "\n";
	ret = max(ret, subsolve(vals));
	swap(firstthree, lastthree);
	//cerr << "\n";
	ret = max(ret, subsolve(vals));
	swap(firsttwo, lasttwo);
	//cerr << "\n";
	ret = max(ret, subsolve(vals));
	return ret;
}


signed main() {
	ios_base::sync_with_stdio(0);

	vector<int> counts(21,0);
	int ans = 0;
	bool hno = false;
	int n; cin >> n;
	f(i,0,n) {
		int x; cin >> x;
		if (x != 1 && x != 11 && x != 13 && x != 17 && x != 19) hno = true;
		counts[x]++;
	}
	f(i,0,21) {
		if (counts[i]) ans += (counts[i] - 1) * i;
	}
	if (counts[1]) ans++;
	if (counts[11]) ans++;
	if (counts[13]) ans++;
	if (counts[17]) ans++;
	if (counts[19]) ans++;
	if (!hno) ans--;
	vector<int> values;
	vi good = {2,5,6,7,10,12,14,15,18,20};
	for (auto i : good) if (counts[i]) values.push_back(i);

	//cerr << ans << "===\n";

	int x =4;
	int lastgood = 0;
	while(x < 21) {
		if (counts[x]) {
			ans += lastgood;
			lastgood = x;
			if (!firsttwo) { firsttwo = x; values.push_back(4); }
			lasttwo = x;
		}
		x *= 2;
	}
	x =3;
	lastgood = 0;
	while(x < 21) {
		if (counts[x]) {
			ans += lastgood;
			lastgood = x;
			if (!firstthree) { firstthree = x; values.push_back(3); }
			lastthree = x;
		}
		x *= 3;
	}

	//cerr << firsttwo << " " << lasttwo << " " << firstthree << " " << lastthree << "===\n";

	ans += solve(values);


	cout << ans << "\n";




}
