CSES - Shared codeLink to this code: https://cses.fi/paste/a435335370beae5f2d6633/
#include<bits/stdc++.h>
#define ll long long
using namespace std;
/* Iterative Function to calculate (x^y)%p in O(log y) */
ll power(long long x, unsigned int y, int p)
{
    int res = 1;     // Initialize result
 
    x = x % p; // Update x if it is more than or
                // equal to p
  
    if (x == 0) return 0; // In case x is divisible by p;
 
    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;
 
        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}
struct fentre
{
    int bt[400050],n;
    fentre()
    {
        memset(bt,0,sizeof bt);
    }
    void update(int ind)
    {
        while(ind<=n)
        {
            bt[ind]++;ind+=ind&-ind;
        }
    }
    int getsm(int ind)
    {int sm=0;
        while(ind>0)
        {
            sm+=bt[ind];ind-=ind&-ind;
        }
        return sm;
    }

};
ll parent[500005],size[500005];
void make_set(int v) {
    parent[v] = v;
    size[v] = 1;
}

int find_set(int v) {
    if (v == parent[v])
        return v;
    return parent[v] = find_set(parent[v]);
}

void union_sets(int a, int b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b) {
        if (size[a] < size[b])
            swap(a, b);
        parent[b] = a;
        size[a] += size[b];
    }
}
bool custom(vector<int>p1,vector<int>p2)
{
    if(p1[0]!=p2[0])
    return p1[0]<p2[0];
    else
    return p1[1]>p2[1];
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int i,k,t,n,m,h,mod=1e9+7;pair<ll,ll>ar[1000005];
    cin>>n;
    set<int>s;vector<vector<int>>vp;
    for(i=0;i<n;i++)
    {int x,y;
        cin>>x>>y;
        s.insert(x);s.insert(y);
        vp.push_back({x,y,i+1});
    }
    int cnt=1;unordered_map<int,int>mp;
    for(auto x:s)
    {
        mp[x]=cnt++;
    }
    for(i=0;i<n;i++)
    {
        vp[i][0]=mp[vp[i][0]]; vp[i][1]=mp[vp[i][1]];
    }
    sort(vp.begin(),vp.end(),custom);
    fentre obj1,obj2;
    obj1.n=cnt-1;
    obj2.n=cnt-1;
    vector<int>ans1(n,0),ans2(n,0); 
    for(int i=0,j=n-1;i<n;i++,j--)
    {
        ans1[vp[i][2]-1]=i-obj1.getsm(vp[i][1]-1);
        obj1.update(vp[i][1]);
        ans2[vp[j][2]-1]=obj2.getsm(vp[j][1]);
        obj2.update(vp[j][1]);
        
    }   
   for(auto x:ans2)
   cout<<x<<" ";
   cout<<endl;
   for(auto x:ans1)
   cout<<x<<" ";
   cout<<endl;
}