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 (x_{i}, y_{i}).

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 |x_{i} - x_{j}| + |y_{i} - y_{j}|. Daniel, as an ordinary person, calculates the distance using the formula $\sqrt{(x_{i} - x_{j})^{2} +(y_{i} - y_{j})^{2}}$.

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 x_{i} and y_{i} (|x_{i}|, |y_{i}| ≤ 10^9).

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 $\sqrt{(1 - 7)^{2} +(1 - 5)^{2}} = 2 \cdot \sqrt{13}$ for Daniel. For pairs (1, 1), (1, 5) and (7, 5), (1, 5) Doctor Manhattan and Daniel will calculate the same distances.

Difficulty: competition

Starter code:

Solutions:
from collections import Counter
n = int(input())
points = Counter([tuple(map(int, input().split(' '))) for i in range(n)])

x, y = Counter([k for k, v in points.elements()]), Counter([v for k, v in points.elements()])

ans = sum([v*(v-1)//2 for k, v in list(x.items())])+sum([v*(v-1)//2 for k, v in list(y.items())])-sum([v*(v-1)//2 for k, v in list(points.items())])
print(ans)


from operator import itemgetter
n=int(input().strip())
ans=0
l=[]
for i in range(n):
	l.append([int(x) for x in input().strip().split()])
 
l.sort(key=itemgetter(1))
x=l[0][1]
y=1
for i in range(1,len(l)):
	if l[i][1]!=x:
		ans=ans+(y*(y-1))//2
		x=l[i][1]
		y=1
	else:
		y=y+1
ans=ans+(y*(y-1))//2
 
l.sort()
x=l[0][0]
y=1
for i in range(1,len(l)):
	if l[i][0]!=x:
		ans=ans+(y*(y-1))//2
		x=l[i][0]
		y=1
	else:
		y=y+1
ans=ans+(y*(y-1))//2
 
x0,x1=l[0][0],l[0][1]
y=1
for i in range(1,len(l)):
	if l[i][0]!=x0 or l[i][1]!=x1:
		ans=ans-(y*(y-1))//2
		x0,x1=l[i][0],l[i][1]
		y=1
	else:
		y=y+1
ans=ans-(y*(y-1))//2
 
print(ans)

n = int(input())
l = []
for i in range(n):
	a,b = map(int,input().split())
	l.append((a,b))

def solve(a):
	ans, d = 0, {}
	for x,_ in a:
		d[x] = d.setdefault(x,0)+1
	for i in d:
		ans += d[i]*(d[i]-1) // 2
	return ans

x = 0
pd = {}
for i in l:
	pd[i] = pd.setdefault(i,0)+1
for i in pd:
	x += pd[i]*(pd[i]-1) // 2

y = solve(l)
z = solve([(p,q) for q,p in l])
print(y+z-x)

c = [tuple(map(int, input().split())) for _ in range(int(input()))]
o = dict()
x = dict()
y = dict()
for v in c:
    o[v] = o.get(v, 0) + 1
    x[v[0]] = x.get(v[0], 0) + 1
    y[v[1]] = y.get(v[1], 0) + 1
ret = 0
for v in x:
    ret += (x[v] * (x[v] - 1)) // 2
for v in y:
    ret += (y[v] * (y[v] - 1)) // 2
for v in o:
    ret -= (o[v] * (o[v] - 1)) // 2
print(ret)


n = int(input())
x2pts = {}
y2pts = {}
watchmen = {}
for i in range(n):
    watchman = tuple(map(int,input().split()))
    watchmen[watchman] = watchmen.get(watchman,0)+1
    x2pts[watchman[0]] = x2pts.get(watchman[0],0)+1
    y2pts[watchman[1]] = y2pts.get(watchman[1],0)+1
pairs = 0
for i in list(watchmen.items()):
    pairs -= i[1]*(i[1]-1)//2
for i in list(x2pts.items()):
    pairs += i[1]*(i[1]-1)//2
for i in list(y2pts.items()):
    pairs += i[1]*(i[1]-1)//2
print(pairs)


#!/usr/bin/env python3
import collections, itertools, functools, math

def solve():
    n = int(input())
    p = [tuple(map(int, input().split())) for _ in range(n)]

    cnt = collections.Counter(x for x, _ in p)
    cnt2 = collections.Counter(y for _, y in p)
    cntp = collections.Counter(p)

    r = 0
    for k, v in cnt.most_common() + cnt2.most_common():
        r += v * (v - 1)
    for k, v in cntp.most_common():
        r -= v * (v - 1)
    return r//2


def __starting_point():
    print(solve())


__starting_point()

import collections
r=0;a,b,c=[collections.Counter() for _ in [0,0,0]]
for _ in range(int(input())):
	x,y=list(map(int, input().split()))
	r+=a[x]+b[y]-c[(x,y)]
	a[x]+=1;b[y]+=1;c[(x,y)]+=1
print(r)


from collections import defaultdict, Counter

n = int(input())

w = []
for i in range(n):
    w.append(tuple(map(int, input().split())))

dx = Counter()
dy = Counter()
for x, y in w:
    dx[x] += 1
    dy[y] += 1

count = sum((v * (v-1) / 2) for v in list(dx.values())) + \
        sum((v * (v-1) / 2) for v in list(dy.values()))

dc = Counter(w)
count -= sum((c * (c-1) / 2) for c in list(dc.values()) if c > 1)

print(int(count))


import collections
r=0;a,b,c=[collections.Counter() for _ in [0,0,0]]
for _ in range(int(input())):
	x,y=map(int, input().split())
	r+=a[x]+b[y]-c[(x,y)]
	a[x]+=1;b[y]+=1;c[(x,y)]+=1
print(r)

import collections
r=0;a,b,c=[collections.Counter() for _ in [0,0,0]]
for _ in range(int(input())):
    x,y=map(int, input().split())
    r+=a[x]+b[y]-c[(x,y)]
    a[x]+=1;b[y]+=1;c[(x,y)]+=1
print(r)

from collections import defaultdict, Counter

n = int(input())

w = []
for i in range(n):
    w.append(tuple(map(int, input().split())))

dx = Counter()
dy = Counter()
for x, y in w:
    dx[x] += 1
    dy[y] += 1

count = sum((v * (v-1) / 2) for v in list(dx.values())) + sum((v * (v-1) / 2) for v in list(dy.values()))

dc = Counter(w)
count -= sum((c * (c-1) / 2) for c in list(dc.values()) if c > 1)

print(int(count))


import re

c = 0
ds = [{},{}]
coords = {}
dup = 0
n = int(input())
for i in range(0, n):
    t = re.split(' ', input())
    T = tuple(t)
    coords[T] = 1 + (0 if (T not in coords) else (coords[T]))
    dup += coords[T]-1
    for j in range(0, len(ds)):
        ds[j][t[j]] = 1 + (0 if (t[j] not in ds[j]) else (ds[j][t[j]]) )

for i in range(0, len(ds)):
    for k, v in list(ds[i].items()):
        c += v*(v-1)/2

print(int(c-dup))
    


3
from collections import Counter
from functools import reduce

n = int(input())
x = Counter()
y = Counter()
points = Counter()
for i in range(n):
  point = list(map(int, input().split()))
  x[point[0]] += 1
  y[point[1]] += 1
  points[(point[0], point[1])] += 1
  
def getPairsNumber(n):
  return n * (n-1) // 2

def getCounterPairsNumber(counter):
  return reduce(lambda s, n: s + getPairsNumber(n), list(counter.values()), 0)

s = getCounterPairsNumber(x) + getCounterPairsNumber(y) - getCounterPairsNumber(points)
print(s)


'''
Created on Apr 30, 2016
Gmail : r.haque.249.rh@gmail.com
@author: Md. Rezwanul Haque
'''
n = int(input())
x2 = {}
y2 = {}
watchMen = {}
for i in range(n):
    watchman = tuple(map(int,input().split()))
    watchMen[watchman] = watchMen.get(watchman,0)+1
    #print(watchMen[watchman])
    x2[watchman[0]] = x2.get(watchman[0],0)+1
    #print(x2[watchman[0]])
    y2[watchman[1]] = y2.get(watchman[1],0)+1
pairs = 0
for i in watchMen.items():
    pairs -= i[1]*(i[1] - 1)//2
for i in x2.items():
    pairs += i[1]*(i[1] - 1)//2
for i in y2.items():
    pairs += i[1]*(i[1] - 1)//2
print(pairs)  

def main():
	n = int(input())
	L = [None] * n
	for i in range(n):
		(x, y) = (int(x) for x in input().split())
		L[i] = (x, y)
	print(solver(L))

def solver(L):
	xDict = dict()
	yDict = dict()
	xyDict = dict()
	for (x, y) in L:
		if (x, y) in xyDict:
			xyDict[(x, y)] += 1
		else:
			xyDict[(x, y)] = 1
	repeats = 0
	for xy in xyDict:
		n = xyDict[xy]
		repeats += n * (n - 1) // 2
	for (x, y) in L:
		if x in xDict:
			xDict[x].append(y)
		else:
			xDict[x] = [y]
		if y in yDict:
			yDict[y].append(x)
		else:
			yDict[y] = [x]
	xSames = 0
	for x in xDict:
		n = len(xDict[x])
		xSames += n * (n - 1) // 2
	ySames = 0	
	for y in yDict:
		n = len(yDict[y])
		ySames += n * (n - 1) // 2
	total = xSames + ySames - repeats
	return total
	
def almostEqual(x, y):
	return abs(x - y) < 10**-8

def distance(x1, y1, x2, y2):
	leg1 = abs(x1 - x2)
	leg2 = abs(y1 - y2)
	return (leg1**2 + leg2**2)**0.5

L = [(1, 1), (7, 5), (1, 5)]
L2 = [(0, 0), (0, 1), (0, 2), (-1, 1), (0, 1), (1, 1)]
L3 = [(0, 0), (0, 0), (0, 0)]
#print(solver(L))
main()

# for i in range(len(L)):
	# 	(x1, y1) = L[i]
	# 	for j in range(i + 1, len(L)):
	# 		(x2, y2) = L[j]
	# 		distx = abs(x1 - x2)
	# 		disty = abs(y1 - y2)
	# 		if distx == 0 or disty == 0:
	# 			count += 1
			#dist1 = abs(x1 - x2) + abs(y1 - y2)
			#dist2 = distance(x1, y1, x2, y2)
			#if almostEqual(dist1, dist2):
			#	count += 1


from collections import Counter
x, y, par, ans = Counter(), Counter(), Counter(), 0
for i in range(int(input())):
    xi, yi = map(int, input().split())
    x[xi] += 1
    y[yi] += 1
    par[(xi, yi)] += 1
for elem in x:
    ans += x[elem] * (x[elem] - 1)
for elem in y:
    ans += y[elem] * (y[elem] - 1)
for elem in par:
    ans -= par[elem] * (par[elem] - 1)
print(ans // 2)

n=int(input())
def inx(x,d):
    if x in d:
        d[x]+=1
    else:
        d[x]=1
    return d

def input2(n):
    dx={}
    dy={}
    dob={}
    ans=1
    for i in range(n):
        x,y=map(int,input().split())
        dx=inx(x,dx)
        dy=inx(y,dy)
        if (x,y) in dob:
            dob[(x,y)]+=1
        else:
            dob[(x,y)]=1
    return dx,dy,dob

dx,dy,dob=input2(n)


def ans(d):
    ans1=0
    for i in d:
        ans1+=d[i]*(d[i]-1)//2
    return ans1

myans=ans(dx)+ans(dy)-ans(dob)
print(myans) 

from collections import Counter

x, y, xy, ans = Counter(), Counter(), Counter(), 0
for i in range(int(input())):
    xi, yi = map(int, input().split())
    x[xi] += 1
    y[yi] += 1
    xy[(xi, yi)] += 1
for i in x:
    ans += x[i] * (x[i] - 1)
for i in y:
    ans += y[i] * (y[i] - 1)
for i in xy:
    ans -= xy[i] * (xy[i] - 1)
print(ans // 2)

def count(t):
  return sum(v*(v-1)//2 for v in t.values())
a,b,c={},{},{}
n=int(input())
for _ in range(n):
  x,y=map(int,input().split())
  a[x]=a.get(x,0)+1
  b[y]=b.get(y,0)+1
  c[(x,y)]=c.get((x,y),0)+1
print(count(a)+count(b)-count(c))

import collections
r=0;a,b,c=[collections.Counter() for _ in [0,0,0]]
for _ in range(int(input())):
	x,y=map(int, input().split())
	r+=a[x]+b[y]-c[(x,y)]
	a[x]+=1;b[y]+=1;c[(x,y)]+=1
print(r)

n = int(input())
w = [tuple(input().split())for _ in range(n)]
x = dict()
y = dict()
z = dict()
def add(e, d):
    if not e in d:
        d[e] = 1
    else:
        d[e] += 1
def pr(d):
    return sum(u * (u - 1) / 2 for u in list(d.values()))
for a in w:
    add(a[0], x)
    add(a[1], y)
    add(a, z)
cnt = pr(x) + pr(y) - pr(z)
print(int(cnt))


def main():
    n = int(input())
    xs, ys, clones = {}, {}, {}
    res = 0
    clones_num = 0
    points = []
    for _ in range(n):
        x, y = list(map(int, input().split()))

        if x not in xs:
            xs[x] = 0
        if y not in ys:
            ys[y] = 0
        if (x, y) not in clones:
            clones[(x, y)] = 0

        xs[x] += 1
        ys[y] += 1
        clones[(x, y)] += 1

    for c in clones:
        n = clones[c]
        clones_num += n * (n - 1) // 2

    for x in xs:
        n = xs[x]
        res += n * (n - 1) // 2

    for y in ys:
        n = ys[y]
        res += n * (n - 1) // 2

    print(res - clones_num)

def __starting_point():
    main()

__starting_point()

q={}
w={}
e={}
r=0
for _ in range(int(input())):
    x,y=map(int,input().split())
    a,s,d=q.get(x,0),w.get(y,0),e.get((x,y),0)
    r+=a+s-d
    q[x],w[y],e[x,y]=a+1,s+1,d+1
print(r)

from collections import Counter
x, y, p = Counter(), Counter(), Counter() 
for _ in range(int(input())):
   i, j = map(int, input().split())
   x[i] += 1
   y[j] += 1
   p[(i, j)] += 1
def cnt(n):
    return n * (n - 1) // 2
ans = sum(map(cnt, x.values())) + sum(map(cnt, y.values())) - sum(map(cnt, p.values()))
print(ans)