#include<bits/stdc++.h>#include<bits/extc++.h>#define oo INT_MAX#define ll long long#define db double#define all(a) a.begin(), a.end()#define met(a, b) memset(a, b, sizeof(a))#define _rep(i, a, b) for (int i = (a); i <= (b); ++i)#define _rev(i, a, b) for (int i = (a); i >= (b); --i)#define _for(i, a, b) for (int i = (a); i < (b); ++i)#define lowbit(x) x &(-x)#define pi acos(-1.0)usingnamespace std;usingnamespace __gnu_pbds;const db eps =1e-6;constint maxn =2e5+9;// FILE *o = freopen("C:\\Users\\Jason.Z\\Desktop\\in.txt", "r", stdin);// assert(o != NULL);// FILE *e = freopen("C:\\Users\\Jason.Z\\Desktop\\y[i].txt", "w", stdout);// assert(e != NULL);
vector<int>bit(maxn);
map<int,int> cnt,id;
map<int, vector<int>> q;voidadd(int v,int x){for(;x <= maxn; x +=lowbit(x))
bit[x]+= v;}inlineintask(int x){int ret =0;for(;x; x -=lowbit(x))
ret += bit[x];return ret;}inlineintalr(int l,int r){returnask(r)-ask(l -1);}int num =0;intmain(){
ios::sync_with_stdio(0);int n;
cin >> n;_rep(i,1, n){int xx, yy ;
cin >> xx >> yy;
cnt[xx]++;
q[yy].push_back(xx);}for(auto t:cnt)
id[t.first]=++ num,add(1, num);
ll ans =0;for(auto t:q){sort(t.second.begin(), t.second.end());int cur_id, l =1;for(auto c:t.second){
cur_id = id[c];
ans +=(ll)alr(l, cur_id)*alr(cur_id, num);if(!--cnt[c])add(-1, cur_id);
l = cur_id +1;}}
cout << ans << endl;}