Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <bits/stdc++.h>
- long long int ncr ( int n, int r) {
- if(r==0) return (long long)1;
- else if(n==r) return (long long)1;
- else return (long long)ncr(n-1,r-1)+ncr(n-1,r);
- }
- using namespace std;
- int main () {
- map <int, int> xx, yy;
- pair <int, int> xxx;
- map < pair <int, int> , int> paira;
- int n, x, y, i;
- scanf("%d", &n);
- int ara[n][2];
- for (i=0; i<n; i++) {
- scanf("%d %d", &x, &y);
- xx[x]++;
- yy[y]++;
- xxx.first = x;
- xxx.second = y;
- paira[xxx]++;
- ara[i][0] = x;
- ara[i][1] = y;
- }
- long long int one=0, two=0, three=0, ans = 0;
- for (i=0; i<n; i++) {
- if (xx[ara[i][0]] > 1) {
- one+= ncr(xx[ara[i][0]], 2);
- xx[ara[i][0]] = 0;
- }
- if (yy[ara[i][1]] > 1) {
- two += ncr (yy[ara[i][1]], 2);
- yy [ara[i][1]] = 0;
- }
- xxx.first = ara[i][0];
- xxx.second = ara[i][1];
- if (paira[xxx] > 1) {
- three += ncr (paira[xxx], 2);
- paira[xxx]=0;
- }
- }
- printf("%I64d\n", one+two - three);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment