#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_;
}