#include<bits/stdc++.h>

using namespace std;

#define FOR(i, x, y) for(int i = (int)(x); i < (int)(y); ++i)
#define MP make_pair
#define fst first
#define snd second
typedef pair<int, int> pii;

const int maxn = 4e5 + 5;

int n, top = 0;
int a[maxn], ord[maxn], rev[maxn], stk[maxn];
char s[maxn];

inline bool cmp(const int &i, const int &j){ return a[i] < a[j]; }

int main(){
	scanf("%d", &n);
	FOR(i, 0, n << 1){
		scanf("%d", a + i);
		ord[i] = i;
	}
	sort(ord, ord + (n << 1), cmp);
	FOR(i, 0, n << 1)
		rev[ord[i]] = i;	
	FOR(i, 0, n << 1){
		if(top && (rev[stk[top]] < n) != (rev[i] < n)){
			s[stk[top]] = '(', s[i] = ')';
			--top;
		}
		else
			stk[++top] = i;
	}
	
	puts(s);
	return 0;
}
#include <bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f
#define PI 3.1415926535898
#define pb push_back
#define F first
#define S second
#define lson i << 1
#define rson i << 1 | 1
#define mem(x, y) memset(x, y, sizeof(x))
#define fin(x) freopen(x, "r", stdin)
#define fout(x) freopen(x, "w", stdout)
#define fcl fclose(stdin), fclose(stdout)
#define ioss ios::sync_with_stdio(false), cout.tie(NULL)
#define pii pair<int, int>
#define vec vector
#define all(x) x.begin(), x.end()
#define lowbit(x) x &(-x)
const int MAX = 6e5 + 10;
const int MOD = 1e9 + 7;
using namespace std;

int n, c[MAX], a[MAX];
void update(int i, int k) //定点更新
{
    while (i <= n)
    {
        c[i] += k;
        i += lowbit(i);
    }
}
int getsum(int i) //求和
{
    int res = 0;
    while (i > 0)
    {
        res += c[i];
        i -= lowbit(i);
    }
    return res;
}

int main()
{
    ioss;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        a[i]++;
    }
    ll ans = 0;
    for (int i = 0; i < n; i++)
    {
        ans += i - getsum(a[i]);
        update(a[i], 1);
    }
    memset(c, 0, sizeof(c));
    cout << ans << endl;
    for (int i = 0; i < n - 1; i++)
    {
        int k = getsum(a[i]), p = i - k;
        update(a[i], 1);
        // cout << k << endl;
        ans -= a[i] - 1;
        ans += n - a[i];
        cout << ans << endl;
    }
    return 0;
}
// (2 * a + n - 1)n/2
// an + n2/2 = x
