#include <bits/stdc++.h>

// #define DEBUG 1

//#define int long long
#define for0(i,n) for (int i=0; i<n; i++)
#define iter(c) for(auto it=c.begin(); it!=c.end(); it++)
#define iter2(c) for(auto it2=c.begin(); it2!=c.end(); it2++)
#define pb push_back
#define ms(a,z) memset(a,z,sizeof(a));
#define mp make_pair
#define X first
#define Y second
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define all(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define pmod(x,m) (((x)%(m)+m)%m)
#ifdef int
#define read(x) scanf("%lld",&x);
#else
#define read(x) scanf("%d",&x);
#endif

#ifdef DEBUG
#define nl cout<<"\n";
#define pr(x) cout<<(x)<<" ";
#define prl(x) cout<<#x " = "<<x<<endl;
#define prp(x) cout<<"("<<(x).first<<" "<<(x).second<<") ";
#define printv(v) {for(int _=0; _<sz(v); _++) cout<<v[_]<<" "; cout<<"\n";}
#define printa(a,s) {for (int _=0; _<s; _++) cout<<a[_]<<" "; cout<<"\n";}
#define print2D(a,m,n) {for (int _=0; _<m; _++) {for (int __=0; __<n; __++) cout<<a[_][__]<<" "; cout<<"\n";} cout<<"\n";}
#define priter(v) iter(v) {pr(*it)} nl
#define debug cout<<"ok at line "<<__LINE__<<endl;
#else
#define nl
#define pr(x)
#define prl(x)
#define prp(x)
#define printv(v)
#define printa(a,s)
#define print2D(a,m,n)
#define priter(v)
#define debug
#endif
#define MAXN 100000

using namespace std;

typedef long long ll;

const int INF = 2147483647;
const long long INFL = 9223372036854775807LL;
const double EPSILON = 0.00000001;
const long long MOD = 1000000007;

int p[MAXN+5];
int Rank[MAXN+5];

void init(int n)
{
    for (int i=0; i<n; i++) {
        p[i] = i;
        Rank[i] = 0;
    }
}

int find_set(int x)
{
    if (p[x] != x)
        p[x] = find_set(p[x]);
    return p[x];
}

int merge_sets(int x, int y)
{
    int px = find_set(x);
    int py = find_set(y);
    if (px == py)
        return 0;
    if (Rank[px] > Rank[py])
        p[py] = px;
    else
        p[px] = py;
    if (Rank[px] == Rank[py])
        Rank[py]++;
    return 1;
}

vector<int> pnts_by_x[MAXN+5], pnts_by_y[MAXN+5]; 
vector<int> components[MAXN+5];

int32_t main()
{
    #ifdef DEBUG
    //freopen("A.txt","r",stdin);
    //freopen("","w",stdout);
    #endif

    int n;
    cin >> n; 
    set<int> unique_x; 
    for0(i,n) {
        int x,y;
        read(x); read(y); 
        pnts_by_x[x].push_back(y); 
        pnts_by_y[y].push_back(x); 
        unique_x.insert(x); 
    }
    
    init(100001); 
    for (int y=1; y<=MAXN; y++) {
        for (int i=0; i<sz(pnts_by_y[y])-1; i++) {
            int x1 = pnts_by_y[y][i];
            int x2 = pnts_by_y[y][i+1]; 
            merge_sets(x1,x2); 
        }
    }
    
    for (int x : unique_x) {
        components[find_set(x)].push_back(x); 
    }
    
    ll ans = 0; 
    for (int c=1; c<=MAXN; c++) {
        if (sz(components[c]) > 0) {
            prl(c)
            set<int> unique_y;
            ll cnt = 0; 
            for (int x : components[c]) {
                pr(x) 
                for (int y : pnts_by_x[x]) {
                    unique_y.insert(y); 
                    cnt++; 
                }
            }
            nl 
            prl(sz(unique_y))
            ans += (ll)sz(unique_y) * (ll)sz(components[c]) - cnt; 
        }
    }
    cout << ans << endl; 
    return 0;
}


Measured memory_bytes: 16124