#include<bits/stdc++.h>
#define int long long
#define uc getchar()
#define ph putchar
#define R register
#define CN const
#define rint R int
#define cint CN int
#define ps ph(' ')
#define pe ph('\n')
using namespace std;
cint inf=1e9+7;
cint mix=1e6+5;
inline int in();
inline void out(rint x);
int n=in(),ans;
struct nodgd{
	int x,id;
	inline bool operator<(CN nodgd&ep)CN{
		return ep.x<x;
	}
} a[mix];
set<int> b;
set<int>::iterator it;
#undef int
int main() {
#define int long long
	for(rint i=1;i<=n;++i)
	a[i]=(nodgd){in(),n+1-i},b.insert(i);
	for(rint i=1;i<=n;++i)
	a[n+i]=(nodgd){in(),i};
	sort(a+1,a+(n<<1)+1);
	for(rint i=1,j=1;i<=n;++i){
		while(j<=(n<<1)){
			it=b.upper_bound(a[j].id);
			if(it!=b.begin())break;
//cerr<<a[j].x<<'\n';
			++j;
		}	ans+=a[j++].x;
		b.erase(--it);
	}	out(ans),pe;
}
inline int in() {
	rint x=0;
	R bool f=0;
	R char s=uc;
	while((s<'0'||'9'<s)&&s!='-')s=uc;
	if(s=='-')f=1,s=uc;
	while('0'<=s&&s<='9')(x*=10)+=s^48,s=uc;
	return f?-x:x;
}
inline void out(rint x) {
	if(x<0)ph('-'),x=-x;
	rint y=x/10;
	if(y)out(y);
	ph((x-y*10)^48);
}
#include <bits/stdc++.h>
using namespace std;

const int N = 200200;

int n, v[N*2], a[N], b[N];
priority_queue<int,vector<int>,greater<int> > Q;

int main() {
    scanf("%d",&n);
    for (int i=1;i<=n*2;i++) scanf("%d",v+i);
    for (int i=1;i<=n;i++) {
        a[i] = max(v[n+1-i],v[n+i]);
        b[i] = min(v[n+1-i],v[n+i]);
    }

    for (int i=1;i<=n;i++) {
        if (i != 1) {
            if (b[i] > Q.top()) {
                Q.pop();
                Q.push(b[i]);
            }
        }
        Q.push(a[i]);
    }

    long long sum = 0;
    for (int i=1;i<=n;i++) {
        sum += Q.top();
        Q.pop();
    }
    printf("%lld\n", sum);
}