#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int n;
ll a[200005];
ll b[200005];
ll sol;
ll ans1;
ll ans2;

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cerr.tie(0);
    
    cin >> n;
    
    for(int i=1;i<=n;i++)
    {
        int r,c;
        cin >> r >> c;
        a[r]++;
        b[c]++;
    }
    
    for(int i=1;i<=n;i++) cout << a[i] << " ";
    cout << "\n";
    for(int i=1;i<=n;i++) cout << b[i] << " ";
    cout << "\n";
    
    sol = 0;
    ans1 = 0;
    ans2 = 0;
    
    ll p = a[1] - 1;
    ans1=ans1+abs(p);
    
    for(int i=2;i<=n;i++)
    {
        p = a[i] + p-1;
        ans1 = ans1 + abs(p);
    }
    
    p = b[1]-1;
    ans2 = ans2+abs(p);
    
    for(int i=2;i<=n;i++)
    {
        p= b[i] + p-1;
        ans2 = ans2 + abs(p);
    }
    
    sol = ans1+ans2;
    
    //cout << ans1 << " " << ans2 << "\n";
    
    cout << sol;
    
    return 0;
}