Today, Wet Shark is given n bishops on a 1000 by 1000 grid. Both rows and columns of the grid are numbered from 1 to 1000. Rows are numbered from top to bottom, while columns are numbered from left to right.

Wet Shark thinks that two bishops attack each other if they share the same diagonal. Note, that this is the only criteria, so two bishops may attack each other (according to Wet Shark) even if there is another bishop located between them. Now Wet Shark wants to count the number of pairs of bishops that attack each other.


-----Input-----

The first line of the input contains n (1 ≤ n ≤ 200 000) — the number of bishops.

Each of next n lines contains two space separated integers x_{i} and y_{i} (1 ≤ x_{i}, y_{i} ≤ 1000) — the number of row and the number of column where i-th bishop is positioned. It's guaranteed that no two bishops share the same position.


-----Output-----

Output one integer — the number of pairs of bishops which attack each other. 


-----Examples-----
Input
5
1 1
1 5
3 3
5 1
5 5

Output
6

Input
3
1 1
2 3
3 5

Output
0



-----Note-----

In the first sample following pairs of bishops attack each other: (1, 3), (1, 5), (2, 3), (2, 4), (3, 4) and (3, 5). Pairs (1, 2), (1, 4), (2, 5) and (4, 5) do not attack each other because they do not share the same diagonal.

Difficulty: interview

Starter code:

Solutions:
a=[0]*2222
b=[0]*2222
r=0
for _ in range(int(input())):
	x,y=map(int,input().split())
	r+=a[x+y]+b[x-y+1111]
	a[x+y]+=1
	b[x-y+1111]+=1
print(r)

from collections import defaultdict
n = int(input())
D1 = defaultdict(int)
D2 = defaultdict(int)
for i in range(n):
    x, y = [int(x) for x in input().split()]
    D1[x+y] += 1
    D2[x-y] += 1
print(sum(D1[k]*(D1[k]-1)//2 for k in D1) + sum(D2[k]*(D2[k]-1)//2 for k in D2))


N = int(input())
glav = [0] * 2016
pob  = [0] * 2016
for i in range(N):
    x, y = map(int, input().split())
    glav[x - y] += 1
    pob[x + y] += 1
s = 0
for i in glav:
    s += i*(i - 1) // 2
for i in pob:
    s += i*(i - 1) // 2
print(s)

n = int(input())
a = []
for i in range(n):
    a.append([int(x) - 1 for x in input().split()])
d1 = [0] * 2000
d2 = [0] * 2000
for i in a:
    d1[i[0] - i[1]] += 1
    d2[i[0] + i[1]] += 1
summ = 0
for i in range(2000):
    summ += d1[i] * (d1[i] - 1) // 2
    summ += d2[i] * (d2[i] - 1) // 2
print(summ)

dio1 = [0] * 1999
dio2 = [0] * 1999
n = int(input())
for i in range(n):
    x, y = [int(i) for i in input().split()]
    dio1[x + y - 2] += 1
    dio2[(1000 - x) + y - 1] += 1
ans = 0
for i in range(1999):
    ans += dio1[i] * (dio1[i] - 1) // 2  + dio2[i] * (dio2[i] - 1) // 2
print(ans)



n = int(input())
dl = [0] * (2000+3)
dr = [0] * (2000+3)
for i in range(n):
	x, y = map(int, input().split())
	dl[x-y]+=1
	dr[1000-x-y]+=1
ans = 0
for i in dr:
	ans += (i*(i-1))//2
for i in dl:
	ans += (i*(i-1))//2
print(ans)

n = int(input())

A = [0] * 3000
B = [0] * 3000

for i in range(n):
	x, y = list(map(int, input().split()))
	A[x + y] += 1
	B[x - y] += 1
ans = 0
for elem in A:
	ans += (elem * (elem - 1)) // 2
for elem in B:
	ans += (elem * (elem - 1)) // 2
print(ans)


#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import time

#   = input()
n   = int(input())

#() = (i for i in input().split())
#   = [i for i in input().split()]

d1 = {}
d2 = {}

for i in range(n):
    (x, y) = (int(i) for i in input().split())
    t = x - y
    if t in list(d1.keys()):
        d1[t] +=1
    else:
        d1[t] = 1

    t = x+y
    if t in list(d2.keys()):
        d2[t] +=1
    else:
        d2[t] = 1

start = time.time()

ans = 0

for i in list(d1.keys()):
    ans += d1[i]*(d1[i]-1)//2

for i in list(d2.keys()):
    ans += d2[i]*(d2[i]-1)//2

print(ans)
finish = time.time()
#print(finish - start)


from collections import defaultdict
import math

def nCr(n,r):
    f = math.factorial
    if n == 1:
        return 0
    return f(n) // (f(r) * f(n-r))

n = int(input())

right_diag = defaultdict(int)
left_diag = defaultdict(int)
for _ in range(n):
    x, y = input().split()
    x, y = int(x), int(y)
    right_diag[x-y] += 1
    left_diag[x+y] += 1

print(sum(nCr(val, 2) for val in right_diag.values()) + sum(nCr(val, 2) for val in left_diag.values()))

read = lambda: list(map(int, input().split()))
n = int(input())
N = 1001
b = [0] * 3000
c = [0] * 3000
for i in range(n):
    x, y = read()
    b[x - y + N] += 1
    c[y + x] += 1
f = lambda x: x * (x - 1) // 2
ans = sum(f(i) for i in b) + sum(f(i) for i in c)
print(ans)


n = int(input())

l, r = [0] * 1999, [0] * 1999

count = 0
for _ in range(n):
    x, y = [int(x) for x in input().split()]
    ldiag = (x + y) - 2
    rdiag = (x + (1001 - y)) - 2
    count += l[ldiag] + r[rdiag]
    l[ldiag] += 1
    r[rdiag] += 1

print(count)


n=int(input())
l=[tuple(map(int,input().split())) for i in range(n)]
d1={}
d2={}
for i in range(n):
    x,y=l[i]    
    d1[x-y]=d1.get(x-y,0)+1
    d2[y+x]=d2.get(y+x,0)+1
ans=0
for k in d1: ans+=(d1[k]-1)*d1[k]//2
for k in d2: ans+=(d2[k]-1)*d2[k]//2
print(ans)

3

n = int(input())

attack = 0
dict_a = dict()
dict_b = dict()
for i in range(n):
    (x, y) = tuple(map(int, input().split()))
    (a, b) = (x+y, x-y)
    if a in dict_a:
        attack += dict_a[a]
        dict_a[a] += 1
    else:
        dict_a[a] = 1
    if b in dict_b:
        attack += dict_b[b]
        dict_b[b] += 1
    else:
        dict_b[b] = 1

print(str(attack))


#!/usr/bin/env python3

try:
    while True:
        n = int(input())
        d = [0] * 4000
        for i in range(n):
            x, y = list(map(int, input().split()))
            d[x + y] += 1
            d[y - x + 3000] += 1
        print(sum(0 if x < 2 else x * (x - 1) >> 1 for x in d))

except EOFError:
    pass


n = int(input())
B = 1000
d = [0] * 2222
D = [0] * 2222
for i in range(n):
    x, y = list(map(int, input().split()))
    d[x - y + B] += 1
    D[x + y] += 1
s = 0
for e in d:
    if e >= 2:
        s += e * (e-1)
for e in D:
    if e >= 2:
        s += e * (e-1)
s >>= 1
print(s)


lim = int(input())
dx, dy = dict(), dict()
summ = 0
for i in range(0, lim):
	x, y =(int(j) for j in input().split())
	diagx = x+y
	diagy = x-y
	if diagx in dx:
		dx[diagx]+=1
	else:
		dx[diagx]=1
	if diagy in dy:
		dy[diagy]+=1
	else:
		dy[diagy]=1
for i in dx:
	summ+= dx[i]*(dx[i]-1)//2
for i in dy:
	summ+= dy[i]*(dy[i]-1)//2
print(summ)

n = int(input())
ar = []
for i in range(n):
    a, b = [int(i) for i in input().split()]
    ar.append((a - b, a + b))
c = [[0, 0] for i in range(2001)]
for i in range(n):
    c[ar[i][0] + 999][0] += 1
    c[ar[i][1]][1] += 1
ct = 0
for i in range(2001):
    ct += (c[i][0] * (c[i][0] - 1) + c[i][1] * (c[i][1] - 1)) // 2
print(ct)


def nC2(n):
    return n * (n - 1) // 2

SIZE = 1000

N = int(input())
a = [[0] * SIZE for i in range(SIZE)]
for i in range(N):
    x, y = map(int, input().split())
    a[x-1][y-1] = 1

ans = 0

#1
for sx in range(SIZE):
    t_cnt = 0
    
    x = sx; y = 0;
    while x >= 0:
        t_cnt += a[x][y]
        x -= 1; y += 1
        
    ans += nC2(t_cnt)

#2
for sy in range(1, SIZE):
    t_cnt = 0
    
    x = SIZE - 1; y = sy;
    while y < SIZE:
        t_cnt += a[x][y]
        x -= 1; y += 1
        
    ans += nC2(t_cnt)

#3
for sx in range(SIZE):
    t_cnt = 0
    
    x = sx; y = 0;
    while x < SIZE:
        t_cnt += a[x][y]
        x += 1; y += 1
        
    ans += nC2(t_cnt)

#4
for sy in range(1, SIZE):
    t_cnt = 0
    
    x = 0; y = sy;
    while y < SIZE:
        t_cnt += a[x][y]
        x += 1; y += 1
        
    ans += nC2(t_cnt)

print(ans)

import math

n = int(input())

a = [0 for t in range(2, 2001)]
b = [0 for t in range(-999, +1000)]
for i in range(n):
    x, y = [int(t) for t in input().split()]

    a[x+y-2] += 1
    b[x-y+999] += 1

ans = 0
for pos in a:
    if pos > 1:
        head = math.factorial(pos)
        tail = 2*math.factorial(pos-2)
        ans += int(head/tail)

for pos in b:
    if pos > 1:
        head = math.factorial(pos)
        tail = 2*math.factorial(pos-2)
        ans += int(head/tail)

print(int(ans))


n = int(input())
a = [True]*1999
a1 = [0]*1999
b = [True]*1999
b1 = [0]*1999
ans = 0
for i in range(n):
    x,y = map(int,input().split())
    d = x - y
    s = x + y
    k = d + 999
    l = s - 2
    if a[k]:
        a[k] = False
        a1[k] += 1
    else:
        #print('!!!')
        ans += a1[k]
        a1[k] += 1
    if b[l]:
        b[l] = False
        b1[l] += 1
    else:
        #print('!!!')
        ans += b1[l]
        b1[l] += 1
#print(a)
#print(a1)
#print(b)
#print(b1)
print(ans)

from math import factorial
T = int(input())
a = {}
b = {}
for i in range(T):
	n, m = list(map(int, input().split(' ')))
	if n-m in a:
		a[n-m] += 1
	elif n-m not in a:
		a[n-m] = 1

	if n+m in b:
		b[n+m] += 1
	elif m+n not in b:
		b[n+m] = 1

ans = 0
for i in a:
	if a[i]>1:
		ans += factorial(a[i])//(2*factorial(a[i]-2))

for i in b:
	if b[i]>1:
		ans += factorial(b[i])//(2*factorial(b[i]-2))
print(ans)

n = int(input())

pos = {}
neg = {}

for _ in range(n):
    x, y = list(map(int, input().split()))
    if x-y not in pos:
        pos[x-y] = 0
    if x+y not in neg:
        neg[x+y] = 0

    pos[x-y] += 1
    neg[x+y] += 1

ret = 0

for _, cnt in list(pos.items()):
    ret += cnt*(cnt-1)/2

for _, cnt in list(neg.items()):
    ret += cnt*(cnt-1)/2

print(int(ret))


n = int(input())
def main(n):
 p = []
 q = []
 for i in range(2):
     p.append([0] * 1000)
 for i in range(2):
     q.append([0] * 1000)
 for i in range(n):
     x, y = list(map(int, input().split()))
     x1, y1, x2, y2 = x - 1, y - 1, x - 1, y - 1
     x1, y1 = x1 - min(x1, y1), y1 - min(x1, y1)
     if x1 == 0:
         p[1][y1] += 1
     else:
         p[0][x1] += 1
     while y2 < 999 and x2 > 0:
         x2 -= 1
         y2 += 1
     if y2 == 999:
         q[1][x2] += 1
     else:
         q[0][y2] += 1
 sum = 0
 for i in range(2):
     for t in range(1000):
         sum += (p[i][t] * (p[i][t] - 1)) // 2
 for i in range(2):
     for t in range(1000):
         sum += (q[i][t] * (q[i][t] - 1)) // 2
 print(sum)
main(n)

       
    
        


n = int(input())
K = [list(map(int, input().split())) for i in range(n)]
D1 = [0] * 2000
D2 = [0] * 2000
for i in range(len(K)):
    D1[K[i][0] - K[i][1] + 1000] += 1
    D2[K[i][0] - (1001 - K[i][1]) + 1000] += 1
P1 = 0
for e in D1:
    P1 += e * (e - 1) // 2
P2 = 0
for e in D2:
    P2 += e * (e - 1) // 2
print(P1 + P2)