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: EASY
Tags: Combinatorics

Implementation

Starter code:

Solutions:
from collections import defaultdict, deque, Counter
from sys import stdin, stdout
from heapq import heappush, heappop
import math
import io
import os
import math
import bisect

def isPrime(x):
	for i in range(2, x):
		if i * i > x:
			break
		if x % i == 0:
			return False
	return True

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(int(i))
			n = n / i
	if n > 2:
		l.append(n)
	return list(set(l))

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def digits(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def ceil(n, x):
	if n % x == 0:
		return n // x
	return n // x + 1

def mapin():
	return map(int, input().split())

def solve(l, r, p):
	return r // p - (l - 1) // p
n = int(input())
k = defaultdict(lambda : 0)
kk = defaultdict(lambda : 0)
for i in range(n):
	(x, y) = mapin()
	k[x + y] += 1
	kk[x - y] += 1
ans = 0
for i in k:
	ans += k[i] * (k[i] - 1) // 2
for i in kk:
	ans += kk[i] * (kk[i] - 1) // 2
print(ans)


from collections import Counter
import math
n = int(input())
ls = {}
arr = {}
for i in range(n):
	(n, m) = map(int, input().split())
	if n + m not in ls:
		ls[n + m] = 1
	else:
		ls[n + m] += 1
	if n - m not in arr:
		arr[n - m] = 1
	else:
		arr[n - m] += 1
ans = 0
for i in ls:
	if ls[i] > 1:
		ans += ls[i] * (ls[i] - 1) // 2
for i in arr:
	if arr[i] > 1:
		ans += arr[i] * (arr[i] - 1) // 2
print(ans)


from collections import defaultdict
n = int(input())
d = defaultdict(int)
e = defaultdict(int)
for i in range(n):
	(x, y) = map(int, input().split())
	d[x + y] += 1
	e[y - (x - 1)] += 1
ans = 0
for i in d.keys():
	ans += d[i] * (d[i] - 1) // 2
for i in e.keys():
	ans += e[i] * (e[i] - 1) // 2
print(ans)


n = int(input())
pine = dict()
mine = dict()
for _ in range(n):
	(a, b) = map(int, input().split())
	pine[a + b] = pine.setdefault(a + b, 0) + 1
	mine[a - b] = mine.setdefault(a - b, 0) + 1
rest = 0
for v in pine.values():
	if v > 1:
		rest += v * (v - 1) // 2
for v in mine.values():
	if v > 1:
		rest += v * (v - 1) // 2
print(rest)


import sys
import math
import collections
import bisect

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()
for t in range(1):
	n = int(input())
	plus = dict()
	minus = dict()
	for i in range(n):
		(x, y) = get_ints()
		if x + y in plus:
			plus[x + y] += 1
		else:
			plus[x + y] = 1
		if x - y in minus:
			minus[x - y] += 1
		else:
			minus[x - y] = 1
	ans = 0
	for i in plus:
		if plus[i] > 1:
			ans += plus[i] * (plus[i] - 1) // 2
	for i in minus:
		if minus[i] > 1:
			ans += minus[i] * (minus[i] - 1) // 2
	print(ans)


n = int(input())
mns = {}
pls = {}
cnt = 0
for i in range(n):
	(x, y) = map(int, input().split())
	mns[x - y] = mns.get(x - y, 0) + 1
	pls[x + y] = pls.get(x + y, 0) + 1
for item in mns.values():
	cnt += item * (item - 1) // 2
for item in pls.values():
	if item > 1:
		cnt += item * (item - 1) // 2
print(cnt)


add = {}
diff = {}
for _ in range(int(input())):
	(a, b) = [int(x) for x in input().split()]
	if a + b in add:
		add[a + b] += 1
	else:
		add[a + b] = 1
	if b - a in diff:
		diff[b - a] += 1
	else:
		diff[b - a] = 1
ans = 0
for i in add:
	if add[i] > 1:
		ans += add[i] * (add[i] - 1) // 2
for i in diff:
	if diff[i] > 1:
		ans += diff[i] * (diff[i] - 1) // 2
print(ans)


def c2(m):
	return d * (d - 1) // 2
m = 1000
n = int(input())
d1 = [0] * (2 * m - 1)
d2 = [0] * (2 * m - 1)
for _ in range(n):
	(x, y) = [int(s) for s in input().strip().split()]
	d1[x + y - 1 - 1] += 1
	d2[m - (x - y) - 1] += 1
res = 0
for d in d1:
	if d > 1:
		res += c2(d)
for d in d2:
	if d > 1:
		res += c2(d)
print(res)


import sys
n = int(sys.stdin.readline())
a = []
b = []
res = 0
for i in range(n):
	(_a, _b) = list(map(int, sys.stdin.readline().split()))
	a.append(_a + _b)
	b.append(_a - _b)
a.sort()
b.sort()
i = 0
while i < n:
	cnt = 1
	while i + 1 < len(a) and a[i] == a[i + 1]:
		cnt += 1
		i += 1
	res += cnt * (cnt - 1) // 2
	i += 1
i = 0
while i < n:
	cnt = 1
	while i + 1 < len(b) and b[i] == b[i + 1]:
		cnt += 1
		i += 1
	res += cnt * (cnt - 1) // 2
	i += 1
print(res)


m = 1000
n = int(input())
arr = [list(map(int, input().split())) for _ in range(n)]
arr2 = [m + 1 + i - j for (i, j) in arr]
arr = [i + j for (i, j) in arr]
dic = {}
dic2 = {}
ans = 0
for i in range(n):
	dic[arr[i]] = dic.get(arr[i], 0) + 1
	dic2[arr2[i]] = dic2.get(arr2[i], 0) + 1
for i in dic.keys():
	if dic[i] >= 2:
		ans += dic[i] * (dic[i] - 1) // 2
for i in dic2.keys():
	if dic2[i] >= 2:
		ans += dic2[i] * (dic2[i] - 1) // 2
print(ans)


n = int(input())
b = {}
d = {}
for _ in range(n):
	(i, j) = map(int, input().split(' '))
	x = b.get(i - j, 0)
	b[i - j] = x + 1
	x = d.get(i + j, 0)
	d[i + j] = x + 1
a = 0
for i in b.keys():
	a += 0.5 * b[i] * (b[i] - 1)
for j in d.keys():
	a += 0.5 * d[j] * (d[j] - 1)
print(int(a))


n = int(input())
a = [0] * 2002
b = [0] * 2002
for i in range(n):
	(c, d) = map(int, input().split())
	a[c + d] += 1
	b[c - d + 1000] += 1
su = 0
for i in range(2002):
	su += a[i] * (a[i] - 1) // 2
	su += b[i] * (b[i] - 1) // 2
print(su)


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)


import sys
from collections import Counter

def read(line):
	return [int(c) for c in line.split()]

def main():
	input()
	test_input = sys.stdin.readlines()
	pairs = [read(line) for line in test_input]
	diags_prc = Counter()
	diags_snd = Counter()
	for (r, c) in pairs:
		diags_prc[r - c] += 1
		diags_snd[r + c] += 1
	ans = sum((v * (v - 1) // 2 for v in diags_prc.values()))
	ans += sum((v * (v - 1) // 2 for v in diags_snd.values()))
	print(ans)
main()


import bisect
from itertools import accumulate
import os
import sys
import math
from decimal import *
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def SieveOfEratosthenes(n):
	prime = []
	primes = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if primes[p] == True:
			prime.append(p)
			for i in range(p * p, n + 1, p):
				primes[i] = False
		p += 1
	return prime

def primefactors(n):
	fac = []
	while n % 2 == 0:
		fac.append(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 2):
		while n % i == 0:
			fac.append(i)
			n = n // i
	if n > 1:
		fac.append(n)
	return fac

def factors(n):
	fac = set()
	fac.add(1)
	fac.add(n)
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			fac.add(i)
			fac.add(n // i)
	return list(fac)
ans1 = [0] * 2222
ans2 = [0] * 2222
ans = 0
for _ in range(int(input())):
	(x, y) = map(int, input().split())
	ans += ans1[x + y] + ans2[x - y]
	ans1[x + y] += 1
	ans2[x - y] += 1
print(ans)


d_p = {}
d_s = {}
n_p = int(input())
t = 0
for i in range(n_p):
	(x, y) = map(int, input().split())
	a = x + y
	s = x - y
	if a not in d_p:
		d_p[a] = 0
	if s not in d_s:
		d_s[s] = 0
	d_p[a] += 1
	d_s[s] += 1
	t += d_p[a] - 1
	t += d_s[s] - 1
print(t)


def main():
	n = int(input())
	(xd, yd) = ({}, {})
	for i in range(n):
		(x, y) = map(int, input().split())
		(x, y) = (y + x, y - x)
		if x in xd:
			xd[x] += 1
		else:
			xd[x] = 1
		if y in yd:
			yd[y] += 1
		else:
			yd[y] = 1
	ans = 0

	def nc2(n):
		return n * (n - 1) // 2
	for i in xd:
		ans += nc2(xd[i])
	for i in yd:
		ans += nc2(yd[i])
	print(ans)
main()


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


n = int(input())
data = [[0] * 1000 for i in range(1000)]
for i in range(n):
	(x, y) = map(int, input().split())
	data[x - 1][y - 1] = 1
answer = 0
for i in range(1000):
	j = 0
	counter = 0
	while i < 1000:
		if data[i][j] == 1:
			counter += 1
		i += 1
		j += 1
	answer += counter * (counter - 1) // 2
for i in range(1000):
	counter = 0
	j = 999
	while i < 1000:
		if data[i][j] == 1:
			counter += 1
		i += 1
		j -= 1
	answer += counter * (counter - 1) // 2
for j in range(1, 1000):
	i = 0
	counter = 0
	while j < 1000:
		if data[i][j] == 1:
			counter += 1
		i += 1
		j += 1
	answer += counter * (counter - 1) // 2
for j in range(1, 999):
	i = 0
	counter = 0
	while -1 < j:
		if data[i][j] == 1:
			counter += 1
		j -= 1
		i += 1
	answer += counter * (counter - 1) // 2
print(answer)


import sys
n = int(input())
(M1, M2) = ({}, {})
for i in range(n):
	(x, y) = map(int, input().split())
	M1[x + y] = M1.get(x + y, 0) + 1
	M2[x - y] = M2.get(x - y, 0) + 1
ans = 0
for cnt in M1.values():
	ans += cnt * (cnt - 1)
for cnt in M2.values():
	ans += cnt * (cnt - 1)
print(ans // 2)


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


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))


d_p = {}
d_s = {}
n_p = int(input())
t = 0
for i in range(n_p):
	(x, y) = map(int, input().split())
	if y != 1:
		d_n = 1 - y
		d = -(1 - y)
		s_n1 = x - d_n
		s_1 = x - d
		if s_n1 not in d_s:
			d_s[s_n1] = 0
		if s_1 not in d_p:
			d_p[s_1] = 0
		d_s[s_n1] += 1
		d_p[s_1] += 1
		t += d_s[s_n1] + d_p[s_1] - 2
	else:
		if x not in d_p:
			d_p[x] = 0
		if x not in d_s:
			d_s[x] = 0
		d_p[x] += 1
		d_s[x] += 1
		t += d_p[x] + d_s[x] - 2
print(t)


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


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) = 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())
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)


n = int(input())
a = [0] * 3000
b = [0] * 3000
for _ in range(0, n):
	(x, y) = map(int, input().split())
	a[x + y] += 1
	b[x - y + 1000] += 1
ans = 0
for u in a:
	ans += u * (u - 1) // 2
for u in b:
	ans += u * (u - 1) // 2
print(ans)


fast = lambda : stdin.readline().strip()
zzz = lambda : [int(i) for i in fast().split()]
(z, zz) = (input, lambda : list(map(int, z().split())))
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))
from re import *
from sys import *
from math import *
from heapq import *
from queue import *
from bisect import *
from string import *
from itertools import *
from collections import *
from math import factorial as f
from bisect import bisect as bs
from bisect import bisect_left as bsl
from collections import Counter as cc
from itertools import accumulate as ac

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def output(answer):
	stdout.write(str(answer))
num = int(z())
(p, m, ans) = ([0] * 2100, [0] * 2100, 0)
for _ in range(num):
	(x, y) = zzz()
	ans += p[x + y] + m[x - y]
	p[x + y] += 1
	m[x - y] += 1
print(ans)


from collections import defaultdict as f
(n, d, e, s) = (int(input()), f(int), f(int), 0)
for i in range(n):
	(x, y) = map(int, input().split())
	d[x + y] += 1
	e[y - (x - 1)] += 1
for i in d.keys():
	s += d[i] * (d[i] - 1) // 2
for i in e.keys():
	s += e[i] * (e[i] - 1) // 2
print(s)


n = int(input())
(cnt1, cnt2) = ({}, {})
for i in range(n):
	(x, y) = map(int, input().split())
	cnt1[x + y] = cnt1.get(x + y, 0) + 1
	cnt2[x - y] = cnt2.get(x - y, 0) + 1
ans = 0
for t in cnt1.values():
	ans += t * (t - 1) // 2
for t in cnt2.values():
	ans += t * (t - 1) // 2
print(ans)


n = int(input())
l = {}
t = {}
inp = []
for i in range(n):
	(x, y) = map(int, input().split(' '))
	inp.append((x, y))
	l[x - y] = l.get(x - y, 0) + 1
	t[x + y] = t.get(x + y, 0) + 1
sol = 0
for i in inp:
	(x, y) = i
	sol += l[x - y] - 1
	sol += t[x + y] - 1
print(sol // 2)


from sys import *
from math import *
n = int(stdin.readline())
m = []
for i in range(n):
	a = list(map(int, stdin.readline().split()))
	m.append(a)
x = [0] * 2002
y1 = [0] * 2002
y2 = [0] * 2002
for i in range(n):
	x[m[i][0] + m[i][1]] += 1
	v = m[i][0] - m[i][1]
	if v < 0:
		y1[abs(v)] += 1
	else:
		y2[v] += 1
ans = 0
for i in range(2002):
	if x[i] != 0:
		ans += x[i] * (x[i] - 1) // 2
	if y1[i] != 0:
		ans += y1[i] * (y1[i] - 1) // 2
	if y2[i] != 0:
		ans += y2[i] * (y2[i] - 1) // 2
print(ans)


n = int(input())
B = 1000
d = [0] * 2222
D = [0] * 2222
for i in range(n):
	(x, y) = 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)


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)


n = int(input())
ID = {}
DI = {}
for i in range(n):
	(x, y) = map(int, input().split())
	if x - y not in ID:
		ID[x - y] = 1
	else:
		ID[x - y] += 1
	if x + y not in DI:
		DI[x + y] = 1
	else:
		DI[x + y] += 1
res = 0
for i in DI.values():
	res += i * (i - 1) // 2
for i in ID.values():
	res += i * (i - 1) // 2
print(res)


n = int(input())
left_diagonals = {}
right_diagonals = {}

def add_value(a, diagonals):
	if a not in diagonals:
		diagonals[a] = 1
	else:
		diagonals[a] += 1
for i in range(0, n):
	(x, y) = list([int(j) for j in input().split()])
	if x == 1:
		add_value(y, left_diagonals)
		add_value(y, right_diagonals)
	else:
		add_value(y - (x - 1), left_diagonals)
		add_value(y + (x - 1), right_diagonals)
summa = 0
for i in left_diagonals.values():
	summa += (i - 1) * i // 2
for i in right_diagonals.values():
	summa += (i - 1) * i // 2
print(summa)


try:
	while True:
		n = int(input())
		d = [0] * 4000
		for i in range(n):
			(x, y) = 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())
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())
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())
rows = []
columns = []
for x in range(n):
	string = input()
	numbers = string.split()
	rows.append(int(numbers[0]))
	columns.append(int(numbers[1]))
vx = [0 for x in range(1999)]
vy = [0 for x in range(1999)]
for x in range(n):
	r = rows[x]
	c = columns[x]
	vx[r - c] += 1
	vy[1001 - r - c] += 1
a = sum(list(map(lambda x: x * (x - 1) // 2, vx + vy)))
print(a)


n = int(input())
dia1 = [0 for i in range(2005)]
dia2 = [0 for i in range(2005)]
for i in range(n):
	(a, b) = map(int, input().split(' '))
	dia1[a + b] += 1
	dia2[a - b + 1000] += 1
sums = 0
for i in range(len(dia1)):
	sums += dia1[i] * (dia1[i] - 1) / 2 + dia2[i] * (dia2[i] - 1) / 2
print(int(sums))


N = int(input())
diag1 = [0 for _ in range(2000)]
diag2 = [0 for _ in range(2000)]
for _ in range(N):
	(a, b) = map(int, input().split())
	(a, b) = (a - 1, b - 1)
	diag1[a + b] += 1
	diag2[a - b] += 1

def blah(n):
	return n * (n - 1) // 2
total = sum(map(blah, diag1)) + sum(map(blah, diag2))
print(total)


from collections import Counter
n = int(input())
(d, D) = (Counter(), Counter())
for _ in range(n):
	(a, b) = map(int, input().split())
	d[a + b - 1] += 1
	D[a + 1001 - b - 1] += 1
res = 0
for x in d.values():
	res += x * (x - 1) // 2
for x in D.values():
	res += x * (x - 1) // 2
print(res)


d = {}
d1 = {}
ans = 0
for _ in range(int(input())):
	(x, y) = map(int, input().split())
	d[x + y] = d.get(x + y, 0) + 1
	d1[x - y] = d1.get(x - y, 0) + 1
for k in d:
	if d[k] > 1:
		ans += d[k] * (d[k] - 1) // 2
for z in d1:
	if d1[z] > 1:
		ans += d1[z] * (d1[z] - 1) // 2
print(ans)


n = int(input())
d = {}
su = {}
final = 0
for i in range(n):
	s = list(map(int, input().split()))
	if s[1] - s[0] in d:
		d[s[1] - s[0]] += 1
	else:
		d[s[1] - s[0]] = 1
	if s[1] + s[0] in su:
		su[s[1] + s[0]] += 1
	else:
		su[s[1] + s[0]] = 1
for i in d:
	final += d[i] * (d[i] - 1) // 2
for j in su:
	final += su[j] * (su[j] - 1) // 2
print(final)


n = int(input())
lis1 = {}
lis2 = {}
ans = 0
for _ in range(n):
	(x, y) = map(int, input().split())
	soma = x + y
	subt = x - y
	ans += lis1.get(soma, 0) + lis2.get(subt, 0)
	lis1[soma] = lis1.get(soma, 0) + 1
	lis2[subt] = lis2.get(subt, 0) + 1
print(ans)


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)


import collections
n = int(input())
diag1 = collections.Counter()
diag2 = collections.Counter()
for _ in range(n):
	(x, y) = map(int, input().split())
	diag1[x - y] += 1
	diag2[y + x] += 1
res = 0
for (c, v) in diag1.most_common():
	res += v * (v - 1)
for (c, v) in diag2.most_common():
	res += v * (v - 1)
print(res // 2)


n = int(input())
cnt = [0] * 3000
cnt2 = [0] * 3000
for i in range(0, n):
	(r, c) = map(int, input().split())
	cnt[r - c + 1000] += 1
	cnt2[r + c] += 1
ans = 0
for i in cnt:
	ans += i * (i - 1) // 2
for i in cnt2:
	ans += i * (i - 1) // 2
print(ans)


from sys import stdin
z = [0] * 2001
z1 = [0] * 2001
x = lambda y: y * (y - 1) // 2
ans = 0
for _ in ' ' * int(stdin.readline()):
	(u, v) = map(int, stdin.readline().split())
	z[u + v] += 1
	z1[u - v] += 1
print(sum((x(z[i]) + x(z1[i]) for i in range(2001))))


def f():
	r = 0
	f = 2000 * [0]
	l = 2000 * [0]
	input()
	import sys
	for i in sys.stdin.readlines():
		[a, b] = list(map(int, i.split(' ')))
		k = 1000 + a - b
		r += f[k]
		f[k] += 1
		k = a + b - 2
		r += l[k]
		l[k] += 1
	print(r)
f()


X = [0 for _ in range(2001)]
Y = [0 for _ in range(2001)]
ans = 0
for _ in range(int(input())):
	(x, y) = [int(_) for _ in input().split()]
	ans += X[x + y] + Y[x - y]
	X[x + y] += 1
	Y[x - y] += 1
print(ans)


import sys

def input():
	return sys.stdin.readline().strip()
n = int(input())
add = {}
low = {}
up = {}
for i in range(n):
	(a, b) = map(int, input().split())
	try:
		add[a + b] += 1
	except:
		add[a + b] = 1
	if a > b:
		try:
			low[a - b] += 1
		except:
			low[a - b] = 1
	else:
		try:
			up[b - a] += 1
		except:
			up[b - a] = 1
count = 0
for i in add:
	count += (add[i] - 1) * add[i] / 2
for i in low:
	count += (low[i] - 1) * low[i] / 2
for i in up:
	count += (up[i] - 1) * up[i] / 2
print(int(count))


n = int(input())
a = [0] * n
b = [0] * n
for i in range(n):
	(a[i], b[i]) = map(int, input().split())
(s, diag1, diag2) = ([0] * 10000, [0] * 20000, [0] * 20000)
cnt = 0
for i in range(n):
	s[a[i] + b[i]] += 1
	if a[i] == b[i]:
		cnt += 1
	elif a[i] > b[i]:
		diag1[a[i] - b[i]] += 1
	else:
		diag2[b[i] - a[i]] += 1
res = 0
for i in s:
	if i > 0:
		res += i * (i - 1) / 2
for i in diag1:
	if i > 0:
		res += i * (i - 1) / 2
for i in diag2:
	if i > 0:
		res += i * (i - 1) / 2
print(int(res + cnt * (cnt - 1) // 2))


import math
n = int(input())
x = []
y = []
z = []
for i in range(20005):
	x.append(0)
	y.append(0)
of = 999
for _ in range(n):
	(a, b) = map(int, input().split())
	if x[a + b] > 0:
		x[a + b] += 1
	else:
		x[a + b] = 1
	if y[a - b + of] > 0:
		y[a - b + of] += 1
	else:
		y[a - b + of] = 1
s = 0
for i in x:
	if i > 1:
		s += i * (i - 1) // 2
for j in y:
	if j > 1:
		s += j * (j - 1) // 2
print(int(s))


n = int(input())
l = []
a = [0] * 2003
b = [0] * 2003
ans = 0
for i in range(n):
	(x, y) = map(int, input().split())
	ans = ans + a[x + y] + b[x - y]
	a[x + y] += 1
	b[x - y] += 1
print(ans)


import random, math
from copy import deepcopy as dc

def randomNumber(s, e):
	return random.randint(s, e)

def randomArray(s, e, s_size, e_size):
	size = random.randint(s_size, e_size)
	arr = [randomNumber(s, e) for i in range(size)]
	return arr

def testcase():
	pass

def brute():
	pass

def effe():
	pass

def solution(pos, maxi):
	adj = []
	count = 0
	for y in range(maxi):
		adj1 = []
		x = 0
		y1 = dc(y)
		c = 0
		while x < maxi and y1 < maxi:
			if pos[x][y1]:
				c += 1
			x += 1
			y1 += 1
		c = c * (c - 1) // 2
		count += c
	for x in range(1, maxi):
		y = 0
		adj1 = []
		x1 = dc(x)
		c = 0
		while x1 < maxi and y < maxi:
			if pos[x1][y]:
				c += 1
			x1 += 1
			y += 1
		c = c * (c - 1) // 2
		count += c
	for y in range(maxi - 1, -1, -1):
		x = 0
		adj1 = []
		y1 = dc(y)
		c = 0
		while x < maxi and y1 >= 0:
			if pos[x][y1]:
				c += 1
			x += 1
			y1 -= 1
		c = c * (c - 1) // 2
		count += c
	for x in range(1, maxi):
		y = maxi - 1
		adj1 = []
		x1 = dc(x)
		c = 0
		while x1 < maxi and y >= 0:
			if pos[x1][y]:
				c += 1
			x1 += 1
			y -= 1
		c = c * (c - 1) // 2
		count += c
	return count

def input_test():
	pos = [[0 for i in range(1000)] for j in range(1000)]
	maxi = float('-inf')
	for _ in range(int(input())):
		(x, y) = map(int, input().strip().split(' '))
		pos[x - 1][y - 1] = 1
		maxi = max(maxi, x, y)
	out = solution(pos, maxi)
	print(out)

def test():
	pass
input_test()


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)


(diag, antidiag) = ([0] * 2005, [0] * 2005)
for _ in range(int(input())):
	(i, j) = map(int, input().split())
	diag[i + j] += 1
	antidiag[j - i + 1000] += 1
ans = 0
for (d, a) in zip(diag, antidiag):
	ans += d * (d - 1) // 2 + a * (a - 1) // 2
print(ans)


binomials = [0, 0, 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66, 78, 91, 105, 120, 136, 153, 171, 190, 210, 231, 253, 276, 300, 325, 351, 378, 406, 435, 465, 496, 528, 561, 595, 630, 666, 703, 741, 780, 820, 861, 903, 946, 990, 1035, 1081, 1128, 1176, 1225, 1275, 1326, 1378, 1431, 1485, 1540, 1596, 1653, 1711, 1770, 1830, 1891, 1953, 2016, 2080, 2145, 2211, 2278, 2346, 2415, 2485, 2556, 2628, 2701, 2775, 2850, 2926, 3003, 3081, 3160, 3240, 3321, 3403, 3486, 3570, 3655, 3741, 3828, 3916, 4005, 4095, 4186, 4278, 4371, 4465, 4560, 4656, 4753, 4851, 4950, 5050, 5151, 5253, 5356, 5460, 5565, 5671, 5778, 5886, 5995, 6105, 6216, 6328, 6441, 6555, 6670, 6786, 6903, 7021, 7140, 7260, 7381, 7503, 7626, 7750, 7875, 8001, 8128, 8256, 8385, 8515, 8646, 8778, 8911, 9045, 9180, 9316, 9453, 9591, 9730, 9870, 10011, 10153, 10296, 10440, 10585, 10731, 10878, 11026, 11175, 11325, 11476, 11628, 11781, 11935, 12090, 12246, 12403, 12561, 12720, 12880, 13041, 13203, 13366, 13530, 13695, 13861, 14028, 14196, 14365, 14535, 14706, 14878, 15051, 15225, 15400, 15576, 15753, 15931, 16110, 16290, 16471, 16653, 16836, 17020, 17205, 17391, 17578, 17766, 17955, 18145, 18336, 18528, 18721, 18915, 19110, 19306, 19503, 19701, 19900, 20100, 20301, 20503, 20706, 20910, 21115, 21321, 21528, 21736, 21945, 22155, 22366, 22578, 22791, 23005, 23220, 23436, 23653, 23871, 24090, 24310, 24531, 24753, 24976, 25200, 25425, 25651, 25878, 26106, 26335, 26565, 26796, 27028, 27261, 27495, 27730, 27966, 28203, 28441, 28680, 28920, 29161, 29403, 29646, 29890, 30135, 30381, 30628, 30876, 31125, 31375, 31626, 31878, 32131, 32385, 32640, 32896, 33153, 33411, 33670, 33930, 34191, 34453, 34716, 34980, 35245, 35511, 35778, 36046, 36315, 36585, 36856, 37128, 37401, 37675, 37950, 38226, 38503, 38781, 39060, 39340, 39621, 39903, 40186, 40470, 40755, 41041, 41328, 41616, 41905, 42195, 42486, 42778, 43071, 43365, 43660, 43956, 44253, 44551, 44850, 45150, 45451, 45753, 46056, 46360, 46665, 46971, 47278, 47586, 47895, 48205, 48516, 48828, 49141, 49455, 49770, 50086, 50403, 50721, 51040, 51360, 51681, 52003, 52326, 52650, 52975, 53301, 53628, 53956, 54285, 54615, 54946, 55278, 55611, 55945, 56280, 56616, 56953, 57291, 57630, 57970, 58311, 58653, 58996, 59340, 59685, 60031, 60378, 60726, 61075, 61425, 61776, 62128, 62481, 62835, 63190, 63546, 63903, 64261, 64620, 64980, 65341, 65703, 66066, 66430, 66795, 67161, 67528, 67896, 68265, 68635, 69006, 69378, 69751, 70125, 70500, 70876, 71253, 71631, 72010, 72390, 72771, 73153, 73536, 73920, 74305, 74691, 75078, 75466, 75855, 76245, 76636, 77028, 77421, 77815, 78210, 78606, 79003, 79401, 79800, 80200, 80601, 81003, 81406, 81810, 82215, 82621, 83028, 83436, 83845, 84255, 84666, 85078, 85491, 85905, 86320, 86736, 87153, 87571, 87990, 88410, 88831, 89253, 89676, 90100, 90525, 90951, 91378, 91806, 92235, 92665, 93096, 93528, 93961, 94395, 94830, 95266, 95703, 96141, 96580, 97020, 97461, 97903, 98346, 98790, 99235, 99681, 100128, 100576, 101025, 101475, 101926, 102378, 102831, 103285, 103740, 104196, 104653, 105111, 105570, 106030, 106491, 106953, 107416, 107880, 108345, 108811, 109278, 109746, 110215, 110685, 111156, 111628, 112101, 112575, 113050, 113526, 114003, 114481, 114960, 115440, 115921, 116403, 116886, 117370, 117855, 118341, 118828, 119316, 119805, 120295, 120786, 121278, 121771, 122265, 122760, 123256, 123753, 124251, 124750, 125250, 125751, 126253, 126756, 127260, 127765, 128271, 128778, 129286, 129795, 130305, 130816, 131328, 131841, 132355, 132870, 133386, 133903, 134421, 134940, 135460, 135981, 136503, 137026, 137550, 138075, 138601, 139128, 139656, 140185, 140715, 141246, 141778, 142311, 142845, 143380, 143916, 144453, 144991, 145530, 146070, 146611, 147153, 147696, 148240, 148785, 149331, 149878, 150426, 150975, 151525, 152076, 152628, 153181, 153735, 154290, 154846, 155403, 155961, 156520, 157080, 157641, 158203, 158766, 159330, 159895, 160461, 161028, 161596, 162165, 162735, 163306, 163878, 164451, 165025, 165600, 166176, 166753, 167331, 167910, 168490, 169071, 169653, 170236, 170820, 171405, 171991, 172578, 173166, 173755, 174345, 174936, 175528, 176121, 176715, 177310, 177906, 178503, 179101, 179700, 180300, 180901, 181503, 182106, 182710, 183315, 183921, 184528, 185136, 185745, 186355, 186966, 187578, 188191, 188805, 189420, 190036, 190653, 191271, 191890, 192510, 193131, 193753, 194376, 195000, 195625, 196251, 196878, 197506, 198135, 198765, 199396, 200028, 200661, 201295, 201930, 202566, 203203, 203841, 204480, 205120, 205761, 206403, 207046, 207690, 208335, 208981, 209628, 210276, 210925, 211575, 212226, 212878, 213531, 214185, 214840, 215496, 216153, 216811, 217470, 218130, 218791, 219453, 220116, 220780, 221445, 222111, 222778, 223446, 224115, 224785, 225456, 226128, 226801, 227475, 228150, 228826, 229503, 230181, 230860, 231540, 232221, 232903, 233586, 234270, 234955, 235641, 236328, 237016, 237705, 238395, 239086, 239778, 240471, 241165, 241860, 242556, 243253, 243951, 244650, 245350, 246051, 246753, 247456, 248160, 248865, 249571, 250278, 250986, 251695, 252405, 253116, 253828, 254541, 255255, 255970, 256686, 257403, 258121, 258840, 259560, 260281, 261003, 261726, 262450, 263175, 263901, 264628, 265356, 266085, 266815, 267546, 268278, 269011, 269745, 270480, 271216, 271953, 272691, 273430, 274170, 274911, 275653, 276396, 277140, 277885, 278631, 279378, 280126, 280875, 281625, 282376, 283128, 283881, 284635, 285390, 286146, 286903, 287661, 288420, 289180, 289941, 290703, 291466, 292230, 292995, 293761, 294528, 295296, 296065, 296835, 297606, 298378, 299151, 299925, 300700, 301476, 302253, 303031, 303810, 304590, 305371, 306153, 306936, 307720, 308505, 309291, 310078, 310866, 311655, 312445, 313236, 314028, 314821, 315615, 316410, 317206, 318003, 318801, 319600, 320400, 321201, 322003, 322806, 323610, 324415, 325221, 326028, 326836, 327645, 328455, 329266, 330078, 330891, 331705, 332520, 333336, 334153, 334971, 335790, 336610, 337431, 338253, 339076, 339900, 340725, 341551, 342378, 343206, 344035, 344865, 345696, 346528, 347361, 348195, 349030, 349866, 350703, 351541, 352380, 353220, 354061, 354903, 355746, 356590, 357435, 358281, 359128, 359976, 360825, 361675, 362526, 363378, 364231, 365085, 365940, 366796, 367653, 368511, 369370, 370230, 371091, 371953, 372816, 373680, 374545, 375411, 376278, 377146, 378015, 378885, 379756, 380628, 381501, 382375, 383250, 384126, 385003, 385881, 386760, 387640, 388521, 389403, 390286, 391170, 392055, 392941, 393828, 394716, 395605, 396495, 397386, 398278, 399171, 400065, 400960, 401856, 402753, 403651, 404550, 405450, 406351, 407253, 408156, 409060, 409965, 410871, 411778, 412686, 413595, 414505, 415416, 416328, 417241, 418155, 419070, 419986, 420903, 421821, 422740, 423660, 424581, 425503, 426426, 427350, 428275, 429201, 430128, 431056, 431985, 432915, 433846, 434778, 435711, 436645, 437580, 438516, 439453, 440391, 441330, 442270, 443211, 444153, 445096, 446040, 446985, 447931, 448878, 449826, 450775, 451725, 452676, 453628, 454581, 455535, 456490, 457446, 458403, 459361, 460320, 461280, 462241, 463203, 464166, 465130, 466095, 467061, 468028, 468996, 469965, 470935, 471906, 472878, 473851, 474825, 475800, 476776, 477753, 478731, 479710, 480690, 481671, 482653, 483636, 484620, 485605, 486591, 487578, 488566, 489555, 490545, 491536, 492528, 493521, 494515, 495510, 496506, 497503, 498501, 499500]

def n_choose_2(n):
	return binomials[n]
n = int(input())
field = [[0 for i in range(1000)] for j in range(1000)]
for i in range(n):
	b = tuple((int(u) - 1 for u in input().split()))
	field[b[0]][b[1]] = 1
cnt = 0
for y in range(1000):
	ond = 0
	for x in range(1000 - y):
		ond += field[x][y + x]
	cnt += n_choose_2(ond)
	ond = 0
	for x in range(y + 1):
		ond += field[x][y - x]
	cnt += n_choose_2(ond)
for x in range(1, 1000):
	ond = 0
	for y in range(1000 - x):
		ond += field[x + y][y]
	cnt += n_choose_2(ond)
	ond = 0
	for ny in range(1000 - x):
		ond += field[x + ny][1000 - 1 - ny]
	cnt += n_choose_2(ond)
print(cnt)


def combination(n, r):
	if n - r < r:
		r = n - r
	s = 1
	j = 1
	for i in range(r):
		s *= n - i
		while j <= r and s % j == 0:
			s = s // j
			j += 1
	return s
n = int(input())
v = []
for i in range(n):
	sLine = input()
	sSplit = sLine.split()
	x = int(sSplit[0])
	y = int(sSplit[1])
	v.append([x, y])
c1 = [0] * 2001
c2 = [0] * 2001
for i in v:
	c1[i[0] + i[1]] += 1
	c2[i[0] - i[1]] += 1
nSum = 0
for i in c1:
	if i >= 2:
		nSum += combination(i, 2)
for i in c2:
	if i >= 2:
		nSum += combination(i, 2)
print(nSum)


import time
n = int(input())
d1 = {}
d2 = {}
for i in range(n):
	(x, y) = (int(i) for i in input().split())
	t = x - y
	if t in d1.keys():
		d1[t] += 1
	else:
		d1[t] = 1
	t = x + y
	if t in d2.keys():
		d2[t] += 1
	else:
		d2[t] = 1
start = time.time()
ans = 0
for i in d1.keys():
	ans += d1[i] * (d1[i] - 1) // 2
for i in d2.keys():
	ans += d2[i] * (d2[i] - 1) // 2
print(ans)
finish = time.time()


diagonales = [0] * 3998
veces = int(input())
resultado = 0
for i in range(veces):
	elemento = list(str(input()).split())
	elemento[0] = int(elemento[0])
	elemento[1] = int(elemento[1])
	diferencia = elemento[1] - elemento[0]
	diagonales[diferencia + 999] += 1
	posicion = elemento[1] + elemento[0] + 1997
	diagonales[posicion] += 1
for j in diagonales:
	if j > 1:
		resultado += (j - 1) * (j - 1 + 1) / 2
print(int(resultado))


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


from collections import Counter
n = int(input())
coord = []
for _ in range(n):
	coord.append([int(num) for num in input().split()])
down = []
for xy in coord:
	down.append(xy[0] + xy[1] - 1)
up = []
for xy in coord:
	up.append(xy[1] - xy[0] + 1)
sum = 0
d = Counter(down)
u = Counter(up)
for val in d.values():
	sum += val * (val - 1) // 2
for val in u.values():
	sum += val * (val - 1) // 2
print(sum)


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)


from collections import Counter
from math import factorial
n = int(input())
ans = 0
num_list = []
for i in range(n):
	(x, y) = map(int, input().split())
	num_list.append((x, y))
add_list = []
minus_list = []
for i in num_list:
	add_list.append(i[0] + i[1])
	minus_list.append(i[0] - i[1])
add_list.sort()
minus_list.sort()
a = [v for (k, v) in Counter(add_list).items() if v > 1]
m = [v for (k, v) in Counter(minus_list).items() if v > 1]
for i in a:
	ans += i * (i - 1) / 2
for i in m:
	ans += i * (i - 1) / 2
print(int(ans))


from itertools import combinations, accumulate, groupby, count
from sys import stdout, stdin, setrecursionlimit
from collections import *
from random import *
from bisect import *
from string import *
from queue import *
from heapq import *
from math import *
from re import *

def fast():
	return stdin.readline().strip()

def zzz():
	return [int(i) for i in fast().split()]
(z, zz) = (input, lambda : list(map(int, z().split())))
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def output(answer):
	stdout.write(str(answer))
dx = [-1, 1, 0, 0, 1, -1, 1, -1]
dy = [0, 0, 1, -1, 1, -1, -1, 1]
num = int(z())
lst1 = {}
lst2 = {}
ans = 0
for i in range(num):
	(x, y) = zzz()
	try:
		lst1[x + y]
	except:
		lst1[x + y] = 0
	try:
		lst2[x - y]
	except:
		lst2[x - y] = 0
	lst1[x + y] += 1
	lst2[x - y] += 1

def solve(x):
	return x * (x - 1) // 2
for i in lst1:
	ans += solve(lst1[i])
for i in lst2:
	ans += solve(lst2[i])
print(ans)


case = int(input())
c1 = {}
c2 = {}
for i in range(0, case):
	s = input().split()
	x1 = int(s[0]) - int(s[1])
	x2 = int(s[0]) + int(s[1])
	if x1 in c1:
		c1[x1] = c1[x1] + 1
	else:
		c1[x1] = 1
	if x2 in c2:
		c2[x2] = c2[x2] + 1
	else:
		c2[x2] = 1
count = 0
for (k, v) in c1.items():
	count = count + v * (v - 1) // 2
for (k, v) in c2.items():
	count = count + v * (v - 1) // 2
print(count)


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


from collections import defaultdict
n = int(input())
freq1 = defaultdict(int)
freq2 = defaultdict(int)
for _ in range(n):
	(x, y) = map(int, input().split())
	freq1[x + y] += 1
	freq2[x - y] += 1
res = 0
for v in freq1.values():
	if v > 1:
		res += v * (v - 1) // 2
for v in freq2.values():
	if v > 1:
		res += v * (v - 1) // 2
print(int(res))


dic1 = {}
dic2 = {}
x = int(input())
for n in range(x):
	(a, b) = map(int, input().split())
	if a + b not in dic1:
		dic1[a + b] = 1
	else:
		dic1[a + b] += 1
	if a - b not in dic2:
		dic2[a - b] = 1
	else:
		dic2[a - b] += 1
res = 0
for n in dic1:
	res += dic1[n] * (dic1[n] - 1) // 2
for n in dic2:
	res += dic2[n] * (dic2[n] - 1) // 2
print(res)


n = int(input())
a = [0] * 2222
b = [0] * 2222
for it in range(n):
	(x, y) = map(int, input().split())
	a[x + y] += 1
	b[x - y] += 1
ret = 0
for i in a:
	ret += i * (i - 1) // 2
for i in b:
	ret += i * (i - 1) // 2
print(ret)


n = int(input())
grid = [[0 for x in range(1000)] for x in range(1000)]
(ans, tmpAns) = (0, 0)

def getNS(n):
	if n < 2:
		return 0
	return n * (n - 1) / 2
for i in range(n):
	(x, y) = [int(i) for i in input().split()]
	grid[x - 1][y - 1] = 1
for i in range(1000):
	for j in range(1000 - i):
		k = j + i
		if grid[j][k] == 1:
			tmpAns += 1
	ans += getNS(tmpAns)
	tmpAns = 0
for i in range(1, 1000):
	for j in range(1000 - i):
		k = j + i
		if grid[k][j] == 1:
			tmpAns += 1
	ans += getNS(tmpAns)
	tmpAns = 0
for i in range(1000):
	for j in range(i, -1, -1):
		k = i - j
		if grid[j][k] == 1:
			tmpAns += 1
	ans += getNS(tmpAns)
	tmpAns = 0
for i in range(1, 1000):
	for j in range(999, i - 1, -1):
		k = 999 - j + i
		if grid[j][k] == 1:
			tmpAns += 1
	ans += getNS(tmpAns)
	tmpAns = 0
print(int(ans))


from collections import defaultdict
from itertools import zip_longest
n = int(input())
d = defaultdict(int)
d1 = defaultdict(int)
for i in range(n):
	(x, y) = map(int, input().split())
	d[x + y] += 1
	d1[x - y] += 1
res = 0
for (i, j) in zip_longest(d.values(), d1.values(), fillvalue=1):
	res += i * (i - 1) // 2
	res += j * (j - 1) // 2
print(res)


(p, m) = ([0] * 2002, [0] * 2002)
a = 0
n = int(input())
for _ in range(n):
	(x, y) = map(int, input().split())
	a += p[x + y] + m[x - y]
	p[x + y] += 1
	m[x - y] += 1
print(a)


import sys
input = sys.stdin.readline
top_bottom = [0] * 1999
bottom_top = [0] * 1999

def get_index_tb(t):
	(r, c) = t
	if r == c:
		return 0
	elif r > c:
		return r - c
	elif c > r:
		return c - r + 999

def get_index_bt(t):
	(r, c) = t
	if r == c == 0:
		return 0
	elif r == c == 999:
		return 1998
	else:
		return r + c
bishops = []
num_bishops = int(input())
for _ in range(num_bishops):
	(r, c) = map(int, input().split())
	bishops.append((r - 1, c - 1))
	top_bottom[get_index_tb((r - 1, c - 1))] += 1
	bottom_top[get_index_bt((r - 1, c - 1))] += 1
res = 0
for (r, c) in bishops:
	res += top_bottom[get_index_tb((r, c))] - 1
	res += bottom_top[get_index_bt((r, c))] - 1
print(res // 2)


from collections import defaultdict as ddict

def nC2(n):
	return n * (n - 1) // 2
SIZE = 1000
N = int(input())
plus = ddict(int)
minus = ddict(int)
for i in range(N):
	(x, y) = map(int, input().split())
	plus[x + y] += 1
	minus[x - y] += 1
ans = 0
for x in plus.values():
	ans += nC2(n=x)
for x in minus.values():
	ans += nC2(n=x)
print(ans)


import math
n = int(input())
summ = []
diff = []
for i in range(n):
	(x, y) = map(int, input().split())
	summ.append(x + y)
	diff.append(x - y)
f1 = [0] * 10 ** 6
f2 = [0] * 10 ** 6
for i in range(n):
	f1[summ[i]] += 1
	f2[diff[i]] += 1
ans = 0
for i in range(10 ** 6):
	if f1[i] > 1:
		ans += f1[i] * (f1[i] - 1) // 2
	if f2[i] > 1:
		ans += f2[i] * (f2[i] - 1) // 2
print(ans)


def solve(n, bishops):
	tablePlus = {}
	tableMinus = {}
	ans = 0
	for (row, col) in bishops:
		product1 = row - col
		product2 = row + col
		if tableMinus.get(product1) == None:
			tableMinus[product1] = 1
		else:
			ans += tableMinus[product1]
			tableMinus[product1] += 1
		if tablePlus.get(product2) == None:
			tablePlus[product2] = 1
		else:
			ans += tablePlus[product2]
			tablePlus[product2] += 1
	return ans
b = []
n = int(input())
for _ in range(n):
	b.append(list(map(int, input().split())))
print(solve(n, b))


n = int(input())
diagonal1 = [0] * 2001
diagonal2 = [0] * 2001
for i in range(n):
	(a, b) = map(int, input().split())
	diagonal1[a - b] += 1
	diagonal2[a + b] += 1
ans = 0
for e in diagonal1:
	ans += e * (e - 1) // 2
for e in diagonal2:
	ans += e * (e - 1) // 2
print(ans)


n = int(input())
a = [0] * 3000
b = [0] * 3000
for _ in range(n):
	(x, y) = map(int, input().split())
	a[x + y] += 1
	b[x - y] += 1
r = 0
for e in a:
	r += e * (e - 1) // 2
for e in b:
	r += e * (e - 1) // 2
print(r)


import functools
import operator as op

def choose(n, r):
	r = min(r, n - r)
	if r == 0:
		return 1
	numer = functools.reduce(op.mul, range(n, n - r, -1))
	denom = functools.reduce(op.mul, range(1, r + 1))
	return numer // denom

def solve():
	res = 0
	n = int(input())
	grid = [[0] * 1001 for _ in range(1001)]
	for i in range(n):
		(x, y) = map(int, input().split())
		grid[x][y] = 1
	for ri in range(1, 1001):
		summary = sum((grid[x][y] for (x, y) in zip(range(ri, 1001), range(1, 1001))))
		if summary >= 2:
			res += choose(summary, 2)
		summary = sum((grid[x][y] for (x, y) in zip(range(ri, 0, -1), range(1, 1001))))
		if summary >= 2:
			res += choose(summary, 2)
	for ri in range(2, 1000):
		summary = sum((grid[x][y] for (x, y) in zip(range(ri, 1001), range(1000, 0, -1))))
		if summary >= 2:
			res += choose(summary, 2)
		summary = sum((grid[x][y] for (x, y) in zip(range(ri, 0, -1), range(1000, 0, -1))))
		if summary >= 2:
			res += choose(summary, 2)
	print(res)
solve()


(d1, d2, count) = ({}, {}, 0)
for _ in range(int(input())):
	(x, y) = map(int, input().split())
	if x + y in d1:
		d1[x + y] += 1
	else:
		d1[x + y] = 1
	if x - y in d2:
		d2[x - y] += 1
	else:
		d2[x - y] = 1
for i in d1.values():
	count += i * (i - 1) // 2
for i in d2.values():
	count += i * (i - 1) // 2
print(count)


n = int(input())
dp = {}
dn = {}
for i in range(n):
	s = input()
	s = s.split()
	t1 = int(s[0]) + int(s[1])
	t2 = int(s[1]) - int(s[0])
	if t1 in dn:
		dn[t1] += 1
	else:
		dn[t1] = 1
	if t2 in dp:
		dp[t2] += 1
	else:
		dp[t2] = 1
su = 0
for i in dp:
	t = dp[i]
	if t != 1:
		su += t * (t - 1) / 2
for i in dn:
	t = dn[i]
	if t != 1:
		su += t * (t - 1) / 2
print(int(su))


import sys
import math
import bisect

def solve(A):
	n = len(A)
	ans = 0
	d1 = dict()
	d2 = dict()
	for i in range(n):
		(x, y) = (A[i][0], A[i][1])
		if x + y not in d1:
			d1[x + y] = 0
		d1[x + y] += 1
		if x - y not in d2:
			d2[x - y] = 0
		d2[x - y] += 1
	for k in d1:
		ans += d1[k] * (d1[k] - 1) // 2
	for k in d2:
		ans += d2[k] * (d2[k] - 1) // 2
	return ans

def main():
	n = int(input())
	A = []
	for i in range(n):
		A.append(list(map(int, input().split())))
	ans = solve(A)
	print(ans)
main()


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def main():
	n = I()
	aa = [LI() for _ in range(n)]
	c = collections.defaultdict(int)
	for (a, b) in aa:
		c[1, a + b] += 1
		c[2, a - b] += 1
	r = 0
	for (k, v) in c.items():
		r += v * (v - 1) // 2
	return r
print(main())


from collections import Counter

def sum_upto(n):
	return int(n * (n + 1) / 2)
n = int(input())
arr1 = list()
arr2 = list()
for i in range(n):
	(x, y) = map(int, input().split())
	arr1.append(x + y)
	arr2.append(x - y)
sum1 = Counter(arr1)
dif1 = Counter(arr2)
ans = 0
for i in sum1:
	ans = ans + sum_upto(sum1[i] - 1)
for j in dif1:
	ans = ans + sum_upto(dif1[j] - 1)
print(int(ans))


from collections import Counter

def comb(n):
	return n * (n - 1) // 2
n = int(input())
d1 = Counter()
d2 = Counter()
for i in range(n):
	(x, y) = map(int, input().split())
	d1[x - y] += 1
	d2[x + y] += 1
total = 0
for x in d1.values():
	total += comb(x)
for y in d2.values():
	total += comb(y)
print(total)


n = int(input())
cache_plus = {}
cache_minus = {}
cnt = 0
for _ in range(n):
	(x, y) = map(int, input().split())
	r = x - y
	if r in cache_minus:
		cache_minus[r] += 1
	else:
		cache_minus[r] = 1
	r = x + y
	if r in cache_plus:
		cache_plus[r] += 1
	else:
		cache_plus[r] = 1
for key in cache_minus:
	x = cache_minus[key]
	cnt += x * (x - 1) // 2
for key in cache_plus:
	x = cache_plus[key]
	cnt += x * (x - 1) // 2
print(cnt)


(pos, neg, ans) = ([0] * 5000, [0] * 5000, 0)
for _ in range(int(input())):
	(x, y) = map(int, input().split())
	ans += pos[x + y] + neg[x - y]
	pos[x + y] += 1
	neg[x - y] += 1
print(ans)


a = [0] * 2100
b = [0] * 2100
n = int(input())
ans = 0
for _ in range(n):
	(x, y) = map(int, input().split())
	ans += a[x + y] + b[x - y]
	a[x + y] += 1
	b[x - y] += 1
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 = []
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)


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


n = int(input())
l = {}
l1 = {}
for i in range(n):
	(a, b) = map(int, input().split())
	l[a - b] = l.get(a - b, 0) + 1
	l1[a + b] = l1.get(a + b, 0) + 1
k = 0
for x in l:
	d = l[x]
	for i in range(1, d):
		k = k + i
for x in l1:
	d = l1[x]
	for i in range(1, d):
		k = k + i
print(k)


n = int(input())
dp = [0] * 5000
dp2 = [0] * 5000
ans = 0
for i in range(n):
	(a, b) = map(int, input().split())
	ans += dp[a + b] + dp2[a - b]
	dp[a + b] += 1
	dp2[a - b] += 1
print(ans)


ls = [0] * 2010
ld = [0] * 2010
n = int(input())
for _ in range(n):
	(x, y) = map(int, input().split())
	ls[x + y] += 1
	ld[x - y] += 1
ans = 0
for i in range(2010):
	if ls[i] != 0:
		ans += ls[i] * (ls[i] - 1) // 2
	if ld[i] != 0:
		ans += ld[i] * (ld[i] - 1) // 2
print(ans)


d = {}
d1 = {}
sm = 0
sh = []
n = int(input())
for i in range(n):
	sh.append(list(map(int, input().split())))
for i in range(n):
	x = sh[i][0]
	y = sh[i][1]
	sm += d.get(x + y, 0)
	sm += d1.get(x - y, 0)
	d[x + y] = d.get(x + y, 0) + 1
	d1[x - y] = d1.get(x - y, 0) + 1
print(sm)


n = int(input())
a = [[*map(int, input().split())] for i in range(n)]
d1 = {}
d2 = {}
for i in a:
	wk1 = i[0] + i[1]
	wk2 = i[0] - i[1]
	if not wk1 in d1:
		d1[wk1] = 0
	d1[wk1] += 1
	if not wk2 in d2:
		d2[wk2] = 0
	d2[wk2] += 1
ans = 0
for i in d1:
	ans += (d1[i] - 1) * d1[i] // 2
for i in d2:
	ans += (d2[i] - 1) * d2[i] // 2
print(ans)


from collections import defaultdict
n = int(input())
diags1 = defaultdict(int)
diags2 = defaultdict(int)
while n:
	n -= 1
	(x, y) = list(map(int, input().split()))
	diags1[x + y] += 1
	diags2[x - y] += 1
ans = 0
for (k, v) in diags1.items():
	ans += v * (v - 1) / 2
for (k, v) in diags2.items():
	ans += v * (v - 1) / 2
print(int(ans))


import sys
input = sys.stdin.readline
read_tuple = lambda _type: map(_type, input().split(' '))
from math import factorial

def solve():
	n = int(input())
	(diag1, diag2) = ({}, {})
	for _ in range(n):
		(x, y) = read_tuple(int)
		(x_1, y_1) = (x - min(x, y) + 1, y - min(x, y) + 1)
		diag1[x_1, y_1] = diag1.get((x_1, y_1), 0) + 1
		y_tmp = 1000 - y + 1
		(x_2, y_2) = (x - min(x, y_tmp) + 1, y_tmp - min(x, y_tmp) + 1)
		diag2[x_2, y_2] = diag2.get((x_2, y_2), 0) + 1
	ans = 0
	for v in diag1.values():
		if v >= 2:
			ans += factorial(v) // (2 * factorial(v - 2))
	for v in diag2.values():
		if v >= 2:
			ans += factorial(v) // (2 * factorial(v - 2))
	print(ans)
solve()


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)


sum = [0] * 2000
mi = [0] * 2000
ans = 0
for i in range(int(input())):
	(x, y) = map(int, input().split())
	sum[x + y - 1] += 1
	mi[x - y] += 1
for i in range(2000):
	if sum[i] > 1:
		ans += sum[i] * (sum[i] + 1) // 2 - sum[i]
	if mi[i] > 1:
		ans += mi[i] * (mi[i] + 1) // 2 - mi[i]
print(ans)


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


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
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)
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)
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)
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)


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())))


(p, m) = (dict(), dict())
attacks = 0
for _ in range(int(input())):
	(x, y) = map(int, input().split())
	if x + y not in p:
		p[x + y] = 0
	if x - y not in m:
		m[x - y] = 0
	attacks += p[x + y] + m[x - y]
	p[x + y] += 1
	m[x - y] += 1
print(attacks)


n = int(input())
a = [0] * 2 * 200000
b = [0] * 2 * 200000
for i in range(0, n):
	(x, y) = list(map(int, input().split()))
	a[x + y] += 1
	b[y - x + n] += 1
ans = 0
for i in a:
	if i > 0:
		ans += i * (i - 1) // 2
for i in b:
	if i > 0:
		ans += i * (i - 1) // 2
print(ans)


n = int(input())
diagonais_principais = {}
diagonais_secundarias = {}
for i in range(n):
	(a, b) = [int(x) for x in input().split()]
	diagonal_p = b - a
	diagonal_s = a + b
	if diagonal_p in diagonais_principais:
		diagonais_principais[diagonal_p] += 1
	else:
		diagonais_principais[diagonal_p] = 1
	if diagonal_s in diagonais_secundarias:
		diagonais_secundarias[diagonal_s] += 1
	else:
		diagonais_secundarias[diagonal_s] = 1
result = 0
for i in diagonais_principais.values():
	result += (i * i - i) // 2
for i in diagonais_secundarias.values():
	result += (i * i - i) // 2
print(result)


n = int(input())
a = [tuple(map(int, input().split())) for _ in range(n)]
f1 = [0] * 2005
f2 = [0] * 2005
for co in a:
	(i, j) = (co[0], co[1])
	f1[i - j] += 1
	f2[999 - i - j] += 1
ans = 0
for x in f1:
	ans += x * (x - 1) // 2
for x in f2:
	ans += x * (x - 1) // 2
print(ans)


def C(n, m):
	j = 1
	o = 1
	for i in range(n - m + 1, n + 1):
		o *= i
		while o % j == 0 and j <= m:
			o /= j
			j += 1
	return o
d = [0 for i in range(2001)]
u = [0 for i in range(2001)]
k = int(input())
for i in range(k):
	(x, y) = map(int, input().split())
	d[1000 + x - y] += 1
	u[x + y - 1] += 1
o = 0
for i in range(1, 2001):
	o += C(d[i], 2)
	o += C(u[i], 2)
print(int(o))


from typing import List
import math

class Solution:
	pass
sol = Solution()
res = 0
n = int(input())
d1 = {}
d2 = {}
ans = 0
for i in range(n):
	(x, y) = map(int, input().split())
	if x - y < 0:
		diff = 1000 - (x - y)
	else:
		diff = x - y
	if diff in d1:
		d1[diff] += 1
	else:
		d1[diff] = 1
	if x + y in d2:
		d2[x + y] += 1
	else:
		d2[x + y] = 1
for (key, value) in d1.items():
	ans += value * (value - 1) // 2
for (key, value) in d2.items():
	ans += value * (value - 1) // 2
print(ans)


n = int(input())
a = [[0 for i in range(1000)] for j in range(1000)]
for i in range(n):
	(x, y) = [int(i) - 1 for i in input().split()]
	a[x][y] = 1
res = 0
for i in range(1000):
	s = 0
	for j in range(1000 - i):
		if a[j][i + j]:
			s += 1
	res += s * (s - 1) // 2
for i in range(1, 1000):
	s = 0
	for j in range(1000 - i):
		if a[i + j][j]:
			s += 1
	res += s * (s - 1) // 2
for i in range(1000):
	s = 0
	for j in range(1000 - i):
		if a[1000 - j - 1][i + j]:
			s += 1
	res += s * (s - 1) // 2
for i in range(1, 1000):
	s = 0
	for j in range(1000 - i):
		if a[1000 - i - j - 1][j]:
			s += 1
	res += s * (s - 1) // 2
print(res)


from collections import defaultdict
x = int(input())
d = defaultdict(int)
d0 = defaultdict(int)
c = 0
for i in range(x):
	(x, y) = map(int, input().split())
	c += d[x - y] + d0[x + y]
	d[x - y] += 1
	d0[x + y] += 1
print(c)


n = int(input())
by_x = dict()
by_y = dict()
for _ in range(n):
	(x, y) = map(int, input().split())
	x -= 1
	y -= 1
	diag_x = y - x
	diag_y = y - (1000 - 1 - x)
	if diag_x not in by_x:
		by_x[diag_x] = 0
	if diag_y not in by_y:
		by_y[diag_y] = 0
	by_x[diag_x] += 1
	by_y[diag_y] += 1
print(sum(map(lambda iter: sum((x * (x - 1) // 2 for x in iter)), (by_x.values(), by_y.values()))))


from collections import Counter

def attacking_pairs(bishops):
	sumc = Counter((x + y for (x, y) in bishops))
	sumd = Counter((x - y for (x, y) in bishops))
	return sum((k * (k - 1) // 2 for k in sumc.values())) + sum((k * (k - 1) // 2 for k in sumd.values()))

def get_input():
	n = int(input())
	bishops = []
	for _ in range(n):
		(x, y) = map(int, input().split())
		bishops.append((x, y))
	return bishops
print(attacking_pairs(get_input()))


import unittest
import sys

class Bishops:

	def __init__(self, test_inputs=None):
		it = iter(test_inputs.split('\n')) if test_inputs else None

		def uinput():
			return next(it) if it else sys.stdin.readline().rstrip()
		[self.n] = map(int, uinput().split())
		(l, s) = (self.n, 2)
		inp = ' '.join((uinput() for i in range(l))).split()
		self.numm = [[int(inp[i]) for i in range(j, l * s, s)] for j in range(s)]
		(self.numa, self.numb) = self.numm
		self.pairs = 0
		self.cnt = {}
		for i in range(len(self.numa)):
			t = self.numa[i] + self.numb[i]
			self.cnt[t] = self.cnt.setdefault(t, 0) + 1
		for c in self.cnt.values():
			self.pairs += c * (c - 1) // 2
		self.cnt = {}
		for i in range(len(self.numa)):
			t = self.numa[i] - self.numb[i]
			self.cnt[t] = self.cnt.setdefault(t, 0) + 1
		for c in self.cnt.values():
			self.pairs += c * (c - 1) // 2

	def calculate(self):
		result = self.pairs
		return str(result)

class unitTests(unittest.TestCase):

	def test_single_test(self):
		test = '5\n1 1\n1 5\n3 3\n5 1\n5 5'
		d = Bishops(test)
		self.assertEqual(d.n, 5)
		self.assertEqual(d.numa, [1, 1, 3, 5, 5])
		self.assertEqual(Bishops(test).calculate(), '6')
		test = '3\n1 1\n2 3\n3 5'
		self.assertEqual(Bishops(test).calculate(), '0')
		test = ''
		test = ''

	def time_limit_test(self, nmax):
		import random
		import timeit
		test = str(nmax) + ' ' + str(nmax) + '\n'
		numnums = [str(i) + ' ' + str(i + 1) for i in range(nmax)]
		test += '\n'.join(numnums) + '\n'
		nums = [random.randint(1, 10000) for i in range(nmax)]
		test += ' '.join(map(str, nums)) + '\n'
		start = timeit.default_timer()
		d = Bishops(test)
		calc = timeit.default_timer()
		d.calculate()
		stop = timeit.default_timer()
		print('\nTimelimit Test: ' + '{0:.3f}s (init {1:.3f}s calc {2:.3f}s)'.format(stop - start, calc - start, stop - calc))
sys.setrecursionlimit(100000)
if sys.argv[-1] == '-ut':
	unittest.main(argv=[' '])
sys.stdout.write(Bishops().calculate())


n = int(input())
A = [0] * 3000
B = [0] * 3000
for i in range(n):
	(x, y) = 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)


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


n = int(input())
res = [0] * 2000
resT = [0] * 2000
while n != 0:
	(x, y) = [int(p) for p in input().split()]
	x -= 1
	y -= 1
	res[x + y] += 1
	resT[x + 999 - y] += 1
	n -= 1
s = 0
for x in range(2000):
	if res[x] > 1:
		s += res[x] * (res[x] - 1) // 2
	if resT[x] > 1:
		s += resT[x] * (resT[x] - 1) // 2
print(s)


n = int(input())
a = [0] * 2000
b = [0] * 2000
for i in range(n):
	(x, y) = map(int, input().split())
	a[x + y - 1] += 1
	b[999 + x - (y - 1)] += 1
s = 0
for i in range(2000):
	s += a[i] * (a[i] - 1) // 2 + b[i] * (b[i] - 1) // 2
print(s)


import sys
from collections import defaultdict

def main():
	n = int(sys.stdin.readline())
	m1 = defaultdict(int)
	m2 = defaultdict(int)
	ans = 0
	for i in range(n):
		(xi, yi) = map(int, sys.stdin.readline().split(' '))
		if xi - yi in m1:
			ans += m1[xi - yi]
		m1[xi - yi] += 1
		if xi + yi in m2:
			ans += m2[xi + yi]
		m2[xi + yi] += 1
	return ans
sys.stdout.write('{}\n'.format(main()))


read = lambda : 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)


(first, second) = ([0] * 2002, [0] * 2002)
for _ in range(int(input())):
	(x, y) = map(int, input().split())
	first[x + y] += 1
	second[x - y] += 1
print(sum(map(lambda num: num * (num - 1) >> 1, first + second)))


l = {}
r = {}
for i in range(int(input())):
	(x, y) = map(int, input().split())
	r[x + y] = r.get(x + y, 0) + 1
	l[x - y] = l.get(x - y, 0) + 1
s = 0
for (_, v) in r.items():
	s += (v * v - v) // 2
for (_, v) in l.items():
	s += (v * v - v) // 2
print(s)


n = int(input())
fdiag = [0 for i in range(1999)]
rdiag = [0 for i in range(1999)]
for i in range(n):
	(r, c) = [int(x) for x in input().split()]
	fdiag[r + c - 2] += 1
	rdiag[r - c + 999] += 1
answer = 0
for x in fdiag:
	if x > 1:
		answer += x * (x - 1) // 2
for x in rdiag:
	if x > 1:
		answer += x * (x - 1) // 2
print(answer)


n = int(input())
m1 = {}
m2 = {}
for i in range(n):
	(x, y) = map(int, input().split())
	if y - x in m1:
		m1[y - x] += 1
	else:
		m1[y - x] = 1
	if x + y in m2:
		m2[x + y] += 1
	else:
		m2[x + y] = 1
ans = 0
for i in m1:
	ans += m1[i] * (m1[i] - 1) // 2
for i in m2:
	ans += m2[i] * (m2[i] - 1) // 2
print(ans)


from collections import defaultdict
n = int(input())
d1 = defaultdict(int)
d2 = defaultdict(int)
for i in range(n):
	(x, y) = map(int, 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())
R = lambda : map(int, input().split())
from collections import defaultdict
l1 = defaultdict(int)
l2 = defaultdict(int)
for i in range(n):
	(x, y) = R()
	l1[y - x] += 1
	l2[1001 - y - x] += 1
s = 0
for d in l1.values():
	s += d * (d - 1) // 2
for d in l2.values():
	s += d * (d - 1) // 2
print(s)


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


plus = [0] * 2100
minus = [0] * 2100
ans = 0
for _ in range(int(input())):
	(x, y) = map(int, input().split())
	ans += plus[x + y] + minus[x - y]
	plus[x + y] += 1
	minus[x - y] += 1
print(ans)


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)


n = int(input())
diff = {}
summ = {}
for i in range(n):
	(x, y) = map(int, input().split())
	if x + y in summ:
		summ[x + y] += 1
	else:
		summ[x + y] = 1
	if x - y in diff:
		diff[x - y] += 1
	else:
		diff[x - y] = 1
ans = 0
for i in summ:
	ans += summ[i] * (summ[i] - 1) // 2
for i in diff:
	ans += diff[i] * (diff[i] - 1) // 2
print(ans)


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)))


from collections import defaultdict
n = int(input())
d = defaultdict(int)
for _ in range(n):
	(a, b) = [int(x) for x in input().split()]
	d[a + b] += 1
	d[a - b + 3000] += 1
sm = 0
for v in d.values():
	sm = sm + v * (v - 1) // 2
print(sm)


cnt1 = [0] * 4009
cnt2 = [0] * 4009
n = int(input())
res = 0
for i in range(n):
	(x, y) = map(int, input().split())
	cnt1[x + y] += 1
	cnt2[x - y + 1000] += 1
for x in cnt1:
	res += x * (x - 1) // 2
for x in cnt2:
	res += x * (x - 1) // 2
print(res)


def soma_gauss(v):
	return (v + 1) * v // 2
tab = {}
n = int(input())
for i in range(n):
	(x, y) = input().split()
	(x, y) = (int(x), int(y))
	index = abs(x - y) + (0 if x >= y else 1000)
	index2 = x + y + 2000
	if index in tab:
		tab[index] += 1
	else:
		tab[index] = 1
	if index2 in tab:
		tab[index2] += 1
	else:
		tab[index2] = 1
result = 0
for e in tab:
	if tab[e] > 1:
		result += soma_gauss(tab[e] - 1)
print(result)


n = int(input())
ans = 0
masS = [0] * 2002
masR = {str(a): 0 for a in range(-999, 1000)}

def par(x):
	a = 0
	for i in range(x):
		a += i
	return a
for i in range(n):
	(a, b) = map(int, input().split())
	a -= 1
	b -= 1
	masS[a + b] += 1
	masR[str(a - b)] += 1
for i in range(-999, 1000):
	if masR[str(i)] > 1:
		ans += par(masR[str(i)])
for i in range(2002):
	if masS[i] > 1:
		ans += par(masS[i])
print(ans)


n = int(input())
cnt = 0
dictt = {}
dictt2 = {}
for i in range(n):
	(a, b) = map(int, input().split())
	try:
		dictt[a + b] += 1
	except:
		dictt[a + b] = 1
	try:
		dictt2[a - b] += 1
	except:
		dictt2[a - b] = 1
for (i, j) in dictt.items():
	if j > 1:
		cnt += j * (j - 1) // 2
for (i, j) in dictt2.items():
	if j > 1:
		cnt += j * (j - 1) // 2
print(cnt)


import math
import cmath
import string
import sys
import bisect
import ctypes
from queue import Queue, LifoQueue, PriorityQueue
from itertools import permutations, combinations
from collections import deque, Counter
n = int(input())
x = [0 for i in range(2000)]
y = [0 for i in range(2000)]
count = 0
for i in range(n):
	(a, b) = list(map(int, input().split()))
	x[a + b - 2] += 1
	y[a - b + 999] += 1
for i in range(1, 1998):
	if x[i]:
		count += x[i] * (x[i] - 1) // 2
	if y[i]:
		count += y[i] * (y[i] - 1) // 2
print(count)


def arr_inp():
	return [int(x) for x in stdin.readline().split()]

def nCr(n, r):
	(f, m) = (factorial, 1)
	for i in range(n, n - r, -1):
		m *= i
	return int(m // f(r))
from math import factorial
from sys import stdin
from collections import Counter, defaultdict
n = int(input())
(a, ans) = ([arr_inp() for i in range(n)], 0)
(dia1, dia2, dia3) = [defaultdict(int) for i in range(3)]
for (i, j) in a:
	if j >= i:
		dia1[j - i + 1] += 1
	else:
		dia2[i - j + 1] += 1
	dia3[i + j - 1] += 1
ans += sum([nCr(i, 2) for i in dia1.values()]) + sum([nCr(i, 2) for i in dia2.values()]) + sum([nCr(i, 2) for i in dia3.values()])
print(ans)


from collections import defaultdict
d1 = defaultdict(int)
d2 = defaultdict(int)
n = int(input())
for i in range(n):
	l = list(map(lambda x: int(x) - 1, input().split()))
	d1[l[0] + l[1]] += 1
	d2[l[0] - l[1]] += 1
total_ = 0
for v in d1.values():
	total_ += v * (v - 1) // 2
for v in d2.values():
	total_ += v * (v - 1) // 2
print(total_)


ft = [1, 1, 2]
me = {}
ma = {}

def fat(n):
	if len(ft) - 1 >= n:
		return ft[n]
	else:
		while len(ft) - 1 <= n:
			r = len(ft) - 1
			ft.append(ft[r] * (r + 1))
		return ft[n]

def comb(a, b):
	n = fat(a)
	k = fat(b)
	m = fat(a - b)
	return n // (k * m)
n = int(input())
for i in range(n):
	(x, y) = [int(i) for i in input().split()]
	if x + y not in ma:
		ma[x + y] = 1
	else:
		ma[x + y] += 1
	if x - y not in me:
		me[x - y] = 1
	else:
		me[x - y] += 1
som = 0
for k in me:
	som += comb(me[k], 2)
for k in ma:
	som += comb(ma[k], 2)
print(som)


n = int(input())
l1 = []
l2 = []
freq1 = [0] * 2001
freq2 = [0] * 2001
ans = 0
for i in range(n):
	(x, y) = map(int, input().split())
	freq1[x + y] += 1
	freq2[x - y] += 1
for i in freq1:
	ans += i * (i - 1) // 2
for j in freq2:
	ans += j * (j - 1) // 2
print(ans)


def combinacao(e, comb):
	if e == comb:
		return 1
	if e < comb:
		return 0
	x = e - comb
	result = 1
	if x > comb:
		while e > x:
			result = result * e
			e = e - 1
		while comb > 1:
			result = result // comb
			comb = comb - 1
	else:
		while e > comb:
			result = result * e
			e = e - 1
		while x > 1:
			result = result // x
			x = x - 1
	return result
bispos = int(input())
posicoes = []
principais = {}
secundarias = {}
for x in range(bispos):
	(i, j) = input().split()
	i = int(i)
	j = int(j)
	p = i - j
	s = i + j
	if p not in principais:
		principais[p] = 1
	else:
		principais[p] += 1
	if s not in secundarias:
		secundarias[s] = 1
	else:
		secundarias[s] += 1
pares = 0
for key in principais:
	if principais[key] > 1:
		pares += combinacao(principais[key], 2)
for key in secundarias:
	if secundarias[key] > 1:
		pares += combinacao(secundarias[key], 2)
print(pares)


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)


size = 10
n = int(input())
cnt = 0
(dp1, dp2) = ({}, {})
for i in range(n):
	(i, j) = map(int, input().split())
	(s, d) = (i + j, i - j)
	if not s in dp1.keys():
		dp1[s] = 0
	if not d in dp2.keys():
		dp2[d] = 0
	dp1[s] += 1
	dp2[d] += 1
for v in dp1.values():
	cnt += v * (v - 1) // 2
for v in dp2.values():
	cnt += v * (v - 1) // 2
print(cnt)


(p, m) = ([0] * 2100, [0] * 2100)
a = 0
for _ in range(int(input())):
	(x, y) = map(int, input().split())
	a += p[x + y] + m[x - y]
	p[x + y] += 1
	m[x - y] += 1
print(a)


def main():
	(term1, term2) = ([0] * 2048, [0] * 2048)
	for _ in range(int(input())):
		(x, y) = map(int, input().split())
		term1[x + y] += 1
		term2[x - y] += 1
	print(sum((sum((t * (t - 1) for t in filter(None, term))) for term in (term1, term2))) // 2)
main()


d1 = dict()
d2 = dict()
for _ in range(int(input())):
	(x, y) = map(int, input().split())
	if x + y in d1:
		d1[x + y] += 1
	else:
		d1[x + y] = 1
	if x - y in d2:
		d2[x - y] += 1
	else:
		d2[x - y] = 1
attack1 = 0
attack2 = 0
for v in d1.values():
	if v >= 2:
		attack1 += v * (v - 1) // 2
for v in d2.values():
	if v >= 2:
		attack2 += v * (v - 1) // 2
print(max(attack1 + attack2, 0))


def foo(x):
	ans = 0
	for _ in range(1, x):
		ans += _
	return ans
pos = 2010 * [0]
neg = 2010 * [0]
for i in range(int(input())):
	(x, y) = map(int, input().split())
	pos[x + y] += 1
	neg[x - y] += 1
ans = 0
for j in range(len(neg)):
	ans += foo(neg[j])
for k in range(len(pos)):
	ans += foo(pos[k])
print(ans)


from collections import Counter
b = [tuple(map(int, input().split())) for i in range(int(input()))]
d1 = sum((x * (x - 1) // 2 for x in Counter((x + y for (x, y) in b)).values()))
d2 = sum((x * (x - 1) // 2 for x in Counter((x - y for (x, y) in b)).values()))
print(d1 + d2)


n = int(input())
grid = [[0] * 1000 for _ in range(1000)]
for _ in range(n):
	(x, y) = map(int, input().split())
	grid[x - 1][y - 1] = 1
num_of_pairs = 0
for r in range(1000):
	row = 0
	local_pairs = 0
	for column in range(r, -1, -1):
		if grid[row][column] == 1:
			local_pairs += 1
		row += 1
	num_of_pairs += (local_pairs - 1) * local_pairs // 2
for r in range(1, 1000):
	row = r
	local_pairs = 0
	for column in range(999, r - 1, -1):
		if grid[row][column] == 1:
			local_pairs += 1
		row += 1
	num_of_pairs += (local_pairs - 1) * local_pairs // 2
for r in range(1000):
	row = 999
	local_pairs = 0
	for column in range(r, -1, -1):
		if grid[row][column] == 1:
			local_pairs += 1
		row -= 1
	num_of_pairs += (local_pairs - 1) * local_pairs // 2
for r in range(998, -1, -1):
	row = r
	local_pairs = 0
	for column in range(999, 998 - r, -1):
		if grid[row][column] == 1:
			local_pairs += 1
		row -= 1
	num_of_pairs += (local_pairs - 1) * local_pairs // 2
print(num_of_pairs)


def main():
	n = int(input())
	points = set()
	for i in range(n):
		(row, col) = (int(x) for x in input().split())
		points.add((row, col))
	print(solver(points, 1000))

def solver(S, size):
	diagonals = [[0] for i in range(size)]
	diagonals[0] = [0] * size
	antiDiagonals = [[0] for i in range(size)]
	antiDiagonals[size - 1] = [0] * size
	for point in S:
		(row1, col1) = getDiagonal(point, size)
		diagonals[row1][col1] += 1
		(row2, col2) = getAntiDiagonal(point, size)
		antiDiagonals[row2][col2] += 1
	total = 0
	for j in range(size):
		total += nChoose2(diagonals[0][j])
	for i in range(1, size):
		total += nChoose2(diagonals[i][0])
	for j in range(size):
		total += nChoose2(antiDiagonals[size - 1][j])
	for i in range(size - 1):
		total += nChoose2(antiDiagonals[i][0])
	return total

def getDiagonal(point, size):
	(row, col) = point
	if row < col:
		return (0, col - row)
	else:
		return (row - col, 0)

def getAntiDiagonal(point, size):
	(row, col) = (point[0] - 1, point[1] - 1)
	total = row + col
	if total < size:
		return (total, 0)
	else:
		return (size - 1, total - size + 1)

def nChoose2(n):
	return n * (n - 1) // 2
main()
points = {(1, 1), (1, 5), (3, 3), (5, 1), (5, 5)}
points2 = {(1, 1), (2, 3), (3, 5)}


w = int(input())
tanque1R = [0] * 2001
tanque2R = [0] * 2001
for i in range(w):
	(x, y) = map(int, input().split())
	tanque1R[1000 + x - y] += 1
	tanque2R[x + y] += 1
resultado = 0
for r in tanque1R:
	resultado += r * (r - 1) / 2
for r in tanque2R:
	resultado += r * (r - 1) / 2
print(int(resultado))


n = int(input())
DIA = [0] * 1999
DIB = [0] * 1999
for i in range(n):
	(a, b) = map(int, input().split())
	DIA[(a - b) % 1999] += 1
	DIB[(a + b) % 1999] += 1
c = 0
for d in DIA:
	c += d * (d - 1) // 2
for e in DIB:
	c += e * (e - 1) // 2
print(c)


n = int(input())
M = {}
for i in range(n):
	(row, col) = map(int, input().split())
	diag1 = col - row
	diag2 = col + row + 1001
	M[diag1] = M.get(diag1, 0) + 1
	M[diag2] = M.get(diag2, 0) + 1
sol = 0
for (k, v) in M.items():
	sol += v * (v - 1) // 2
print(sol)


IL = lambda : list(map(int, input().split()))
I = lambda : int(input())
f = lambda x: x * (x - 1) // 2
n = I()
d = [[0 for i in range(2001)], [0 for i in range(2001)]]
for i in range(n):
	(x, y) = IL()
	d[0][x + y] += 1
	d[1][x - y] += 1
print(sum(map(f, d[0] + d[1])))


hi = int(input())
rightways = {}
leftways = {}
pairs = 0
for m in range(hi):
	i = input().split()
	j = int(i[0])
	k = int(i[1])
	if j - k in rightways.keys():
		pairs += rightways[j - k]
		rightways[j - k] += 1
	else:
		rightways[j - k] = 1
	if j + k - 1 in leftways.keys():
		pairs += leftways[j + k - 1]
		leftways[j + k - 1] += 1
	else:
		leftways[j + k - 1] = 1
print(pairs)


n = int(input())
a = {}
b = {}
for i in range(n):
	(x, y) = map(int, input().split())
	if x + y not in a:
		a[x + y] = 1
	else:
		a[x + y] += 1
	if x - y not in b:
		b[x - y] = 1
	else:
		b[x - y] += 1
s = 0
for i in a:
	s += a[i] * (a[i] - 1) // 2
for i in b:
	s += b[i] * (b[i] - 1) // 2
print(s)


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:
		ans += a1[k]
		a1[k] += 1
	if b[l]:
		b[l] = False
		b1[l] += 1
	else:
		ans += b1[l]
		b1[l] += 1
print(ans)