#include #include #pragma GCC target ("avx") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; using namespace atcoder; using ll=long long; #define rep(i,a,b) for(it i=(it)(a);i<=(it)b;i++) #define nrep(i,a,b) for(it i=(it)(a);i>=(it)b;i--) #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define moda 998244353LL #define modb 1000000007LL #define gyaku 166374059LL #define dai 2500000000000000000LL #define aoi 1e+18 #define tyu 2500000000 #define giri 1000000000 #define en 3.14159265358979 #define endl '\n' #define sho -dai #define eps 1e-14 #define yn(x) cout<<(x ? "Yes\n":"No\n"); #define YN(x) cout<<(x ? "YES\n":"NO\n"); #define cou(x) cout<>x; using it=long long; using un=unsigned long long; using db=long double; using st=string; using ch=char; using bo=bool; using P=pair; using ip=pair; using mint=modint; using mints=modint998244353; using minto=modint1000000007; using vi=vector; using ivi=vector; using vd=vector; using vs=vector; using vc=vector; using vb=vector; using vp=vector

; using ivp=vector; using vm=vector; using vms=vector; using vmo=vector; using sp=set

; using isp=set; using ss=set; using sc=set; using si=set; using isi=set; using svi=set; using vvi=vector; using ivvi=vector; using vvd=vector; using vvs=vector; using vvb=vector; using vvc=vector; using vvp=vector; using ivvp=vector; using vvm=vector; using vvms=vector; using vvmo=vector; using vsi=vector; using ivsi=vector; using vsp=vector; using ivsp=vector; using vvsi=vector; using ivvsi=vector; using vvsp=vector; using ivvsp=vector; using vvvi=vector; using ivvvi=vector; using vvvd=vector; using vvvm=vector; using vvvvi=vector; using ivvvvi=vector; template void scan(vector &a){ rep(i,0,a.size()-1)cin>>a[i]; } template void scan(vector &a,vector&b){ rep(i,0,a.size()-1)cin>>a[i]>>b[i]; } template void scan(vector> &a){ rep(i,0,a.size()-1)cin>>a[i].first>>a[i].second; } ivp za(ivp &a,int n){ map x,y; rep(i,0,n-1) x[a[i].first]=0,y[a[i].second]=0; int now=0; for(auto i:x){ x[i.first]=now; now++; } now=0; for(auto i:y){ y[i.first]=now; now++; } rep(i,0,n-1) a[i].first=x[a[i].first],a[i].second=y[a[i].second]; return a; } it p(ivp &x,int n){ it ok=0; fenwick_tree mae(n); int mati=x[0].first;ivi tai; rep(i,0,n-1) if(mati!=x[i].first)mae.add(x[i].second,1); rep(i,0,n-1){ if(mati!=x[i].first){ mati=x[i].first; rep(j,i,n-1){ if(x[j].first==mati)mae.add(x[j].second,-1); else break; } tai.clear(); } ok+=mae.sum(x[i].second+1,n); } return ok; } it q(ivp &x,int n){ it ok=0; fenwick_tree mae(n); int mati=x[0].first;ivi tai; rep(i,0,n-1) if(mati!=x[i].first)mae.add(x[i].second,1); rep(i,0,n-1){ if(mati!=x[i].first){ mati=x[i].first; rep(j,i,n-1){ if(x[j].first==mati)mae.add(x[j].second,-1); else break; } tai.clear(); } ok+=mae.sum(0,x[i].second); } return ok; } it r(ivp &x,it n){ map cnt; rep(i,0,n-1)cnt[x[i].first]++; it sum=n*(n-1)/2; for(auto i:cnt) sum-=i.second*(i.second-1)/2; return sum; } it s(ivp &x,it n){ map cnt; rep(i,0,n-1)cnt[x[i].second]++; it sum=n*(n-1)/2; for(auto i:cnt) sum-=i.second*(i.second-1)/2; return sum; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int n;cin>>n; ivp z(n);scan(z); z=za(z,n);sort(all(z)); db a=p(z,n),b=q(z,n),c=r(z,n),d=s(z,n); cout<