#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=1000005;
struct node{
	int c,id,val;
}s[N];
bool cmp1(node a,node b){return a.val<b.val;}
bool cmp2(node a,node b){return a.id<b.id;}
int st[N],top;
int main(){
	int n;
	scanf("%d",&n);n<<=1;
	for(int i=1;i<=n;i++) scanf("%d",&s[i].val),s[i].c=0,s[i].id=i;
	sort(s+1,s+n+1,cmp1);
	for(int i=n/2+1;i<=n;i++) s[i].c=1;
	sort(s+1,s+n+1,cmp2);
	int nl=-1;
	for(int i=1;i<=n;i++){
		if(nl==-1) nl=s[i].c,putchar('('),st[++top]=s[i].id;
		else if(s[i].c==nl) putchar('('),st[++top]=s[i].id;
		else putchar(')'),st[top--]=0;
		if(!top) nl=-1;
	}
	putchar('\n'); 
}

//================code===================//

//#define TLE

#ifdef TLE
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#endif

#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <ctime>


#define ci(t) cin>>t
#define co(t) cout<<t
#define LL long long
#define ld double
#define fa(i,a,b) for(LL i=(a);i<(LL)(b);++i)
#define fd(i,a,b) for(LL i=(a);i>(LL)(b);--i)
#define setp tuple<LL,LL,LL>
#define setl pair<LL,LL>
#define micro 0.000001

using namespace std;

LL gcd(LL a, LL b) { return a % b ? gcd(b, a % b) : b; }

#ifdef OHSOLUTION
#define ce(t) cerr<<t
#define AT cerr << "\n=================ANS=================\n"
#define AE cerr << "\n=====================================\n"
#define DB(a) cerr << __LINE__ << ": " << #a << " = " << (a) << endl;
#define __builtin_popcount __popcnt
#define __builtin_popcountll __popcnt64
#else
#define AT
#define AE
#define ce(t)
#endif

pair <int, int> vu[9] = { {0,1},{1,0},{0,-1} ,{-1,0},{0,0},{1,-1}, {-1,1} , {-1,-1},{-1,-1} }; //RDLU EWSN

template<typename T, typename U> void ckmax(T& a, U b) { a = a < b ? b : a; }
template<typename T, typename U> void ckmin(T& a, U b) { a = a > b ? b : a; }
struct gcmp { bool operator()(LL a, LL b) { return a < b; } bool operator()(setl& a, setl& b) { return a.second < b.second; } };
struct lcmp { bool operator()(LL a, LL b) { return a > b; } bool operator()(setl& a, setl& b) { return a.second > b.second; } };

const int max_v = 2e5 + 7;
const int max_k = 5e2 + 7;
const int bsz = (1ll << 10) + 7;
const int INF = 1e9 + 7;
const LL LNF = (LL)5e18 + 7ll;
LL mod = 998244353;
template<typename T, typename U> void MOD(T& a, U b) { a += b; if (a >= mod) a -= mod; };

int main()
{
#ifdef OHSOLUTION
	freopen("input.txt", "r", stdin);
#endif
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);	    
	int n; ci(n);

	vector<LL> va(n);
	vector<LL> vb(n);

	fa(i, 0, n) ci(va[i]);
	fa(i, 0, n) ci(vb[i]);
	

	unordered_map<LL, vector<int>> xh;
	fd(i, n-1, -1) va[i] += i,xh[va[i]].push_back(i);

	LL d = 0;
	LL ans = 0;
	vector<LL> arr(n+1);

	auto upd = [&](int i)
	{
		++i;
		for (; i<=n; i += i & -i) ++arr[i];
	};

	auto qur = [&](int i)
	{
		++i;
		LL ret = 0;
		for (; i; i -= i & -i)ret += arr[i];
		return ret;
	};

	fa(i, 0, n)
	{
		if (xh[vb[i] + d].empty())
		{
			co(-1);
			return 0;
		}

		int t = xh[vb[i] + d].back();

		

		xh[vb[i] + d].pop_back();

		ans += t - qur(t);
		upd(t);
		++d;
	}

	co(ans);

	return 0;
}


