Let's define the sum of two permutations *p* and *q* of numbers 0, 1, ..., (*n* - 1) as permutation <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/a6967136eb87d05a01f795f6061b884a1a9f4f4b.png" style="max-width: 100.0%;max-height: 100.0%;"/>, where *Perm*(*x*) is the *x*-th lexicographically permutation of numbers 0, 1, ..., (*n* - 1) (counting from zero), and *Ord*(*p*) is the number of permutation *p* in the lexicographical order.

For example, *Perm*(0) = (0, 1, ..., *n* - 2, *n* - 1), *Perm*(*n*! - 1) = (*n* - 1, *n* - 2, ..., 1, 0)

Misha has two permutations, *p* and *q*. Your task is to find their sum.

Permutation *a* = (*a*<sub class="lower-index">0</sub>, *a*<sub class="lower-index">1</sub>, ..., *a*<sub class="lower-index">*n* - 1</sub>) is called to be lexicographically smaller than permutation *b* = (*b*<sub class="lower-index">0</sub>, *b*<sub class="lower-index">1</sub>, ..., *b*<sub class="lower-index">*n* - 1</sub>), if for some *k* following conditions hold: *a*<sub class="lower-index">0</sub> = *b*<sub class="lower-index">0</sub>, *a*<sub class="lower-index">1</sub> = *b*<sub class="lower-index">1</sub>, ..., *a*<sub class="lower-index">*k* - 1</sub> = *b*<sub class="lower-index">*k* - 1</sub>, *a*<sub class="lower-index">*k*</sub> &lt; *b*<sub class="lower-index">*k*</sub>.
The first line contains an integer *n* (1 ≤ *n* ≤ 200 000).

The second line contains *n* distinct integers from 0 to *n* - 1, separated by a space, forming permutation *p*.

The third line contains *n* distinct integers from 0 to *n* - 1, separated by spaces, forming permutation *q*.
// update one element in the array;
// query on some segment using combine function.

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const int M = 1e9 + 7;
const int N = 1e6 + 5;  // limit for array size
int n;  // array size
struct node
{
    int value;
};

node t[2 * N];
int a[N], b[N], fact[N];

node combine(node l, node r)
{
    node tmp;
    tmp.value = l.value + r.value;
    return tmp;
}

void build() // build the tree
{   // t[i] = t[i * 2] + t[i * 2 + 1];
    for (int i = n - 1; i > 0; --i) t[i] = combine(t[i << 1], t[i << 1 | 1]);
}

void update(int p, node value) // set value at position p
{
    for (t[p += n] = value; p >>= 1; ) t[p] = combine(t[p << 1], t[p << 1 | 1]);
}

node query(int l, int r) // query on interval [l, r)
{
    node resl = {0};
    node resr = {0};
    for (l += n, r += n; l < r; l >>= 1, r >>= 1)
    {
        if (l & 1) resl = combine(resl, t[l++]);
        if (r & 1) resr = combine(t[--r], resr);
    }
    return combine(resl, resr);
}

int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> b[i];
    for (int i = 0; i < n; i++)
    {
        fact[i] = a[i] - query(0, a[i]).value;
        update(a[i], {1});
    }
    for (int i = 0; i < 2 * n; i++) t[i].value = 0;
    for (int i = 0; i < n; i++) 
    {
        fact[i] += b[i] - query(0, b[i]).value;
        update(b[i], {1});
    }
    // for (int i = 0; i < n; i++) cout << fact[i] << " ";
    // cout << "\n";
    // for (int i = 0; i < n; i++)
    // {
    //     int tmp = n - i - 1;
    //     if (fact[i] > tmp) 
    //     {
    //         fact[0] -= (n - i);
    //         break;
    //     }
    // }
    for (int i = n - 1; i >= 0; i--)
    {
        int tmp = n - i - 1;
        if (fact[i] > tmp) 
        {
            fact[i] -= (n - i);
            if (i) fact[i - 1]++;
        }
    }
    // for (int i = 0; i < n; i++) cout << fact[i] << " ";
    // cout << "\n";
    for (int i = 0; i < 2 * n; i++) t[i].value = 0;

    for (int i  = 0; i < n; i++)
    {
        int lo = 0, hi = n;
        while (1)
        {
            int mid = lo + (hi - lo) / 2;
            int tmp = mid - query(0, mid).value;
            if (tmp == fact[i])
            {
                if (t[n + mid].value == 1)
                {
                    lo = mid + 1;
                }
                else
                {
                    cout << mid << " ";
                    update(mid, {1});
                    break;
                }
            }
            if (tmp > fact[i]) hi = mid - 1;
            else if (tmp < fact[i]) lo = mid + 1;
        }
    }
    return 0;
}