#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef vector<int> V;
#define F(N,S,E) for(int N=(int)(S);N<=(int)(E);N++)
#define R(N,S,E) for(int N=(int)(S);N>=(int)(E);N--)
#define D(N,E) for(int N=0;N<(int)(E);N++)
LL read(){LL x;scanf("%lld",&x);return x;}

const int N=2.1e5;
int a[N],b[N];
int st[N];
int main(){
	int n=read();
	F(i,1,n)a[n-i+1]=read();
	F(i,1,n)b[i]=read();
	F(i,1,n)if(a[i]<b[i])swap(a[i],b[i]);
	// F(i,1,n)cerr<<a[i]<<" "<<b[i]<<endl;
	priority_queue<pair<int,int> > q1;
	F(i,1,n){
		if(!q1.empty()&&q1.top().first+b[i]>0){
			pair<int,int> t=q1.top();
			q1.pop();
			if(--st[t.second]==0){
				q1.push(make_pair(-a[t.second],t.second));
			}
			st[i]=1;
			q1.push(make_pair(-b[i],i));
		}
		else{
			q1.push(make_pair(-a[i],i));
		}
	}
	// F(i,1,n)cerr<<i<<" "<<st[i]<<endl;
	LL ans=0;
	F(i,1,n)ans+=st[i]==0?a[i]:st[i]==1?a[i]+b[i]:0;
	printf("%lld\n",ans);
	return 0;
}
// Good Bye rng_58
/**
 *    author:  otera    
**/
#include<bits/stdc++.h>
using namespace std;

#define int long long
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60;
#define rep(i, n) for(int i = 0; i < n; ++ i)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void solve() {
    int n; cin >> n;
    for(int i = 0; i < n; ++ i) {
        cout << 2 * i % n + 1 << " " << (2 * i + 1) % n + 1 << "\n";
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(20);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}