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 ;
}

CodeForces - 651C Watchmen (去重)的更多相关文章

  1. codeforces 651C Watchmen

    Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn t ...

  2. CodeForces 651C Watchmen map

    Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn t ...

  3. Codeforces 651C Watchmen【模拟】

    题意: 求欧几里得距离与曼哈顿距离相等的组数. 分析: 化简后得到xi=xj||yi=yj,即为求x相等 + y相等 - x与y均相等. 代码: #include<iostream> #i ...

  4. codeforces 651C(map、去重)

    题目链接:http://codeforces.com/contest/651/problem/C 思路:结果就是计算同一横坐标.纵坐标上有多少点,再减去可能重复的数量(用map,pair存一下就OK了 ...

  5. 【CodeForces - 651C 】Watchmen(map)

    Watchmen 直接上中文 Descriptions: 钟表匠们的好基友马医生和蛋蛋现在要执行拯救表匠们的任务.在平面内一共有n个表匠,第i个表匠的位置为(xi, yi). 他们需要安排一个任务计划 ...

  6. Codeforces 650A Watchmen

    传送门 time limit per test 3 seconds memory limit per test 256 megabytes input standard input output st ...

  7. (水题)Codeforces - 650A - Watchmen

    http://codeforces.com/contest/650/problem/A 一开始想了很久都没有考虑到重复点的影响,解欧拉距离和曼哈顿距离相等可以得到 $x_i=x_j$ 或 $y_i=y ...

  8. CodeForces 651C

    Description Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg s ...

  9. codeforces Codeforces 650A Watchmen

    题意:两点(x1,y1), (x2,y2)的曼哈顿距离=欧几里得距离 也就是:x1=x2或y1=y2,再删除重合点造成的重复计数即可. #include <stdio.h> #includ ...

随机推荐

  1. NCE L6

  2. codewars--js--Valid Braces--正则、键值数组

    问题描述: Write a function that takes a string of braces, and determines if the order of the braces is v ...

  3. 2020数据字典php-直接复制

    [2020数据字典php-直接复制] <?php /** * 生成mysql数据字典 */ header ( "Content-type: text/html; charset=utf ...

  4. nginx配置访问https[自签版]

    通过openssl生成证书 (1)设置server.key,这里需要设置两遍密码: openssl genrsa -des3 -out server.key 1024 (2)参数设置,首先这里需要输入 ...

  5. JS DOM用不同方法获取节点及对节点插入、复制和移除

    操作节点的方法 appendChild() insertBefore() replaceChild() cloneNode() normalize() splitText() sppendChild( ...

  6. vue使用JSEncrypt实现rsa加密及挂载方法

    挂载全局方法 使用jsencrypt进行rsa加密 原文链接:Js参数RSA加密传输,jsencrypt.js的使用 - CSDN博客* https://blog.csdn.net/p31201115 ...

  7. 关于hp proliant sl210t服务器raid 1阵列配置(HP P420/Smart Array P420阵列卡配置)

    hp proliant sl210t服务器,一般都会带有两个阵列卡 一个服务器自带的Dynamic Smart Array B120i RAID控制器,一个为Slot卡槽上的Smart Array P ...

  8. 我眼中的ASP.NET.MVC

    MVC MVC全名 : Model View Controller ( Model-模型 View-视图  Controller-控制器)是一种经典的,经久不衰的,屹立不倒的软件设计框架.实现了业务逻 ...

  9. [20200103]GUID转换GUID_BASE64.txt

    [20200103]GUID转换GUID_BASE64.txt --//最近在做一个项目优化,里面大量使用uuid.优缺点在链接:http://blog.itpub.net.x.y265/viewsp ...

  10. Socket通讯探索(二)-socket集群

    前面我们在章节“Socket通讯探索(一)”中如何实现一个tcp连接,但是这仅仅是一个最初级的BIO实现,且没有添加线程池,实际应用中很少采用这种方式,因为不得不考虑当大量的Tcp连接建立的时候,服务 ...