#include using namespace std; using ll = long long; int cs[21]; int trs[21][21]; int dp[1 << 20][21]; int main() { ios::sync_with_stdio(false); int n; cin >> n; vector as(n); for(int i = 0; i < n; ++i) { cin >> as[i]; cs[as[i]] += 1; } int res = 0; for(int i = 1; i <= 20; ++i) { if(cs[i] == 0) continue; res += i*(cs[i] - 1); } for(int i = 1; i <= 20; ++i) { for(int j = 1; j <= 20; ++j) { if(cs[i] > 0 && cs[j] > 0) { trs[i][j] = gcd(i, j); } else { trs[i][j] = 0; } } } for(int i = 1; i <= 20; ++i) { dp[1 << (i-1)][i] = 0; } for(int i = 1; i < 1 << 20; ++i) { for(int b = 1; b <= 20; ++b) { if(!(i & (1 << (b-1)))) continue; for(int j = 1; j <= 20; ++j) { if(i & (1 << (j-1))) continue; dp[i | (1 << (j-1))][j] = max(dp[i | (1 << (j-1))][j], dp[i][b] + trs[b][j]); } } } int best = 0; for(int i = 1; i <= 20; ++i) { best = max(best, dp[(1 << 20) - 1][i]); } cout << best+res << '\n'; return 0; }