#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define deb(x) cout<< #x << " " << x << "\n";
#define MAX 9223372036854775807
#define MIN -9223372036854775807
#define setbits(n) __builtin_popcountll(n)
#define mkunique(a) a.resize(unique(a.begin(),a.end())-a.begin());
const ll mod=1e9+7;



int main(){
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll T=clock();
    
    ll n;
    cin>>n; n*=2;
    vector<ll> a(n), b;
    for(ll i=0;i<n;i++)
        cin>>a[i];
    multiset<ll> s;
    ll ans=0, val=0;
    for(ll i=0;i<n/2;i++){
        if(a[i]<a[n-i-1]) swap(a[i],a[n-i-1]);
        if(s.size()>0 && *s.rbegin()>a[i]){
            ans+=*s.rbegin();
            s.erase(--s.end());
            s.insert(a[i]);
            s.insert(a[n-i-1]);
        }
        else{
            ans+=a[i];
            s.insert(a[n-i-1]);
        }
    }
    cout<<ans;

 
    cerr<<"\n\nTIME: "<<(long double)(clock()-T)/CLOCKS_PER_SEC<<" sec\n";
    T = clock();
    return 0;
}
#include <bits/stdc++.h>
#define N 400005
#define ll long long
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int T;
int n;
int a[N];
int main()
{
    n = read();
    ll ans = 0;
    for(int i=1;i<=2*n;i++) a[i] = read(), ans += a[i];
    priority_queue<int> q;
    for (int i = 1 ; i <= n; i += 1) {
        q.push(-a[n - i + 1]);
        q.push(-a[n + i]);
        ans += q.top();
        q.pop();
    }
    cout << ans << endl;
}
// 1 2 3 4 5 6 7 8
//
