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.

Input

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.

Output

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.

Examples
input
3
1 1
7 5
1 5
output
2
input
6
0 0
0 1
0 2
-1 1
0 1
1 1
output
11
Note

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,pair存一下)

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <stack>
#include <map>
using namespace std;
#define ll long long
ll a,b;
map<ll,ll> mp1;
map<ll,ll> mp2;
map< pair<ll,ll>,ll> mp;
int main()
{
int n,m;
while(scanf("%d",&n)!=EOF){
ll ans=,num=;
mp1.clear();
mp2.clear();
mp.clear();
for(int i=;i<=n;i++){
scanf("%lld%lld",&a,&b);
num+=mp[make_pair(a,b)];
mp[make_pair(a,b)]++;
if(mp1.find(a)==mp1.end())
mp1[a]=;
else {
ans+=mp1[a];
mp1[a]++;
}
if(mp2.find(b)==mp2.end())
mp2[b]=;
else {
ans+=mp2[b];
mp2[b]++;
}
}
printf("%lld",(ll)ans-num);
}
return ;
}

最新文章

  1. java并发编程学习:用 Semaphore (信号量)控制并发资源
  2. Android 隐藏关闭软键盘
  3. CSS3入门--线条动画特效实例
  4. 31. Flatten Binary Tree to Linked List
  5. 计算hashCode的常见方法
  6. linux实践——内核编程 基础模块
  7. python MySQLdb中文乱码
  8. POJ 3356 AGTC(最小编辑距离)
  9. 《C++ Primer Plus 6th》读书笔记 - 第九章 内存模型和名称空间
  10. 让MyEclipse里的Tomcat自动reloadable
  11. @media max-width 与jquery宽度取值的差异
  12. OpenLayers3--ol3--新特性
  13. Servlet--ServletContext接口
  14. 【HTTP】http协议一些重要的知识点
  15. [Ubuntu]修改文件夹及所有子文件夹权限
  16. SpringBoot四种读取properties文件的方式
  17. 使用 Charles 抓取 App 网络请求
  18. 惊闻企业Web应用生成平台 活字格 V4.0 免费了,不单可视化设计器免费,服务器也免费!
  19. 20155206 2016-2017-2 《Java程序设计》第6周学习总结
  20. 通过图形化工具来画shape

热门文章

  1. 【题解】 2月19日 厦门双十中学NOIP2014模拟D2 T2 采药人接水果
  2. JavaScrip流程控制之switch选择,for循环
  3. npm安装Vue.js
  4. ORACLE ANALYZE使用小结
  5. Java面向对象入门(2)-访问修饰符
  6. vmware进程,虚拟机NAT模式配置固定ip,访问外网与ping通主机
  7. AOV拓扑排序实验总结-1
  8. Page Object设计模式(二)——poium测试库
  9. P2055 [ZJOI2009]假期的宿舍【二分图/最大流】
  10. H5---禁止长按