#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll,ll>;

ll solve_sub(ll N, vector<ll>& V) {
    priority_queue<pii> q;
    ll ans = 0;
    for ( int i = 0; i < N; i++ ) {
        int i2 = 2*N-1-i;
        q.push(pii(V[i],i));
        q.push(pii(V[i2],i2));
        ans += q.top().first;
        q.pop();
    }
    return ans;
}

ll solve_sub_0(ll N, vector<ll>& V) {
    ll ans = 0;
    for ( int i = 0; i < N; i++ ) {
        int i1 = N-1-i, i2 = N+i;
        ans += max(V[i1],V[i2]);
    }
    return ans;
}

ll solve() {
    ll N;
    cin >> N;
    vector<ll> V(2*N);
    for ( int i = 0; i < 2*N; i++ ) cin >> V[i];
    ll ans = solve_sub(N, V);
    return ans;
}

auto solve_small_1(ll N, vector<ll>& V) {
    ll ans = 0;
    vector<ll> ans_v;
    vector<ll> used(2*N);
    auto dfs = [&](auto self, int d, ll s) -> void {
        if ( d == N ) {
            ans = max(ans, s);
            return;
        }
        int h0, h1, c = 0;
        for ( int i = 0; i < 2*N; i++ ) {
            if ( used[i] == 0 ) {
                c++;
                if ( c <= N-d ) {
                    h0 = i;
                } else {
                    h1 = i;
                    break;
                }
            }
        }
        for ( int i = 0; i < 2*N; i++ ) {
            if ( used[i] > 0 ) continue;
            int i1 = i;
            int i2 = i < h1 ? h1 : h0;
            used[i1] = 1;
            used[i2] = 1;
            ans_v.push_back(i1);
            self(self, d+1, s+V[i1]);
            ans_v.pop_back();
            used[i1] = 0;
            used[i2] = 0;
        }
    };
    dfs(dfs,0,0LL);
    return ans;
}
struct Data {
    int id;
    ll N;
    vector<ll> V;
};
void test() {
    mt19937_64 mt64(0);
    uniform_int_distribution<ll> rnd_n(3, 4);
    uniform_int_distribution<ll> rnd_v(0, 9);

    int id = 0;
    vector<Data> ts;
    ts.push_back({++id,4,{3,2,8,6,7,6,1,6}});
    ts.push_back({++id,3,{1,2,3,4,5,6}});
    ts.push_back({++id,4,{1,4,5,8,7,6,3,2}});
    for ( int i = 0; i < 100; i++ ) {
        int n = rnd_n(mt64);
        vector<ll> a;
        for ( int j = 0; j < 2*n; j++ ) {
            a.push_back(rnd_v(mt64));
        }
        ts.push_back({++id,n,a});
    }
    
    for ( Data& t : ts ) {
        auto ans0 = solve_sub(t.N,t.V);
        auto ans1 = solve_small_1(t.N,t.V);
        if ( ans0 != ans1 ) {
            cout << t.id << " " << ans0 << " " << ans1 << "\n";
        }
    }
    cout << "end" << "\n";
}

int main() {
    // test();

    auto ans = solve();
    cout << ans << "\n";
    return 0;
}
#include <bits/stdc++.h>
using namespace std;

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)((n)-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T>
string join(const vector<T>&v, string del=", "){ stringstream s;
    for(auto x : v) s << del << x; return s.str().substr(del.size());
}
template<typename T>
ostream& operator<<(ostream& o, const vector<T>&v){
    if(v.size()) o << "[" << join(v) << "]"; return o;
}
template<typename T>
ostream& operator<<(ostream& o, const vector<vector<T> >&vv){
    int l = vv.size();
    if(l){ o<<endl; rep(i,l) o << (i==0 ? "[ " : ",\n  " ) << vv[i] << (i==l-1 ? " ]" : ""); }
    return o;
}
template<typename T1, typename T2>
ostream& operator<<(ostream& o, const pair<T1, T2>& p){
    return o << "(" << p.first << ", " << p.second << ")";
}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const double PI = (1*acos(0.0));
const double EPS = 1e-9;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const ll mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");
    int n; cin >> n;
    vl a(n);
    rep(i,n) cin >> a[i];

    ll ans = a[0];
    rep(i,n) ans = __gcd(ans, a[i]);
    cout << ans << endl;
    return 0;
}