#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
vector<int>a;
ll dp[(1<<20)+2][11];
ll go(int mask, int round){
//cout<<mask<<" mask, round "<<round<<endl;
if(dp[mask][round]!=-1)return dp[mask][round];
// if(__builtin_popcount(mask)==((1<<n)-1)){
// //base case
// return 0;
// }
if(round==n+1)return 0;
ll ans=0;
for(int i=0;i<n;++i){
for(int j=i+1;j<n;++j){
if(((mask>>i)&1)==0 && ((mask>>j)&1)==0){
//ith number and jth number are not touched yet
//cout<<i<<" i,j "<<j<<endl;
int newMask = mask | (1<<i);
newMask = newMask | (1<<j);
ans=max(ans, __gcd(a[i], a[j])*round+ go(newMask, round+1));
}
}
}
return dp[mask][round]=ans;
}
long long solve (int N, vector<int> A) {
// Write your code here
n=2*N;
for(int x:A)a.push_back(x);
memset(dp, -1, sizeof(dp));
return go(0,1);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int N;
cin >> N;
vector<int> A(2*N);
for(int i_A = 0; i_A < 2*N; i_A++)
{
cin >> A[i_A];
}
long long out_;
out_ = solve(N, A);
cout << out_;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKdHlwZWRlZiBsb25nIGxvbmcgbGw7CmludCBuOwp2ZWN0b3I8aW50PmE7CmxsIGRwWygxPDwyMCkrMl1bMTFdOwpsbCBnbyhpbnQgbWFzaywgaW50IHJvdW5kKXsKICAgLy9jb3V0PDxtYXNrPDwiIG1hc2ssIHJvdW5kICI8PHJvdW5kPDxlbmRsOwogICBpZihkcFttYXNrXVtyb3VuZF0hPS0xKXJldHVybiBkcFttYXNrXVtyb3VuZF07CiAgIC8vIGlmKF9fYnVpbHRpbl9wb3Bjb3VudChtYXNrKT09KCgxPDxuKS0xKSl7CiAgIC8vICAgIC8vYmFzZSBjYXNlIAogICAvLyAgICByZXR1cm4gMDsKCiAgIC8vIH0KICAgaWYocm91bmQ9PW4rMSlyZXR1cm4gMDsKICAgbGwgYW5zPTA7CiAgIGZvcihpbnQgaT0wO2k8bjsrK2kpewogICAgICBmb3IoaW50IGo9aSsxO2o8bjsrK2opewogICAgICAgICBpZigoKG1hc2s+PmkpJjEpPT0wICYmICgobWFzaz4+aikmMSk9PTApewogICAgICAgICAgICAvL2l0aCBudW1iZXIgYW5kIGp0aCBudW1iZXIgYXJlIG5vdCB0b3VjaGVkIHlldCAKICAgICAgICAgICAgLy9jb3V0PDxpPDwiIGksaiAiPDxqPDxlbmRsOwogICAgICAgICAgICBpbnQgbmV3TWFzayA9IG1hc2sgfCAoMTw8aSk7CiAgICAgICAgICAgIG5ld01hc2sgID0gbmV3TWFzayB8ICgxPDxqKTsKICAgICAgICAgICAgYW5zPW1heChhbnMsIF9fZ2NkKGFbaV0sIGFbal0pKnJvdW5kKyBnbyhuZXdNYXNrLCByb3VuZCsxKSk7CiAgICAgICAgIH0KICAgICAgfQogICB9CiAgIHJldHVybiBkcFttYXNrXVtyb3VuZF09YW5zOwp9Cgpsb25nIGxvbmcgc29sdmUgKGludCBOLCB2ZWN0b3I8aW50PiBBKSB7CiAgIC8vIFdyaXRlIHlvdXIgY29kZSBoZXJlCiAgIG49MipOOwogICBmb3IoaW50IHg6QSlhLnB1c2hfYmFjayh4KTsKICAgbWVtc2V0KGRwLCAtMSwgc2l6ZW9mKGRwKSk7CiAgIHJldHVybiBnbygwLDEpOwogICAKfQoKaW50IG1haW4oKSB7CgogICAgaW9zOjpzeW5jX3dpdGhfc3RkaW8oMCk7CiAgICBjaW4udGllKDApOwogICAgaW50IE47CiAgICBjaW4gPj4gTjsKICAgIHZlY3RvcjxpbnQ+IEEoMipOKTsKICAgIGZvcihpbnQgaV9BID0gMDsgaV9BIDwgMipOOyBpX0ErKykKICAgIHsKICAgIAljaW4gPj4gQVtpX0FdOwogICAgfQoKICAgIGxvbmcgbG9uZyBvdXRfOwogICAgb3V0XyA9IHNvbHZlKE4sIEEpOwogICAgY291dCA8PCBvdXRfOwp9