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. Linux运维---1.磁盘相关知识

    一 磁盘物理结构 (1) 盘片:硬盘的盘体由多个盘片叠在一起构成. 在硬盘出厂时,由硬盘生产商完成了低级格式化(物理格式化),作用是将空白的盘片(Platter)划分为一个个同圆心.不同半径的磁道(T ...

  2. 解决IIS程序池回收webapi定时程序造成的影响

    问题描述: webapi中有一个定时器线程,在iis程序池在1740分钟回收后,定时器中止 问题解决步骤: 1.设置程序池定期回收,设置每天定时回收 2.在windows自带的任务计划中,添加一条任务 ...

  3. 在Docker中运行SpringBoot程序

    1.将SpringBoot项目中pom.xml的build插件更换为: <build> <plugins> <plugin> <groupId>org. ...

  4. android编译/反编译常用工具及项目依赖关系

    项目依赖关系 apktool:依赖smali/baksmali,XML部分 AXMLPrinter2 JEB:dx 工具依赖 AOSP , 反编译dex 依赖 apktool dex2jar:依赖 A ...

  5. AndroidStudio报错:Could not download gradle.jar:No cacahed version available for offline mode

    场景 在讲Android Studio 的.gradle目录从默认C盘修改为 别的目录后,新建app提示: Could not download gradle.jar:No cacahed versi ...

  6. 常量, char[], const char[], char*, const char*, char* const以及const char* const的详解

    注意,这里用char类型只是举了一个例子,其他的int之类的也通用. 1: 常量: 例子: char str[] = "Hello world!"; char ch = 'a'; ...

  7. 【算法】蓝桥杯 试题 基础练习 Huffuman树

    资源限制 时间限制:1.0s   内存限制:512.0MB 问题描述 Huffman树在编码中有着广泛的应用.在这里,我们只关心Huffman树的构造过程. 给出一列数{pi}={p0, p1, …, ...

  8. 正则表达式中的exec()方法

    推荐该博主的内容链接: https://blog.csdn.net/ddwddw4/article/details/84658398?ops_request_misc=%7B%22request%5F ...

  9. VBA操作IE

    1.参照项目   Microsoft Internet Controls   Microsoft HTML Object   2.sample Sub GetIEItem() Dim objIE As ...

  10. Sercet sharing

    Secret Sharing Shamir门限 条件: \(0<k\leq n<p\) \(S<p,p\)是素数 Lagrange插值公式 \[ f(x)=\sum^{k}_{j=1 ...