Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (xi, yi).
They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen i and j to
be |xi - xj| + |yi - yj|.
Daniel, as an ordinary person, calculates the distance using the formula .
The success of the operation relies on the number of pairs (i, j) (1 ≤ i < j ≤ n), such that the distance between watchman i and watchmen j calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs.
The first line of the input contains the single integer n (1 ≤ n ≤ 200 000) — the number of watchmen.
Each of the following n lines contains two integers xi and yi (|xi|, |yi| ≤ 109).
Some positions may coincide.
Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel.
3 1 1 7 5 1 5
2
6 0 0 0 1 0 2 -1 1 0 1 1 1
11
In the first sample, the distance between watchman 1 and watchman 2 is
equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and for
Daniel. For pairs (1, 1), (1, 5) and (7, 5), (1, 5) Doctor
Manhattan and Daniel will calculate the same distances.
用map存下数值为x的数量,数值为y的数量,还有数对为(x,y)的数量。容易观察出数对左边或右边相等时是符合题意的,听说差的绝对值之和,也就是曼哈顿距离可以看作直角三角形的两条直角边长度的和,而两点距离正好是斜边的长度,所以只有当数对至少一边相等时,两种距离才相等。
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <stack>
#include <bitset>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#define Si(a) scanf("%d",&a)
#define Sl(a) scanf("%lld",&a)
#define Sd(a) scanf("%lf",&a)
#define Ss(a) scanf("%s",a)
#define Pi(a) printf("%d\n",(a))
#define Pl(a) printf("%lld\n",(a))
#define Pd(a) printf("%lf\n",(a))
#define Ps(a) printf("%s\n",(a))
#define W(a) while(a--)
#define mem(a,b) memset(a,(b),sizeof(a))
#define FOP freopen("data.txt","r",stdin)
#define inf 0x3f3f3f3f
#define maxn 1000010
#define mod 1000000007
#define PI acos(-1.0)
#define LL long long
using namespace std;
typedef pair<int ,int> p;
map<int,int> mx;
map<int,int> my;
map<p,int> mp;
int main()
{
int n,x,y;
Si(n);
while(n--)
{
Si(x),Si(y);
mx[x]++,my[y]++;
mp[p(x,y)]++;
}
LL ans=0;
int temp;
map<int,int>::iterator i;
for(i=mx.begin();i!=mx.end();i++)
{
ans+=(LL)i->second*(i->second-1)/2;
}
for(i=my.begin();i!=my.end();i++)
{
ans+=(LL)i->second*(i->second-1)/2;
}
map<p,int>::iterator j;
for(j=mp.begin();j!=mp.end();j++)
{
ans-=(LL)j->second*(j->second-1)/2;
}
Pl(ans);
return 0;
}