The next lecture in a high school requires two topics to be discussed. The $i$-th topic is interesting by $a_i$ units for the teacher and by $b_i$ units for the students.

The pair of topics $i$ and $j$ ($i < j$) is called good if $a_i + a_j > b_i + b_j$ (i.e. it is more interesting for the teacher).

Your task is to find the number of good pairs of topics.


-----Input-----

The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) — the number of topics.

The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the interestingness of the $i$-th topic for the teacher.

The third line of the input contains $n$ integers $b_1, b_2, \dots, b_n$ ($1 \le b_i \le 10^9$), where $b_i$ is the interestingness of the $i$-th topic for the students.


-----Output-----

Print one integer — the number of good pairs of topic.


-----Examples-----
Input
5
4 8 2 6 2
4 5 4 1 3

Output
7

Input
4
1 3 2 4
1 3 2 4

Output
0

Source: codeforces | Difficulty: MEDIUM
Tags: Data structures

Sorting

Amortized analysis


Solutions:
def helper(n, a, b):
	c = []
	for i in range(n):
		c.append(a[i] - b[i])
	c = sorted(c)
	p1 = 0
	p2 = n - 1
	count = 0
	while p2 > p1:
		x1 = c[p1]
		x2 = c[p2]
		if x1 + x2 > 0:
			count += p2 - p1
			p2 -= 1
		else:
			p1 += 1
	return count
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
print(helper(n, a, b))


import os, sys, bisect, copy
from collections import defaultdict, Counter, deque
from functools import lru_cache
if os.path.exists('in.txt'):
	sys.stdin = open('in.txt', 'r')
if os.path.exists('out.txt'):
	sys.stdout = open('out.txt', 'w')

def input():
	return sys.stdin.readline()

def mapi(arg=0):
	return map(int if arg == 0 else str, input().split())
n = int(input())
a = list(mapi())
b = list(mapi())
c = [a[i] - b[i] for i in range(n)]
d = [-i for i in c]
c.sort()
res = 0
for i in range(n):
	l = i
	r = n - 1
	while l < r:
		mid = l + r + 1 >> 1
		if c[i] + c[mid] > 0:
			r = mid - 1
		else:
			l = mid
	res += n - r - 1
print(res)


from pprint import pprint
n = int(input())
data = list(map(int, input().split()))
datb = list(map(int, input().split()))
datc = [data[x] - datb[x] for x in range(n)]
datc.sort()
import bisect
res = 0
for i in range(n - 1, -1, -1):
	x = datc[i]
	if x <= 0:
		break
	c = bisect.bisect_right(datc, -x)
	res += i - c
print(res)


n = int(input())
li = sorted((i - j for (i, j) in zip(map(int, input().split()), map(int, input().split()))))
l = 0
r = n - 1
s = 0
while l < r:
	if li[l] + li[r] > 0:
		s += r - l
		r -= 1
	else:
		l += 1
print(s)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [i - j for (i, j) in zip(a, b)]
c.sort()
i = 0
j = n - 1
ans = 0
while i <= j:
	while i < n and c[i] + c[j] <= 0:
		i += 1
	if j >= i:
		ans += j - i
	j -= 1
print(ans)


import os
import sys
from io import BytesIO, IOBase
import heapq as h
from bisect import bisect_left
from types import GeneratorType
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		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 = self.os.read(self._fd, max(self.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 = self.os.read(self._fd, max(self.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:
			self.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))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import time
start_time = time.time()
import collections as col
import math, string
from functools import reduce

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())
MOD = 10 ** 9 + 7

def solve():
	N = getInt()
	A = getInts()
	B = getInts()
	C = [A[j] - B[j] for j in range(N)]
	C.sort()
	i = 0
	j = N
	while j > 1 and C[j - 1] + C[0] > 0:
		j -= 1
	ans = N - j
	i += 1
	while i < N:
		j = max(j, i + 1)
		while j > i + 1 and C[j - 1] + C[i] > 0:
			j -= 1
		ans += N - j
		i += 1
	return ans
print(solve())


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(n):
	a[i] = a[i] - b[i]
a.sort()
cnt = 0
l = 0
h = n - 1
while l < h:
	if a[l] + a[h] > 0:
		cnt += h - l
		h -= 1
	else:
		l += 1
print(cnt)


T = int(input())
state0 = [int(x) for x in input().split()]
state1 = [int(x) for x in input().split()]
stated = sorted([x - y for (x, y) in zip(state0, state1)])
l = len(stated)
count = 0
npos = {}
plus = -1
for (i, s) in enumerate(stated):
	if s <= 0:
		try:
			npos[s] += 1
		except:
			npos[s] = 1
	elif s > 0:
		plus = i
		break
if plus == -1:
	plus = len(stated)
count += (l - plus) * (l - plus - 1) // 2
negs = list(npos.keys())[::-1]
n = 0
for i in range(plus, len(stated)):
	if n < len(negs):
		while negs[n] + stated[i] > 0:
			count += npos[negs[n]] * (l - i)
			n += 1
			if n >= len(negs):
				break
	else:
		break
print(count)


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 = 10 ** 9 + 7
mod2 = 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 IF(c, t, f):
	return t if c else f

def main():
	t = 1
	rr = []
	for _ in range(t):
		n = I()
		a = LI()
		b = LI()
		c = [-inf] + sorted([b[i] - a[i] for i in range(n)])
		r = 0
		i = n
		for j in range(1, n + 1):
			t = c[j]
			while t + c[i] >= 0:
				i -= 1
			r += i
			if j <= i:
				r -= 1
		rr.append(r // 2)
	return JA(rr, '\n')
print(main())


from sys import stdin

def inp():
	return stdin.buffer.readline().rstrip().decode('utf8')

def itg():
	return int(stdin.buffer.readline())

def mpint():
	return map(int, stdin.buffer.readline().split())

def discrete_binary_search(func, lo, hi):
	while lo < hi:
		mi = lo + (hi - lo) // 2
		if func(mi):
			hi = mi
		else:
			lo = mi + 1
	return lo

def pair_calculator(length, func, check=False, distinct=True):
	result = 0
	for i in range(length):
		bound = discrete_binary_search(lambda x: func(i, x), i, length)
		result += length - bound
		if bound == i and distinct:
			result -= 1
	if check:
		ans = 0
		for i in range(length):
			for j in range(i, length):
				if i != j or not distinct:
					ans += func(i, j)
		assert result == ans, 'expected: %d, got %d' % (ans, result)
	return result
n = itg()
a = mpint()
b = mpint()
c = [ai - bi for (ai, bi) in zip(a, b)]
c.sort()
print(pair_calculator(len(c), lambda i, j: c[i] > -c[j]))


import bisect
import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
z = [a[i] - b[i] for i in range(n)]
z.sort()
t = 0
for (i, d) in enumerate(z[:-1]):
	h = bisect.bisect(z, -d, i + 1)
	t += n - h
print(t)


def arr():
	return [int(i) for i in input().split()]
n = int(input())
a = arr()
b = arr()
c = [i - j for (i, j) in zip(a, b)]
c.sort()
ans = 0
(i, j) = (0, n - 1)
while i <= j:
	while i < n and c[i] + c[j] <= 0:
		i += 1
	if j >= i:
		ans += j - i
	j -= 1
print(ans)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(n):
	a[i] -= b[i]
a = sorted(a)
i = 0
j = n - 1
ans = 0
while i < j:
	while i < j and a[i] + a[j] <= 0:
		i += 1
	if i < j:
		ans += j - i
	j -= 1
print(ans)


def solve(n, teacher, students):
	result = 0
	interests = [teacher[i] - students[i] for i in range(n)]
	interests.sort()
	begin = 0
	end = n - 1
	while begin != end:
		if interests[begin] + interests[end] > 0:
			result += end - begin
			end -= 1
		else:
			begin += 1
	return result

def main():
	n = int(input())
	teacher = list(map(int, input().split()))
	students = list(map(int, input().split()))
	result = solve(n, teacher, students)
	print(result)
	return 0
main()


from operator import sub

def main():
	j = int(input()) - 1
	l = sorted(map(sub, map(int, input().split()), map(int, input().split())))
	i = r = 0
	while i < j:
		while i < j and l[i] + l[j] > 0:
			r += j - i
			j -= 1
		while i < j and l[i] + l[j] <= 0:
			i += 1
	print(r)
main()


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [a[i] - b[i] for i in range(n)]
c.sort()
ind = n - 1
wyn = 0
for i in range(n):
	while True:
		if ind > i and c[i] + c[ind] > 0:
			ind -= 1
		else:
			break
	if ind <= i:
		ind = min(n - 1, i)
	wyn += n - 1 - ind
print(wyn)


def pair(ne, a, b):
	ans = 0
	p = []
	lp = 0
	n = []
	ln = 0
	z = 0
	for i in range(ne):
		if a[i] > b[i]:
			p.append(a[i] - b[i])
			lp += 1
		elif a[i] == b[i]:
			z += 1
		else:
			n.append(b[i] - a[i])
			ln += 1
	ans += lp * z
	p.sort()
	n.sort()
	i = 0
	j = 0
	while i < ln and j < lp:
		if n[i] < p[j]:
			ans += lp - j
			i += 1
		elif n[i] >= p[j]:
			j += 1
	ans += lp * (lp - 1) // 2
	return ans
n = int(input())
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
print(pair(n, a, b))


def I():
	return list(map(int, input().split()))

def bin(arr, t):
	l = 0
	r = len(arr) - 1
	while l <= r:
		mid = l + (r - l) // 2
		if arr[mid] >= t:
			r = mid - 1
		else:
			l = mid + 1
	return r
n = int(input())
a = I()
b = I()
s = [b[i] - a[i] for i in range(n)]
s.sort()
c = 0
for i in range(n):
	j = bin(s, -s[i])
	if j > i:
		j -= 1
	c += j + 1
print(c // 2)


from math import *
from copy import *
from string import *
from random import *
from sys import stdin
from sys import maxsize
from operator import *
from itertools import *
from collections import Counter
from collections import defaultdict

def BinarySearch(arr, k, i):
	left = i + 1
	right = len(arr) - 1
	while left <= right:
		mid = (left + right) // 2
		if arr[mid] >= k and (mid == i + 1 or arr[mid - 1] < k):
			return mid
		elif arr[mid] >= k:
			right = mid - 1
		else:
			left = mid + 1
	return len(arr)

def solve(A, B):
	n = len(A)
	diff = [0] * n
	for i in range(n):
		diff[i] = A[i] - B[i]
	diff = sorted(diff)
	ans = 0
	for i in range(n - 1):
		zz = 0
		if diff[i] <= 0:
			zz = BinarySearch(diff, abs(diff[i]) + 1, i)
		else:
			zz = BinarySearch(diff, 0, i)
		ans += n - zz
	return ans
N = int(input())
a = list(map(int, stdin.readline().rstrip().split()))
b = list(map(int, stdin.readline().rstrip().split()))
print(solve(a, b))


import sys
input = sys.stdin.readline

def bin(s, e):
	if s == e:
		if a[s] > -a[i]:
			return s
		else:
			return s + 1
	m = s + e >> 1
	if a[m] > -a[i]:
		return bin(s, m)
	else:
		return bin(m + 1, e)
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(n):
	a[i] -= b[i]
cnt = 0
a.sort()
idx1 = 0
idx2 = 1
for i in range(n - 1):
	cnt += n - bin(i + 1, n - 1)
print(cnt)


def bin(q, m):
	l = 0
	r = m
	while r - l > 1:
		x = (l + r) // 2
		if -otr[x] < q:
			l = x
		else:
			r = x
	if m == 1:
		if -otr[0] < q:
			return 1
		return 0
	if r == m:
		if -otr[-1] < q:
			return m
		return l + 1
	if l == 0:
		if -otr[0] >= q:
			return 0
	return l + 1
n = int(input())
mass = [int(x) for x in input().split()]
arr = [int(x) for x in input().split()]
pol = list()
otr = list()
for i in range(n):
	x = mass[i] - arr[i]
	if x > 0:
		pol.append(x)
	else:
		otr.append(x)
otr.sort(reverse=True)
m = len(pol)
answer = m * (m - 1) // 2
if len(otr) > 0:
	for i in pol:
		answer += bin(i, len(otr))
print(answer)


x = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(x):
	a[i] = a[i] - b[i]
a.sort()
left = 0
right = x - 1
count = 0
while left < right:
	if a[left] + a[right] > 0:
		count = count + right - left
		right = right - 1
	else:
		left = left + 1
print(count)


t = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [i - j for (i, j) in zip(a, b)]
c = sorted(c)
left = t - 1
ans = 0
for i in range(t - 1):
	while c[i] + c[left] > 0 and i < left:
		left -= 1
	left = max(left, i)
	ans += t - left - 1
print(ans)


def bin(l, n):
	left = 0
	right = len(l) - 1
	while left <= right:
		mid = left + (right - left) // 2
		if l[mid] < n:
			left = mid + 1
		else:
			right = mid - 1
	return left
t = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
diff = [a[i] - b[i] for i in range(t)]
diff.sort()
s = 0
i = len(diff) - 1
while diff[i] > 0 and i > 0:
	j = bin(diff, -1 * diff[i] + 1)
	s += i - j
	i -= 1
print(s)


def count_good_pairs(teacher_reviews, student_reviews):
	balance = list(sorted([t - s for (t, s) in zip(teacher_reviews, student_reviews)], reverse=True))
	good_pairs_count = 0
	left_idx = 0
	right_idx = len(balance) - 1
	while left_idx < right_idx:
		left_item = balance[left_idx]
		right_item = balance[right_idx]
		if left_item + right_item <= 0:
			right_idx -= 1
			continue
		good_pairs_count += right_idx - left_idx
		left_idx += 1
	return good_pairs_count
input()
teacher_reviews = [int(x) for x in input().split()]
student_reviews = [int(x) for x in input().split()]
result = count_good_pairs(teacher_reviews, student_reviews)
print(result)


n = int(input())
A = input().split()
B = input().split()
T = []
S = []
Z = 0
for i in range(n):
	temp = int(A[i]) - int(B[i])
	if temp < 0:
		S.append(-temp)
	elif temp > 0:
		T.append(temp)
	else:
		Z += 1
ans = int(len(T) * (len(T) - 1) / 2)
if Z:
	ans += len(T) * Z
T.sort(reverse=True)
S.sort(reverse=True)
i = 0
j = 0
while i < len(T) and j < len(S):
	while T[i] <= S[j]:
		j += 1
		if j == len(S):
			break
	if j == len(S):
		break
	ans += len(S) - j
	i += 1
print(ans)


from math import *
inf = 10 ** 10
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [a[i] - b[i] for i in range(n)]
c.sort()
ans = 0
for i in range(n):
	lb = 0
	ub = n
	while lb + 1 < ub:
		tx = (lb + ub) // 2
		dx = (ub - lb) // 2
		if c[tx] + c[i] > 0:
			ub -= dx
		else:
			lb += dx
	dx = (lb + ub) // 2
	for j in range(4):
		try:
			if dx > 0 and c[dx - 1] + c[i] > 0:
				dx -= 1
			if i >= dx or c[dx] + c[i] <= 0:
				dx += 1
		except:
			dx += 1
	ans += max(n - dx, 0)
print(ans // 2)


def binary(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= 1 - arr[k]:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return leftGreater
n = int(input())
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))
ans = []
for i in range(n):
	ans.append(arr1[i] - arr2[i])
ans.sort()
count = 0
for i in range(n):
	if ans[i] > 0:
		res = binary(ans, len(ans), i)
		if res != -1:
			count += i - res
print(count)


from bisect import bisect_right
(n, c) = (int(input()), 0)
a = list(map(int, input().split()))
for (i, x) in enumerate(map(int, input().split())):
	a[i] -= x
ls = sorted(a)
for (i, x) in enumerate(ls):
	if x > 0:
		c += (n - i) * (n - i - 1) // 2
		break
	c += n - bisect_right(ls, -x)
print(c)


(n,) = map(int, input().split())
a = sorted((x - y for (x, y) in zip(map(int, input().split()), map(int, input().split()))))
(r, d) = (0, n)
while d:
	f = a[n - d] + a[n - 1] > 0
	r += f * d - f
	n -= f
	d -= 1
print(r)


N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
lis = []
for i in range(N):
	lis.append(b[i] - a[i])
lis.sort()
ans = 0
sub = 0
import bisect
for i in range(N):
	ns = a[i] - b[i]
	ans += bisect.bisect_left(lis, ns)
	if a[i] > b[i]:
		sub += 1
print((ans - sub) // 2)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
factor = [0 for _ in range(n)]
for i in range(n):
	factor[i] = a[i] - b[i]
factor.sort(reverse=True)
ans = 0
(i, j) = (0, n - 1)
while i < j:
	k = factor[i] + factor[j]
	if k <= 0:
		j -= 1
	else:
		ans += j - i
		i += 1
print(ans)


from collections import defaultdict
import bisect

def solve(n, a, b):
	c = []
	for i in range(n):
		c.append(a[i] - b[i])
	c.sort()
	ans = 0
	for i in range(n):
		if c[i] <= 0:
			continue
		pos = bisect.bisect_left(c, -c[i] + 1)
		ans += i - pos
	return ans
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
print(solve(n, a, b))


n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
ss = 0
for i in range(n):
	a[i] -= b[i]
a.sort()
ss = 0
j = n - 1
for i in range(n):
	if a[i] > 0:
		ss += n - i - 1
	else:
		while j > 0 and a[j] + a[i] > 0:
			j -= 1
		ss += n - j - 1
print(ss)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = [b[i] - a[i] for i in range(n)]
x.sort()
from bisect import bisect_left

def find_lt(a, x, low):
	i = bisect_left(a, x, lo=low)
	if i:
		return i - 1 - low + 1
	else:
		return 0
ctr = 0
ans = 0
for j in x:
	to_search = -j
	ans += find_lt(x, to_search, ctr + 1)
	ctr += 1
print(ans)


n = int(input())
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
diff1 = []
diff2 = []
for i in range(n):
	diff1.append(l1[i] - l2[i])
diff1.sort()
ans = -sum((val > 0 for val in diff1))
for i in range(n):
	l = i
	r = n
	while l < r:
		mid = (l + r) // 2
		if diff1[i] + diff1[mid] > 0:
			r = mid
		else:
			l = mid + 1
	ans += n - l
print(ans)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
diffs = sorted([a[i] - b[i] for i in range(n)])
(i, j) = (0, n)
res = 0
while i < n and diffs[i] < 0:
	while j > 0 and diffs[j - 1] + diffs[i] > 0:
		j -= 1
	res += n - j
	i += 1
zeroes = 0
while i < n and diffs[i] == 0:
	zeroes += 1
	i += 1
positives = n - i
res += zeroes * positives
if positives > 1:
	res += positives * (positives - 1) // 2
print(res)


import sys
input = sys.stdin.readline
t = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [a[i] - b[i] for i in range(t)]
c.sort()
total = 0
last = t - 1
for i in range(t):
	if c[i] < 1:
		for j in range(last, -1, -1):
			if c[j] + c[i] < 1:
				last = j + 1
				break
		total += max(0, t - last)
		last = min(last, t - 1)
	else:
		total += t - i - 1
print(total)


import bisect
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = sorted(list([x - y for (x, y) in zip(a, b)]))
total = 0
for (i, low) in enumerate(d):
	target = -low
	pos = bisect.bisect(d, target, lo=i + 1)
	total += n - pos
print(total)


try:
	import bisect

	def get(A, B, n):
		D = [0] * n
		for i in range(n):
			D[i] = A[i] - B[i]
		D.sort()
		total = 0
		for i in range(n - 1, -1, -1):
			if D[i] > 0:
				total += n - i - 1
			else:
				k = bisect.bisect_right(D, -D[i], 0, len(D))
				total += n - k
		return total
	if __name__ == '__main__':
		n = int(input())
		a = list(map(int, input().strip().split()))[:n]
		b = list(map(int, input().strip().split()))[:n]
		k = get(a, b, n)
		print(k)
except:
	pass


R = lambda : map(int, input().split())
(n,) = R()
a = sorted((x - y for (x, y) in zip(R(), R())))
r = 0
for d in range(n, 1, -1):
	if a[n - d] + a[n - 1] > 0:
		r += d - 1
		n -= 1
print(r)


def getpos(v):
	v = -1 * v
	l = 0
	h = n
	while l < h:
		m = (l + h) // 2
		if c[m] == v:
			while m < n and c[m] == v:
				m += 1
			return m
		elif c[m] < v:
			l = m + 1
		else:
			h = m
	return l
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = sorted([i - j for (i, j) in zip(a, b)])
zeros = 0
gzeros = 0
lz = 0
for i in c:
	if i == 0:
		zeros += 1
	elif i > 0:
		gzeros += 1
	else:
		lz += n - getpos(i)
output = lz + zeros * gzeros + gzeros * (gzeros - 1) // 2
print(output)


import bisect
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
c = [None] * n
for i in range(n):
	c[i] = a[i] - b[i]
c.sort()
for i in range(n):
	if c[i] <= 0:
		continue
	pos = bisect.bisect_left(c, -c[i] + 1, 0, n)
	ans += i - pos
print(ans)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = []
for i in range(0, n):
	c.append(a[i] - b[i])
c.sort()
p1 = n - 1
p2 = 0
ans = 0
while p1 > p2:
	while p2 < p1 and c[p1] + c[p2] <= 0:
		p2 += 1
	ans += p1 - p2
	p1 -= 1
print(ans)


def rr():
	return input().rstrip()

def rri():
	return int(rr())

def rrl():
	return list(map(int, rr().split()))

def rrt():
	return tuple(map(int, rr().split()))
from collections import defaultdict

def mus(d=0):
	return defaultdict(defaultdict(d))

def ms(x, y, d=0):
	return [[0] * y for i in range(x)]

def ar(x, d=0):
	return [d] * x

def ppm(m, n=0, x=0, y=0):
	print('\n'.join(('\t'.join((str(m[j][i]) for j in range(y or n))) for i in range(x or n))))

def ppa(a, n):
	print('\t'.join(map(str, a[0:n])))

def ppl(a=0, x=[1]):
	x[0] = a or x[0] + 1
	print('-' + '- -' * 14 + '-# ' + str(x[0] - 2) + ' #-' + '- -' * 14 + '-')

def yn(x):
	return 'YES' if x else 'NO'
from itertools import groupby

def rnar():
	return (rri(), rrl())

def rn2ar():
	return (rri(), rrl(), rrl())

def r2nar():
	return (rri(), rri(), rrl())

def read():
	return rn2ar()

def solve(n, a1, a2):
	a3 = list(map(lambda x: x[0] - x[1], zip(a1, a2)))
	a3.sort()
	try:
		lz = 0
		while a3[lz] < 0:
			lz += 1
		rz = lz
		while a3[rz] == 0:
			rz += 1
	except IndexError:
		return 0
	negative = list(reversed(a3[:lz]))
	zeros = rz - lz
	positive = list(a3[rz:])
	tt = 0
	i = 0
	j = 0
	while i < len(negative) and j < len(positive):
		if negative[i] + positive[j] > 0:
			tt += len(positive) - j
			i += 1
		else:
			j += 1
	zp = zeros * len(positive)
	pp = len(positive) * (len(positive) - 1) // 2
	tt = tt + zp + pp
	answ = tt
	return answ
test_count = 1
for _ in range(test_count):
	input_data = read()
	result = solve(*input_data)
	print(result)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
l = []
for i in range(n):
	l.append(a[i] - b[i])
l.sort()
count = 0
i = 0
j = len(l) - 1
while i < j:
	if l[i] > -l[j]:
		count += j - i
		j -= 1
	else:
		i += 1
print(count)


import sys
import os
import time
import collections
from collections import Counter, deque
import itertools
import math
import timeit
import random
import string

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

def divs(n, start=1):
	divisors = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				divisors.append(i)
			else:
				divisors.extend([i, n // i])
	return divisors

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def flin(d, x, default=-1):
	left = right = -1
	for i in range(len(d)):
		if d[i] == x:
			if left == -1:
				left = i
			right = i
	if left == -1:
		return (default, default)
	else:
		return (left, right)

def ceil(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

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

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def prr(a, sep=' '):
	print(sep.join(map(str, a)))

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)
input = sys.stdin.readline

def upper_bound(a, p, l, r):
	ans = -1
	while l <= r:
		mid = l + (r - l) // 2
		if a[mid] > p:
			ans = mid
			r = mid - 1
		else:
			l = mid + 1
	return ans
n = ii()
a = li()
b = li()
d = [a[i] - b[i] for i in range(n)]
d.sort()
res = 0
for i in range(n):
	p = upper_bound(d, -d[i], i + 1, n - 1)
	if p != -1:
		res += n - p
print(res)


from sys import stdin, stdout, setrecursionlimit

class Tail_Recursion_Optimization:

	def __init__(self, RECURSION_LIMIT, STACK_SIZE):
		setrecursionlimit(RECURSION_LIMIT)
		threading.stack_size(STACK_SIZE)
		return None

class SOLVE:

	def solve(self):
		R = stdin.readline
		W = stdout.write
		n = int(R())
		a = [int(x) for x in R().split()]
		b = [int(x) for x in R().split()]
		c = []
		for i in range(n):
			c.append(a[i] - b[i])
		c.sort(reverse=True)
		pairs = 0
		for i in range(n - 1):
			(l, r, pos) = (i + 1, n - 1, i)
			if c[i] <= 0:
				break
			while l <= r:
				mid = (l + r) // 2
				if c[mid] >= -c[i] + 1:
					pos = mid
					l = mid + 1
				else:
					r = mid - 1
			pairs += pos - i
		W('%d\n' % pairs)
		return 0

def main():
	s = SOLVE()
	s.solve()
main()


n = int(input())
avals = [int(a) for a in input().split()]
bvals = [int(a) for a in input().split()]
vals = sorted([a - b for (a, b) in zip(avals, bvals)], reverse=True)

def find_last(i):
	val = -vals[i]
	left = i
	right = n
	while right - left > 1:
		mid = (right + left) // 2
		if vals[mid] > val:
			left = mid
		else:
			right = mid
	return left
pairs = 0
for i in range(n):
	if vals[i] < 0:
		break
	j = find_last(i)
	pairs += j - i
print(pairs)


from sys import stdin

def binary_search(arr, low, high, x):
	if low == high:
		return low
	mid = (low + high) // 2
	if arr[mid] < x:
		return binary_search(arr, mid + 1, high, x)
	else:
		return binary_search(arr, low, mid, x)
n = int(stdin.readline().rstrip())
l1 = list(map(int, stdin.readline().rstrip().split(' ')))
l2 = list(map(int, stdin.readline().rstrip().split(' ')))
l3 = [0] * n
l = dict()
for i in range(n):
	l3[i] = l1[i] - l2[i]
l3.sort()
t = 0
for i in range(n - 1):
	val = 1 - l3[i]
	a = binary_search(l3, i + 1, n - 1, val)
	if l3[i] + l3[a] > 0:
		t += n - a
print(t)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
difs = [x - y for (x, y) in zip(a, b)]
difs = sorted(difs)
i = 0
j = n - 1
total = 0
while j > i:
	if difs[j] + difs[i] > 0:
		total += j - i
		j -= 1
	else:
		i += 1
print(total)


n = int(input())
a = [int(s) for s in input().split()]
b = [int(s) for s in input().split()]
c = []
for i in range(n):
	c.append(a[i] - b[i])
c.sort()
i = 0
j = n - 1
count = 0
while i < j:
	if c[i] > 0:
		count = count + (j - i)
		j = j - 1
		continue
	elif abs(c[i]) < c[j]:
		count = count + (j - i)
		j = j - 1
	else:
		i = i + 1
print(count)


def answer(array):
	array = sorted(array, reverse=True)
	(left, right, counter) = (0, len(array) - 1, 0)
	while left < right:
		if array[left] + array[right] > 0:
			counter += right - left
			left += 1
		else:
			right -= 1
	return counter
size = int(input())
stud = list(map(int, input().split()))
teach = list(map(int, input().split()))
array = []
for i in range(size):
	array.append(stud[i] - teach[i])
print(answer(array))


n = int(input())
teacher = list(map(int, input().split()))
student = list(map(int, input().split()))
store = []
for i in range(n):
	store.append(teacher[i] - student[i])
store.sort()
(l, r) = (0, n - 1)
res = 0
while l < r:
	cur = store[r] + store[l]
	if cur > 0:
		res += r - l
		r -= 1
	else:
		l += 1
print(res)


def f(c, low, high, val):
	k = 0
	while low <= high:
		mid = (low + high) // 2
		if c[mid] > val:
			k = k + (high - mid + 1)
			high = mid - 1
		else:
			low = mid + 1
	return k
n = int(input())
x1 = input()
x2 = input()
a = []
b = []
a = x1.split(' ')
b = x2.split(' ')
c = []
for i in range(n):
	a[i] = int(a[i])
	b[i] = int(b[i])
	c.append(a[i] - b[i])
c.sort()
final = 0
for i in range(len(c)):
	final = final + f(c, i + 1, n - 1, -1 * c[i])
print(final)


n = int(input().strip())
a = list(map(int, input().strip().split()))
b = list(map(int, input().strip().split()))
c = []
for i in range(n):
	c.append(a[i] - b[i])
c.sort()
from bisect import bisect_right
ans = 0
for i in range(n):
	j = bisect_right(c, -c[i])
	j = max(j, i + 1)
	ans += n - j
print(ans)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = []
for i in range(0, n):
	c.append(a[i] - b[i])
c.sort(reverse=True)
s = 0
i = -1
k = n - 1
while i < k:
	i += 1
	while i < k:
		if c[i] + c[k] > 0:
			s += k - i
			break
		else:
			k -= 1
print(s)


N = 200001
tree = [0] * (2 * N)

def build(arr):
	for i in range(n):
		tree[n + i] = arr[i]
	for i in range(n - 1, 0, -1):
		tree[i] = tree[i << 1] + tree[i << 1 | 1]

def updateTreeNode(p, value):
	tree[p + n] = value
	p = p + n
	i = p
	while i > 1:
		tree[i >> 1] = tree[i] + tree[i ^ 1]
		i >>= 1

def query(l, r):
	res = 0
	l += n
	r += n
	while l < r:
		if l & 1:
			res += tree[l]
			l += 1
		if r & 1:
			r -= 1
			res += tree[r]
		l >>= 1
		r >>= 1
	return res
from collections import defaultdict
import bisect
n = int(input().strip())
a = [int(i) for i in input().strip().split()]
b = [int(i) for i in input().strip().split()]
minus = [(a[i] - b[i], i) for i in range(n)]
minus.sort()
order = dict()
for (index, i) in enumerate(minus):
	order[i[1]] = index
minus = [i[0] for i in minus]
total = 0
temp = [0 for i in range(n)]
build(temp)
for i in range(n - 1):
	result = -(a[i] - b[i])
	ans = bisect.bisect_right(minus, result)
	total += n - ans
	if ans < n:
		total -= 1 if result < a[i] - b[i] else 0
		total -= query(ans, n)
	updateTreeNode(order[i], 1)
print(total)


t = int(input())
tpref = input().split()
diff = [int(tpref[i]) - int(x) for (i, x) in enumerate(input().split())]

def find(data, target):
	ans = -1
	start = 0
	end = len(data) - 1
	while start <= end:
		mid = (start + end) // 2
		if data[mid] <= target:
			start = mid + 1
		else:
			ans = mid
			end = mid - 1
	return ans
sdiff = sorted(diff)
out = 0
l = len(sdiff)
for (i, n) in enumerate(reversed(sdiff)):
	if n <= 0:
		break
	k = find(sdiff, -n)
	out += l - k - i - 1
print(out)


n = int(input())
a1 = input().split()
a1 = [int(y) for y in a1]
a2 = input().split()
a2 = [int(y) for y in a2]
null = [a1[i] - a2[i] for i in range(n)]
null.sort()
l = 0
r = n - 1
ans = 0
while l < r:
	if null[r] + null[l] > 0:
		ans += r - l
		r -= 1
	else:
		l += 1
print(ans)


import sys
input = sys.stdin.readline
read = lambda : map(int, input().split())
read_float = lambda : map(float, input().split())

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def factorial(x, m):
	val = 1
	while x > 0:
		val = val * x % m
		x -= 1
	return val

def fact(x):
	val = 1
	while x > 0:
		val *= x
		x -= 1
	return val

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	return a * b // math.gcd(a, b)

def nCr(n, k):
	if k > n:
		return 0
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

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 swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	(prime[0], prime[1]) = (False, False)
	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 phi(n):
	result = n
	p = 2
	while p * p <= n:
		if n % p == 0:
			while n % p == 0:
				n = n // p
			result = result * (1.0 - 1.0 / float(p))
		p = p + 1
	if n > 1:
		result = result * (1.0 - 1.0 / float(n))
	return int(result)

def is_prime(n):
	if n == 0:
		return False
	if n == 1:
		return True
	for i in range(2, int(n ** (1 / 2)) + 1):
		if not n % i:
			return False
	return True
MAXN = int(100000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i
spf = [0 for i in range(MAXN)]

def factoriazation(x):
	res = []
	for i in range(2, int(x ** 0.5) + 1):
		while x % i == 0:
			res.append(i)
			x //= i
	if x != 1:
		res.append(x)
	return res

def factors(n):
	res = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			res.append(i)
			res.append(n // i)
	return list(set(res))

def int_array():
	return list(map(int, input().strip().split()))

def float_array():
	return list(map(float, input().strip().split()))

def str_array():
	return input().strip().split()

def binary_search(low, high, w, h, n):
	while low < high:
		mid = low + (high - low) // 2
		if check(mid, w, h, n):
			low = mid + 1
		else:
			high = mid
	return low

def check(councils, a, k):
	summ = 0
	for x in a:
		summ += min(x, councils)
	return summ // councils >= k
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
from itertools import permutations
import math
import bisect as bis
import random
import sys

def solve():
	n = int(input())
	a = list(read())
	b = list(read())
	diff = [x - y for (x, y) in zip(a, b)]
	newdiff = list(sorted(diff))
	s = 0
	for i in range(len(newdiff)):
		j = bis.bisect_left(newdiff, 1 - newdiff[i])
		s += max(i - j, 0)
	print(s)
for _ in range(1):
	solve()


from bisect import bisect_right
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = [i - j for (i, j) in zip(a, b)]
x.sort()
ans = 0
for i in x:
	if i > 0:
		ans -= 1
	ans += n - bisect_right(x, -i)
print(ans // 2)


from collections import defaultdict
from sys import stdin
input = stdin.readline
n = int(input())
ll = []
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(n):
	ll.append(a[i] - b[i])
ll.sort()
s = 0
l = 0
r = n - 1
while l < r:
	if ll[l] + ll[r] > 0:
		s += r - l
		r -= 1
	else:
		l += 1
print(s)


from bisect import bisect_right
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
r = []
for i in range(n):
	r.append(a[i] - b[i])
r.sort()
ans = 0
if r[-1] <= 0:
	print(ans)
else:
	for i in range(n):
		if r[i] <= 0:
			j = bisect_right(r, abs(r[i]))
			ans += n - j
		else:
			ans += (n - i - 1) * (n - i) // 2
			break
	print(ans)


import bisect
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
diff = [x - y for (x, y) in zip(a, b)]
diff.sort()
result = 0
for (i, val) in enumerate(diff):
	if val < 0:
		continue
	target = 1 - val
	index = bisect.bisect_left(diff, target)
	if index < i:
		result += i - index
print(result)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
sub = [a[i] - b[i] for i in range(n)]
sub.sort()
import bisect
total = 0
for elem in sub:
	if elem > 0:
		break
	total += n - bisect.bisect_right(sub, -elem)
remains = n - bisect.bisect_right(sub, 0)
print(total + remains * (remains - 1) // 2)


q = int(input())
w = list(map(int, input().split()))
e = list(map(int, input().split()))
m = []
n = []
for i in range(q):
	bb = w[i] - e[i]
	if bb > 0:
		m.append(bb)
	else:
		n.append(bb)
m.sort()
n.sort()
zz = len(m)
s = zz * (zz - 1) // 2
z = zz
for i in range(len(n)):
	while True:
		if z - 1 >= 0 and m[z - 1] + n[i] > 0:
			z -= 1
		else:
			break
	s += zz - z
	i += 1
print(s)


import bisect
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
x = [0] * n
for i in range(len(a)):
	x[i] = a[i] - b[i]
x.sort()
ans = 0
for i in range(n):
	if x[i] <= 0:
		continue
	else:
		ans += i - bisect.bisect_left(x, -x[i] + 1)
print(ans)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = []
for i in range(n):
	c.append(a[i] - b[i])
c = list(sorted(c))
pos_ind = 0
for i in range(n):
	if c[i] > 0:
		pos_ind = i
		break
if pos_ind > 0:
	num_pairs = int((n - pos_ind) * (n - pos_ind - 1) * 0.5)
	good_ind = pos_ind
	minus_ind = pos_ind - 1
	while minus_ind >= 0 and good_ind < n:
		if c[minus_ind] + c[good_ind] > 0:
			num_pairs += n - good_ind
			minus_ind -= 1
		else:
			good_ind += 1
	print(int(num_pairs))
elif c[0] <= 0:
	print(0)
else:
	num_pairs = int((n - pos_ind) * (n - pos_ind - 1) * 0.5)
	print(int(num_pairs))


from bisect import bisect

def solve(A, B):
	n = len(A)
	C = [a - b for (a, b) in zip(A, B)]
	C.sort()
	ans = 0
	for i in range(n):
		j = bisect(C, -C[i], i + 1, n)
		ans += n - j
	return ans
n = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
print(solve(A, B))


import sys
input = lambda : sys.stdin.readline().rstrip()
from bisect import bisect_left as bl, bisect_right as br
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
neg = []
pos = []
ans = 0
for i in range(n):
	if a[i] - b[i] <= 0:
		neg.append(b[i] - a[i])
	else:
		pos.append(a[i] - b[i])
ans += len(pos) * (len(pos) - 1) // 2
neg.sort()
pos.sort()
for i in pos:
	z = bl(neg, i)
	ans += z
print(ans)


def solve():
	n = int(input())
	lst1 = list(map(int, input().split()))
	lst2 = list(map(int, input().split()))
	lst = [lst1[i] - lst2[i] for i in range(n)]
	lst.sort()
	l = 0
	r = n - 1
	ans = 0
	while l != r:
		if lst[l] + lst[r] > 0:
			r -= 1
		else:
			ans += n - r - 1
			l += 1
	print(ans + (n - l) * (n - l - 1) // 2)
for i in range(1):
	solve()


from sys import *
input = stdin.readline

class ordered_set:

	def __init__(self, LOG):
		self.LOG = LOG
		self.Sz = 1 << LOG
		self.fen = [0] * self.Sz

	def update(self, ind, val):
		while ind < self.Sz:
			self.fen[ind] += val
			ind += ind & -ind

	def get(self, ind):
		sum = 0
		while ind:
			sum += self.fen[ind]
			ind -= ind & -ind
		return sum

	def order_of_key(self, x):
		return self.get(x - 1)

	def find_by_order(self, ind):
		ans = 0
		for i in range(self.LOG):
			x = 1 << self.LOG - i - 1
			print((x, self.fen[ans + x], ind))
			if self.fen[ans + x] <= ind:
				ind -= self.fen[ans + x]
				ans += x
		return ans + 1

	def upper_bound(self, x):
		return self.find_by_order(self.get(x))

	def lower_bound(self, x):
		return self.upper_bound(x - 1)
fen = ordered_set(20)
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = [0] * (n * 2)
for i in range(n):
	C[i * 2] = [A[i] - B[i], (i + 1) * 2]
	C[i * 2 + 1] = [B[i] - A[i], (i + 1) * 2 + 1]
C.sort(key=lambda x: x[0])
ans = 0
prv = -1
D = []
for i in C:
	if i[0] != prv:
		for j in D:
			fen.update(j, 1)
		D = []
	if i[1] % 2 == 0:
		ans += fen.get(i[1])
	else:
		D.append(i[1])
	prv = i[0]
print(ans)


def main():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = []
	for i in range(n):
		d = a[i] - b[i]
		c.append(d)
	c.sort()
	(i, j) = (0, 0)
	ans = 0
	while i < n:
		if c[i] > 0:
			t = c[i] * -1 + 1
			while j >= 0 and c[j] >= t:
				j -= 1
			if j == -1:
				j = 0
			else:
				j += 1
			ans += i - j
		else:
			j += 1
		i += 1
	print(ans)
main()


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
z = [a[i] - b[i] for i in range(n)]
z.sort()
(i, j, r) = (n - 1, 0, 0)
while i >= j:
	while j < n and z[i] + z[j] <= 0:
		j += 1
	if i > j:
		r += i - j
	i -= 1
print(r)


def solve(teach, stu):
	diffs = []
	for i in range(len(teach)):
		diffs.append(teach[i] - stu[i])
	diffs = sorted(diffs)
	ans = 0
	(i, j) = (0, len(diffs) - 1)
	while i < j:
		if diffs[j] + diffs[i] > 0:
			ans += j - i
			j -= 1
		else:
			i += 1
	return ans
n = int(input())
teach = [int(x) for x in input().split()]
stu = [int(x) for x in input().split()]
print(solve(teach, stu))


from sys import stdin
inf = stdin
n = int(inf.readline())
arr1 = list(map(int, inf.readline().split(' ')))
arr2 = list(map(int, inf.readline().split(' ')))
posi = []
negi = []
for i in range(n):
	arr2[i] = arr1[i] - arr2[i]
	if arr2[i] > 0:
		posi.append(arr2[i])
	else:
		negi.append(arr2[i])
posi.sort()
negi.sort(reverse=True)
ans = len(posi) * (len(posi) - 1) // 2
n = len(negi)
prev = 0
for i in range(0, len(posi)):
	while prev != n and negi[prev] + posi[i] > 0:
		prev += 1
	ans += prev
print(ans)


import sys
from collections import deque

def main():
	input_list = get_input()
	input_list = parse_input(input_list)
	print(solve(input_list))

def get_input():
	input_list = []
	for line in sys.stdin:
		input_list.append(line.rstrip('\n'))
	return input_list

def parse_input(input_list):
	input_list = [[int(y) for y in x.split(' ')] for x in input_list]
	pair_list = [input_list[1][x] - input_list[2][x] for x in range(len(input_list[1]))]
	pair_list.sort()
	return pair_list

def solve(pair_list):
	total = 0
	pair_list = deque(pair_list)
	for i in range(len(pair_list)):
		temp = pair_list[0]
		pair_list.popleft()
		total += len(pair_list) - binary_search(pair_list, 0, len(pair_list) - 1, temp)
	return total

def binary_search(num_list, lower, upper, value):
	if lower > upper:
		if lower != len(num_list):
			return lower
		else:
			return lower
	mid = lower + (upper - lower) // 2
	if num_list[mid] + value > 0:
		return binary_search(num_list, lower, mid - 1, value)
	else:
		return binary_search(num_list, mid + 1, upper, value)
main()


n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = []
for (a, b) in zip(A, B):
	C.append(a - b)
C.sort()
i = n - 1
j = 0
pair = 0
while j < i:
	if C[j] + C[i] > 0:
		pair += i - j
		i -= 1
	else:
		j += 1
print(pair)


N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
D = [0] * N
C = 0
L = 0
R = N - 1
for I in range(N):
	D[I] = A[I] - B[I]
D.sort()
while L < R:
	if D[L] + D[R] > 0:
		C += R - L
		R -= 1
	else:
		L += 1
print(C)


import sys
import math
input = sys.stdin.readline
t = 1
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ans = 0
	diff = []
	for i in range(n):
		diff.append(a[i] - b[i])
	diff.sort()
	ind = -1
	j = n - 1
	ans = 0
	rem = 0
	for i in range(n):
		if diff[i] <= 0:
			while diff[j] > abs(diff[i]):
				rem += 1
				j -= 1
			ans += rem
		else:
			ind = i
			break
	if ind != -1:
		ans += (n - ind - 1) * (n - ind) // 2
	print(ans)


import bisect
I = lambda : map(int, input().rstrip().split())
n = int(input())
a = list(I())
b = list(I())
c = sorted((a[x] - b[x] for x in range(n)))
ans = 0
l = 0
r = n - 1
while l < r:
	if c[l] + c[r] > 0:
		ans += r - l
		r -= 1
	else:
		l += 1
print(ans)


n = int(input())
ar = list(map(int, input().split()))
br = list(map(int, input().split()))
pos = []
neg = []
p1 = 0
z1 = 0
n1 = 0
for i in range(n):
	x = ar[i] - br[i]
	if x > 0:
		pos.append(x)
		p1 += 1
	elif x == 0:
		z1 += 1
	else:
		n1 += 1
		neg.append(x)
pos.sort()
neg.sort(reverse=True)
ans = p1 * (p1 - 1) // 2 + p1 * z1
i = 0
j = 0
while i < p1 and j < n1:
	if neg[j] + pos[i] <= 0:
		i += 1
		continue
	if neg[j] + pos[i] > 0:
		ans += p1 - i
		j += 1
		continue
print(ans)


import math
import bisect
N = int(input())
teacher = list(map(int, input().split()))
student = list(map(int, input().split()))
difference = []
for i in range(N):
	difference.append(teacher[i] - student[i])
difference.sort()
total = 0
for index in range(len(difference)):
	total += len(difference) - bisect.bisect(difference, -difference[index], index + 1)
print(total)


def main():
	import bisect
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ab = [a[i] - b[i] for i in range(n)]
	ab.sort()
	ans = 0
	for x in ab:
		id = bisect.bisect_left(ab, 1 - x)
		ans += n - id
		if x >= 1 - x:
			ans -= 1
	print(ans // 2)
main()


n = int(input())
aa = list(map(int, input().split()))
bb = list(map(int, input().split()))
lis = []
for i in range(n):
	lis.append(aa[i] - bb[i])
ans = 0
lis.sort()
j = n - 1
for i in range(n):
	while i < j and lis[j] + lis[i] > 0:
		j -= 1
	ans += min(n - j - 1, n - i - 1)
print(ans)


nSubjects = int(input())
tLike = [int(x) for x in input().split()]
sLike = [int(x) for x in input().split()]
difLike = sorted([tLike[i] - sLike[i] for i in range(nSubjects)], reverse=True)
nGood = 0
end = nSubjects - 1
for (i, like) in enumerate(difLike):
	if like <= 0:
		break
	while difLike[end] + like <= 0:
		end -= 1
	nGood += end - i
print(nGood)


from bisect import bisect_left, bisect_right
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
(a_b, b_a) = ([], [])
for i in range(n):
	a_b.append(a[i] - b[i])
	b_a.append(b[i] - a[i])
s_arr = [b_a[0]]
ans = 0
a_b.sort()
(i, j) = (0, len(a_b) - 1)
while i < j:
	while i < j and a_b[i] + a_b[j] <= 0:
		i += 1
	ans += j - i
	j -= 1
print(ans)


from bisect import bisect_left

def solve(n, a, b):
	ans = 0
	x = sorted([(a[i] - b[i], i) for i in range(n)])
	y = sorted([b[i] - a[i] for i in range(n)])
	for (v, i) in x:
		k = bisect_left(y, v)
		ans += k if a[i] - b[i] <= b[i] - a[i] else k - 1
	return ans // 2

def main():
	inp = lambda : [int(x) for x in input().split()]
	i = lambda : int(input())
	n = i()
	(a, b) = (inp(), inp())
	print(solve(n, a, b))
main()


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = sorted([a[i] - b[i] for i in range(len(a))])
ans = 0

def wo(i):
	global c
	if c[i] + c[i + 1] > 0:
		return i + 1
	if c[i] + c[-1] <= 0:
		return -1
	x1 = i + 1
	x2 = len(c) - 1
	while x2 - x1 > 1:
		m = (x2 + x1) // 2
		if c[i] + c[m] > 0:
			x2 = m
		else:
			x1 = m
	return x2
for i in range(len(a) - 1):
	q = wo(i)
	if q > 0:
		ans = ans + len(a) - wo(i)
print(ans)


n = int(input())
d = []
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = [a[i] - b[i] for i in range(n)]
from bisect import bisect_left
d.sort()
ans = 0
for i in range(n):
	ans += max(i - bisect_left(d, -d[i] + 0.1), 0)
print(ans)


def binarySearch(A, start, end, x):
	if start > end:
		return start
	mid = (start + end) // 2
	if A[mid] == x:
		return mid
	elif A[mid] > x:
		return binarySearch(A, start, mid - 1, x)
	else:
		return binarySearch(A, mid + 1, end, x)
n = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [A[i] - B[i] for i in range(n)]
C.sort()
toplam = 0
for i in range(n):
	tmp = -C[i] + 1
	s = binarySearch(C, 0, n - 1, tmp)
	if s < n and C[s] == tmp:
		while C[s] == tmp and s >= 0:
			s -= 1
		s += 1
	toplam += n - s
	if tmp <= 0:
		toplam -= 1
print(toplam // 2)


import collections
import itertools
import sys
from bisect import bisect_left
from collections import defaultdict, Counter
from math import sqrt, ceil
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

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

def find_lt(a, x):
	i = bisect_left(a, x)
	if i:
		return i
	return -1

def main():
	n = inp()
	v1 = inlt()
	v2 = inlt()
	d1 = [a - v2[i] for (i, a) in enumerate(v1)]
	d2 = [-1 * v for v in d1]
	d1.sort()
	d2.sort()
	r = 0
	for d in d1:
		lt = find_lt(d2, d)
		if lt != -1:
			r += lt if d <= 0 else lt - 1
	print(r // 2)
main()


n = int(input())
a = [int(s) for s in input().split()]
b = [int(s) for s in input().split()]
arr = [a[i] - b[i] for i in range(len(a))]
i = 0
j = n - 1
arr.sort()
count = 0
while i < j:
	if arr[i] + arr[j] > 0:
		count += j - i
		j -= 1
	else:
		i += 1
print(count)


import bisect, collections

def solution():
	n = int(input().strip())
	a = [int(x) for x in input().strip().split(' ')]
	b = [int(x) for x in input().strip().split(' ')]
	d = [x - y for (x, y) in zip(a, b)]
	d2 = sorted(d)
	res = 0
	for x in d:
		res += n - bisect.bisect_left(d2, 1 - x) - (1 if x > 0 else 0)
	print(res // 2)

def main():
	for _ in range(1):
		solution()
main()


def binary_search(val, low, high):
	if low == high:
		return low
	mid = low + high >> 1
	if a[mid] == val and a[mid - 1] != val:
		return mid
	elif a[mid] < val:
		return binary_search(val, mid + 1, high)
	elif a[mid] >= val:
		return binary_search(val, low, mid)
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
for i in range(n):
	a[i] = a[i] - b[i]
a.sort()
for i in range(n):
	if a[i] > 0:
		ans += n - i - 1
	else:
		pair_index = binary_search(abs(a[i]) + 1, i + 1, n)
		ans += n - pair_index
print(ans)


n = int(input())
a = sorted(list((a - b for (a, b) in zip(map(int, input().split()), map(int, input().split())))))
l = 0
r = n - 1
cnt = 0
while l < r:
	if a[l] + a[r] > 0:
		cnt += r - l
		r -= 1
	else:
		l += 1
print(cnt)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
count = 0
c = sorted((a[i] - b[i] for i in range(n)))
i = 0
j = n - 1
while i < j:
	while c[i] + c[j] <= 0 and i < j:
		i += 1
	count += j - i
	j -= 1
print(count)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
dif = [0] * n
for i in range(n):
	dif[i] = a[i] - b[i]
dif = sorted(dif)
import bisect
ans = 0
for i in range(n):
	if dif[i] > 0:
		index = bisect.bisect_right(dif, -dif[i])
		ans += i - index
print(ans)


import operator as op
from functools import reduce
from bisect import bisect_left as bl

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
(u, v) = ([], [])
(s, g, e) = (0, 0, 0)
for i in range(len(a)):
	if a[i] - b[i] > 0:
		u.append(a[i] - b[i])
		s += 1
	elif a[i] - b[i] < 0:
		v.append(b[i] - a[i])
		g += 1
	else:
		e += 1
u.sort()
v.sort()
ans = 0
if s > 1:
	ans += ncr(s, 2)
ans += s * e
for i in range(len(u)):
	x = bl(v, u[i])
	ans += x
print(ans)


def mod_bin_search(arr, k, l, r):
	if l <= r:
		m = (l + r) // 2
		if arr[m] <= k:
			if m + 1 <= r:
				if k < arr[m + 1]:
					return m
				else:
					return mod_bin_search(arr, k, m + 1, r)
			else:
				return m
		else:
			return mod_bin_search(arr, k, l, m - 1)
	else:
		return -1
n = int(input())
(a, b) = (list(map(int, input().split())), list(map(int, input().split())))
rec = [0, 0, 0]
less_ind = []
more_ind = []
for i in range(n):
	if a[i] > b[i]:
		rec[2] += 1
		more_ind.append(a[i] - b[i])
	elif a[i] < b[i]:
		rec[0] += 1
		less_ind.append(0 - a[i] + b[i])
	else:
		rec[1] += 1
more_ind.sort()
count = rec[2] * (rec[2] - 1) // 2 + rec[1] * rec[2]
if len(more_ind) > 0:
	for i in less_ind:
		ind = mod_bin_search(more_ind, i, 0, len(more_ind) - 1)
		if ind == -1 and i < more_ind[0]:
			count += len(more_ind)
		else:
			count += len(more_ind) - (ind + 1)
print(count)


from collections import defaultdict as dc
bit = dc(lambda : 0)

def up(id, lnt):
	while id < lnt:
		bit[id] += 1
		id += id & -id

def qr(id):
	res = 0
	while id:
		res += bit[id]
		id -= id & -id
	return res
x = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a_b = []
b_a = []
st = set()
for n in range(x):
	a_b.append(a[n] - b[n])
	b_a.append(b[n] - a[n])
	st.add(a_b[n])
	st.add(a_b[n] - 1)
	st.add(b_a[n])
id = 1
vis = {}
st = sorted(list(st))
for n in st:
	vis[n] = id
	id += 1
id += 1
res = 0
for n in range(x - 1, -1, -1):
	res += qr(vis[a_b[n] - 1])
	up(vis[b_a[n]], id)
print(res)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
(ans, d) = (0, [])
for i in range(n):
	d.append(a[i] - b[i])
d.sort()
pos = 0
for i in range(n):
	if d[i] <= 0:
		x = 1 - d[i]
	else:
		pos = n - i
		break
	(l, r) = (0, n)
	while l < r:
		mid = l + r >> 1
		if d[mid] < x:
			l = mid + 1
		else:
			r = mid
	if l == n - 1 and d[l] != d[n - 1]:
		l = n
	ln = n - l
	ans += ln
ans += pos * (pos - 1) // 2
print(ans)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
k = len(a)
ans = 0
c = [a[i] - b[i] for i in range(k)]
c.sort()
(lo, hi) = (0, k - 1)
while lo <= hi:
	if c[lo] + c[hi] > 0:
		ans += hi - lo
		hi -= 1
	else:
		lo += 1
print(ans)


N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
plus = []
minus = []
nol = 0
for i in range(N):
	if a[i] > b[i]:
		plus.append(a[i] - b[i])
	elif a[i] < b[i]:
		minus.append(a[i] - b[i])
	else:
		nol += 1
plus.sort()
minus.sort(reverse=True)
count = 0
curr = 0
for i in range(len(plus)):
	while curr < len(minus) and plus[i] + minus[curr] > 0:
		curr += 1
	count += curr
if len(plus) > 0:
	count += len(plus) * (len(plus) - 1) // 2
	count += nol * len(plus)
print(count)


import os
import sys
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))
input = lambda : sys.stdin.readline().rstrip('\r\n')
topics = int(input())
tea = list(map(int, input().split()))
stu = list(map(int, input().split()))
zer = []
pos = []
neg = []
good = 0
for j in range(topics):
	val = tea[j] - stu[j]
	if val == 0:
		zer.append(val)
	elif val > 0:
		pos.append(val)
	else:
		neg.append(abs(val))
pos.sort()
neg.sort()
good += len(pos) * len(zer)
good += len(pos) * (len(pos) - 1) // 2

def findbigger(value, list1, cv):
	while cv < len(list1) - 1 and list1[cv] <= value:
		cv += 1
	if cv == len(list1) - 1 and list1[cv] <= value:
		return [False, cv]
	else:
		return [True, cv]
highest = 0
for k in neg:
	vals = findbigger(k, pos, highest)
	highest = vals[1]
	if vals[0] == True:
		good += len(pos) - highest
	else:
		break
print(good)


from collections import defaultdict
IA = lambda : map(int, input().split())
n = int(input())
a = list(IA())
b = list(IA())
for i in range(0, n):
	a[i] = a[i] - b[i]
a = sorted(a)
l = 0
r = n - 1
ans = 0
while r > l:
	if a[l] + a[r] > 0:
		ans += r - l
		r -= 1
	else:
		l += 1
print(ans)


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
from collections import defaultdict
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))
input = lambda : sys.stdin.readline().rstrip('\r\n')
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list()
for i in range(n):
	c.append(a[i] - b[i])
c.sort(reverse=True)
count = 0
j = n - 1
for i in range(n):
	if c[i] <= 0:
		break
	while c[i] + c[j] <= 0 and j > i:
		j -= 1
	count += j - i
print(count)


from bisect import bisect_left as bl
n = int(input())
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
diff = []
for i in range(n):
	diff.append(a[i] - b[i])
diff.sort()
ans = 0
for i in range(n):
	if diff[i] > 0:
		ans += (n - i) * (n - i - 1) // 2
		break
	lb = bl(diff, -diff[i] + 1)
	ans += n - lb
print(ans)


import math
import time
from collections import defaultdict, deque
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
n = int(input())
a = list(map(int, stdin.readline().split()))
b = list(map(int, stdin.readline().split()))
diff = []
for i in range(n):
	diff.append(a[i] - b[i])
diff.sort()
ans = 0
for i in range(n):
	if diff[i] <= 0:
		ans += n - bisect_left(diff, 1 - diff[i])
	else:
		ans += n - i - 1
print(ans)


import sys

def readInt():
	return int(rl())

def readList():
	return list(map(int, rl().strip().split()))

def readStr():
	return rl().strip()

def makeMatrix(a, b, value):
	z = [value] * a
	for i in range(a):
		z[i] = [value] * b
	return z
rl = input
n = readInt()
a = readList()
b = readList()
for i in range(n):
	a[i] -= b[i]
a.sort()
r = n - 1
l = 0
ans = 0
while r >= 0:
	while l < n and a[l] + a[r] <= 0:
		l += 1
	if l >= n or l >= r:
		break
	ans += r - l
	r -= 1
print(ans)


import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')
input()
p = []
n = []
z = 0
for (i, j) in zip(map(int, input().split()), map(int, input().split())):
	if i - j > 0:
		p.append(i - j)
	elif not i - j:
		z += 1
	else:
		n.append(i - j)
n.sort(reverse=True)
p.sort()
ans = len(p) * (len(p) - 1) / 2 + len(p) * z
count = 0
j = 0
for i in p:
	while j < len(n) and i + n[j] > 0:
		count += 1
		j += 1
	ans += count
print(int(ans))


from sys import stdin, gettrace
if not gettrace():

	def input():
		return next(stdin)[:-1]

def main():
	n = int(input())
	aa = [int(a) for a in input().split()]
	bb = [int(a) for a in input().split()]
	cc = [a - b for (a, b) in zip(aa, bb)]
	cc.sort(reverse=True)
	i = 0
	j = n - 1
	res = 0
	while i < j:
		if -cc[j] >= cc[i]:
			j -= 1
		else:
			res += j - i
			i += 1
	print(res)
main()


tamanho = int(input())
listasub = sorted((i - j for (i, j) in zip(map(int, input().split()), map(int, input().split()))))
inicio = 0
fim = tamanho - 1
resposta = 0
while inicio < fim:
	if listasub[inicio] + listasub[fim] > 0:
		resposta += fim - inicio
		fim -= 1
	else:
		inicio += 1
print(resposta)


import bisect

def main():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = []
	for (x, y) in zip(a, b):
		c.append(x - y)
	c.sort()
	ans = 0
	for i in range(n):
		if c[i] < 0:
			continue
		pos = i - bisect.bisect(c, -c[i])
		if pos > 0:
			ans += pos
	print(ans)
main()


from sys import stdin
from collections import defaultdict
import bisect
n = int(stdin.readline())
alist = list(map(int, stdin.readline().strip().split()))
blist = list(map(int, stdin.readline().strip().split()))
clist = []
for i in range(n):
	clist.append(alist[i] - blist[i])
clist.sort()
neg_pos_pairs = 0
for (i, num) in enumerate(clist):
	if num <= 0:
		ind = bisect.bisect_left(clist, -num + 1)
		neg_pos_pairs += n - ind
	else:
		break
poscount = n - i
print(neg_pos_pairs + poscount * (poscount - 1) // 2)


n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = []
for i in range(n):
	c.append(a[i] - b[i])
c.sort()
k = 0
for i in range(n):
	p = i + 1
	q = n - 1
	while p <= q:
		m = (p + q) // 2
		if c[i] + c[m] <= 0:
			p = m + 1
		else:
			q = m - 1
	k = k + (n - p)
print(k)


n = int(input())
a = input().split()
b = input().split()
a = list(map(int, a))
b = list(map(int, b))
x = []
for i in range(n):
	x.append(a[i] - b[i])
x.sort()
ans = 0
for i in range(n - 1):
	v = x[i]
	p = i + 1
	a = n - p
	while a >= 1:
		while p + a < n and x[p + a] <= -v:
			p += a
		a = a // 2
	if x[p] <= -v:
		p = p + 1
	ans += n - p
print(ans)


from bisect import bisect
n = int(input())
arr1 = [int(p) for p in input().split()]
arr2 = [int(p) for p in input().split()]
count = 0
arr = []
for i in range(n):
	arr.append(arr1[i] - arr2[i])
arr.sort()
i = 0
j = 0
for i in range(len(arr)):
	if arr[i] <= 0:
		continue
	else:
		count += i - bisect(arr, -arr[i])
print(count)


n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = sorted([a[i] - b[i] for i in range(n)])
ans = 0
pol = [x for x in c if x > 0]
if len(pol) > 0:
	pol = pol[0]
	left = right = c.index(pol)
else:
	print(0)
	exit(0)
while right < n:
	if left != 0:
		if c[left - 1] + c[right] >= 1:
			left -= 1
		else:
			ans += right - 1 - left + 1
			right += 1
	else:
		ans += right - 1 - left + 1
		right += 1
print(ans)


import sys
I = sys.stdin.readline
n = int(I())
a = list(map(int, I().split()))
b = list(map(int, I().split()))
c = []
for i in range(n):
	c.append(a[i] - b[i])
c.sort(reverse=True)
i = 0
j = n - 1
ans = 0
while i < j:
	if c[j] + c[i] > 0:
		ans += j - i
		i += 1
	else:
		j -= 1
print(ans)


import sys
import bisect
input = sys.stdin.readline
N = int(input())
arr1 = [int(x) for x in input().split(' ')]
arr2 = [int(x) for x in input().split(' ')]
arr3 = sorted([arr1[i] - arr2[i] for i in range(N)])
s = 0
for i in range(N):
	if arr3[i] <= 0:
		continue
	x = bisect.bisect_left(arr3, -arr3[i] + 1)
	s += i - x
print(s)


def Cn2(n):
	return int(n * (n - 1) / 2)

def pair(arr1, arr2, n):
	res = [arr1[i] - arr2[i] for i in range(n)]
	res.sort()
	(left, right) = (0, n - 1)
	counts = 0
	while left < right:
		if res[left] + res[right] > 0:
			right -= 1
		else:
			left += 1
			counts += n - 1 - right
	positive = Cn2(n - right)
	return counts + positive
n = int(input())
arr1 = [int(s) for s in input().split(' ')]
arr2 = [int(s) for s in input().split(' ')]
ans = pair(arr1, arr2, n)
print(ans)


def binary_search(arr, st, ed, comp):
	ans = -1
	while st <= ed:
		mid = (st + ed) // 2
		if arr[mid] + comp > 0:
			ans = mid
			ed = mid - 1
		else:
			st = mid + 1
	return ans
n = int(input())
a = input().split()
b = input().split()
nums = []
for i in range(n):
	a[i] = int(a[i])
	b[i] = int(b[i])
	nums.append(a[i] - b[i])
nums.sort()
num_pairs = 0
for i in range(n):
	large_start_idx = binary_search(nums, i + 1, n - 1, nums[i])
	if large_start_idx == -1:
		continue
	num_pairs += n - large_start_idx
print(num_pairs)


import sys
from math import gcd, sqrt
sys.setrecursionlimit(10 ** 5)
inf = float('inf')
en = lambda x: list(enumerate(x))
ii = lambda : int(input())
r = lambda : map(int, input().split())
rr = lambda : list(r())
n = ii()
a = rr()
b = rr()

def CountPairs(arr, n):
	arr.sort()
	count = 0
	l = 0
	r = n - 1
	while l < r:
		if arr[l] + arr[r] > 0:
			count += r - l
			r -= 1
		else:
			l += 1
	return count
arr = [i - j for (i, j) in zip(a, b)]
print(CountPairs(arr, len(arr)))


import bisect

def solve(n, a, b):
	ans = 0
	d = sorted([a[i] - b[i] for i in range(n)])
	pc = sum([1 if dd > 0 else 0 for dd in d])
	for (i, dd) in enumerate(d):
		if dd > 0:
			ans += n - i - 1
		elif dd == 0:
			ans += pc
		else:
			idx = bisect.bisect_right(d, -dd)
			ans += n - idx
	return ans

def main():
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	print(solve(n, a, b))
main()


from random import randint as rnd
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = sorted([[abs(a[i] - b[i]), a[i] <= b[i]] for i in range(n)])
k = 0
for i in range(n):
	if not c[i][1]:
		k += i
print(k)


import bisect
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = []
for i in range(n):
	dif = a[i] - b[i]
	ans.append(dif)
ans.sort()
count = 0
for i in range(n):
	val = ans[i]
	if val <= 0:
		continue
	else:
		to_find = -val + 1
		no = bisect.bisect_left(ans, to_find)
		count += i - no
print(count)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
arr = [a[i] - b[i] for i in range(n)]
arr.sort(reverse=True)
r = n - 1
res = 0
for i in range(n):
	while r > i and arr[i] + arr[r] <= 0:
		r -= 1
	if r - i > 0:
		res += r - i
print(res)


import sys
import bisect

def ri():
	return int(input())

def rl():
	return list(map(int, input().split()))
for _ in range(1):
	n = ri()
	a = rl()
	b = rl()
	c = [(a[i] - b[i], b[i] - a[i]) for i in range(n)]
	c = sorted(c, key=lambda x: x[1])
	x = [i for (i, j) in c]
	y = [j for (i, j) in c]
	ans = 0
	for i in range(n):
		f = x[i]
		z = bisect.bisect_left(y, f)
		z = max(z - i - 1, 0)
		ans += z
	print(ans)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
A = []
for i in range(n):
	A.append(a[i] - b[i])
A.sort()
e = 0
d = n - 1
s = 0
while A[d] > 0 and e < d:
	if A[d] + A[e] > 0:
		s += d - e
		d -= 1
	else:
		e += 1
print(s)


from bisect import bisect_left
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [x - y for (x, y) in zip(a, b)]
c.sort()
d = 0
for i in range(len(c)):
	if c[i] < 1:
		pass
	else:
		pos = bisect_left(c, 1 - c[i], 0, i)
		d = d + i - pos
print(d)


from sys import stdin
try:
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().rstrip().split()))
	b = list(map(int, stdin.readline().rstrip().split()))
	arr = [a[i] - b[i] for i in range(n)]
	arr.sort()
	(count, start) = (0, 0)
	end = n - 1
	while start < end:
		if arr[start] + arr[end] <= 0:
			start += 1
		else:
			count += end - start
			end -= 1
	print(count)
except:
	pass


import sys, os
from io import BytesIO, IOBase
import collections, itertools, bisect, heapq, math, string
BUFSIZE = 8192
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))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def main():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = [a[i] - b[i] for i in range(n)]
	sc = sorted(c)
	ans = 0
	for x in range(len(sc)):
		if sc[x] > 0:
			pos = bisect.bisect_left(sc, -sc[x] + 1)
			ans += x - pos
	print(ans)
main()


n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
l = []
for i in range(n):
	l.append(a[i] - b[i])
l.sort()
i = 0
j = 1
total = 0
while i < n and i + j <= n:
	if l[i] + l[-j] > 0:
		total += n - i - j
		j += 1
	else:
		i += 1
print(total)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = sorted([a[i] - b[i] for i in range(n)])
ans = 0
for i in range(n - 1):
	l = i
	r = n
	while l + 1 != r:
		m = l + (r - l) // 2
		if c[m] > -c[i]:
			r = m
		else:
			l = m
	ans += n - r
print(ans)


n = int(input())
a = [int(c) for c in input().split()]
b = [int(c) for c in input().split()]
c = [ai - bi for (ai, bi) in zip(a, b)]
c.sort()
l = 0
r = n - 1
ans = 0
while l < r:
	if c[l] + c[r] > 0:
		ans += r - l
		r -= 1
	else:
		l += 1
print(ans)


I = lambda : map(int, input().split())
n = int(input())
a = sorted([i - j for (i, j) in zip(I(), I())])
(l, r, res) = (0, n - 1, 0)
while l < r:
	if a[l] + a[r] > 0:
		res += r - l
		r -= 1
	else:
		l += 1
print(res)


from bisect import bisect_left as bl
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [a[i] - b[i] for i in range(n)]
c.sort()
total = 0
for i in range(n):
	total += max(i - bl(c, -c[i] + 1), 0)
print(total)


def main():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	new = []
	for i in range(n):
		new.append(a[i] - b[i])
	new.sort()
	j = 0
	r = -1
	ans = 0
	if new[-1] <= 0:
		print(0)
	else:
		while j < n and new[j] <= 0:
			while -r < n and new[r] + new[j] > 0:
				r -= 1
			ans += -r - 1
			j += 1
		if n - j > 1:
			k = n - j - 1
			ans += k * (k + 1) // 2
		print(ans)
main()


from bisect import bisect_right as upper_bound
from sys import stdin, stdout

def main():
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().strip().split()))
	b = list(map(int, stdin.readline().strip().split()))
	arr = [a[i] - b[i] for i in range(n)]
	arr.sort()
	cnt = 0
	for i in range(n):
		pos = max(i + 1, upper_bound(arr, -arr[i]))
		cnt += n - pos
	stdout.write(str(cnt))
main()


import sys
input = lambda : sys.stdin.readline().rstrip()
n = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = []
append = C.append
for i in range(n):
	append(A[i] - B[i])
C.sort()
import bisect
ans = 0
for c in C:
	ans += n - bisect.bisect_right(C, -c)
	if c > 0:
		ans -= 1
print(ans // 2)


from sys import stdin

def binSearch(arr, low, high, x):
	if low == high:
		return low
	mid = (low + high) // 2
	if arr[mid] < x:
		return binSearch(arr, mid + 1, high, x)
	else:
		return binSearch(arr, low, mid, x)
n = int(stdin.readline())
a = list(map(int, stdin.readline().rstrip().split(' ')))
b = list(map(int, stdin.readline().rstrip().split(' ')))
arr = [0] * n
for i in range(n):
	arr[i] = a[i] - b[i]
arr = sorted(arr)
answer = 0
for i in range(n - 1):
	idx = binSearch(arr, i + 1, n - 1, -arr[i] + 1)
	if arr[idx] + arr[i] > 0:
		answer += n - idx
print(answer)


n = int(input())
ans = 0
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
l = [a[i] - b[i] for i in range(n)]
l.sort()
left = 0
right = n - 1
while left < right:
	while left < right and l[right] + l[left] <= 0:
		left += 1
	ans += right - left
	right -= 1
print(ans)


from math import *

def binarySearch(arr, x, i):
	l = i
	r = len(arr) - 1
	while l <= r:
		mid = (l + r) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] < x:
			l = mid + 1
		else:
			r = mid - 1
	return -1

def js(arr, x):
	l = 0
	r = len(arr) - 1
	ans = -1
	while l <= r:
		m = (l + r) // 2
		if arr[m] <= x:
			ans = m
			l = m + 1
		else:
			r = m - 1
	return ans

def jg(arr, x, i):
	l = i
	r = len(arr) - 1
	ans = -1
	while l <= r:
		m = (l + r) // 2
		if arr[m] >= x:
			ans = m
			r = m - 1
		else:
			l = m + 1
	return ans
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = []
ans = 0
for i in range(n):
	d.append(a[i] - b[i])
d.sort()
rslt = 0
for i in range(n - 1):
	if d[i] <= 0:
		dif = abs(d[i]) + 1
		ans = jg(d, dif, i + 1)
		if ans != -1:
			rslt += n - ans
	else:
		dif = -d[i] + 1
		ans = jg(d, dif, i + 1)
		if ans != -1:
			rslt += n - ans
print(rslt)


from collections import Counter
import bisect
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
diff = Counter([a[i] - b[i] for i in range(len(a))])
diff = sorted(([i, diff[i]] for i in diff))
cumsum = [0] * len(diff)
cumsum[-1] = diff[-1][1]
for i in range(len(cumsum) - 2, -1, -1):
	cumsum[i] = cumsum[i + 1] + diff[i][1]
s = 0
for i in range(len(a)):
	pos = bisect.bisect_left(diff, [b[i] - a[i] + 1, 0])
	if pos < len(cumsum):
		s += cumsum[pos]
		if a[i] > b[i]:
			s -= 1
print(s // 2)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
for i in range(n):
	a[i] -= b[i]
a.sort()
(l, r) = (0, n - 1)
while l < r:
	if a[l] + a[r] > 0:
		ans += r - l
		r -= 1
	else:
		l += 1
print(ans)


import os
import sys
from io import BytesIO, IOBase
import bisect

def main():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	for i in range(n):
		a[i] -= b[i]
	a.sort()
	ans = 0
	ub = bisect.bisect_right
	for i in a:
		ans += n - ub(a, -i)
		if 2 * i > 0:
			ans -= 1
	ans //= 2
	print(ans)
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))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
input = sys.stdin.readline
import bisect
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
(pos, neg) = ([], [])
for i in range(n):
	if a[i] > b[i]:
		pos.append(a[i] - b[i])
	else:
		neg.append(b[i] - a[i])
pos.sort()
neg.sort()
ans = 0
for i in range(len(pos)):
	posi = bisect.bisect_left(neg, pos[i])
	ans += posi + i
print(ans)


def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) // 2)
		if arr[m] > k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [a[i] - b[i] for i in range(n)]
c.sort()
ans = 0
for i in range(n - 1):
	temp = c[i]
	c[i] = -10 ** 18
	ans += countGreater(c, n, -temp)
print(ans)


def main():
	import sys
	from bisect import bisect_left
	input = sys.stdin.readline
	N = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	C = [a - b for (a, b) in zip(A, B)]
	C.sort()
	ans = 0
	for (i, c) in enumerate(C):
		j = bisect_left(C, -c + 1)
		ans += N - j
		if c > 0:
			ans -= 1
	print(ans // 2)
main()


from bisect import bisect_right

def d(arr, n):
	counter = 0
	for i in range(n):
		index = bisect_right(arr, -arr[i], lo=i + 1, hi=n)
		counter += n - index
	print(counter)
length = int(input())
teacher = [int(el) for el in input().split(' ')]
student = [int(el) for el in input().split(' ')]
diff = sorted([teacher[i] - student[i] for i in range(length)])
d(diff, length)


def findPairs(arr, n):
	l = 0
	r = n - 1
	result = 0
	while l < r:
		if arr[l] + arr[r] > 0:
			result += r - l
			l += 1
		else:
			r -= 1
	return result
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
k = [a[i] - b[i] for i in range(n)]
k.sort(reverse=True)
print(findPairs(k, n))


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
diff = []
count = 0
for i in range(len(a)):
	diff.append(a[i] - b[i])
diff.sort()

def binarysearch(diff, num):
	low = 0
	mid = 0
	high = len(diff) - 1
	while low <= high:
		mid = (low + high) // 2
		if diff[mid] >= num:
			high = mid - 1
		else:
			low = mid + 1
	return mid
for i in range(len(diff)):
	if diff[i] <= 0:
		x = binarysearch(diff, -diff[i] + 1)
		if x < len(diff) and diff[x] >= -diff[i] + 1:
			count += len(diff) - x
		elif x + 1 < len(diff) and diff[x + 1] >= -diff[i] + 1:
			count += len(diff) - x - 1
	else:
		count += len(diff) - i - 1
print(count)


from collections import defaultdict
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = [0] * n
d = defaultdict()
for i in range(0, n):
	c[i] = a[i] - b[i]
	if not c[i] in d:
		d[c[i]] = 0
	if c[i] > 0:
		d[c[i]] += 1
	if c[i] < 0:
		c[i] = -c[i]
c.sort()
tot = 0
for i in range(0, n):
	if not c[i] in d:
		continue
	if d[c[i]] > 0:
		tot += i
		d[c[i]] -= 1
print(tot)


from math import *
import bisect
N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
L = [a[i] - b[i] for i in range(N)]
L.sort()
count = 0
for i in range(N):
	if L[i] > 0:
		count += i - bisect.bisect_left(L, 1 - L[i], 0, N)
print(count)


import bisect
n = int(input())
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
diff = [0] * n
for x in range(n):
	diff[x] = a[x] - b[x]
diff.sort()
i = 0
ans = 0
while i < n:
	if diff[i] > 0:
		ans += i - bisect.bisect_right(diff, -diff[i])
	i += 1
print(ans)


N = int(input())
L = list(map(int, input().split()))
L2 = list(map(int, input().split()))
C = []
for i in range(N):
	C.append(L[i] - L2[i])
C.sort()
L = 0
R = N - 1
count = 0
while L < R:
	if C[L] + C[R] > 0:
		count += R - L
		R -= 1
	else:
		L += 1
print(count)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [a[i] - b[i] for i in range(n)]
c.sort()
if c[0] > 0:
	print((n - 1) * n // 2)
else:
	pairs = 0
	l = 0
	r = n - 1
	while l < r:
		if c[l] + c[r] > 0:
			pairs += r - l
			r -= 1
		else:
			l += 1
	print(pairs)


q = int(input())
w = list(map(int, input().split()))
e = list(map(int, input().split()))
for i in range(q):
	w[i] = w[i] - e[i]
w = sorted(w)
i = 0
j = q - 1
t = 0
while j > i:
	if w[i] + w[j] > 0:
		t += j - i
		j -= 1
	else:
		i += 1
print(t)


import bisect
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = []
count = 0
for i in range(n):
	c.append(a[i] - b[i])
c.sort()
for j in range(n):
	if c[j] > 0:
		count += j - bisect.bisect_left(c, 1 - c[j], lo=0, hi=j)
print(count)


from bisect import bisect_left

def solve(arr, n):
	ls = sorted(filter(lambda p: p > 0, arr))
	m = len(ls)
	ans = m * (m - 1) // 2 + sum(map(lambda p: m - bisect_left(ls, 1 - p), filter(lambda p: p <= 0, arr)))
	return ans
n = int(input())
arr = list(map(int, input().split()))
brr = list(map(int, input().split()))
print(solve(list([arr[x] - brr[x] for x in range(n)]), n))


import sys
from math import sqrt, floor, factorial, gcd
from collections import deque, Counter
inp = sys.stdin.readline
read = lambda : list(map(int, inp().strip().split()))

def solve():
	n = int(inp())
	d = [i - j for (i, j) in zip(read(), read())]
	d.sort(reverse=True)
	(i, j) = (0, n - 1)
	ans = 0
	while i < j:
		if d[i] + d[j] <= 0:
			j -= 1
		else:
			ans += abs(i - j)
			i += 1
	print(ans)
solve()


import sys
import math
import itertools
import functools
import collections
import operator
import fileinput
import copy
ORDA = 97

def ii():
	return int(input())

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

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

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

def divs(n, start=1):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	newnumber = 0
	while number > 0:
		newnumber += number % base
		number //= base
	return newnumber

def cdiv(n, k):
	return n // k + (n % k != 0)
n = ii()
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = []
for i in range(n):
	c.append(a[i] - b[i])
c.sort()
(l, r) = (0, n - 1)
ans = 0
while l < r:
	if c[l] + c[r] > 0:
		ans += r - l
		r -= 1
	else:
		l += 1
print(ans)


def binary_search(target, arr, start, end, found):
	if end <= start:
		if arr[start] == target:
			return start
		if found != -1:
			return found
		if arr[start] >= target:
			return start
		else:
			return start + 1
	mid = (start + end) // 2
	if arr[mid] == target:
		return binary_search(target, arr, start, mid - 1, mid)
	elif arr[mid] > target:
		return binary_search(target, arr, start, mid - 1, found)
	else:
		return binary_search(target, arr, mid + 1, end, found)
n = int(input())
diffs = [0] * n
line = input().split()
for i in range(n):
	diffs[i] = int(line[i])
line = input().split()
for i in range(n):
	diffs[i] -= int(line[i])
diffs.sort()
ans = 0
prev = n - 1
for index in range(n - 1):
	elem = diffs[index]
	if elem < -diffs[n - 1]:
		target = n
	elif elem > 0:
		target = index + 1
	else:
		target = binary_search(-elem + 1, diffs, index + 1, min(prev, n - 1), -1)
		prev = target
	ans += max(0, n - 1 - target + 1)
print(ans)


n = int(input())
list1 = list(map(int, input().split()))
list2 = list(map(int, input().split()))
diff = list()
for i in range(n):
	diff.append(list1[i] - list2[i])
diff.sort()
count = 0
i = 0
j = n - 1
while i < j:
	if diff[i] + diff[j] > 0:
		count += j - i
		j -= 1
	else:
		i += 1
print(count)


R = lambda : map(int, input().split())
(n,) = R()
a = sorted((x - y for (x, y) in zip(R(), R())))
r = i = j = 0
while i + j < n:
	if a[i] + a[-j - 1] > 0:
		j += 1
	else:
		r += j
		i += 1
print(r + j * (j - 1) // 2)


t = int(input())
x = []
a = list(map(int, input().strip().split(' ')))
b = list(map(int, input().strip().split(' ')))
for i in range(t):
	a[i] -= b[i]
a.sort()
ans = 0
pp = t - 1
for i in range(t):
	while pp and a[pp] + a[i] > 0:
		pp -= 1
	ans += min(t - 1 - pp, t - (i + 1))
print(ans)


def binarysearch(arr, val):
	(l, r) = (0, len(arr) - 1)
	pos = abs(val)
	while l < r:
		mid = (l + r) // 2
		if arr[mid] > pos:
			r = mid
		else:
			l = mid
		if r - l == 1:
			break
	n = len(arr)
	if arr[l] > pos:
		return len(arr) - l
	elif arr[r] > pos:
		return len(arr) - r
	else:
		return 0
n = int(input())
arr = list(map(int, input().split()))
brr = list(map(int, input().split()))
diff = []
for i in range(n):
	diff.append(arr[i] - brr[i])
diff.sort()
ans = 0
cnt = 0
for i in diff:
	if i > 0:
		cnt += 1
for i in range(n):
	if diff[i] < 0:
		val = binarysearch(diff, diff[i])
		ans += val
	elif diff[i] == 0:
		ans += cnt
print(ans + cnt * (cnt - 1) // 2)


import os
import sys
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))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def fact(x):
	if x == 0:
		return 1
	else:
		return x * fact(x - 1)

def lower_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def abs(x):
	return x if x >= 0 else -x

def binary_search(li, val, lb, ub):
	ans = 0
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = 1
			break
	return ans

def sieve_of_eratosthenes(n):
	ans = []
	arr = [1] * (n + 1)
	(arr[0], arr[1], i) = (0, 0, 2)
	while i * i <= n:
		if arr[i] == 1:
			j = i + i
			while j <= n:
				arr[j] = 0
				j += i
		i += 1
	for k in range(n):
		if arr[k] == 1:
			ans.append(k)
	return ans

def nc2(x):
	if x == 1:
		return 0
	else:
		return x * (x - 1) // 2
for _ in range(1):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	diff = []
	for i in range(n):
		diff.append(a[i] - b[i])
	diff.sort()
	l = 0
	r = n - 1
	ans = 0
	while True:
		if diff[r] + diff[l] > 0:
			ans += r - l
			r -= 1
		else:
			l += 1
		if l == r or r < 0 or l >= n:
			break
	print(ans)


from bisect import bisect_right
n = int(input())
ai = [*map(int, input().split())]
bi = [*map(int, input().split())]
k = [i - j for (i, j) in zip(ai, bi)]
k.sort()
ans = 0
for i in k:
	if i > 0:
		ans -= 1
	ans += n - bisect_right(k, -i)
print(ans // 2)


import bisect
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [aa - bb for (aa, bb) in zip(a, b)]
c.sort()
count = 0
for (i, j) in enumerate(c):
	if j > 0:
		pos = bisect.bisect_left(c, -j + 1)
		count += i - pos
print(count)


n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = [a[x] - b[x] for x in range(n)]
cnt = 0
c.sort()
s = 0
e = n - 1
while s != e:
	if c[e] + c[s] > 0:
		cnt += e - s
		e -= 1
	else:
		s += 1
print(cnt)


n = int(input())
a = sorted(list(map(lambda x, y: x - y, list(map(int, input().split())), list(map(int, input().split())))))
ans = 0
j = n
for i in a:
	while j > 0 and a[j - 1] > -i:
		j -= 1
	ans += n - j
	if i > 0:
		ans -= 1
print(ans >> 1)


import sys
input = sys.stdin.readline
from math import *
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
d = [0 for i in range(n)]
f = {}

def bs(r, n, i):
	ans = 0
	l = 0
	rr = n - 1
	while rr >= l:
		mid = l + (rr - l) // 2
		if r[mid] >= i:
			rr = mid - 1
		else:
			ans = mid + 1
			l = mid + 1
	return ans
p = 0
for i in range(n):
	d[i] = a[i] - b[i]
	if d[i] in f:
		f[d[i]] += 1
	else:
		f[d[i]] = 1
	if d[i] > 0:
		p += 1
d.sort()
r = []
for i in range(n):
	r.append(-d[i])
r = r[::-1]
c = 0
ne = 0
for i in range(n):
	if d[i] <= 0:
		c += bs(r, len(r), d[i])
	else:
		c += bs(r, len(r), d[i]) - 1
print(c // 2)


import sys
input = sys.stdin.readline
from bisect import bisect_left
n = int(input())
x = [*map(int, input().split())]
y = [xi - yi for (xi, yi) in zip(x, map(int, input().split()))]
y.sort()
ans = 0
for i in range(n):
	k = y[i]
	a = bisect_left(y, -k + 1)
	ans += n - a
print((ans - len([i for i in y if i > 0])) // 2)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = []
for j in range(n):
	c.append(a[j] - b[j])
c.sort()
i = 0
j = len(c) - 1
sum = 0
while i < j:
	if c[i] + c[j] <= 0:
		d = j - i
		sum += d
		i += 1
	else:
		j += -1
p = int(n * (n - 1) // 2)
print(p - sum)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a = list(map(lambda x1, x2: x1 - x2, a, b))
a.sort()
p1 = 0
p2 = n - 1
c = 0
while p1 < p2:
	if a[p1] + a[p2] > 0:
		c += p2 - p1
		p2 -= 1
	else:
		p1 += 1
print(c)


import sys
import bisect
from collections import defaultdict as dd

def data():
	return sys.stdin.readline().strip()

def out(var):
	sys.stdout.write(str(var))

def l():
	return list(sp())

def strl():
	return list(strsp())

def sp():
	return map(int, data().split())

def strsp():
	return map(str, data().split())
n = int(data())
a = l()
b = l()
(c, d) = ([], [])
for i in range(n):
	e = a[i] - b[i]
	if e <= 0:
		c.append(-e)
	else:
		d.append(e)
c.sort()
d.sort()
f = len(d) * (len(d) - 1) // 2
for i in range(len(c)):
	r = bisect.bisect(d, c[i])
	f += len(d) - r
print(f)


n = int(input())
arr1 = list(map(int, input().strip().split()))
arr2 = list(map(int, input().strip().split()))
for i in range(n):
	arr1[i] = arr1[i] - arr2[i]
arr1 = sorted(arr1)
cnt = 0
for i in range(0, n - 1):
	x = arr1[i]
	l = i + 1
	r = n - 1
	ans = n
	while l <= r:
		mid = (l + r) // 2
		if arr1[mid] + x > 0:
			ans = min(ans, mid)
			r = mid - 1
		else:
			l = mid + 1
	cnt += n - ans
print(cnt)


import sys
input = sys.stdin.readline

def solve(a, b):
	arr = []
	for (i, j) in zip(a, b):
		arr.append(i - j)
	arr.sort()
	res = 0
	l = 0
	r = len(arr) - 1
	while l < r:
		if arr[l] + arr[r] > 0:
			res += r - l
			r -= 1
		else:
			l += 1
	print(res)
n = input()
a = list(map(int, input().split()))
b = list(map(int, input().split()))
solve(a, b)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(n):
	a[i] -= b[i]
a.sort()
ind = 0
for i in range(n):
	if a[i] >= 0:
		ind = i
		break
if a[ind] == 0:
	ind1 = ind
	for j in range(ind, n):
		if a[j] > 0:
			ind1 = j
			break
else:
	ind1 = ind
	for j in range(ind, n):
		if a[j] > 0:
			ind1 = j
			break
v = 0
if a[ind1] > 0:
	v += n - 1 - ind1 + 1
if a[ind] == 0:
	v += 1
ans = 0
ans += v * (v - 1) // 2
if a[ind1] > 0 and a[ind] == 0 and (ind1 - ind > 1):
	ans += (ind1 - ind - 1) * (n - 1 - ind1 + 1)
if ans < 0:
	ans = 0
if a[0] >= 0 or a[n - 1] <= 0:
	print(ans)
	exit()
l = 0
r = n - 1
while a[l] < 0 and a[r] > 0:
	if a[r] + a[l] > 0:
		r -= 1
	else:
		ans += n - 1 - r
		l += 1
if a[l] < 0:
	while a[l] < 0:
		ans += n - 1 - r
		l += 1
print(ans)


import sys
from bisect import bisect, bisect_left

def solve():
	input = sys.stdin.readline
	N = int(input())
	A = [int(a) for a in input().split()]
	B = [int(b) for b in input().split()]
	C = [A[i] - B[i] for i in range(N)]
	C.sort()
	count = 0
	for (i, c) in enumerate(C):
		least = bisect(C, -c)
		count += N - max(least, i + 1)
	print(count)
	return 0
solve()


n = int(input())
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))
arr = []
for i in range(n):
	arr.append(arr1[i] - arr2[i])
arr.sort()
l = 0
r = n - 1
result = 0
while l < r:
	if arr[l] + arr[r] > 0:
		result += r - l
		r -= 1
	else:
		l += 1
print(result)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
dif = list(map(lambda x, y: x - y, a, b))
dif.sort()
left = 0
right = len(dif) - 1
total = 0
while left < right:
	if dif[left] + dif[right] > 0:
		total += right - left
		right -= 1
	else:
		left += 1
print(total)


n = int(input())
lst = list(map(int, input().split()))
arr = list(map(int, input().split()))
diff = [lst[i] - arr[i] for i in range(n)]
diff.sort()
numOfPair = 0
i = 0
j = n - 1
while i < j:
	if diff[i] + diff[j] > 0:
		numOfPair += j - i
		j -= 1
	else:
		i += 1
print(numOfPair)


from bisect import bisect_right
n = int(input())
a = sorted(list(map(lambda x, y: x - y, list(map(int, input().split())), list(map(int, input().split())))))
ans = 0
for i in a:
	ans += n - bisect_right(a, -i, 0, n)
	if i > 0:
		ans -= 1
print(ans >> 1)


import sys, math
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return s[:len(s) - 1]

def invr():
	return map(int, input().split())
t = 1
for tt in range(t):
	n = inp()
	a = inlt()
	b = inlt()
	qw = []
	for i in range(len(a)):
		qw.append(a[i] - b[i])
	qw.sort()
	for i in range(len(qw)):
		if qw[i] > 0:
			break
	q = i - 1
	w = q + 1
	c = (n - w) * (n - w - 1) // 2
	while q >= 0 and w < len(qw):
		if qw[q] + qw[w] > 0:
			c = c + n - w
			q = q - 1
		else:
			w = w + 1
	print(c)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ab = sorted([a[i] - b[i] for i in range(n)])
ans = 0
l = 0
r = n - 1
while r > 0 and l < r:
	if ab[r] + ab[l] > 0:
		ans += r - l
		r -= 1
		continue
	l += 1
print(ans)


def topics(n, t, s):
	diffs = []
	for i in range(n):
		diffs.append(t[i] - s[i])
	diffs.sort()
	right = n - 1
	left = 0
	sm = 0
	while left < right:
		while left < right and diffs[right] + diffs[left] <= 0:
			left += 1
		sm += right - left
		right -= 1
	return sm
n = int(input())
t = [int(i) for i in input().split(' ')]
s = [int(i) for i in input().split(' ')]
print(topics(n, t, s))


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [0] * n
for i in range(n):
	c[i] = a[i] - b[i]
c.sort()
x = 0
k = 0
for i in range(n - 1, -1, -1):
	while x < i and c[x] + c[i] <= 0:
		x = x + 1
	if x == i:
		break
	k += i - x
print(k)


import sys
from math import ceil, sqrt
read = sys.stdin.buffer.readline
mi = lambda : map(int, read().split())
li = lambda : list(mi())
cin = lambda : int(read())

def isp(n):
	i = 2
	while i * i <= n:
		if n % i == 0:
			return False
		i += 1
	return True
primes = []
for _ in range(1):
	n = cin()
	a = li()
	b = li()
	d = dict()
	for i in range(n):
		if a[i] - b[i] in d:
			d[a[i] - b[i]] += 1
		else:
			d[a[i] - b[i]] = 1
	a = []
	for el in list(d.keys()):
		a.append([el, d[el]])
	a.sort(key=lambda x: x[0])
	pref = [0]
	for i in range(len(a)):
		pref.append(pref[-1] + a[i][1])
	n = len(a)
	ans = 0
	for i in range(n - 1):
		if a[i][0] > 0:
			ct = d[a[i][0]]
			ans += ct * (ct - 1) // 2
		key = 1 - a[i][0]
		(l, h) = (i + 1, n - 1)
		li = n
		while l <= h:
			mid = (l + h) // 2
			if a[mid][0] == key:
				li = mid
				break
			elif a[mid][0] > key:
				h = mid - 1
				li = mid
			else:
				l = mid + 1
		ans += a[i][1] * (pref[-1] - pref[li])
	if a[-1][0] > 0:
		ct = a[-1][1]
		ans += ct * (ct - 1) // 2
	print(ans)


from bisect import *
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
l = []
p = -1
for i in range(n):
	l.append(a[i] - b[i])
l = sorted(l)
ans = 0
for i in range(n):
	if l[i] > 0:
		p = bisect_left(l, -l[i] + 1, 0, n)
		ans = ans + i - p
print(ans)


m = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = []
for i in range(m):
	d.append(a[i] - b[i])
d.sort()
ans = 0
l = 0
r = m - 1
while r > 0 and l < r:
	if d[l] + d[r] > 0:
		ans += r - l
		r -= 1
		continue
	else:
		l += 1
print(ans)


import bisect
import sys
input = sys.stdin.readline
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
D = [0] * n
for i in range(n):
	D[i] = A[i] - B[i]
D.sort()
total = 0
for i in range(n - 1, -1, -1):
	if D[i] > 0:
		total += n - i - 1
	else:
		k = bisect.bisect_right(D, -D[i], 0, len(D))
		total += n - k
print(total)


from bisect import bisect_left
n = int(input())
a = list((int(j) for j in input().split()))
b = input().split()
pos = []
neg = []
zeros = 0
for i in range(n):
	a[i] -= int(b[i])
	if a[i] < 0:
		neg.append(-a[i])
	elif a[i] == 0:
		zeros += 1
	else:
		pos.append(a[i])
neg.sort()
pos.sort()
nc = len(neg)
pc = len(pos)
s = pc * (pc - 1) // 2 + zeros * pc
for i in pos:
	s += bisect_left(neg, i)
print(s)


import math
from decimal import *
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
arr = []
for i in range(n):
	arr.append(a[i] - b[i])
ans = 0
arr = sorted(arr, reverse=True)
(i, j) = (0, n - 1)
while i < j:
	if arr[i] + arr[j] <= 0:
		j -= 1
	else:
		ans += j - i
		i += 1
print(ans)


import sys
from bisect import bisect_right

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

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

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
N = INT()
A = LIST()
B = LIST()
C = [0] * N
for i in range(N):
	C[i] = A[i] - B[i]
C.sort()
ans = 0
for (i, c) in enumerate(C):
	idx = max(bisect_right(C, -c), i + 1)
	ans += N - idx
print(ans)


n = int(input())
arr = list(map(int, input().split()))
ls = list(map(int, input().split()))
a = [arr[i] - ls[i] for i in range(n)]
a.sort()
start = 0
end = n - 1
count = 0
while end > start:
	if a[start] + a[end] <= 0:
		start += 1
	else:
		count += end - start
		end -= 1
print(count)


from bisect import bisect
n = int(input())
L = [int(x) for x in input().strip().split(' ')]
M = [int(x) for x in input().strip().split(' ')]
C = [x - y for (x, y) in zip(L, M)]
C.sort()
ans = 0
for x in C:
	ans = ans + n - bisect(C, -x)
	if x > 0:
		ans -= 1
print(ans // 2)


import sys
input = sys.stdin.readline
n = input()
a = [int(x) for x in input().strip().split()]
b = [int(x) for x in input().strip().split()]
d = [a[i] - b[i] for i in range(len(a))]
d.sort()
(s, e, ans) = (0, len(d) - 1, 0)
while s < e:
	if d[s] + d[e] <= 0:
		s += 1
	else:
		ans += e - s
		e -= 1
print(ans)


from bisect import bisect_left
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = [a - b for (a, b) in zip(A, B)]
C.sort()
ans = 0
for i in range(n - 1):
	idx = n - bisect_left(C, -C[i] + 1)
	pos = n - i - 1
	ans += min(idx, pos)
print(ans)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(0, n):
	a[i] = a[i] - b[i]
a.sort()
l = 0
h = n - 1
ans = 0
count = 0
while l < h:
	if a[l] + a[h] > 0:
		count = count + 1
		h = h - 1
	else:
		l = l + 1
		ans = count + ans
n = n - l
n = n * (n - 1)
print(ans + n // 2)


import bisect

def cast(cre, typ):
	return type(typ)(map(cre, typ))

def range_sum(n):
	return int(n * (n + 1) / 2)

def solution():
	n = int(input())
	(a, b) = (cast(int, input().split()), cast(int, input().split()))
	c = sorted([a[i] - b[i] for i in range(n)])
	ans = range_sum(n - 1)
	cnt = 0
	for i in range(n - 1):
		if c[i] > 0:
			break
		cnt += bisect.bisect_right(c, -c[i]) - (i + 1)
	print(ans - cnt)
solution()


n = int(input())
a = [int(j) for j in input().split()]
b = [int(j) for j in input().split()]
ans = 0
d = []
for i in range(n):
	d.append(a[i] - b[i])
d.sort()
ans = 0
left = 0
right = n - 1
while left < right:
	if d[left] + d[right] > 0:
		ans += right - left
		right -= 1
	else:
		left += 1
print(ans)


import bisect
size = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
p = []
n = []
z = 0
for i in range(size):
	tmp = a[i] - b[i]
	if tmp > 0:
		p.append(tmp)
	elif tmp == 0:
		z += 1
	else:
		n.append(abs(tmp))
lp = len(p)
count = lp * (lp - 1) // 2 + lp * z
p.sort()
for i in n:
	count += lp - bisect.bisect_right(p, i)
print(count)


def fun(val, r):
	ret = 0
	l = 0
	while l <= r:
		m = (r + l) // 2
		if c[m] > val:
			ret = m
			r = m - 1
		else:
			l = m + 1
	return ret
n = int(input())
a = [int(var) for var in input().split()]
b = [int(var) for var in input().split()]
c = []
ans = 0
cnt = 1
for i in range(n):
	c.append(a[i] - b[i])
c.sort()
for i in range(n):
	if c[i] > 0:
		ans += i - fun(-c[i], i)
print(ans)


from bisect import *
n = int(input())
z = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]
q = [z[i] - x[i] for i in range(n)]
q.sort()
ans = 0
for i in range(len(q)):
	ans += min(len(q) - bisect_right(q, -q[i]), len(q) - i - 1)
print(ans)


from bisect import bisect_right as br
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = [-1 for _ in range(n)]
for i in range(n):
	c[i] = a[i] - b[i]
c.sort()
ans = 0
for i in range(n):
	x = br(c, -c[i])
	if c[i] > 0:
		x += 1
	ans += n - x
ans //= 2
print(ans)


from bisect import bisect_left
n = int(input())
a = [int(_) for _ in input().split()]
b = [int(_) for _ in input().split()]
u = sorted([i - j for (i, j) in zip(a, b)])
v = sorted([i - j for (i, j) in zip(b, a)])
a = 0
for x in u:
	a += bisect_left(v, x) - (1 if x > 0 else 0)
print(a // 2)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
sup_a = []
eq = []
inf_a = []
sup_a_val = []
inf_a_val = []
for i in range(n):
	if a[i] > b[i]:
		sup_a.append(i)
		sup_a_val.append(a[i] - b[i])
	elif a[i] == b[i]:
		eq.append(i)
	else:
		inf_a.append(i)
		inf_a_val.append(abs(a[i] - b[i]))
x1 = len(sup_a)
x2 = len(eq)
x3 = len(inf_a)
res = x2 * x1 + x1 * (x1 - 1) // 2
sup_a_val.sort()
inf_a_val.sort()
pos = 0
if x1 > 0:
	for i in range(x3):
		if sup_a_val[pos] > inf_a_val[i]:
			res += x1 - pos
		else:
			while pos < x1:
				if sup_a_val[pos] <= inf_a_val[i]:
					pos += 1
				else:
					break
			if pos == x1:
				break
			else:
				res += x1 - pos
		if pos == x1:
			break
print(res)


import os
import sys
from io import BytesIO, IOBase
from bisect import bisect_left

def solution(n, brr, arr):
	carr = sorted([a - b for (a, b) in zip(arr, brr)])
	res = sum((i - bisect_left(carr, -carr[i] + 1) for i in range(n) if carr[i] > 0))
	print(res)

def main():
	n = r_int()
	arr = r_array()
	brr = r_array()
	solution(n, brr, arr)
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 r_array():
	return [int(x) for x in input().split()]

def r_int():
	return int(input())

def p_array(arr):
	for x in arr:
		print(x, end=' ')
	print()
main()


from bisect import bisect_right

def pairOftopics(arr):
	arr.sort()
	count = 0
	for i in range(len(arr)):
		if arr[i] > 0:
			r = len(arr) - i
			count += int(r * (r - 1) / 2)
			break
		index = bisect_right(arr, -arr[i])
		count += len(arr) - index
	print(count)
n = int(input())
arr1 = [int(ele) for ele in input().split()]
arr2 = [int(ele) for ele in input().split()]
arr3 = [-1 for i in range(n)]
for i in range(n):
	arr3[i] = arr1[i] - arr2[i]
pairOftopics(arr3)


n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
for i in range(n):
	a[i] -= b[i]
a.sort()
left = 0
right = n - 1
count = 0
while left < right:
	if a[left] + a[right] > 0:
		count += right - left
		right -= 1
	else:
		left += 1
print(count)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = sorted([a[i] - b[i] for i in range(n)])
ptr = n - 1
ans = 0
for i in range(n):
	while ptr >= 0 and d[i] > -d[ptr]:
		ptr -= 1
	ans += min(n - i - 1, n - ptr - 1)
print(ans)


import io
import os

class SortedList:

	def __init__(self, iterable=[], _load=200):
		values = sorted(iterable)
		self._len = _len = len(values)
		self._load = _load
		self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
		self._list_lens = [len(_list) for _list in _lists]
		self._mins = [_list[0] for _list in _lists]
		self._fen_tree = []
		self._rebuild = True

	def _fen_build(self):
		self._fen_tree[:] = self._list_lens
		_fen_tree = self._fen_tree
		for i in range(len(_fen_tree)):
			if i | i + 1 < len(_fen_tree):
				_fen_tree[i | i + 1] += _fen_tree[i]
		self._rebuild = False

	def _fen_update(self, index, value):
		if not self._rebuild:
			_fen_tree = self._fen_tree
			while index < len(_fen_tree):
				_fen_tree[index] += value
				index |= index + 1

	def _fen_query(self, end):
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		x = 0
		while end:
			x += _fen_tree[end - 1]
			end &= end - 1
		return x

	def _fen_findkth(self, k):
		_list_lens = self._list_lens
		if k < _list_lens[0]:
			return (0, k)
		if k >= self._len - _list_lens[-1]:
			return (len(_list_lens) - 1, k + _list_lens[-1] - self._len)
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		idx = -1
		for d in reversed(range(len(_fen_tree).bit_length())):
			right_idx = idx + (1 << d)
			if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
				idx = right_idx
				k -= _fen_tree[idx]
		return (idx + 1, k)

	def _delete(self, pos, idx):
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len -= 1
		self._fen_update(pos, -1)
		del _lists[pos][idx]
		_list_lens[pos] -= 1
		if _list_lens[pos]:
			_mins[pos] = _lists[pos][0]
		else:
			del _lists[pos]
			del _list_lens[pos]
			del _mins[pos]
			self._rebuild = True

	def _loc_left(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(lo, pos) = (-1, len(_lists) - 1)
		while lo + 1 < pos:
			mi = lo + pos >> 1
			if value <= _mins[mi]:
				pos = mi
			else:
				lo = mi
		if pos and value <= _lists[pos - 1][-1]:
			pos -= 1
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value <= _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def _loc_right(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(pos, hi) = (0, len(_lists))
		while pos + 1 < hi:
			mi = pos + hi >> 1
			if value < _mins[mi]:
				hi = mi
			else:
				pos = mi
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value < _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def add(self, value):
		_load = self._load
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len += 1
		if _lists:
			(pos, idx) = self._loc_right(value)
			self._fen_update(pos, 1)
			_list = _lists[pos]
			_list.insert(idx, value)
			_list_lens[pos] += 1
			_mins[pos] = _list[0]
			if _load + _load < len(_list):
				_lists.insert(pos + 1, _list[_load:])
				_list_lens.insert(pos + 1, len(_list) - _load)
				_mins.insert(pos + 1, _list[_load])
				_list_lens[pos] = _load
				del _list[_load:]
				self._rebuild = True
		else:
			_lists.append([value])
			_mins.append(value)
			_list_lens.append(1)
			self._rebuild = True

	def discard(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_right(value)
			if idx and _lists[pos][idx - 1] == value:
				self._delete(pos, idx - 1)

	def remove(self, value):
		_len = self._len
		self.discard(value)
		if _len == self._len:
			raise ValueError('{0!r} not in list'.format(value))

	def pop(self, index=-1):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		value = self._lists[pos][idx]
		self._delete(pos, idx)
		return value

	def bisect_left(self, value):
		(pos, idx) = self._loc_left(value)
		return self._fen_query(pos) + idx

	def bisect_right(self, value):
		(pos, idx) = self._loc_right(value)
		return self._fen_query(pos) + idx

	def count(self, value):
		return self.bisect_right(value) - self.bisect_left(value)

	def __len__(self):
		return self._len

	def __getitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		return self._lists[pos][idx]

	def __delitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		self._delete(pos, idx)

	def __contains__(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_left(value)
			return idx < len(_lists[pos]) and _lists[pos][idx] == value
		return False

	def __iter__(self):
		return (value for _list in self._lists for value in _list)

	def __reversed__(self):
		return (value for _list in reversed(self._lists) for value in reversed(_list))

	def __repr__(self):
		return 'SortedList({0})'.format(list(self))

def solve(N, A, B):
	ans = 0
	sl = SortedList()
	for (a, b) in zip(A, B):
		d = b - a
		numSmaller = sl.bisect_left(-d)
		ans += numSmaller
		sl.add(d)
	return ans
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
(N,) = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
ans = solve(N, A, B)
print(ans)


from bisect import bisect_left
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
diff = [i - j for (i, j) in zip(a, b)]
res = 0
diff = sorted(diff)
for (idx, i) in enumerate(diff):
	if i > 0:
		res += n - idx - 1
	else:
		res += n - bisect_left(diff, abs(i) + 1)
print(res)


from collections import Counter
from operator import sub
R1 = lambda : list(map(int, input().split()))
R2 = lambda : int(input())
R3 = lambda : Counter(map(int, input().split()))
n = R2()
c = sorted(map(sub, R1(), R1()))
i = s = 0
j = n - 1
while i < j:
	if c[i] + c[j] > 0:
		s += j - i
		j -= 1
	else:
		i += 1
print(s)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
amb = []
for i in range(n):
	amb.append(a[i] - b[i])
amb.sort()
fans = 0
for i in range(n):
	e = amb[i]
	l = 0
	h = n - 1
	while l <= h:
		mid = (l + h) // 2
		if amb[mid] >= -e + 1:
			h = mid - 1
		else:
			l = mid + 1
	x = l
	if x < i:
		fans += n - x - 1
	else:
		fans += n - x
print(fans // 2)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
pos = []
neg = []
for i in range(n):
	if a[i] > b[i]:
		pos.append(a[i] - b[i])
	else:
		neg.append(b[i] - a[i])
cp = 0
cn = 0
pos.sort()
lp = len(pos)
ln = len(neg)
neg.sort()
ans = lp * (lp - 1)
ans = ans // 2
if lp > 0 and ln > 0:
	while cp < lp:
		if pos[cp] > neg[cn]:
			cn += 1
		else:
			ans += cn
			cp += 1
		if cn >= ln:
			ans += cn * (lp - cp)
			break
print(ans)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = []
v = 0
for i in range(n):
	c.append(a[i] - b[i])
c.sort()
i = 0
j = n - 1
while True:
	if i >= j:
		break
	if c[i] + c[j] > 0:
		v += j - i
		j = j - 1
	else:
		i += 1
print(v)


import sys
input = sys.stdin.buffer.readline
n = int(input())
data = [int(i) for i in input().split()]
tmp = [int(i) for i in input().split()]
for i in range(n):
	data[i] -= tmp[i]
data.sort()
ans = 0

def search(l, r, x):
	sol = n
	while l <= r:
		m = (l + r) // 2
		if data[m] + x > 0:
			sol = m
			r = m - 1
		else:
			l = m + 1
	return sol
for i in range(n):
	ans += n - search(i + 1, n - 1, data[i])
print(ans)


n = int(input())
l1 = [int(x) for x in input().split()]
l2 = [int(x) for x in input().split()]
t = []
for i in range(n):
	t += [l1[i] - l2[i]]
t.sort()
i = 0
j = n - 1
ans = 0
for i in range(n):
	while t[i] + t[j] > 0 and j >= 0:
		j -= 1
	ans += n - max(i + 1, j + 1)
print(ans)


import bisect
t = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
diff = [a[i] - b[i] for i in range(t)]
diff.sort()
s = 0
i = len(diff) - 1
while diff[i] > 0 and i > 0:
	j = bisect.bisect_left(diff, -1 * diff[i] + 1)
	s += i - j
	i -= 1
print(s)


import bisect
n = int(input())
ls1 = list(map(int, input().split()))
ls2 = list(map(int, input().split()))
ls3 = []
ans = 0
s = len(ls1)
for i in range(len(ls1)):
	ls3.append(ls1[i] - ls2[i])
ls3.sort()
for i in range(len(ls3)):
	ans += s - bisect.bisect_right(ls3, -ls3[i], i + 1, len(ls3))
print(ans)


def sol(a, b):
	n = len(a)
	diff = []
	for i in range(len(a)):
		diff.append(a[i] - b[i])
	diff.sort()
	(i, j) = (0, len(diff) - 1)
	ans = 0
	while i < j:
		if diff[i] + diff[j] <= 0:
			i += 1
		else:
			ans += j - i
			j -= 1
	return ans
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
print(sol(a, b))


import bisect
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = []
pos_count = 0
for i in range(n):
	diff = a[i] - b[i]
	if diff > 0:
		pos_count += 1
	else:
		c.append(-diff)
ans = pos_count * (pos_count - 1) // 2
c.sort()
for i in range(n):
	diff = a[i] - b[i]
	if diff > 0:
		index = bisect.bisect_right(c, diff - 1)
		ans += index
print(ans)


n = int(input())
l = list(map(int, input().split()))
m = list(map(int, input().split()))
c = 0
for i in range(n):
	l[i] = l[i] - m[i]
l = sorted(l)
i = 0
j = n - 1
while i < j:
	if l[i] + l[j] > 0:
		c += j - i
		j = j - 1
	else:
		i += 1
print(c)


def bs(arr, target, n):
	start = 0
	end = n - 1
	ans = n
	while start <= end:
		mid = (start + end) // 2
		if arr[mid] <= target:
			start = mid + 1
		else:
			ans = mid
			end = mid - 1
	return ans
n = int(input())
l = [int(x) for x in input().split()]
k = [int(x) for x in input().split()]
ans = 0
for i in range(n):
	l[i] = l[i] - k[i]
l.sort()
for j in range(n):
	if l[j] <= 0:
		ans += n - bs(l, abs(l[j]), n)
	else:
		ans += (n - j) * (n - j - 1) // 2
		break
print(ans)


n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = [B[i] - A[i] for i in range(n)]
C.sort()
import bisect
ans = 0
for i in range(n):
	c = A[i] - B[i]
	t = bisect.bisect_left(C, c)
	ans += t
	if c * -1 < c:
		ans -= 1
ans = ans // 2
print(ans)


n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
ra = []
rb = []
for i in range(n):
	if a[i] - b[i] > 0:
		ra.append(a[i] - b[i])
	else:
		rb.append(b[i] - a[i])
ra = sorted(ra)
rb = sorted(rb)
ind = 0
sy = len(ra) * (len(ra) - 1) // 2
if len(rb) > 0:
	for i in ra:
		if rb[-1] < i:
			ind = len(rb) - 1
			sy += len(rb)
		else:
			for j in range(ind, len(rb)):
				if rb[j] >= i:
					ind = j
					sy += j
					break
print(sy)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
neg = []
pos = []
zero = 0
for i in range(0, n):
	if a[i] - b[i] > 0:
		pos.append(a[i] - b[i])
	elif a[i] - b[i] < 0:
		neg.append(a[i] - b[i])
	else:
		zero += 1
ans = 0
ans += len(pos) * (len(pos) - 1) // 2
ans += len(pos) * zero
neg.sort()
pos.sort()
ele = len(pos) - 1
for i in range(0, len(neg)):
	while ele > 0 and pos[ele - 1] + neg[i] > 0:
		ele -= 1
	if ele >= 0 and pos[ele] + neg[i] > 0:
		ans += len(pos) - ele
print(ans)


n = int(input())

def binarySearch(l, b):
	length = len(l)
	if length == 1:
		if l[0] + b > 0:
			return 1
		return 0
	if l[length // 2] + b > 0:
		return length - length // 2 + binarySearch(l[:length // 2], b)
	elif length // 2 + 1 < length:
		return binarySearch(l[length // 2 + 1:], b)
	return 0
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = []
for i in range(n):
	c.append(a[i] - b[i])
count = 0
c.sort()
ind = n
for i in range(n):
	if c[i] > 0:
		ind = i
		break
ind2 = n
while n - 1 >= ind:
	num = c[n - ind2] + c[n - 1] > 0
	count += num * (ind2 - 1)
	n -= num
	ind2 -= 1
print(count)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = []
for i in range(n):
	c.append(a[i] - b[i])
c.sort()
ans = 0
right = n - 1
left = 0
while left < right:
	if c[left] + c[right] > 0:
		ans += right - left
		right -= 1
	else:
		left += 1
print(ans)


def searchInsert(nums, target) -> int:
	l = 0
	r = len(nums) - 1
	while l <= r:
		m = l + (r - l) // 2
		if nums[m] == target:
			if len(nums) - 1 > m:
				if nums[m + 1] != target:
					return m + 1
				else:
					l = m + 1
			else:
				return m + 1
		elif target < nums[m]:
			r = m - 1
		elif target > nums[m]:
			l = m + 1
	return l
n = int(input())
z = input().split(' ')
z = [int(i) for i in z]
y = input().split(' ')
y = [int(i) for i in y]
for i in range(len(z)):
	z[i] -= y[i]
z.sort()
x = []
n = []
zc = 0
for i in z:
	if i > 0:
		x.append(i)
	elif i < 0:
		n.append(abs(i))
	else:
		zc += 1
ans = max(0, len(x) * (len(x) - 1) / 2)
ans += zc * len(x)
for i in n:
	p = searchInsert(x, i)
	ans += len(x) - p
print(int(ans))


from bisect import bisect_right

def bi(a, x):
	i = bisect_right(a, x)
	if i == n:
		return -1
	else:
		return i
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = []
d = []
for i in range(n):
	c.append(a[i] - b[i])
c.sort()
for i in range(n):
	if c[i] < 0:
		if bi(c, -1 * c[i]) != -1:
			d.append(n - bi(c, -1 * c[i]))
	if c[i] == 0:
		if i != -1:
			if bi(c, 0) != -1:
				d.append(n - bi(c, 0))
	if c[i] > 0:
		d.append(n - i - 1)
print(sum(d))


import math, sys
from collections import Counter, defaultdict, deque
from sys import stdin, stdout
input = stdin.readline
li = lambda : list(map(int, input().split()))

def binarysearch(c, val, i):
	start = 0
	end = i
	leftgreater = i
	while start <= end:
		mid = (start + end) // 2
		if c[mid] == val:
			while mid - 1 >= 0 and c[mid - 1] == val:
				mid -= 1
			leftgreater = mid
			break
		if c[mid] > val:
			leftgreater = mid
			end = mid - 1
		else:
			start = mid + 1
	return leftgreater

def case():
	n = int(input())
	a = li()
	b = li()
	c = []
	for i in range(n):
		c.append(a[i] - b[i])
	c.sort()
	ans = 0
	for i in range(n):
		if c[i] <= 0:
			continue
		k = binarysearch(c, 1 - c[i], i)
		ans += i - k
	print(ans)
for _ in range(1):
	case()


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
n = int(input())
teach = list(map(int, input().split()))
stud = list(map(int, input().split()))
res = list(map(lambda x, y: x - y, teach, stud))
res.sort()
(start, end) = (0, n - 1)
ans = 0
while start < end:
	if res[start] + res[end] > 0:
		ans += end - start
		end -= 1
	else:
		start += 1
print(ans)


def findPairs(arr, n, x):
	l = 0
	r = n - 1
	result = 0
	while l < r:
		if arr[l] + arr[r] > x:
			result += r - l
			l += 1
		else:
			r -= 1
	return result
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
p = [[a[i], b[i]] for i in range(n)]
diff = [a[i] - b[i] for i in range(n)]
diff.sort(reverse=True)
print(findPairs(diff, n, 0))


from sys import stdin
stdin.readline

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

def it():
	return int(stdin.readline().strip())
n = it()
(a, b) = (mp(), mp())
c = []
for i in range(n):
	c += [a[i] - b[i]]
c.sort()
e = count = 0
d = n - 1
while e < d and d > 0:
	if c[e] + c[d] > 0:
		count += d - e
		d -= 1
	else:
		e += 1
print(count)


num1 = int(input())
arr1 = []
arr2 = []
arr = []
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))
for i in range(0, num1):
	a = arr1[i] - arr2[i]
	arr.append(a)
arr.sort(reverse=True)
l = 0
r = num1 - 1
a = 0
while l < r:
	if arr[l] + arr[r] > 0:
		a += r - l
		l += 1
	else:
		r -= 1
print(a)


def Merge(diff1, diff2):
	diff1 = sorted(diff1, reverse=True)
	diff2 = sorted(diff2, reverse=True)
	end = len(diff2)
	res = 0
	for d1 in range(len(diff1)):
		for d2 in range(end):
			if diff1[d1] + diff2[d2] > 0:
				res += 1
			else:
				end = d2
				break
	return res

def Count(diff):
	if len(diff) <= 1:
		return 0
	res = Count(diff[:len(diff) // 2]) + Count(diff[len(diff) // 2:]) + Merge(diff[:len(diff) // 2], diff[len(diff) // 2:])
	return res
n = int(input())
teachers = list(map(int, input().split()))
students = list(map(int, input().split()))
diff = [teachers[i] - students[i] for i in range(n)]
positive = []
pos_numbers = 0
nagetive = []
nag_numbers = 0
zero = 0
for d in diff:
	if d > 0:
		positive.append(d)
		pos_numbers += 1
	elif d < 0:
		nagetive.append(d)
		nag_numbers += 1
	else:
		zero += 1
res = pos_numbers * (pos_numbers - 1) // 2 + pos_numbers * zero
positive = sorted(positive, reverse=False)
nagetive = sorted(nagetive, reverse=True)
start = 0
for d1 in range(pos_numbers):
	for d2 in range(start, nag_numbers):
		if positive[d1] + nagetive[d2] <= 0:
			res += d2
			start = d2
			break
	else:
		res += nag_numbers
print(res)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

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

def bin_search(arr, l, r, val):
	if arr[r] <= val:
		return r + 1
	if r - l < 2:
		if arr[l] > val:
			return l
		else:
			return r
	mid = int((l + r) / 2)
	if arr[mid] <= val:
		return bin_search(arr, mid, r, val)
	else:
		return bin_search(arr, l, mid, val)

def pr_list(a):
	print(*a, sep=' ')

def main():
	n = inp()
	a1 = inlt()
	b1 = inlt()
	diff = [a1[i] - b1[i] for i in range(n)]
	diff.sort()
	out = 0
	while len(diff) != 1:
		curr = -1 * diff.pop(-1)
		i = bin_search(diff, 0, len(diff) - 1, curr)
		out = out + max(len(diff) - i, 0)
	print(out)
	return 0
main()


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = []
for i in range(len(a)):
	c.append(a[i] - b[i])
c.sort()
ans = 0
for i in range(len(c) - 1):
	l = i
	r = len(c)
	while r - l > 1:
		mid = (l + r) // 2
		if c[mid] > -c[i]:
			r = mid
		if c[mid] <= -c[i]:
			l = mid
	ans += n - r
print(ans)


from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heapify
import sys, bisect, math, itertools, fractions, pprint
sys.setrecursionlimit(10 ** 8)
mod = 10 ** 9 + 7
INF = float('inf')

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

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

def inpln(n):
	return list((int(sys.stdin.readline()) for i in range(n)))
n = inp()
a = inpl()
b = inpl()
c = [a[i] - b[i] for i in range(n)]
c.sort()
res = 0
for (i, t) in enumerate(c):
	x = bisect.bisect_left(c, 1 - t)
	res += n - x
	if x <= i:
		res -= 1
print(res // 2)


from sys import stdin, stdout
import math
from itertools import permutations, combinations
from collections import defaultdict
from bisect import bisect_left

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

def In():
	return map(int, stdin.readline().split())

def I():
	return int(stdin.readline())
P = 1000000007
n = I()
a = L()
b = L()
lis = []
ind = []
for i in range(n):
	lis.append(a[i] - b[i])
lis.sort()
c = 0
for i in range(n):
	if lis[i] <= 0:
		continue
	else:
		x = bisect_left(lis, -lis[i] + 1)
		c += i - x
print(c)


n = int(input())
a = list(map(int, input().split()))
s = list(map(int, input().split()))
d = sorted([a[q] - s[q] for q in range(n)])
(q1, ans) = (n - 1, 0)
for q in range(n):
	while q1 > -1 and d[q1] > -d[q]:
		q1 -= 1
	ans += min(n - q1 - 1, n - q - 1)
print(ans)


def f(a):
	lo = len(a) - 1
	ans = 0
	for i in range(0, len(a)):
		hi = i
		while lo > hi:
			if a[hi] + a[lo] > 0:
				break
			else:
				lo -= 1
		if lo > hi:
			ans += lo - hi
	return ans
n = input()
a = [*map(int, input().strip().split())]
b = [*map(int, input().strip().split())]
a = list(map(lambda x, y: x - y, a, b))
a.sort(reverse=True)
print(f(a))


n = int(input())
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
nums = []
for i in range(n):
	nums.append(a[i] - b[i])
nums.sort()
c = 0
start = 0
end = n - 1
while start < end:
	if nums[end] <= 0:
		break
	elif nums[start] + nums[end] > 0:
		c += end - start
		end -= 1
	else:
		start += 1
print(c)


from bisect import bisect_right
n = int(input())
lst1 = list(map(int, input().split()))
lst2 = list(map(int, input().split()))
temp1 = [0 for i in range(n)]
for i in range(n):
	temp1[i] = lst1[i] - lst2[i]
temp1.sort()
ans = 0
for i in temp1:
	if i > 0:
		ans -= 1
	ans += n - bisect_right(temp1, -i)
print(ans // 2)


n = int(input())
a = list(map(int, input().strip().split(' ')))
b = list(map(int, input().strip().split(' ')))
for i in range(n):
	a[i] = a[i] - b[i]
a.sort(reverse=True)
nop = 0
last = n - 1
for i in range(0, last + 1):
	while a[last] + a[i] <= 0 and last > i:
		last -= 1
	nop += last - i
	if last <= i:
		break
print(nop)


n = int(input())
ab = []
for (el1, el2) in zip(map(int, input().split()), map(int, input().split())):
	ab.append(el1 - el2)
ans = 0
ab.sort()
(l, r) = (0, n - 1)
while l < r:
	if ab[l] > -ab[r]:
		ans += r - l
		r -= 1
	else:
		l += 1
print(ans)


n = int(input())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
for i in range(len(al)):
	al[i] -= bl[i]
al = sorted(al)
i = 0
j = n - 1
ans = 0
while i < j:
	while i < j and al[i] + al[j] <= 0:
		i += 1
	if i < j:
		ans += j - i
	j -= 1
print(ans)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [0] * n
for i in range(n):
	c[i] = a[i] - b[i]
c.sort()
lis = [0] * n
count = 0
for i in range(1, n):
	r = lis[i - 1]
	for j in range(lis[i - 1], -1, -1):
		if c[j] + c[i] <= 0:
			break
		else:
			r -= 1
	lis[i] = r + 1
	count += i - lis[i]
print(count)


import sys
from bisect import bisect_left

def main():

	def GCD(x, y):
		while y:
			(x, y) = (y, x % y)
		return x

	def lcm(a, b):
		return a * b // GCD(a, b)

	def merge(a, start, mid, end, d):
		p = start
		q = mid + 1
		arr = [0] * (end - start + 1)
		k = 0
		coun = 0
		for i in range(start, end + 1):
			if p > mid:
				arr[k] = a[q]
				q += 1
				k += 1
			elif q > end:
				arr[k] = a[p]
				d[a[p]] += coun
				k += 1
				p += 1
			elif a[p] < a[q]:
				arr[k] = a[p]
				d[a[p]] += coun
				k += 1
				p += 1
			else:
				arr[k] = a[q]
				k += 1
				q += 1
				coun += 1
		for i in range(k):
			a[start] = arr[i]
			start += 1

	def mergesort(a, start, end, d):
		if start < end:
			mid = (start + end) // 2
			mergesort(a, start, mid, d)
			mergesort(a, mid + 1, end, d)
			merge(a, start, mid, end, d)

	def inversion(l):
		d = {}
		for i in l:
			d[i] = 0
		mergesort(l, 0, len(l) - 1, d)
		return d

	def binary_search_lower(A, low, high, k):
		if high - low != 1:
			mid = (low + high) // 2
			x = A[mid]
			if x >= k:
				return binary_search_lower(A, low, mid, k)
			else:
				return binary_search_lower(A, mid, high, k)
		if A[low] >= k:
			return low
		else:
			return high

	def binary_expo(x, n):
		if n == 0:
			return 1
		elif n % 2 == 0:
			return binary_expo(x * x, n // 2)
		else:
			return x * binary_expo(x * x, (n - 1) // 2)

	def modu_expo(x, n, m):
		if n == 0:
			return 1
		elif n % 2 == 0:
			return modu_expo(x * x % m, n // 2, m)
		else:
			return x * modu_expo(x * x % m, (n - 1) // 2, m) % m

	def eEuclid(c, m):
		if m == 0:
			global d
			global x
			global y
			d = c
			x = 1
			y = 0
		else:
			eEuclid(m, c % m)
			temp = x
			x = y
			y = temp - c // m * y

	def mod_Inv(c, m):
		eEuclid(c, m)
		return (x % m + m) % m

	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
	n = int(sys.stdin.readline())
	A = [int(y) for y in sys.stdin.readline().split()]
	B = [int(y) for y in sys.stdin.readline().split()]
	l = []
	for i in range(n):
		l.append(A[i] - B[i])
	l.sort()
	ans = 0
	for i in range(n):
		key = l[i]
		if key <= 0:
			continue
		else:
			key = 1 - key
			ans += i - bisect_left(l, key)
	print(ans)
main()


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(n):
	a[i] = a[i] - b[i]
negatives = []
positives = []
zeroes = 0
for i in a:
	if i < 0:
		negatives.append(i)
	else:
		positives.append(i)
		if i == 0:
			zeroes += 1
negatives.sort(key=lambda number: abs(number))
positives.sort()
new = []
i = j = 0
while i < len(negatives) and j < len(positives):
	if abs(negatives[i]) < positives[j]:
		new.append(negatives[i])
		i += 1
	else:
		new.append(positives[j])
		j += 1
while i < len(negatives):
	new.append(negatives[i])
	i += 1
while j < len(positives):
	new.append(positives[j])
	j += 1
p = 0
ans = 0
for num in reversed(new):
	if num > 0:
		p += 1
	elif num < 0:
		ans += p
print(ans + len(positives) * (len(positives) - 1) // 2 - zeroes * (zeroes - 1) // 2)


import sys

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

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

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))
mod = int(1000000000.0) + 7
n = iinput()
a = get_list()
b = get_list()
d = [a[i] - b[i] for i in range(n)]
d.sort()
ans = 0
l = 0
r = n - 1
while l < r:
	if d[l] + d[r] > 0:
		ans += r - l
		r -= 1
	else:
		l += 1
print(ans)


x = int(input())
y = input().split()
y1 = input().split()
r = []
n = 0
for a in range(0, x):
	t = int(y[a]) - int(y1[a])
	if t < 0:
		r.append([abs(t), 'z'])
		n += 1
	else:
		r.append([t, 'p'])
r = sorted(r)
l = 0
t = 0
if r[0] == r[-1] and r[0][0] == 0:
	print(0)
else:
	a = 0
	while a < x:
		if r[a][1] == 'z':
			t += 1
		if r[a][0] == 0:
			b = a
			while b < len(r) and r[b][0] == 0:
				b += 1
			l += (x - b - (n - t)) * (b - a)
			a = b
		else:
			l += x - 1 - a - (n - t)
			a += 1
	print(l)


from bisect import bisect_right

def byebye(a, x):
	i = bisect_right(a, x)
	if i == testcase:
		return -1
	else:
		return i
testcase = int(input())
firstarr = list(map(int, input().split()))
secondarr = list(map(int, input().split()))
final = []
dis = []
for i in range(testcase):
	final.append(firstarr[i] - secondarr[i])
final.sort()
final1 = []
for i in range(testcase):
	final1.append(firstarr[i])
sum1 = 0
for i in range(testcase):
	sum1 += final1[i]
sum2 = 0
for i in range(testcase):
	sum2 += firstarr[i]
for i in range(testcase):
	if final[i] < 0:
		val = byebye(final, -1 * final[i])
		if val != -1:
			dis.append(testcase - val)
	if final[i] == 0:
		if i != -1:
			val = byebye(final, 0)
			if val != -1:
				dis.append(testcase - val)
	if final[i] > 0:
		dis.append(testcase - i - 1)
print(sum(dis))


import os
import sys
n = int(sys.stdin.readline().strip())
a = list(map(int, sys.stdin.readline().split()))
b = list(map(int, sys.stdin.readline().split()))
c = [0] * n
for i in range(n):
	c[i] = a[i] - b[i]
c = sorted(c)
right = n - 1
ans = 0
for left in range(n):
	while right >= 0 and c[left] + c[right] > 0:
		right -= 1
	ans += n - 1 - right
for i in range(n):
	if c[i] > 0:
		ans -= 1
print(ans // 2)


import bisect
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
aD = sorted([a[i] - b[i] for i in range(n)])
temp = 0
ans = 0
for i in range(n):
	if aD[i] > 0:
		t = -1 * aD[i] + 1
		p = bisect.bisect_left(aD, t, 0, i)
		ans += i - p
print(ans)


def ii():
	return int(input())

def ai():
	return list(map(int, input().split()))

def mi():
	return map(int, input().split())
n = ii()
a = ai()
b = ai()
for i in range(n):
	a[i] -= b[i]
(le, rg) = (0, n - 1)
a.sort()
ans = 0
while le < rg:
	if a[rg] + a[le] > 0:
		ans += rg - le
		rg -= 1
	else:
		le += 1
print(ans)


from collections import Counter
R1 = lambda : list(map(int, input().split()))
R2 = lambda : int(input())
R3 = lambda : Counter(map(int, input().split()))
n = R2()
(a, b) = (R1(), R1())
c = [0] * n
for i in range(n):
	c[i] = a[i] - b[i]
c.sort()
i = s = 0
j = n - 1
while i < j:
	if c[i] + c[j] > 0:
		s += j - i
		j -= 1
	else:
		i += 1
print(s)


import sys
read = lambda : list(map(int, sys.stdin.readline().strip().split()))
import bisect
n = int(input())
a = read()
b = read()
diff = []
difff = []
for i in range(n):
	diff.append(a[i] - b[i])
	difff.append(b[i] - a[i])
diff.sort()
difff.sort()
ans = 0
for num in difff:
	j = bisect.bisect(diff, num)
	while j < n and diff[j] == num:
		j += 1
		if j == n:
			break
	if num < 0:
		ans -= 1
	ans += n - j
print(ans // 2)


from sys import stdin
from bisect import bisect_left as bl

def solve(k, n):
	k.sort()
	ans = 0
	for i in range(n - 1):
		p = k[i]
		if p > 0:
			h = n - i
			ans += h * (h - 1) // 2
			return ans
		else:
			p = abs(p) + 1
			h = bl(k, p, lo=i + 1, hi=len(k))
			if h >= n:
				continue
			h = n - h
			ans += h
	return ans

def main():
	inp = stdin.readline
	n = int(inp())
	a = list(map(int, inp().split()))
	b = list(map(int, inp().split()))
	k = []
	for i in range(n):
		k.append(a[i] - b[i])
	ans = solve(k, n)
	print(ans)
main()


import sys
import math
import collections
import operator as op
from collections import deque
from math import gcd, inf, sqrt, pi, cos, sin, ceil, log2, floor
from bisect import bisect_right, bisect_left, bisect
from functools import reduce
from sys import stdin, stdout, setrecursionlimit
setrecursionlimit(2 ** 20)

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

def prime_factors(n):
	i = 2
	factors = []
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return list(factors)

def sumDigits(no):
	return 0 if no == 0 else int(no % 10) + sumDigits(int(no / 10))
MOD = 1000000007
PMOD = 998244353
N = 10 ** 9 + 7
LOGN = 30
T = 1
for _ in range(T):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().rstrip().split()))
	b = list(map(int, stdin.readline().rstrip().split()))
	c = [0] * n
	for i in range(n):
		c[i] = a[i] - b[i]
	ans = 0
	c.sort()
	for i in range(n):
		if c[i] <= 0:
			ans += n - bisect_right(c, -c[i])
		else:
			break
	if n - i >= 2:
		print(ans + ncr(n - i, 2))
	else:
		print(ans)


import sys
fast_reader = sys.stdin.readline
fast_writer = sys.stdout.write

def input():
	return fast_reader().strip()

def print(*argv):
	fast_writer(' '.join((str(i) for i in argv)))
	fast_writer('\n')
for _ in range(1):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	l = [a[i] - b[i] for i in range(n)]
	l.sort()
	i = 0
	j = n - 1
	ans = 0
	while i <= j:
		if l[i] + l[j] > 0:
			ans += j - i
			j -= 1
		else:
			i += 1
	print(ans)


from bisect import bisect_left
from collections import deque
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
a_b = [x - y for (x, y) in zip(a, b)]
b_a = [-x for x in a_b]
a_b.sort(reverse=True)
b_a.sort()
count = 0
a_b.pop(-1)
b_a = deque(b_a)
for (i, x) in enumerate(a_b):
	b_a.popleft()
	j = bisect_left(b_a, x)
	count += j
print(count)


from collections import Counter
from collections import defaultdict
import math
import random
import heapq as hq
from math import sqrt
import sys
from functools import reduce

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def tinput():
	return input().split()

def rinput():
	return map(int, tinput())

def rlinput():
	return list(rinput())
mod = int(1000000000.0) + 7

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))
import bisect
n = iinput()
a = rlinput()
b = rlinput()
find = [a[i] - b[i] for i in range(n)]
find.sort()
ans = 0
for i in range(n):
	temp = bisect.bisect_right(find, -find[i])
	ans += n - max(temp, i + 1)
print(ans)


import sys
input = sys.stdin.readline
n = int(input())
ar = [int(x) for x in input().split()]
br = [int(x) for x in input().split()]
cr = [0] * n
dr = [0] * n
for i in range(n):
	cr[i] = ar[i] - br[i]
pos = []
neg = []
count = 0
ans = 0
for i in cr:
	if i > 0:
		pos.append(i)
	elif i < 0:
		neg.append(-1 * i)
	else:
		count += 1
pos.sort()
neg.sort()
temp = 0
k = 0
tp = k
for i in range(len(pos)):
	for j in range(k, len(neg)):
		if neg[j] < pos[i]:
			temp += 1
			tp += 1
		else:
			k = tp
			break
	k = tp
	ans += temp
ans += count * len(pos)
ans += len(pos) * (len(pos) - 1) // 2
print(ans)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
count = 0
sub = [a[i] - b[i] for i in range(n)]
sub.sort(reverse=True)
r = n - 1
for j in range(n):
	if sub[j] <= 0:
		break
	while sub[j] + sub[r] <= 0:
		r -= 1
	count += r - j
print(count)


import bisect
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = sorted([a - b for (a, b) in zip(A, B)])
ans = 0
for (i, c) in enumerate(C):
	if c > 0:
		g = N - i - 1
	else:
		t = -c + 1
		ind = bisect.bisect_left(C, t)
		g = N - ind
	ans += g
print(ans)


import bisect
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = [x - y for (x, y) in zip(a, b)]
c.sort()
if c[-1] <= 0:
	print(0)
elif c[0] > 0:
	print(len(c) * (len(c) - 1) // 2)
else:
	ans = 0
	for (i, v) in enumerate(c):
		if v <= 0:
			p = bisect.bisect(c, 1 - v - 1, i + 1)
			if p < len(c):
				ans += len(c) - p
		else:
			break
	ans += (len(c) - i) * (len(c) - i - 1) // 2
	print(ans)


def lb(c, e):
	l = 0
	r = len(c) - 1
	ans = -1
	while l <= r:
		mid = (l + r) // 2
		if c[mid] < e:
			l = mid + 1
		else:
			ans = mid
			r = mid - 1
	return ans
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
c = []
for i in range(n):
	c.append(a[i] - b[i])
c.sort()
for i in range(n):
	if c[i] > 0:
		pos = lb(c, 1 - c[i])
		ans += i - pos
		if pos == -1:
			ans -= 1
print(ans)


from sys import *
n = int(stdin.readline())
a = [int(x) for x in stdin.readline().split()]
b = [int(x) for x in stdin.readline().split()]
count = 0
c = []
for i in range(n):
	a[i] = a[i] - b[i]
a = sorted(a)
i = 0
j = n - 1
while i < j:
	if a[i] + a[j] > 0:
		count += j - i
		j = j - 1
	else:
		i = i + 1
print(count)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
l = [x - y for (x, y) in zip(a, b)]
l.sort()
z = l.count(0)
p = sum((1 for x in l if x > 0))
m = n - z - p
idx = n
cnt = p * (p - 1) // 2 + z * p
for i in range(m):
	while l[idx - 1] + l[i] > 0:
		idx -= 1
	cnt += n - idx
print(cnt)


import bisect
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [0] * n
index = 0
for (i, j) in zip(a, b):
	c[index] = i - j
	index += 1
d = sorted(c)
ans = 0
for i in range(n):
	if d[i] <= 0:
		if d[i] == 0:
			x = bisect.bisect_left(d, 1)
		else:
			x = bisect.bisect_left(d, abs(d[i]) + 1)
		index = x + 1
		ans += n - index + 1
	else:
		index = i + 1
		ans += n - index
print(ans)


import sys, math, bisect
sys.setrecursionlimit(10 ** 5 + 10)

def input():
	return sys.stdin.readline()[:-1]

def main():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	t = sorted([a[k] - b[k] for k in range(n)])
	ans = 0
	for k in range(n - 1):
		if t[k] > 0:
			ans += n - k - 1
		else:
			ans += n - bisect.bisect_left(t, -t[k] + 1)
	print(ans)
main()


import os
from io import BytesIO, IOBase
import sys
from collections import defaultdict, deque, Counter
from bisect import *
from math import sqrt
import math
from itertools import permutations

def main():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = []
	for (i, v) in enumerate(a):
		c.append(v - b[i])
	c.sort()
	i = 0
	j = n - 1
	ans = 0
	while i < j:
		if c[i] + c[j] > 0:
			ans += j - i
			j -= 1
		else:
			i += 1
	print(ans)
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))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = []
for i in range(n):
	c.append(a[i] - b[i])
c.sort()
sum = 0
for i in range(1, n):
	left = 0
	right = i - 1
	ans = -1
	while left <= right:
		mid = int((left + right) / 2)
		if c[mid] > -c[i]:
			ans = mid
			right = mid - 1
		else:
			left = mid + 1
	if ans != -1:
		sum += i - ans
print(sum)


from bisect import bisect_left

def pairOfTopics(n, a, b):
	l = []
	for x in range(n):
		l.append(a[x] - b[x])
	l.sort()
	ans = 0
	for x in range(n - 1):
		i = bisect_left(l, 0 - l[x] + 1, x + 1, n)
		ans += n - i
	return ans
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
print(pairOfTopics(n, a, b))


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
E = 0
d = []
for i in range(n):
	d.append(a[i] - b[i])
d.sort()
for i in range(n):
	if d[i] <= 0:
		continue
	start = 0
	end = i
	while start < end:
		k = (start + end) // 2
		if d[k] + d[i] > 0:
			end = k - 1
		else:
			start = k + 1
	for j in range(max(0, end - 1), min(i - 1, start + 1) + 1):
		if d[j] + d[i] > 0:
			E += i - j
			break
print(E)


n = int(input())
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
array = sorted([i - j for (i, j) in zip(a, b)], reverse=True)
(i, j) = (0, n - 1)
tot = 0
while i <= j:
	if array[i] + array[j] > 0:
		tot += j - i
		i += 1
	else:
		j -= 1
print(tot)


import sys
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
(pos, neg, zero) = ([], [], 0)
ans = 0
for i in range(n):
	if a[i] - b[i] == 0:
		zero += 1
	elif a[i] - b[i] > 0:
		pos.append(a[i] - b[i])
	else:
		neg.append(b[i] - a[i])
pos.sort()
neg.sort()
for i in pos:
	ans += bisect_left(neg, i)
	ans += len(pos) - 1
for i in neg:
	ans += len(pos) - bisect_right(pos, i)
ans //= 2
ans += zero * len(pos)
print(ans)


import bisect

def main():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	dp = [0 for _ in range(n)]
	for i in range(n):
		dp[i] = a[i] - b[i]
	cnt = 0
	dp.sort()
	ans = 0
	for i in dp:
		if i > 0:
			ans -= 1
		ans += n - bisect.bisect_right(dp, -i)
	print(ans // 2)
main()


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = sorted([a[i] - b[i] for i in range(n)])
if d[-1] <= 0:
	print(0)
else:
	answer = 0
	(lo, hi) = (0, n - 1)
	while lo < hi:
		if d[lo] + d[hi] > 0:
			answer += hi - lo
			hi -= 1
		else:
			lo += 1
	print(answer)


n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = n * [None]
for i in range(n):
	c[i] = a[i] - b[i]
c.sort()
zozadu = -1
spolu = 0
nulovych = 0
for i in range(n):
	if c[i] > 0:
		spolu = spolu + 0.5 * (n - i - 1) * (n - i)
		break
	spolu = spolu + -zozadu - 1
	while c[i] + c[zozadu] > 0:
		spolu = spolu + 1
		zozadu = zozadu - 1
print(int(spolu))


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
li = []
for i in range(n):
	li.append(a[i] - b[i])
li.sort()
l = 0
r = n - 1
s = 0
while l < r:
	if li[l] + li[r] > 0:
		s += r - l
		r -= 1
	else:
		l += 1
print(s)


def findPairs(arr, n, x):
	l = 0
	r = n - 1
	result = 0
	while l < r:
		if arr[l] + arr[r] < x:
			result += r - l
			l += 1
		else:
			r -= 1
	return result
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
pos = []
neg = []
for j in range(n):
	neg.append(b[j] - a[j])
neg.sort()
res = findPairs(neg, len(neg), 0)
print(int(res))


from bisect import bisect_left
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
k = []
for i in range(n):
	k.append(b[i] - a[i])
k.sort()
ans = 0
for i in range(n):
	d = a[i] - b[i]
	c = bisect_left(k, d)
	if d <= 0:
		ans += c
	else:
		ans += c - 1
print(ans // 2)


import sys
import heapq
from math import ceil, floor, gcd, fabs, factorial, fmod
from collections import defaultdict as dd, deque, Counter as c
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(var):
	sys.stdout.write(var)

def l():
	return list(map(int, data().split()))

def sl():
	return list(map(str, data().split()))

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [[val for i in range(n)] for j in range(m)]
n = int(data())
a = l()
b = l()
diff = []
for i in range(n):
	diff.append(a[i] - b[i])
diff.sort()
answer = 0
for i in range(n - 1):
	if diff[i] <= 0:
		k = abs(diff[i]) + 1
	else:
		k = diff[i]
	temp = n - bl(diff, k, i + 1, n)
	answer += temp
print(answer)


import math
from bisect import bisect
from itertools import groupby

def rints():
	return list(map(int, input().split()))
n = int(input())
a = rints()
b = rints()
gain = [a[i] - b[i] for i in range(n)]
gain.sort()
ans = 0
for val in gain:
	add = n - bisect(gain, -val)
	ans += add
	if add and val > 0:
		ans -= 1
print(ans // 2)


R = lambda : map(int, input().split())
n = int(input())
a = list(R())
b = list(R())
dif = [(b[i] - a[i], 1) for i in range(n)]
for x in dif:
	if x[0] < 0:
		dif.append((-x[0], 0))
dif = sorted(dif)
count = 0
ans = 0
for i in range(1, len(dif)):
	if dif[i][1] == 1:
		count += 1
	if dif[i][1] == 0:
		ans += count
		count = max(0, count - 1)
print(ans)


import bisect, math
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = []
for i in range(n):
	C.append(A[i] - B[i])
C.sort()
ans = 0
for i in range(n):
	if C[i] > 0:
		k = bisect.bisect_left(C, 1 - C[i])
		ans += i - k
print(ans)


import sys
import bisect
RI = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
n = int(ri())
a = RI()
b = RI()
c = [a[i] - b[i] for i in range(n)]
c.sort()
i = 0
while i < len(c) and c[i] < 0:
	i += 1
ans = 0
for i in range(i, n):
	pos = bisect.bisect_left(c, 1 - c[i])
	if pos < i:
		ans += i - pos
print(ans)


k = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(k):
	b[i] = a[i] - b[i]
b.sort()
s = 0
(x, y) = (0, k - 1)
while x < y:
	if b[y] + b[x] > 0:
		s += y - x
		y -= 1
	else:
		x += 1
print(s)


import io
import os
import random

class TreapMultiSet(object):
	root = 0
	size = 0

	def __init__(self, data=None):
		if data:
			data = sorted(data)
			self.root = treap_builder(data)
			self.size = len(data)

	def add(self, key):
		self.root = treap_insert(self.root, key)
		self.size += 1

	def remove(self, key):
		self.root = treap_erase(self.root, key)
		self.size -= 1

	def discard(self, key):
		try:
			self.remove(key)
		except KeyError:
			pass

	def ceiling(self, key):
		x = treap_ceiling(self.root, key)
		return treap_keys[x] if x else None

	def higher(self, key):
		x = treap_higher(self.root, key)
		return treap_keys[x] if x else None

	def floor(self, key):
		x = treap_floor(self.root, key)
		return treap_keys[x] if x else None

	def lower(self, key):
		x = treap_lower(self.root, key)
		return treap_keys[x] if x else None

	def max(self):
		return treap_keys[treap_max(self.root)]

	def min(self):
		return treap_keys[treap_min(self.root)]

	def __len__(self):
		return self.size

	def __nonzero__(self):
		return bool(self.root)
	__bool__ = __nonzero__

	def __contains__(self, key):
		return self.floor(key) == key

	def __repr__(self):
		return 'TreapMultiSet({})'.format(list(self))

	def __iter__(self):
		if not self.root:
			return iter([])
		out = []
		stack = [self.root]
		while stack:
			node = stack.pop()
			if node > 0:
				if right_child[node]:
					stack.append(right_child[node])
				stack.append(~node)
				if left_child[node]:
					stack.append(left_child[node])
			else:
				out.append(treap_keys[~node])
		return iter(out)

	def __getitem__(self, index):
		return treap_find_kth(self.root, index)

	def bisect_left(self, value):
		return treap_bisect_left(self.root, value)

	def bisect_right(self, value):
		return treap_bisect_right(self.root, value)

class TreapSet(TreapMultiSet):

	def add(self, key):
		(self.root, duplicate) = treap_insert_unique(self.root, key)
		if not duplicate:
			self.size += 1

	def __repr__(self):
		return 'TreapSet({})'.format(list(self))

class TreapHashSet(TreapMultiSet):

	def __init__(self, data=None):
		if data:
			self.keys = set(data)
			super(TreapHashSet, self).__init__(self.keys)
		else:
			self.keys = set()

	def add(self, key):
		if key not in self.keys:
			self.keys.add(key)
			super(TreapHashSet, self).add(key)

	def remove(self, key):
		self.keys.remove(key)
		super(TreapHashSet, self).remove(key)

	def discard(self, key):
		if key in self.keys:
			self.remove(key)

	def __contains__(self, key):
		return key in self.keys

	def __repr__(self):
		return 'TreapHashSet({})'.format(list(self))

class TreapHashMap(TreapMultiSet):

	def __init__(self, data=None):
		if data:
			self.map = dict(data)
			super(TreapHashMap, self).__init__(self.map.keys())
		else:
			self.map = dict()

	def __setitem__(self, key, value):
		if key not in self.map:
			super(TreapHashMap, self).add(key)
		self.map[key] = value

	def __getitem__(self, key):
		return self.map[key]

	def add(self, key):
		raise TypeError('add on TreapHashMap')

	def get(self, key, default=None):
		return self.map.get(key, default=default)

	def remove(self, key):
		self.map.pop(key)
		super(TreapHashMap, self).remove(key)

	def discard(self, key):
		if key in self.map:
			self.remove(key)

	def __contains__(self, key):
		return key in self.map

	def __repr__(self):
		return 'TreapHashMap({})'.format(list(self))
left_child = [0]
right_child = [0]
subtree_size = [0]
treap_keys = [0]
treap_prior = [0.0]

def treap_builder(sorted_data):

	def build(begin, end):
		if begin == end:
			return 0
		mid = (begin + end) // 2
		root = treap_create_node(sorted_data[mid])
		left_child[root] = build(begin, mid)
		right_child[root] = build(mid + 1, end)
		subtree_size[root] = end - begin
		ind = root
		while True:
			lc = left_child[ind]
			rc = right_child[ind]
			if lc and treap_prior[lc] > treap_prior[ind]:
				if rc and treap_prior[rc] > treap_prior[rc]:
					(treap_prior[ind], treap_prior[rc]) = (treap_prior[rc], treap_prior[ind])
					ind = rc
				else:
					(treap_prior[ind], treap_prior[lc]) = (treap_prior[lc], treap_prior[ind])
					ind = lc
			elif rc and treap_prior[rc] > treap_prior[ind]:
				(treap_prior[ind], treap_prior[rc]) = (treap_prior[rc], treap_prior[ind])
				ind = rc
			else:
				break
		return root
	return build(0, len(sorted_data))

def treap_create_node(key):
	treap_keys.append(key)
	treap_prior.append(random.random())
	left_child.append(0)
	right_child.append(0)
	subtree_size.append(1)
	return len(treap_keys) - 1

def treap_split(root, key):
	left_pos = right_pos = 0
	stack = []
	while root:
		if key < treap_keys[root]:
			left_child[right_pos] = right_pos = root
			root = left_child[root]
			stack.append(right_pos)
		else:
			right_child[left_pos] = left_pos = root
			root = right_child[root]
			stack.append(left_pos)
	(left, right) = (right_child[0], left_child[0])
	right_child[left_pos] = left_child[right_pos] = right_child[0] = left_child[0] = 0
	treap_update(stack)
	return (left, right)

def treap_merge(left, right):
	(where, pos) = (left_child, 0)
	stack = []
	while left and right:
		if treap_prior[left] > treap_prior[right]:
			where[pos] = pos = left
			where = right_child
			left = right_child[left]
		else:
			where[pos] = pos = right
			where = left_child
			right = left_child[right]
		stack.append(pos)
	where[pos] = left or right
	node = left_child[0]
	left_child[0] = 0
	treap_update(stack)
	return node

def treap_insert(root, key):
	if not root:
		return treap_create_node(key)
	(left, right) = treap_split(root, key)
	return treap_merge(treap_merge(left, treap_create_node(key)), right)

def treap_insert_unique(root, key):
	if not root:
		return (treap_create_node(key), False)
	(left, right) = treap_split(root, key)
	if left and treap_keys[left] == key:
		return (treap_merge(left, right), True)
	return (treap_merge(treap_merge(left, treap_create_node(key)), right), False)

def treap_erase(root, key):
	if not root:
		raise KeyError(key)
	if treap_keys[root] == key:
		return treap_merge(left_child[root], right_child[root])
	node = root
	stack = [root]
	while root and treap_keys[root] != key:
		parent = root
		root = left_child[root] if key < treap_keys[root] else right_child[root]
		stack.append(root)
	if not root:
		raise KeyError(key)
	if root == left_child[parent]:
		left_child[parent] = treap_merge(left_child[root], right_child[root])
	else:
		right_child[parent] = treap_merge(left_child[root], right_child[root])
	treap_update(stack)
	return node

def treap_ceiling(root, key):
	while root and treap_keys[root] < key:
		root = right_child[root]
	if not root:
		return 0
	min_node = root
	min_key = treap_keys[root]
	while root:
		if treap_keys[root] < key:
			root = right_child[root]
		else:
			if treap_keys[root] < min_key:
				min_key = treap_keys[root]
				min_node = root
			root = left_child[root]
	return min_node

def treap_higher(root, key):
	while root and treap_keys[root] <= key:
		root = right_child[root]
	if not root:
		return 0
	min_node = root
	min_key = treap_keys[root]
	while root:
		if treap_keys[root] <= key:
			root = right_child[root]
		else:
			if treap_keys[root] < min_key:
				min_key = treap_keys[root]
				min_node = root
			root = left_child[root]
	return min_node

def treap_floor(root, key):
	while root and treap_keys[root] > key:
		root = left_child[root]
	if not root:
		return 0
	max_node = root
	max_key = treap_keys[root]
	while root:
		if treap_keys[root] > key:
			root = left_child[root]
		else:
			if treap_keys[root] > max_key:
				max_key = treap_keys[root]
				max_node = root
			root = right_child[root]
	return max_node

def treap_lower(root, key):
	while root and treap_keys[root] >= key:
		root = left_child[root]
	if not root:
		return 0
	max_node = root
	max_key = treap_keys[root]
	while root:
		if treap_keys[root] >= key:
			root = left_child[root]
		else:
			if treap_keys[root] > max_key:
				max_key = treap_keys[root]
				max_node = root
			root = right_child[root]
	return max_node

def treap_min(root):
	if not root:
		raise ValueError('min on empty treap')
	while left_child[root]:
		root = left_child[root]
	return root

def treap_max(root):
	if not root:
		raise ValueError('max on empty treap')
	while right_child[root]:
		root = right_child[root]
	return root

def treap_update(path):
	for node in reversed(path):
		assert node != 0
		lc = left_child[node]
		rc = right_child[node]
		subtree_size[node] = subtree_size[lc] + 1 + subtree_size[rc]

def treap_find_kth(root, k):
	if not root or not 0 <= k < subtree_size[root]:
		raise IndexError('treap index out of range')
	while True:
		lc = left_child[root]
		left_size = subtree_size[lc]
		if k < left_size:
			root = lc
			continue
		k -= left_size
		if k == 0:
			return treap_keys[root]
		k -= 1
		rc = right_child[root]
		root = rc

def treap_bisect_left(root, key):
	index = 0
	while root:
		if treap_keys[root] < key:
			index += subtree_size[left_child[root]] + 1
			root = right_child[root]
		else:
			root = left_child[root]
	return index

def treap_bisect_right(root, key):
	index = 0
	while root:
		if treap_keys[root] <= key:
			index += subtree_size[left_child[root]] + 1
			root = right_child[root]
		else:
			root = left_child[root]
	return index

def solve(N, A, B):
	ans = 0
	sl = TreapMultiSet()
	for (a, b) in zip(A, B):
		d = b - a
		numSmaller = sl.bisect_left(-d)
		ans += numSmaller
		sl.add(d)
	return ans
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
(N,) = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
ans = solve(N, A, B)
print(ans)


from bisect import bisect_left
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
amb = [a[x] - b[x] for x in range(n)]
amb.sort()
res = 0
for i in range(n):
	if amb[i] <= 0:
		continue
	res += i - bisect_left(amb, -amb[i] + 1)
print(res)


from bisect import bisect_right
occur = {}
n = int(input())
t = [int(x) for x in input().split()]
s = [int(x) for x in input().split()]
ar = []
for i in range(n):
	ar.append(t[i] - s[i])
ar.sort()
ans = 0
for i in ar:
	if i > 0:
		if i in occur:
			occur[i] += 1
		else:
			occur[i] = 1
for i in range(n):
	temp = bisect_right(ar, abs(ar[i]))
	if temp < n:
		ans += n - temp
for i in occur:
	if occur[i] > 1:
		ans += occur[i] * (occur[i] - 1) // 2
print(ans)


q = int(input())
teach = list(map(int, input().split()))
stud = list(map(int, input().split()))
diff = [teach[x] - stud[x] for x in range(q)]
count = 0
diff.sort()
x = 0
y = q - 1
while x < y:
	if diff[x] + diff[y] > 0:
		count += y - x
		y -= 1
	else:
		x += 1
print(count)


from bisect import bisect_left
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [0] * n
for i in range(n):
	c[i] = a[i] - b[i]
c = sorted(c)
ans = 0
for i in range(n):
	j = n - bisect_left(c, -c[i] + 1, i + 1, n)
	ans += j
print(ans)


import sys
input = lambda : sys.stdin.readline().rstrip()
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
part = []
for i in range(n):
	part.append(a[i] - b[i])
part.sort()
ans = 0
for i in range(n):
	if part[i] > 0:
		ans += n - i - 1
	else:
		L = 0
		R = n
		while L < R - 1:
			mid = (L + R) // 2
			if part[mid] > abs(part[i]):
				R = mid
			else:
				L = mid
		ans += n - R
print(ans)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = []
for i in range(n):
	x.append(a[i] - b[i])
x.sort()
i = 0
j = n - 1
count = 0
while i < j and j < n:
	if x[j] <= 0:
		break
	elif x[i] + x[j] > 0:
		count = count + j - i
		j -= 1
	else:
		i += 1
print(count)


a = int(input())
arryp = map(int, input().split())
arrys = map(int, input().split())
z = 0
m = 1
h = 1
ary = [0] * a
result = 0
v = 0
ary = [i - j for (i, j) in zip(arryp, arrys)]
ary.sort(key=int, reverse=True)
for i in range(a):
	if ary[i] > 0:
		z += 1
	else:
		break
x = z - 1
for n in range(z, a):
	for i in range(x, -1, -1):
		if ary[n] + ary[i] > 0:
			result += i + 1
			x -= x - i
			break
		elif i == 0:
			v = 1
	if v == 1:
		break
result += int(z * ((z - 1) / 2))
print(result)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = [a[i] - b[i] for i in range(n)]
d.sort()
cc = 0
for i in range(n):
	u = b[i] - a[i] + 1
	(l, r) = (0, n)
	while l < r:
		m = (l + r) // 2
		if d[m] < u:
			l = m + 1
		else:
			r = m
	cc += n - l
	if a[i] - b[i] >= u:
		cc -= 1
print(cc // 2)


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def binRight(el, a: list):
	l = 0
	r = len(a)
	while l + 1 < r:
		m = (l + r) // 2
		if a[m] <= el:
			l = m
		else:
			r = m
	if r == 1:
		if a[0] > el:
			r = 0
	return r

def main():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	positive = []
	negative = []
	numP = 0
	numZ = 0
	for i in range(n):
		tmp = a[i] - b[i]
		if tmp > 0:
			positive.append(tmp)
			numP += 1
		elif tmp == 0:
			numZ += 1
		else:
			negative.append(tmp * -1)
	positive.sort()
	ans = numP * (numP - 1) // 2 + numP * numZ
	NP = len(positive)
	for el in negative:
		pos = binRight(el, positive)
		ans += NP - pos
	print(ans)
main()


n = int(input())
l = list(map(int, input().split()))
ll = list(map(int, input().split()))
for i in range(n):
	l[i] -= ll[i]
l.sort()
i = 0
j = n - 1
x = 0
while i < j:
	if l[i] + l[j] > 0:
		j -= 1
	else:
		x += n - 1 - j
		i += 1
x += (n - i - 1) * (n - i) // 2
print(x)


n = int(input())
a = map(int, input().split())
b = map(int, input().split())
c = [p[0] - p[1] for p in zip(a, b)]
c.sort()
res = 0
i = 0
j = len(c) - 1
while True:
	while i < j and c[i] + c[j] > 0:
		j -= 1
	if i >= j:
		break
	res += n - j - 1
	i += 1
res += n - i - 1
res += (n - i - 1) * (n - i - 2) // 2
print(res)


import bisect
from collections import Counter, defaultdict
from sys import stdin, stdout
input = stdin.readline
I = lambda : int(input())
M = lambda : map(int, input().split())
LI = lambda : list(map(int, input().split()))
n = I()
a = LI()
b = LI()
c = []
ans = 0
ch = defaultdict(int)
for i in range(n):
	c += [a[i] - b[i]]
c.sort()
cu = 0
for i in range(n):
	if c[i] > 0:
		ans -= 1
	ans += n - bisect.bisect_right(c, -c[i])
print(ans // 2)


from sys import stdin, stdout
import sys
from bisect import bisect_left, bisect_right
n = int(stdin.readline().strip())
a = list(map(int, stdin.readline().strip().split(' ')))
b = list(map(int, stdin.readline().strip().split(' ')))
c = [a[i] - b[i] for i in range(n)]
d = [-1 * (a[i] - b[i]) for i in range(n)]
d.sort()
ans = 0
for i in c:
	t1 = bisect_left(d, i)
	if i > 0:
		t1 -= 1
	ans += t1
stdout.write(str(ans // 2) + '\n')


from bisect import bisect_left as bl
n = int(input())
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
x = [x1 - x2 for (x1, x2) in zip(b, a)]
x.sort()
count = 0
for i in range(n):
	val = a[i] - b[i]
	ct = bl(x, val)
	if b[i] - a[i] < val:
		ct -= 1
	count += ct
print(count // 2)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(n):
	a[i] -= b[i]
a.sort(reverse=True)
(i, j) = (0, n - 1)
tot = 0
while i <= j:
	while a[i] + a[j] <= 0 and j > i:
		j -= 1
	tot += j - i
	i += 1
print(tot)


from bisect import bisect_right
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = []
D = []
x = 0
for i in range(n):
	t = A[i] - B[i]
	if t == 0:
		x += 1
	elif t > 0:
		C.append(t)
	else:
		D.append(t)
C.sort()
D.sort()
m = len(C)
i = 0
res = 0
while i < len(D):
	res += m - bisect_right(C, -D[i])
	i += 1
res = res + m * (m - 1) // 2 + x * m
print(res)


import bisect

def run():
	n = int(input())
	nums1 = list(map(int, input().split()))
	nums2 = list(map(int, input().split()))
	nums = []
	ans = n * (n - 1) // 2
	for i in range(n):
		nums.append(nums1[i] - nums2[i])
	nums = sorted(nums)
	t = 0
	for i in range(n):
		if nums[i] > 0:
			break
		else:
			index = bisect.bisect_right(nums, -nums[i])
			t += max(index - i - 1, 0)
	print(ans - t)
run()


def main():
	n = int(input())
	a = (int(e) for e in input().split(' '))
	b = (int(e) for e in input().split(' '))
	d = [e[0] - e[1] for e in zip(a, b)]
	d.sort(reverse=True)
	(i, j, ans) = (0, len(d) - 1, 0)
	while i < j:
		if d[i] + d[j] > 0:
			ans += j - i
			i += 1
		else:
			j -= 1
	print(ans)
main()


a = int(input())
j = 0
b = list(map(int, input().split()))
for i in map(int, input().split()):
	b[j] -= i
	j += 1
b = sorted(b)
(i, j, k, k1) = (0, a - 1, 0, 0)
while i < a:
	if b[i] <= 0:
		if j > -1:
			while b[i] + b[j] > 0:
				if j > -1:
					j -= 1
					k1 += 1
				else:
					break
		k += k1
	else:
		o = a - i - 1
		k += o * (o + 1) // 2
		break
	i += 1
print(k)


def run_length_compress(string):
	string.append('@')
	n = len(string)
	begin = 0
	end = 1
	cnt = 1
	ans = []
	while True:
		if end >= n:
			break
		if string[begin] == string[end]:
			end += 1
			cnt += 1
		else:
			ans.append((cnt, string[begin]))
			begin = end
			end = begin + 1
			cnt = 1
	return ans

class BIT:

	def __init__(self, n):
		self.size = n
		self.bit = [0] * (n + 1)

	def _sum(self, i):
		s = 0
		while i > 0:
			s += self.bit[i]
			i -= i & -i
		return s

	def add(self, i, val):
		i += 1
		while i <= self.size:
			self.bit[i] += val
			i += i & -i

	def get_sum(self, l, r):
		return self._sum(r) - self._sum(l)
from collections import deque
import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
diff_p = [(a[i] - b[i], i) for i in range(n) if a[i] - b[i] > 0]
diff_m = [(a[i] - b[i], i) for i in range(n) if a[i] - b[i] < 0]
diff_0 = [(a[i] - b[i], i) for i in range(n) if a[i] - b[i] == 0]
diff_p = sorted(diff_p)
diff_m = deque(sorted(diff_m))
bit = BIT(n)
for (_, i) in diff_0:
	bit.add(i, 1)
ans = 0
for (num, i) in diff_p:
	while diff_m:
		if diff_m[-1][0] + num > 0:
			(num2, j) = diff_m.pop()
			bit.add(j, 1)
		else:
			break
	ans += bit.get_sum(0, n)
	bit.add(i, 1)
print(ans)


def r(t=int):
	return list(map(t, input().split()))

def ri(t=int):
	return t(input())

def cd(it):
	ret_val = dict()
	for v in it:
		ret_val[v] = ret_val.get(v, 0) + 1
	return ret_val
n = ri()
a = r()
b = r()
f = list()
for (ai, bi) in zip(a, b):
	d = ai - bi
	f.append(d)
f.sort()
j = len(f) - 1
ans = 0
l = len(f)
import bisect
for i in range(l - 1):
	if f[i] > 0:
		ans += l - i - 1
	else:
		ans += l - bisect.bisect_right(f, 0 - f[i])
print(ans)


n = int(input())
ans = i = 0
j = n - 1
diff = []
p = []
j = n - 1
list1 = list(map(int, input().split()))
list2 = list(map(int, input().split()))
zip_object = zip(list1, list2)
for (list1_i, list2_i) in zip_object:
	diff.append(list1_i - list2_i)
diff.sort()
while i < j:
	if diff[i] + diff[j] > 0:
		ans += j - i
		j = j - 1
	else:
		i += 1
print(ans)


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

def I():
	return int(input())

def S():
	return str(input())

def L():
	return list(R())
from collections import Counter
import math
import sys
from itertools import permutations
import bisect
n = I()
a = L()
b = L()
c = [a[i] - b[i] for i in range(n)]
d = dict()
for cc in c:
	d[cc] = 1 if not cc in d else d[cc] + 1
cnt = 0
ans = 0
sum = {}
ss = 0
l = list(d)
l.sort()
v = 0
for i in l:
	sum[i] = ss
	ss += d[i]
	if i > 0:
		v += d[i]
for i in l:
	ind = bisect.bisect(l, -i)
	if ind < len(l):
		ans += (ss - sum[l[ind]]) * d[i]
print((ans - v) // 2)


n = int(input())
teacher = list(map(int, input().split()))
student = list(map(int, input().split()))
temp = (teacher[i] - student[i] for i in range(n))
temp = sorted(temp)
l = 0
h = n - 1
count = 0
while l < h:
	if temp[l] + temp[h] > 0:
		count += h - l
		h -= 1
	else:
		l += 1
print(count)


import unittest

def PairOfTopicsSolver(a, b):
	topics = sorted(zip(a, b), key=lambda x: x[1] - x[0])
	res = 0
	for i in range(len(topics)):
		low = i
		high = len(topics)
		while low + 1 < high:
			mid = (low + high) // 2
			if topics[i][0] + topics[mid][0] > topics[i][1] + topics[mid][1]:
				low = mid
			else:
				high = mid
		res += low - i
	return res

class PairOfTopicsTest(unittest.TestCase):

	def test_GivenTests(self):
		self.assertEqual(PairOfTopicsSolver([4, 8, 2, 6, 2], [4, 5, 4, 1, 3]), 7)
		self.assertEqual(PairOfTopicsSolver([1, 2, 3, 4], [1, 2, 3, 4]), 0)

	def test_SimpleTest_twoTopics(self):
		self.assertEqual(PairOfTopicsSolver([1, 2], [2, 3]), 0)
		self.assertEqual(PairOfTopicsSolver([5, 2], [2, 3]), 1)

	def test_SimpleTest_threeTopics(self):
		self.assertEqual(PairOfTopicsSolver([1, 2, 10], [2, 3, 1]), 2)

	def test_SimpleTest_mediumSizedInput(self):
		a = [10, 5, 2]
		b = [1, 20, 3]
		self.assertEqual(PairOfTopicsSolver(a, b), 1)
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
print(PairOfTopicsSolver(a, b))


def upper_bound(key, List):
	l = 0
	r = len(List) - 1
	if List[-1] <= key:
		return r + 1
	while l < r:
		mid = l + r >> 1
		if List[mid] > key:
			r = mid
		else:
			l = mid + 1
	return l
N = int(input())
T = [int(x) for x in input().split()]
S = [int(x) for x in input().split()]
for i in range(N):
	T[i] -= S[i]
T.sort()
Ans = 0
for i in range(N - 1):
	if T[i] <= 0:
		Ans += N - upper_bound(-T[i], T)
	else:
		Ans += N - i - 1
print(Ans)


def bn(l, r, x):
	opa = n
	while l <= r:
		m = (l + r) // 2
		if a[m] + x > 0:
			opa = m
			r = m - 1
		else:
			l = m + 1
	return opa
from sys import stdin
input = stdin.buffer.readline
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a = [a[i] - b[i] for i in range(n)]
a.sort()
ans = 0
for i in range(n - 1):
	ans += n - bn(i + 1, n - 1, a[i])
print(ans)


from bisect import bisect_left as bl
from bisect import bisect_right as br
import heapq
import math
from collections import *
from functools import reduce, cmp_to_key
import sys
input = sys.stdin.readline
M = mod = 10 ** 9 + 7

def factors(n):
	return sorted(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def inv_mod(n):
	return pow(n, mod - 2, mod)

def li():
	return [int(i) for i in input().rstrip('\n').split()]

def st():
	return input().rstrip('\n')

def val():
	return int(input().rstrip('\n'))

def li2():
	return [i for i in input().rstrip('\n')]

def li3():
	return [int(i) for i in input().rstrip('\n')]
n = val()
l1 = li()
l2 = li()
for i in range(n):
	l1[i] -= l2[i]
l1.sort()
ans = 0
for i in range(n):
	curr = l1[i]
	curr = 0 - l1[i]
	curr += 1
	ans += n - bl(l1, curr)
	if curr <= l1[i]:
		ans -= 1
print(ans // 2)


from sys import stdin, exit
from typing import List, Tuple, Dict

def find_first_g_t(arr: List[int], then: int):
	(l, r) = (0, len(arr) - 1)
	first_gt = None
	while l <= r:
		s = (l + r) // 2
		if arr[s] > then:
			first_gt = s
			r = s - 1
		else:
			l = s + 1
	return first_gt
stdin.readline()
student_units = [int(v) for v in stdin.readline().rstrip().split()]
teacher_units = [int(v) for v in stdin.readline().rstrip().split()]
vals = list(map(lambda x, y: x - y, student_units, teacher_units))
vals.sort()
rez = 0
for (i, v) in enumerate(vals):
	if v > 0:
		rez += len(vals) - i - 1
		continue
	fgt_i = find_first_g_t(vals, abs(v))
	if fgt_i is not None:
		rez += len(vals) - fgt_i
print(rez)


from bisect import bisect, bisect_left

def linp():
	return list(map(int, input().split(' ')))

def slinp():
	return sorted(linp())

def inp():
	return int(input())

def fnp():
	return float(input())

def dinp():
	s = linp()
	return (s[0], s[1])

def tinp():
	s = linp()
	return (s[0], s[1], s[2])

def main():
	n = inp()
	a = linp()
	b = linp()
	dct = dict()
	for i in range(n):
		k = a[i] - b[i]
		if k in dct.keys():
			dct[k] += 1
		else:
			dct[k] = 1
	e = [k for k in dct.keys()]
	e.sort()
	ele = []
	for i in e:
		ele.append(dct[i])
	nm = ele[:]
	for i in range(len(ele) - 2, -1, -1):
		ele[i] += ele[i + 1]
	pid = bisect(e, 0)
	if pid == len(ele):
		print(0)
		return
	ans = ele[pid] * (ele[pid] - 1) // 2
	for i in range(len(e)):
		f = e[i]
		if f < 1:
			k = -1 * f
			id = bisect(e, k)
			if id == len(e):
				continue
			else:
				ans += nm[i] * ele[id]
		else:
			break
	print(ans)
t = 1
for i in range(t):
	main()


import bisect
n = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = sorted([A[i] - B[i] for i in range(n)])
ans = 0
for i in range(n - 1):
	if C[i] < 0:
		ans += n - bisect.bisect_left(C, -C[i] + 0.5, lo=i + 1)
	elif C[i] == 0:
		ans += n - bisect.bisect_left(C, 0.5, lo=i + 1)
	else:
		ans += (n - i) * (n - i - 1) // 2
		break
print(ans)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [a[i] - b[i] for i in range(n)]
u = 0
c.sort()
for j in range(n):
	if c[j] > 0:
		left = 0
		right = j
		while left < right:
			mid = (left + right) // 2
			if c[j] + c[mid] <= 0:
				left = mid + 1
			else:
				right = mid
		u += j - left
print(u)


lens = int(input())
diff = sorted([x - y for (x, y) in zip([int(x) for x in input().split()], [int(x) for x in input().split()])])
answer = 0
j = 0
for i in range(lens - 1, -1, -1):
	while j < i and diff[i] + diff[j] <= 0:
		j += 1
	answer += max(i - j, 0)
print(answer)


from bisect import bisect_left
a = int(input())
total = 0
z = list(map(int, input().split()))
r = list(map(int, input().split()))
t = []
g = []
for i in range(len(z)):
	t.append(z[i] - r[i])
	g.append(r[i] - z[i])
g.sort()
for i in range(len(t)):
	total += bisect_left(g, t[i])
	if t[i] > 0:
		total = total - 1
print(total // 2)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [0] * n
d = [0] * (n + 1)
for i in range(n):
	c[i] = a[i] - b[i]
	d[i + 1] = d[i] + i + 1
c = list(sorted(c))
combinations = [0] * n
right = n - 1
cnt = 0
deff = 0
for i in range(n):
	if c[i] > 0:
		deff = n - i - 1
		break
	while c[right] > -c[i]:
		right -= 1
		cnt += 1
	combinations[i] = cnt
res = 0
j = 0
res = sum(combinations)
res += d[deff]
print(res)


import bisect
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
a_minus_b = []
for i in range(n):
	a_minus_b.append(a[i] - b[i])
a_minus_b = sorted(a_minus_b)
count = 0
for i in range(n):
	pos = bisect.bisect_right(a_minus_b, b[i] - a[i])
	count += n - pos
	if b[i] - a[i] < a[i] - b[i]:
		count -= 1
print(count // 2)


from bisect import *
n = int(input())
l = [*map(int, input().split())]
m = [*map(int, input().split())]
arr = [l[i] - m[i] for i in range(n)]
arr.sort()
ans = 0
for i in range(n):
	if arr[i] > 0:
		ind = bisect_left(arr, -arr[i] + 1)
		ans += i - ind
print(ans)


n = int(input())
t = list(map(int, input().split()))
b = list(map(int, input().split()))
diff = [t[i] - b[i] for i in range(n)]
neg = []
pos = []
for i in diff:
	if i <= 0:
		neg.append(abs(i))
	else:
		pos.append(i)
pos.sort()
neg.sort()
i = 0
j = 0
ans = len(pos) * (len(pos) - 1) // 2
while j < len(pos) and i < len(neg):
	if neg[i] < pos[j]:
		i += 1
	else:
		ans += i
		j += 1
if j < len(pos):
	ans += (len(pos) - j) * len(neg)
print(ans)


n = int(input())
s = input()
s1 = s.split()
a = [int(i) for i in s1]
s = input()
s1 = s.split()
b = [int(i) for i in s1]
l = []
for i in range(len(a)):
	l.append(a[i] - b[i])
l.sort()
i = 0
j = len(l) - 1
cnt = 0
while j > i:
	if l[j] + l[i] > 0:
		cnt = cnt + j - i
	else:
		while i < len(l) and l[i] + l[j] <= 0:
			i = i + 1
		if j > i:
			cnt = cnt + j - i
	j = j - 1
print(cnt)


from sys import stdin, stdout
t = int(stdin.readline())
arr1 = [int(x) for x in stdin.readline().split()]
arr2 = [int(x) for x in stdin.readline().split()]
arr = [0] * t
for i in range(t):
	arr[i] = arr1[i] - arr2[i]
arr.sort()
ptr1 = 0
ptr2 = t - 1
ans = 0
while ptr2 > ptr1:
	if arr[ptr2] + arr[ptr1] > 0:
		ptr2 -= 1
	else:
		ans = ans + (ptr2 - ptr1)
		ptr1 += 1
stdout.write(str(int(t * (t - 1) / 2 - ans)))


n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [i - j for (i, j) in zip(a, b)]
c.sort()
(i, j, res) = (0, n - 1, 0)
while i <= j:
	while i < n and c[i] + c[j] <= 0:
		i += 1
	if j >= i:
		res += j - i
	j -= 1
print(res)


from sys import stdin
count = 0

def merge_sort(l, r):
	global count
	if l < r:
		p = (l + r) // 2
		merge_sort(l, p)
		merge_sort(p + 1, r)
		merge(l, p, r)

def merge(l, p, r):
	global count
	L = d[l:p + 1]
	R = d[p + 1:r + 1]
	nL = [-i for i in L][::-1]
	s_l = p - l + 1
	s_r = r - p
	new = []
	i = 0
	j = 0
	while i < s_l and j < s_r:
		if L[i] < R[j]:
			new.append(L[i])
			i += 1
		else:
			new.append(R[j])
			j += 1
	new += L[i:] + R[j:]
	d[l:r + 1] = new
	i = 0
	j = 0
	while i < s_l and j < s_r:
		if nL[i] < R[j]:
			count += s_r - j
			i += 1
		else:
			j += 1
(n,) = map(int, stdin.readline().split())
a = list(map(int, stdin.readline().split()))
b = list(map(int, stdin.readline().split()))
d = [a[i] - b[i] for i in range(n)]
merge_sort(0, n - 1)
print(count)


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
from bisect import bisect_left as bs

def solve(n, a, b):
	diff = [a[i] - b[i] for i in range(n)]
	diff = sorted(diff)
	cnt = 0
	for i in range(n):
		ind = bs(diff, b[i] - a[i] + 1)
		if a[i] - b[i] >= b[i] - a[i] + 1:
			cnt -= 1
		cnt += n - ind
	return cnt // 2
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
print(solve(n, a, b))


def search(i1, i2, ls, value):
	if i2 - i1 == 1 or i1 == i2:
		if ls[i1] + value > 0:
			return i1
		elif ls[i2] + value > 0:
			return i2
		else:
			return i2 + 1
	avg = (i1 + i2) // 2
	if ls[avg] + value > 0:
		return search(i1, avg, ls, value)
	else:
		return search(avg, i2, ls, value)
N = int(input())
Alist = list(map(int, input().split()))
Blist = list(map(int, input().split()))
Dlist = [Alist[n] - Blist[n] for n in range(N)]
Dlist.sort()
goodpairs = 0
for (index, D) in enumerate(Dlist):
	if D <= 0:
		pass
	elif index == 0:
		goodpairs = N * (N - 1) // 2
		break
	else:
		minindex = search(0, index - 1, Dlist, D)
		goodpairs += index - minindex
print(goodpairs)


import sys
import math

def read_line():
	return sys.stdin.readline()[:-1]

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

def read_int_line():
	return [int(v) for v in sys.stdin.readline().split()]
n = read_int()
a = read_int_line()
b = read_int_line()
c = [0] * n
for i in range(n):
	c[i] = a[i] - b[i]
c.sort()
i = 0
j = n - 1
cnt = 0
while i <= j:
	if c[i] + c[j] > 0:
		cnt += j - i
		j -= 1
	else:
		i += 1
print(cnt)


from sys import stdin, stdout
from bisect import bisect_left, bisect_right
n = int(stdin.readline())
ans = 0
tea = [int(i) for i in stdin.readline().split()]
stu = [int(i) for i in stdin.readline().split()]
com = [tea[i] - stu[i] for i in range(n)]
com.sort()
for i in com:
	k = bisect_right(com, -i)
	ans += n - k
	if i > 0:
		ans -= 1
ans //= 2
stdout.write(str(ans) + '\n')


import math, sys
from collections import defaultdict, Counter, deque
from functools import reduce
INF = float('inf')
MOD = int(1000000000.0) + 7

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

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

def primeFactors(n):
	factors = defaultdict(int)
	i = 2
	while i ** 2 <= n:
		while n % i == 0:
			factors[i] += 1
			n //= i
		i += 1
	if n > 1:
		factors[n] += 1
	return factors

def main():
	n = int(input())
	a = array()
	b = array()
	diff = []
	for i in range(n):
		diff.append(a[i] - b[i])
	diff = sorted(diff, reverse=True)
	ans = 0
	for i in range(n - 1):
		if diff[i] > 0:
			l = i + 1
			r = n - 1
			while l <= r:
				m = (l + r) // 2
				if diff[m] + diff[i] > 0:
					l = m + 1
				else:
					r = m - 1
			ans += l - i - 1
	print(ans)

class DSU:

	def __init__(self, n):
		self.p = [i for i in range(n + 1)]
		self.size = [1 for i in range(n + 1)]
		self.minmax = [[i, i] for i in range(n + 1)]
		self.n = n

	def find(self, node):
		if self.p[node] != node:
			self.p[node] = self.find(self.p[node])
		return self.p[node]

	def union(self, source, dest):
		source = self.find(source)
		dest = self.find(dest)
		if source != dest:
			if self.size[source] < self.size[dest]:
				(source, dest) = (dest, source)
			self.p[dest] = source
			self.size[source] += self.size[dest]
			mini = min(self.minmax[source][0], self.minmax[dest][0])
			maxi = max(self.minmax[source][1], self.minmax[dest][1])
			self.minmax[source] = [mini, maxi]

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

def print(*args, sep=' ', end='\n'):
	first = True
	for arg in args:
		if not first:
			sys.stdout.write(sep)
		sys.stdout.write(str(arg))
		first = False
	sys.stdout.write(end)

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

def array():
	return list(map(int, input().split()))
t = 1
for _ in range(t):
	main()


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
diff = []
for i in range(n):
	diff.append(a[i] - b[i])
diff.sort()
(l, r, res) = (0, n - 1, 0)
while l < r:
	if diff[l] + diff[r] > 0:
		res += r - l
		r -= 1
	else:
		l += 1
print(res)


def count_lower_bound(k, arr, start, end):
	left = start
	right = end
	lower_bound = end + 1
	while left <= right:
		mid = left + (right - left) // 2
		if arr[mid] > k:
			lower_bound = min(lower_bound, mid)
			right = mid - 1
		else:
			left = mid + 1
	if lower_bound == end + 1:
		return 0
	else:
		return end - lower_bound + 1

def solve(n, a, b):
	s = [a[i] - b[i] for i in range(n)]
	s.sort()
	result = 0
	for i in range(n):
		result += count_lower_bound(-s[i], s, i + 1, n - 1)
	return result

def main():
	n = int(input().strip())
	a = list(map(int, input().strip().split()))
	b = list(map(int, input().strip().split()))
	print(solve(n, a, b))
main()


from bisect import bisect_left, bisect_right
from collections import deque
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
a_b = [x - y for (x, y) in zip(a, b)]
b_a = [-x for x in a_b]
a_b.sort(reverse=True)
b_a.sort()
p = bisect_left(b_a, 0)
q = bisect_right(b_a, 0)
b_a_ = b_a[q:]
a_b_ = a_b[:p]
count = 0
for (i, x) in enumerate(a_b_):
	j = bisect_left(b_a_, x)
	count += q - i - 1 + j
print(count)


import bisect
n = int(input())
d = sorted((a - b for (a, b) in zip(map(int, input().split()), map(int, input().split()))))
ret = 0
i = bisect.bisect(d, 0)
if i == n:
	i = 0 if d[0] > 0 else n
elif d[i] < 0:
	i += 1
while i < n:
	j = bisect.bisect(d, -d[i], 0, i)
	if d[j] == -d[i]:
		j += 1
	ret += i - j
	i += 1
print(ret)


import sys
input = sys.stdin.readline
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = [A[i] - B[i] for i in range(n)]
C.sort()
import bisect
ANS = 0
for i in range(n):
	x = bisect.bisect_right(C, -C[i])
	ANS += n - max(x, i + 1)
print(ANS)


from sys import stdin
from collections import deque
mod = 10 ** 9 + 7
import sys
from queue import PriorityQueue
from bisect import bisect_right
from bisect import bisect_left
from collections import defaultdict
from math import sqrt, factorial, gcd, log2, inf, ceil
import heapq
input = lambda : sys.stdin.readline().rstrip()
from sys import stdin, stdout
from heapq import heapify, heappush, heappop
from itertools import permutations
from math import factorial as f

def ncr(x, y):
	return f(x) // (f(y) * f(x - y))
n = int(input())
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
ba = []
for i in range(n):
	ba.append(l1[i] - l2[i])
ba.sort()
ans = 0
for i in range(n):
	if ba[i] > 0:
		ans += n - i - 1
	else:
		z = bisect_right(ba, -ba[i] + 1)
		z1 = bisect_left(ba, -ba[i] + 1)
		if z != z1:
			ans += n - z1
		else:
			ans += n - z
print(ans)


from bisect import bisect_right
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = sorted([a[i] - b[i] for i in range(n)])
result = 0
for i in range(n):
	curr = c[i]
	j = bisect_right(c, -curr, i + 1)
	result += n - j
print(result)


import sys

def trova(a, b, x):
	if x >= a:
		return a
	if x <= b:
		while x == C[b]:
			b = b - 1
		return b
	m = (a + b) // 2
	if x == C[m]:
		while x == C[m]:
			m = m - 1
		return m
	if a == b:
		while C[a] == x:
			a = a - 1
		return a
	if x < C[m]:
		trova(m, b, x)
		return
	if x > C[m]:
		trova(a, m, x)
		return
T = 1
t = 0
while t < T:
	N = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	n = 0
	C = []
	while n < N:
		C.append(A[n] - B[n])
		n += 1
	C.sort(reverse=True)
	n = 0
	out = 0
	inizio = 0
	fine = N - 1
	while inizio < fine:
		if C[inizio] + C[fine] > 0:
			out += fine - inizio
			inizio += 1
		else:
			fine -= 1
	print(out)
	t += 1


from sys import *
from math import *
from bisect import *
n = int(stdin.readline())
a = list(map(int, stdin.readline().split()))
b = list(map(int, stdin.readline().split()))
c = []
for i in range(n):
	c.append(a[i] - b[i])
ans = 0
c.sort()

def fun(m, i):
	if c[i] + c[m] > 0:
		return 1
	else:
		return 0
for i in range(n):
	l = i + 1
	h = n - 1
	x = n
	while l <= h:
		m = (l + h) // 2
		if fun(m, i):
			x = m
			h = m - 1
		else:
			l = m + 1
	ans += n - x
print(ans)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
s = sorted(list(map(lambda x: x[0] - x[1], zip(a, b))))
count = 0
for i in range(n - 1):
	(L, R, x) = (i + 1, n - 1, n)
	while L <= R:
		M = (L + R) // 2
		if s[i] + s[M] > 0:
			x = M
			R = M - 1
		else:
			L = M + 1
	count += n - x
print(count)


def solve():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = [a[i] - b[i] for i in range(n)]
	c.sort()
	ans = 0
	k = 0
	right = n - 1
	left = 0
	while left < n and c[left] + c[right] <= 0:
		left += 1
	k = right - left
	ans += max(0, k)
	right -= 1
	while c[right] > 0 and right != -1:
		while c[left] + c[right] <= 0:
			left += 1
		k = right - left
		ans += max(0, k)
		right -= 1
	print(ans)
solve()


from bisect import *
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = []
for i in range(n):
	c.append(a[i] - b[i])
c.sort()
cn = 0
for i in range(n - 1, -1, -1):
	y = c[i]
	g = bisect_left(c, 1 - y, 0, max(i, 0))
	try:
		if g == i:
			cn += 0
		else:
			cn += i - g
	except:
		continue
print(cn)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
neg = []
pos = []
for i in range(n):
	if a[i] - b[i] > 0:
		pos.append(a[i] - b[i])
	else:
		neg.append(b[i] - a[i])
neg.sort()
pos.sort()
dp = [0 for i in range(n + 1)]
i = 0
j = 0
while i < len(pos):
	while j < len(neg):
		if pos[i] > neg[j]:
			dp[i + 1] = dp[i + 1] + 1
		else:
			break
		j = j + 1
	dp[i + 1] = dp[i + 1] + dp[i]
	i = i + 1
print(sum(dp) + len(pos) * (len(pos) - 1) // 2)


size = int(input())
teacher = input().split()
students = input().split()
diff = []
for i in range(size):
	diff.append(int(teacher[i]) - int(students[i]))
diff = sorted(diff, reverse=True)
start = 0
last = len(diff) - 1
answer = 0
while start < last and diff[start] >= 0:
	num = diff[start] + diff[last]
	if num <= 0:
		last -= 1
	else:
		answer += last - start
		start += 1
print(answer)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = sorted(map(lambda x, y: x - y, a, b))
sum = 0
r = n - 1
ad = 0
for i in range(0, n):
	if d[i] > 0:
		sum += n - i - 1
	else:
		while r > 0 and d[r] + d[i] > 0:
			r -= 1
		sum += n - r - 1
print(sum)


import bisect
from math import gcd
import sys
input = sys.stdin.readline
from collections import defaultdict as dd
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
dif = [0] * n
for i in range(n):
	dif[i] = a[i] - b[i]
dif.sort()
ans = 0
for i in range(n):
	di = a[i] - b[i]
	ind = bisect.bisect_right(dif, -di)
	x = n - ind
	if ind < n and di >= dif[ind]:
		x -= 1
	ans += x
print(ans // 2)


from sys import exit

def i():
	return input()

def ii():
	return int(input())

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

def liis():
	return list(map(int, input().split()))

def print_array(a):
	print(' '.join(map(str, a)))
n = ii()
a = liis()
b = liis()
v = []
for i in range(len(a)):
	v.append(a[i] - b[i])
v = sorted(v)[::-1]
count = 0
last = len(v) - 1
for (idx, i) in enumerate(v):
	while last > idx and i + v[last] <= 0:
		last -= 1
	if last > idx:
		count += last - idx
print(count)


def find(ar, x, n):
	l = 0
	h = n - 1
	if ar[0] >= x + 1:
		return 0
	else:
		while l <= h:
			mid = (l + h) // 2
			if ar[mid] >= x + 1 and ar[mid - 1] < x + 1:
				return mid
			elif ar[mid] < x + 1:
				l = mid + 1
			elif ar[mid - 1] >= x + 1:
				h = mid - 1
n = int(input())
a = input()
A = list(map(int, list(a.split())))
b = input()
B = list(map(int, list(b.split())))
c = [0] * n
for i in range(n):
	c[i] = A[i] - B[i]
c.sort()
if c[n - 1] <= 0:
	print(0)
else:
	ans = 0
	for i in range(n - 1, -1, -1):
		if c[i] <= 0:
			break
		else:
			y = find(c, -1 * c[i], n)
			ans = ans + i - y
	print(ans)


import sys
n = int(sys.stdin.readline())
a = list(map(int, sys.stdin.readline().split()))
b = list(map(int, sys.stdin.readline().split()))
diff = [0] * n
last = 0

def dicho(d, f, v):
	global last
	if d >= f:
		last = f
		return
	if v + diff[d + (f - d) // 2] > 0:
		dicho(d, d + (f - d) // 2, v)
	elif v + diff[d + (f - d) // 2] <= 0:
		dicho(f - (f - d) // 2, f, v)
for i in range(n):
	diff[i] = a[i] - b[i]
diff.sort()
total = 0
for i in range(1, n):
	if diff[i - 1] + diff[i] > 0:
		last = 0
		dicho(0, i - 1, diff[i])
		if diff[i] + diff[last] <= 0:
			last += 1
		total += i - last
print(total)


import bisect
n = int(input())
alist = [int(a) for a in input().split()]
blist = [int(a) for a in input().split()]
clist = [alist[i] - blist[i] for i in range(len(alist))]
clist.sort()
good = 0
l = 0
r = n - 1
while l < r:
	if clist[l] + clist[r] > 0:
		good += r - l
		r += -1
	else:
		l += 1
print(good)


n = int(input())
a = sorted([x - y for (x, y) in zip(map(int, input().split()), map(int, input().split()))])
l = 0
r = n - 1
ans = 0
while l < r:
	if a[l] + a[r] > 0:
		ans = ans + r - l
		r = r - 1
	else:
		l = l + 1
print(ans)


I = lambda : map(int, input().split())
n = int(input())
dict = sorted([i - j for (i, j) in zip(I(), I())])
(ans, l, r) = (0, 0, n - 1)
while l < r:
	if dict[l] + dict[r] > 0:
		ans += r - l
		r -= 1
	else:
		l = l + 1
print(ans)


def binn(sp, numb):
	l = -1
	r = len(sp)
	while l + 1 != r:
		mid = (l + r) // 2
		if sp[mid] + numb > 0:
			r = mid
		else:
			l = mid
	return len(sp) - r
n = int(input())
s1 = list(map(int, input().split()))
s2 = list(map(int, input().split()))
a = []
for i in range(len(s1)):
	a.append(s1[i] - s2[i])
a.sort()
sp = [a[0]]
ans = 0
for i in range(1, len(a)):
	ans += binn(sp, a[i])
	sp.append(a[i])
print(ans)


t = int(input())
a = [int(j) for j in input().split()]
b = [int(j) for j in input().split()]
c = []
for i in range(t):
	c.append(a[i] - b[i])
c.sort()
ans = 0
for i in range(t):
	if c[i] <= 0:
		continue
	find = -c[i] + 1
	(l, r) = (0, i)
	while l < r:
		mid = l + (r - l) // 2
		if c[mid] < find:
			l = mid + 1
		else:
			r = mid
	ans += i - l
print(ans)


import sys
input = sys.stdin.readline

def binRight(el, a: list):
	l = 0
	r = len(a)
	while l + 1 < r:
		m = (l + r) // 2
		if a[m] <= el:
			l = m
		else:
			r = m
	if r == 1:
		if a[0] > el:
			r = 0
	return r

def main():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	positive = []
	negative = []
	numP = 0
	numZ = 0
	for i in range(n):
		tmp = a[i] - b[i]
		if tmp > 0:
			positive.append(tmp)
			numP += 1
		elif tmp == 0:
			numZ += 1
		else:
			negative.append(tmp * -1)
	positive.sort()
	ans = numP * (numP - 1) // 2 + numP * numZ
	NP = len(positive)
	for el in negative:
		pos = binRight(el, positive)
		ans += NP - pos
	print(ans)
main()


import bisect
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(n):
	a[i] = a[i] - b[i]
a.sort()
ans = 0
i = 0
while i < n and a[i] <= 0:
	ind = bisect.bisect_left(a, -a[i] + 1)
	ans += n - ind
	i += 1
left = n - i
ans += left * (left - 1) // 2
print(ans)


from bisect import bisect_right as left
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
m = []
ans = 0
for i in range(n):
	m.append(a[i] - b[i])
m.sort()
(p, ne) = ([], [])
ans = 0
for i in range(n):
	if m[i] > 0:
		ans -= 1
	ans += n - left(m, -m[i])
print(ans // 2)


inputFunc = lambda : map(int, input().split())
(size,) = inputFunc()
limits = sorted((a - b for (a, b) in zip(inputFunc(), inputFunc())))
(pt1, pt2) = (0, size - 1)
good = 0
while pt1 < pt2:
	if limits[pt1] + limits[pt2] > 0:
		good += pt2 - pt1
		pt2 -= 1
	else:
		pt1 += 1
print(good)


import bisect
length = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = []
for i1 in range(length):
	c.append(a[i1] - b[i1])
c.sort()
result = 0
for i1 in range(length):
	ideal = 1 - c[i1]
	index = bisect.bisect_left(c, ideal, i1 + 1, length)
	result += length - index
print(result)


import sys
from sys import stdin, stdout
import bisect
import math
import heapq

def modinv(n, p):
	return pow(n, p - 2, p)

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())
import math

def Divisors(n):
	l = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
	return l
import statistics

def main():
	n = inin()
	a = ain()
	b = ain()
	for i in range(n):
		a[i] = a[i] - b[i]
	a.sort()
	ans = 0
	for i in range(n):
		x = -a[i]
		p = bisect.bisect_right(a, x, i + 1, n)
		ans += n - p
	print(ans)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			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))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import sys

class ostream:

	def __lshift__(self, a):
		sys.stdout.write(str(a))
		return self
cout = ostream()
endl = '\n'

def readnumbers(zero=0):
	conv = ord if py2 else lambda x: x
	A = []
	numb = zero
	sign = 1
	i = 0
	s = sys.stdin.buffer.read()
	try:
		while True:
			if s[i] >= b'0'[0]:
				numb = 10 * numb + conv(s[i]) - 48
			elif s[i] == b'-'[0]:
				sign = -1
			elif s[i] != b'\r'[0]:
				A.append(sign * numb)
				numb = zero
				sign = 1
			i += 1
	except:
		pass
	if s and s[-1] >= b'0'[0]:
		A.append(sign * numb)
	return A
main()


n = int(input())
a = list(map(int, input().split()))
c = []
b = list(map(int, input().split()))
s = 0
for (i, j) in zip(a, b):
	c.append(i - j)
c.sort()
d = n - 1
e = 0
while c[d] > 0 and d > e:
	if c[d] + c[e] > 0:
		s += d - e
		d -= 1
	else:
		e += 1
print(s)


n = int(input())
l = list(map(int, input().split()))
m = list(map(int, input().split()))
for i in range(n):
	l[i] -= m[i]
l.sort()
i = 0
j = n - 1
count = 0
while j > i:
	if l[j] + l[i] > 0:
		count += j - i
		j -= 1
	else:
		i += 1
print(count)


from sys import stdin

def func(arr, l, r, x):
	while l < r:
		mid = (l + r) // 2
		if arr[mid] + x > 0:
			r = mid
		else:
			l = mid + 1
	return l
n = int(stdin.readline())
a = list(map(int, stdin.readline().split()))
b = list(map(int, stdin.readline().split()))
arr = []
for i in range(n):
	arr.append(a[i] - b[i])
arr = sorted(arr)
count = 0
for i in range(n - 1):
	pos = func(arr, i + 1, n, arr[i])
	count += n - pos
print(count)


n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
pair = 0
c = [a[i] - b[i] for i in range(n)]
c.sort()
if c[n - 1] <= 0:
	pair = 0
else:
	pair = 0
	actual = 0
	i = 0
	while c[i] <= 0:
		i += 1
	j = i
	if i == 0:
		pair = n * (n - 1) // 2
	else:
		pair = (n - i) * (n - i - 1) // 2
		j = i - 1
		while i < n:
			while j >= 0:
				if c[j] + c[i] <= 0:
					break
				j -= 1
				actual += 1
			pair += actual
			i += 1
print(pair)


from bisect import bisect_left
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
l = [i - j for (i, j) in zip(a, b)]
l.sort()
ans = 0
for i in range(len(l)):
	if l[i] > 0:
		ans += i - bisect_left(l, -l[i] + 1)
print(ans)


from bisect import *
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = sorted((a[i] - b[i] for i in range(n)))
print(sum((max(i - bisect_right(c, -c[i]), 0) for i in range(n))))


import collections
import bisect

def solve(n, teacherInterests, studentInterests):
	diffs = []
	for (t, s) in zip(teacherInterests, studentInterests):
		diffs.append(t - s)
	diffs.sort()
	ans = 0
	for (i, difference) in enumerate(diffs):
		if difference <= 0:
			continue
		pos = bisect.bisect_left(diffs, -difference + 1)
		ans += i - pos
	return ans
n = int(input().strip())
teacherInterests = list(map(int, input().strip().split()))
studentInterests = list(map(int, input().strip().split()))
print(solve(n, teacherInterests, studentInterests))


x = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
k = 0
c = []
c = sorted([a[i] - b[i] for i in range(x)])
for i in range(x):
	p = i + 1
	q = x - 1
	while p <= q:
		m = (p + q) // 2
		if c[i] + c[m] <= 0:
			p = m + 1
		else:
			q = m - 1
	k = k + (x - p)
print(k)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
p = []
o = []
for i in range(len(a)):
	x = a[i] - b[i]
	y = b[i] - a[i]
	p.append(x)
	o.append(y)
p.sort(reverse=True)
o.sort()
i = 0
j = len(a) - 1
cnt = 0
while i < j:
	if p[i] > o[j]:
		cnt = cnt + (j - i)
		i = i + 1
	else:
		j = j - 1
print(cnt)


from bisect import bisect_left as lower_bound

def findNumOfPair(a, n):
	ans = 0
	for i in range(n):
		if a[i] <= 0:
			continue
		j = lower_bound(a, -a[i] + 1)
		ans += i - j
	return ans
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
arr = []
for i in range(n):
	arr.append(a[i] - b[i])
arr.sort()
k = findNumOfPair(arr, n)
print(k)


import math

class Read:

	@staticmethod
	def string():
		return input()

	@staticmethod
	def int():
		return int(input())

	@staticmethod
	def list(sep=' '):
		return input().split(sep)

	@staticmethod
	def list_int(sep=' '):
		return list(map(int, input().split(sep)))

def solve():
	n = Read.int()
	a = Read.list_int()
	b = Read.list_int()
	c = []
	d = []
	e = []
	for i in range(n):
		t = a[i] - b[i]
		if t < 0:
			c.append(t)
		elif t > 0:
			d.append(t)
		else:
			e.append(t)
	len_d = len(d)
	res = len(e) * len_d
	res += (len_d - 1) * (len_d / 2)
	d.sort()
	f = len_d // 2

	def get_pos(x, s, e):
		if e - s < 2:
			if x + d[s] > 0:
				return s
			else:
				return e
		center = (e - s) // 2 + s
		if d[center] + x <= 0:
			return get_pos(x, center, e)
		else:
			return get_pos(x, s, center)
	if len_d == 0:
		print(int(res))
		return
	for i in c:
		if i + d[0] > 0:
			res += len_d
		elif i + d[-1] > 0:
			p = get_pos(i, 0, len_d - 1)
			res += len_d - p
	print(int(res))
query_count = 1
while query_count:
	query_count -= 1
	solve()


import bisect
n = int(input())
a = list(map(int, input().strip().split()))
b = list(map(int, input().strip().split()))
diff = []
for i in range(n):
	diff.append(a[i] - b[i])
diff.sort()
res = 0
for i in range(n):
	if diff[i] <= 0:
		continue
	pos = bisect.bisect_left(diff, -diff[i] + 1)
	res += i - pos
print(res)


import sys
from collections import defaultdict
import heapq

def search(num, arr):
	(l, r) = (0, len(arr) - 1)
	ans = -1
	while l <= r:
		mid = (l + r) // 2
		if arr[mid] == num:
			ans = mid
			r = mid - 1
		elif arr[mid] < num:
			l = mid + 1
		else:
			ans = mid
			r = mid - 1
	return ans
n = int(sys.stdin.readline())
a = list(map(int, sys.stdin.readline().split()))
b = list(map(int, sys.stdin.readline().split()))
c = [0 for _ in range(n)]
for i in range(n):
	c[i] = a[i] - b[i]
c.sort()
pos = []
neg = []
for i in range(n):
	if c[i] > 0:
		pos.append(c[i])
	else:
		neg.append(c[i])
ans = 0
m = len(pos)
ans += m * (m - 1) // 2
if m == 0:
	print(0)
else:
	for i in range(len(neg)):
		ind = search(-neg[i] + 1, pos)
		if ind != -1:
			ans += m - ind
	print(ans)


import bisect

def solve(n, a, b):
	c = []
	cnt = 0
	for i in range(n):
		c.append(a[i] - b[i])
	c.sort()
	for i in range(n):
		if c[i] <= 0:
			continue
		pos = bisect.bisect_left(c, -c[i] + 1)
		cnt += i - pos
	print(cnt)
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
solve(n, a, b)


from bisect import bisect_left
n = int(input())
a = [int(i) for i in input().split(' ')]
b = [int(i) for i in input().split(' ')]
g = [a[i] - b[i] for i in range(n)]
count = 0
g.sort()
for i in range(n):
	x = bisect_left(g, -g[i] + 1)
	if x != n:
		count += n - x
		if g[i] > -g[i] + 1:
			count -= 1
print(count // 2)


import sys
input = sys.stdin.buffer.readline
n = int(input())
data = list(map(lambda x: x[0] - x[1], zip([int(i) for i in input().split()], [int(i) for i in input().split()])))
data.sort()
ans = 0

def search(l, r, x):
	ans_ = n
	while l <= r:
		m = (l + r) // 2
		if data[m] + x > 0:
			ans_ = m
			r = m - 1
		else:
			l = m + 1
	return ans_
for i in range(n):
	ans += n - search(i + 1, n - 1, data[i])
print(ans)


import sys
input = sys.stdin.readline
from bisect import *
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [ai - bi for (ai, bi) in zip(a, b)]
c.sort()
ans = 0
for ci in c:
	ans += n - bisect_right(c, -ci)
	if ci > 0:
		ans -= 1
print(ans // 2)


from bisect import bisect_left, bisect_right
for _ in range(1):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	p1 = [0] * n
	p2 = [0] * n
	for i in range(n):
		p1[i] = a[i] - b[i]
		p2[i] = b[i] - a[i]
	p2.sort()
	cnt = 0
	for i in p1:
		ind = bisect_left(p2, i)
		cnt += ind
	c2 = 0
	for i in p1:
		if i > 0:
			c2 += 1
	cnt -= c2
	print(max(0, cnt // 2))


n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
s = []
for i in range(n):
	s.append(x[i] - y[i])
s.sort()
s.append(1234567890)
(pointer, ans) = (n, 0)
for i in range(n):
	while pointer >= 0 and s[pointer] + s[i] > 0:
		pointer -= 1
	ans += n - pointer - 1 - (i >= pointer + 1)
print(ans // 2)


import sys
input = sys.stdin.readline
from bisect import bisect_left

def main():
	n = int(input())
	alst = list(map(int, input().split()))
	blst = list(map(int, input().split()))
	clst = [-(a - b) for (a, b) in zip(alst, blst)]
	clst.sort()
	ans = 0
	for (a, b) in zip(alst, blst):
		ans += bisect_left(clst, a - b)
		if a - b > -(a - b):
			ans -= 1
	print(ans // 2)
for _ in range(1):
	main()


data = input().rstrip().split()
t = int(data[0])
aa = input().rstrip().split()
aa = [int(a) for a in aa]
bb = input().rstrip().split()
bb = [int(b) for b in bb]
dd = [a - b for (a, b) in zip(aa, bb)]
dd.sort()
i = 0
j = len(dd) - 1
s = 0
while True:
	if i >= j:
		break
	if dd[i] + dd[j] > 0:
		s += j - i
		j = j - 1
	else:
		i += 1
print(s)


def binary_search(arr, numElems, target):
	low = 0
	high = numElems
	while low != high:
		mid = (low + high) // 2
		if arr[mid] <= target:
			low = mid + 1
		else:
			high = mid
	return low
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
A_neg = []
A_pos = []
for i in range(n):
	p = a[i] - b[i]
	if p > 0:
		A_pos.append(p)
	else:
		A_neg.append(p)
A_pos.sort()
l = len(A_pos)
cnt = l * (l - 1) // 2
for i in A_neg:
	index = binary_search(A_pos, l, abs(i))
	no_of_ele_greater_than_index = l - index
	cnt += no_of_ele_greater_than_index
print(cnt)


from bisect import bisect_right
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [a[i] - b[i] for i in range(n)]
c.sort()
res = 0
for i in range(n):
	if c[i] <= 0:
		x = -c[i]
		j = bisect_right(c, x, i + 1)
		res += n - j
	else:
		res += n - i - 1
print(res)


from collections import deque, defaultdict
import bisect
n = int(input())
arr = list(map(int, input().split()))
brr = list(map(int, input().split()))
lis = deque()
for i in range(n):
	diff = arr[i] - brr[i]
	lis.append(diff)
lis = list(lis)
lis.sort()
lis = deque(lis)
ans = 0
while lis:
	now = lis.popleft()
	if now < 0:
		now = abs(now) + 1
	else:
		now = -(now - 1)
	ind = bisect.bisect_left(lis, now)
	ans += len(lis) - ind
print(ans)


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

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

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

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator, bisect
from collections import deque, defaultdict, OrderedDict
import collections

def main():
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	for _ in range(1):
		n = ri()
		a = ria()
		b = ria()
		c = sorted([i - j for (i, j) in zip(a, b)])
		ans = 0
		for i in range(n):
			if c[i] > 0:
				ans += i - bisect.bisect(c, -c[i])
		print(ans)
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			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, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			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()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

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

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


from bisect import bisect_right

def main():
	nTopics = int(input())
	differencesInInterest = [teacher_sInterest - students_Interest for (teacher_sInterest, students_Interest) in zip(map(int, input().split()), map(int, input().split()))]
	differencesInInterest.sort()
	return nGoodPairsOfTopics(nTopics, differencesInInterest)

def nGoodPairsOfTopics(nTopics, differencesInInterest):
	if differencesInInterest[-1] < 1:
		return 0
	iLast = bisect_right(differencesInInterest, 0) - 1
	return sum((i - bisect_right(differencesInInterest, -differencesInInterest[i]) for i in range(nTopics - 1, iLast, -1)))
print(main())


import bisect
n = int(input())
l1 = list(map(int, input().split(' ')))
l2 = list(map(int, input().split(' ')))
diffs = []
for i in range(n):
	diffs.append(l1[i] - l2[i])
diffs = sorted(diffs)
ans = 0
for i in range(n):
	if diffs[i] > 0:
		ans += i - bisect.bisect_left(diffs, -diffs[i] + 1)
print(ans)


import bisect
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = sorted([i - j for (i, j) in zip(a, b)])
ans = 0
for i in range(n):
	if c[i] > 0:
		ans += i - bisect.bisect(c, -c[i])
print(ans)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = sorted([a[i] - b[i] for i in range(n)])
i = 0
j = n - 1
res = 0
while i < j:
	if c[j] + c[i] > 0:
		res += j - i
		j -= 1
	else:
		i += 1
print(res)


n = int(input())
l = [[0] * n] * 1
s = [[0] * n] * 1
m = [[0] * n] * 1
i = 0
l[0] = input().split(' ')
l[0] = [int(j) for j in l[i]]
s[0] = input().split(' ')
s[0] = [int(j) for j in s[i]]
flag = 0
for i in range(n):
	m[0][i] = l[0][i] - s[0][i]
x = 0
y = n - 1
m[0].sort()
while x < y:
	if m[0][x] + m[0][y] > 0:
		if x >= y:
			break
		flag = flag + y - x
		y = y - 1
	else:
		x = x + 1
print(flag)


n = int(input())
teachers = [int(x) for x in input().split()]
students = [int(x) for x in input().split()]
abstracts = [teachers[i] - students[i] for i in range(n)]
abstracts.sort()
count = 0
(p, q) = (0, n - 1)
while p < q:
	s = abstracts[p] + abstracts[q]
	if s > 0:
		count += q - p
		q -= 1
	else:
		p += 1
print(count)


import sys
import os
import time
import collections
from collections import Counter, deque
import itertools
import math
import timeit
import random
from io import BytesIO, IOBase
from bisect import bisect_left as bl
from bisect import bisect_right as br

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

def divs(n, start=1):
	divisors = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				divisors.append(i)
			else:
				divisors.extend([i, n // i])
	return divisors

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def flin(d, x, default=-1):
	left = right = -1
	for i in range(len(d)):
		if d[i] == x:
			if left == -1:
				left = i
			right = i
	if left == -1:
		return (default, default)
	else:
		return (left, right)

def modpow(b, p, m):
	res = 1
	b = b % m
	while p:
		if p & 1:
			res = res * b % m
		b = b * b % m
		p >>= 1
	return res

def mod_inv(a, m):
	return modpow(a, m - 2, m)

def ncr(n, r, m):
	res = 1
	if r == 0:
		return 1
	if n - r < r:
		r = n - r
	(p, k) = (1, 1)
	while r:
		res = res % m * (n % m * mod_inv(r, m) % m) % m
		n -= 1
		r -= 1
	return res

def ncrlis(n, r, m, fact):
	return fact[n] * (mod_inv(fact[r], m) * mod_inv(fact[n - r], m)) % m % m

def ceil(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

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

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def prr(a, sep=' '):
	print(sep.join(map(str, a)))

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)
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))
input = lambda : sys.stdin.readline().rstrip('\r\n')
n = ii()
a = li()
b = li()
res = 0
d = [a[i] - b[i] for i in range(n)]
d.sort(reverse=True)
cnt = 0
(l, r) = (0, n - 1)
while l < r:
	if d[l] + d[r] <= 0:
		r -= 1
	else:
		cnt += r - l
		l += 1
print(cnt)


n = int(input())
mass = [int(x) for x in input().split()]
arr = [int(x) for x in input().split()]
pol = list()
otr = list()
for i in range(n):
	x = mass[i] - arr[i]
	if x > 0:
		pol.append(x)
	else:
		otr.append(-x)
otr.sort()
pol.sort()
l1 = 0
l2 = 0
m = len(otr)
n = len(pol)
answer = n * (n - 1) // 2
while l1 < n and l2 < m:
	if pol[l1] > otr[l2]:
		l2 += 1
	else:
		answer += l2
		l1 += 1
answer += (n - l1) * m
print(answer)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = sorted([a[i] - b[i] for i in range(n)], reverse=True)
ans = 0
i = 0
j = n - 1
while i < j:
	if c[i] + c[j] <= 0:
		j -= 1
	else:
		ans += j - i
		i += 1
print(ans)


n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
d = []
for i in range(n):
	d.append(a[i] - b[i])
d.sort()
c = 0
(k1, k2) = (n - 1, 0)
while d[k1] > 0 and k1 > k2:
	if d[k1] + d[k2] > 0:
		c += k1 - k2
		k1 -= 1
	else:
		k2 += 1
print(c)


def sol():
	N = int(input())
	A = list(map(int, input().split(' ')))
	B = list(map(int, input().split(' ')))
	sub = [A[i] - B[i] for i in range(len(A))]
	sub.sort(reverse=True)
	r = len(A) - 1
	pair_total = 0
	for l in range(len(A)):
		if sub[l] <= 0:
			break
		while sub[l] + sub[r] <= 0:
			r -= 1
		pair_total += r - l
	print(pair_total)
sol()


def dosearch(a: list, x: int) -> int:
	n = len(a)
	i = 0
	j = n // 2
	while j >= 1:
		while i + j < n and a[i + j] <= x:
			i += j
		j //= 2
	return i

def f(n: int) -> int:
	return n * (n - 1) // 2
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = [a[i] - b[i] for i in range(n)]
d.sort()
neg = []
z = 0
pos = []
for x in d:
	if x < 0:
		neg += (x,)
	elif x == 0:
		z += 1
	else:
		pos += (x,)
p = len(pos)
if p == 0:
	exit(print(0))
ans = z * p
pos.insert(0, 0)
p += 1
for x in neg:
	t = -x
	i = dosearch(pos, t)
	ans += p - i - 1
print(ans + f(p - 1))


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
(d1, d2) = ([], [])
for i in range(n):
	d1.append(a[i] - b[i])
	d2.append(-d1[i])
d1.sort()
d2.sort()
ans = 0
j = 0
tem = 0
for i in range(n):
	if j < n:
		while d1[i] > d2[j]:
			tem = tem + 1
			j = j + 1
			if j >= n:
				break
	ans = ans + tem
ind = 0
while d1[ind] <= 0:
	ind = ind + 1
	if ind >= n:
		break
pos = n - ind
print(int((ans - pos) / 2))


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
diff = [a[i] - b[i] for i in range(n)]
diff.sort()

def search(a, t):
	l = 0
	r = len(a) - 1
	ind = 0
	while r - l >= 0:
		mid = (l + r) // 2
		if a[mid] <= t:
			l = mid + 1
		if a[mid] > t:
			r = mid - 1
			ind = mid
	return ind
ans = 0
for i in range(n):
	if diff[i] > 0:
		ind = search(diff, -diff[i])
		ans += i - ind
print(ans)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
nums = [a[i] - b[i] for i in range(n)]
nums.sort()
cnt = 0
(i, j) = (0, n - 1)
while i < j:
	if nums[i] > -nums[j]:
		cnt += j - i
		j -= 1
	else:
		i += 1
print(cnt)


import sys
n = int(sys.stdin.readline())
list_numa = list(map(int, sys.stdin.readline().split()))
list_numb = list(map(int, sys.stdin.readline().split()))
list_numc = []
i = 0
list_count = [0, 0, 0]
for _ in list_numa:
	now = list_numa[i] - list_numb[i]
	i += 1
	if now > 0:
		list_count[1] += 1
	elif now < 0:
		list_count[-1] += 1
	else:
		list_count[0] += 1
		continue
	list_numc.append(now)
list_numc.sort()
result = list_count[0] * list_count[1]
left_bound = list_count[-1] - 1
for i in range(list_count[1]):
	i += list_count[-1]
	if left_bound == i:
		continue
	if left_bound >= 0:
		while list_numc[i] > -list_numc[left_bound]:
			left_bound -= 1
			if left_bound < 0:
				break
	result += i - left_bound - 1
print(result)


n = int(input())
pr = list(map(lambda a, b: int(a) - int(b), input().split(), input().split()))
pr.sort()
ptr = n - 1
ans = 0
for i in range(n):
	while ptr >= 0 and pr[ptr] > -pr[i]:
		ptr -= 1
	ans += n - 1 - max(ptr, i)
print(ans)


import bisect
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ls = [a[i] - b[i] for i in range(n)]
ls.sort()
ans = 0
for i in range(n):
	x = bisect.bisect_left(ls, -ls[i] + 1)
	if i > x:
		ans += n - 1 - x
	else:
		ans += n - x
print(ans // 2)


import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

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

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

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

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline()[:-1]

def main():
	n = II()
	aa = LI()
	bb = LI()
	dd = [a - b for (a, b) in zip(aa, bb)]
	dd.sort()
	ans = 0
	j = n
	for (i, d) in enumerate(dd):
		while j - 1 > i and d + dd[j - 1] > 0:
			j -= 1
		if j <= i:
			ans += (n - i) * (n - i - 1) // 2
			break
		ans += n - j
	print(ans)
main()


n = int(input())
x = [0] * n
y = [0] * n
x = input().split()
y = input().split()
a = [0] * n
for i in range(n):
	x[i] = int(x[i])
	y[i] = int(y[i])
	a[i] = x[i] - y[i]
a.sort()
l = 0
r = n - 1
final = 0
while l < r:
	if a[l] + a[r] > 0:
		final = final + r - l
		r = r - 1
	else:
		l = l + 1
print(final)


topicnum = int(input())
a = input().split(' ')
b = input().split(' ')
c = []
res = 0
for i in range(topicnum):
	a[i] = int(a[i])
	b[i] = int(b[i])
	c.append(a[i] - b[i])
c.sort()
start = 0
end = topicnum - 1
while end > start:
	if c[start] + c[end] <= 0:
		start += 1
	elif c[start] + c[end] > 0:
		res += end - start
		end -= 1
print(res)


from bisect import bisect_left
n = int(input())
arr = list(map(int, input().split()))
brr = list(map(int, input().split()))
diff = sorted([i - j for (i, j) in zip(arr, brr)])
result = 0
for (idx, i) in enumerate(diff):
	if i > 0:
		result += n - idx - 1
	else:
		result += n - bisect_left(diff, abs(i) + 1)
print(result)


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def get_str():
	return input().decode().strip()

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

def oint():
	return int(input())
n = oint()
a = list(rint())
b = list(rint())
c = [0] * n
for i in range(n):
	c[i] = a[i] - b[i]
c.sort(reverse=True)
e = n - 1
ans = 0
for s in range(n):
	for ee in range(e, s, -1):
		if c[s] + c[ee] > 0:
			ans += ee - s
			e = ee
			break
	else:
		break
print(ans)


a = int(input())
te = list(map(int, input().split()))
st = list(map(int, input().split()))
pos = []
neg = []
ze = 0
for i in range(a):
	k = te[i] - st[i]
	if k == 0:
		ze += 1
	elif k > 0:
		pos.append(k)
	else:
		neg.append(abs(k))
t = len(pos)
ans = t
if t > 0:
	ans = t * (t - 1) // 2
ans += t * ze
pos.sort()
neg.sort()
start = 0
for i in pos:
	r = 0
	for j in range(start, len(neg)):
		if i > neg[j]:
			r += 1
		else:
			break
	start += r
	ans += start
print(ans)


def main():
	from bisect import bisect_left as bl
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = [b[i] - a[i] for i in range(n)]
	c.sort()
	ans = 0
	for (idx, i) in enumerate(c):
		k = bl(c, -1 * i)
		if idx < k:
			ans += k - 1
		else:
			ans += k
	print(ans // 2)
	return
main()


def topic(n, t, s):
	c = []
	x = 0
	for i in range(n):
		c.append(t[i] - s[i])
	c.sort()
	i = 0
	j = len(c) - 1
	while i < j:
		if c[i] > -c[j]:
			x += j - i
			j -= 1
		else:
			i += 1
	print(x)
n = int(input())
arr = input()
a = arr.split()
a = list(map(int, a))
arr2 = input()
b = arr2.split()
b = list(map(int, b))
topic(n, a, b)


import sys
n = int(sys.stdin.readline().rstrip())
a = list(map(int, sys.stdin.readline().rstrip().split()))
b = list(map(int, sys.stdin.readline().rstrip().split()))
chk = [0] * n
for i in range(n):
	chk[i] = a[i] - b[i]
chk.sort()
re = 0
for i in range(1, n):
	if chk[i] > 0:
		st = 0
		ed = i - 1
		while True:
			mid = int((st + ed) / 2)
			if chk[i] + chk[mid] > 0:
				ed = mid
			else:
				st = mid + 1
			if st > ed or mid == int((st + ed) / 2):
				break
		if mid < 0:
			mid = 0
		if mid > i - 1:
			mid = i - 1
		if chk[i] + chk[mid] > 0:
			re += i - mid
print(re)


from sys import stdin, stdout
import bisect as bs
for _ in range(1):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	b = list(map(int, stdin.readline().split()))
	ai_bi = [aa - bb for (aa, bb) in zip(a, b)]
	ai_bi.sort()
	ans = 0
	for i in range(n):
		v = ai_bi[i]
		if v <= 0:
			pos = bs.bisect_right(ai_bi, abs(v))
			ans += n - pos
		else:
			ans += n - i - 1
	print(ans)


from bisect import bisect_left
import io
import os
import sys
from atexit import register
import random
import math
import itertools
DEBUG = False
STRESSTEST = False
if not DEBUG:
	input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
sys.stdout = io.BytesIO()
register(lambda : os.write(1, sys.stdout.getvalue()))
tokens = []
tokens_next = 0

def nextStr():
	global tokens, tokens_next
	while tokens_next >= len(tokens):
		tokens = input().split()
		tokens_next = 0
	tokens_next += 1
	if type(tokens[tokens_next - 1]) == str:
		return tokens[tokens_next - 1]
	return tokens[tokens_next - 1].decode()

def nextInt():
	return int(nextStr())

def nextIntArr(n):
	return [nextInt() for i in range(n)]

def print(*argv, end='\n'):
	for arg in argv:
		sys.stdout.write((str(arg) + ' ').encode())
	sys.stdout.write(end.encode())

def genTestCase():
	raise NotImplementedError

def bruteforce(a):
	raise NotImplementedError

def doStressTest():
	while True:
		curTest = genTestCase()
		mySoln = solve(curTest)
		bruteforceSoln = bruteforce(curTest)
		if mySoln != bruteforceSoln:
			print('### Found case ###')
			print(curTest)
			print(f'{mySoln} should have been: {bruteforceSoln}')
			return

def solve(a, b):
	arr = [a[i] - b[i] for i in range(len(a))]
	arr = sorted(arr)
	res = 0
	for i in range(len(arr)):
		c = bisect_left(arr, -arr[i] + 1, 0, i)
		res += i - 1 - c + 1
	return res
if not DEBUG and STRESSTEST:
	raise Exception('Wrong flags!')
if STRESSTEST:
	doStressTest()
else:
	n = nextInt()
	a = nextIntArr(n)
	b = nextIntArr(n)
	res = solve(a, b)
	print(res)
sys.stdout.flush()


from math import factorial
from collections import Counter, defaultdict
from heapq import heapify, heappop, heappush
import os
import sys
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))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def N():
	return int(input())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)
mod = 1000000007
INF = float('inf')
from bisect import bisect_right

def main():
	n = N()
	a = list(RL())
	b = list(RL())
	ab = []
	for i in range(n):
		ab.append(a[i] - b[i])
	ab.sort()
	res = 0
	for i in range(n):
		p = bisect_right(ab, -ab[i])
		if p < n:
			now = n - p if p >= i else n - p - 1
			res += now
	print(res // 2)
main()


import bisect
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
p = []
m = []
for i in range(n):
	if a[i] - b[i] > 0:
		p.append(a[i] - b[i])
	else:
		m.append(a[i] - b[i])
p.sort()
ans = len(p) * (len(p) - 1) // 2
for i in m:
	ans += len(p) - bisect.bisect_left(p, abs(i) + 1)
print(ans)


import bisect
n = int(input())
a = [int(k) for k in input().split()]
b = [int(k) for k in input().split()]
count = 0
freq = []
for i in range(n):
	freq.append(a[i] - b[i])
freq.sort()
for i in range(n):
	if freq[i] > 0:
		j = bisect.bisect_right(freq, -freq[i])
		count += i - j
print(count)


import bisect
n = int(input())
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
diff = [0] * n
for x in range(n):
	diff[x] = a[x] - b[x]
diff.sort()
i = n - 1
j = 0
ans = 0
res = 1
if diff[j] > 0:
	ans = int(n * (n - 1) / 2)
	res = 0
if diff[i] <= 0:
	res = 0
while i >= 0 and res == 1:
	if diff[i] <= 0:
		i -= 1
		continue
	if diff[j] > -1 * diff[i]:
		ans += i - j
		i -= 1
	else:
		j += 1
print(ans)


n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
p = [0] * n
for i in range(0, n):
	p[i] = a[i] - b[i]
p = sorted(p)
if p[n - 1] + p[n - 2] <= 0:
	print(0)
else:
	k = 0
	l = n - 1
	s = 0
	while l > k:
		if p[l] + p[k] > 0:
			s += l - k
			l = l - 1
		else:
			k = k + 1
	print(s)


import sys, bisect
n = int(input())
lis1 = list(map(int, input().split()))
lis2 = list(map(int, input().split()))
arr = sorted([lis1[i] - lis2[i] for i in range(n)])
ans = 0
for i in range(n):
	if arr[i] <= 0:
		continue
	index = bisect.bisect_left(arr, 1 - arr[i])
	ans += i - index
print(ans)


n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = []
cnt = 0
y = 0
for x in range(n):
	c.append(a[x] - b[x])
c.sort()
while c[0] + c[y] <= 0:
	y += 1
	if y == n - 1:
		break
	if y > n - 1:
		y = n - 1
		break
for x in range(n):
	if c[x] > 0:
		cnt += (n - x) * (n - x - 1) // 2
		break
	while c[x] + c[y] > 0:
		y -= 1
		if y < x:
			break
		continue
	cnt += n - y - 1
print(cnt)


import sys
input = sys.stdin.readline
from bisect import bisect_left
x = int(input())
(*li,) = map(int, input().split())
(*li1,) = map(int, input().split())
li2 = [0] * x
for i in range(x):
	li2[i] = li[i] - li1[i]
li2.sort()
cnt = 0
for i in range(x):
	if li2[i] > 0:
		a = bisect_left(li2, -li2[i] + 1, 0, i)
		cnt += i - a
print(cnt)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
arr = [x - y for (x, y) in zip(a, b)]
arr.sort()
i = 0
j = n - 1
ans = 0
while i < j:
	if arr[i] + arr[j] > 0:
		ans += j - i
		j -= 1
	else:
		i += 1
print(ans)


n = int(input())
arr = list(map(int, input().split()))
brr = list(map(int, input().split()))
crr = [arr[i] - brr[i] for i in range(n)]
crr.sort(reverse=True)
i = 0
j = n - 1
ans = 0
ct = n - 1
while i < j:
	if crr[i] + crr[j] > 0:
		ans += ct
		ct -= 1
		i += 1
	else:
		ct -= 1
		j -= 1
print(ans)


x = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a = sorted([a[i] - b[i] for i in range(x)])
d = x
output = 0
while d != 0:
	if a[x - d] + a[x - 1] > 0:
		output += d - 1
		x -= 1
	d -= 1
print(output)


def floor(arr, l, r, x, n):
	while l <= r:
		mid = int(l + (r - l) / 2)
		if arr[mid] == x:
			mid += 1
			while mid < n and arr[mid] == x:
				mid += 1
			if mid >= n:
				return -1
			return mid
		elif arr[mid] > x:
			l = mid + 1
		else:
			r = mid - 1
	return l
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
pairs = 0
diff = []
diff_inv = []
for i in range(n):
	diff.append(a[i] - b[i])
diff.sort()
for i in range(n):
	diff_inv.append(-1 * diff[i])
for i in range(n - 1):
	j = floor(diff_inv, i + 1, n - 1, diff[i], n)
	if j != -1 and j < n:
		pairs += n - j
print(pairs)


import bisect
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
K = [A[i] - B[i] for i in range(N)]
K.sort()
ans = 0
for i in range(N):
	r = 1 - K[i]
	x = bisect.bisect_left(K, r)
	V = N - x
	if K[i] >= r:
		V -= 1
	ans += V
print(ans // 2)


from sys import stdin

def inp():
	return stdin.buffer.readline().rstrip().decode('utf8')

def itg():
	return int(stdin.buffer.readline())

def mpint():
	return map(int, stdin.buffer.readline().split())

class FenwickTree:

	def __init__(self, lst):
		self.bit = lst

	def update(self, index, k):
		while index < len(self.bit):
			self.bit[index] += k
			index |= index + 1

	def query(self, end):
		k = 0
		while end:
			k += self.bit[end - 1]
			end &= end - 1
		return k
n = itg()
a = mpint()
b = mpint()
c = [next(a) - next(b) for _ in range(n)]
x = [(c[i], i) for i in range(n)]
y = [(-c[i], i) for i in range(n)]
x.sort()
y.sort()
tree = FenwickTree([0] * n)
idx = ans = 0
for i in range(n):
	while idx < n and x[i][0] > y[idx][0]:
		tree.update(y[idx][1], 1)
		idx += 1
	ans += tree.query(x[i][1])
print(ans)


n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
diff = []
pos = []
for i in range(0, len(a)):
	if a[i] > b[i]:
		pos.append(a[i] - b[i])
	else:
		diff.append(b[i] - a[i])
tt = len(pos)
ans = tt * (tt - 1) // 2
diff.sort()
for i in range(0, len(pos)):
	trg = pos[i] - 1
	low = 0
	high = len(diff) - 1
	rr = 0
	while low <= high:
		mid = low + high >> 1
		if diff[mid] > trg:
			high = mid - 1
		else:
			rr = mid + 1
			low = mid + 1
	ans += rr
print(ans)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import ceil, floor
from copy import *
from collections import deque, defaultdict
from collections import Counter as counter
from itertools import combinations
from itertools import permutations as permutate
from bisect import bisect_left as bl
from operator import *
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192
from sys import stderr

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

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 1000000007

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

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def fsep():
	return map(float, inp().split())

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def pow(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
from functools import reduce

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

def gcd(a, b):
	if a == b:
		return a
	while b > 0:
		(a, b) = (b, a % b)
	return a

def prefix_sum(ar):
	return list(accumulate(ar))

def suffix_sum(ar):
	return list(accumulate(ar[::-1]))[::-1]

def N():
	return int(inp())
from collections import defaultdict

def numberOfSetBits(i):
	i = i - (i >> 1 & 1431655765)
	i = (i & 858993459) + (i >> 2 & 858993459)
	return ((i + (i >> 4) & 252645135) * 16843009 & 4294967295) >> 24
sys.setrecursionlimit(100005)

def solve():

	class SortedList:

		def __init__(self, iterable=[], _load=200):
			values = sorted(iterable)
			self._len = _len = len(values)
			self._load = _load
			self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
			self._list_lens = [len(_list) for _list in _lists]
			self._mins = [_list[0] for _list in _lists]
			self._fen_tree = []
			self._rebuild = True

		def _fen_build(self):
			self._fen_tree[:] = self._list_lens
			_fen_tree = self._fen_tree
			for i in range(len(_fen_tree)):
				if i | i + 1 < len(_fen_tree):
					_fen_tree[i | i + 1] += _fen_tree[i]
			self._rebuild = False

		def _fen_update(self, index, value):
			if not self._rebuild:
				_fen_tree = self._fen_tree
				while index < len(_fen_tree):
					_fen_tree[index] += value
					index |= index + 1

		def _fen_query(self, end):
			if self._rebuild:
				self._fen_build()
			_fen_tree = self._fen_tree
			x = 0
			while end:
				x += _fen_tree[end - 1]
				end &= end - 1
			return x

		def _fen_findkth(self, k):
			_list_lens = self._list_lens
			if k < _list_lens[0]:
				return (0, k)
			if k >= self._len - _list_lens[-1]:
				return (len(_list_lens) - 1, k + _list_lens[-1] - self._len)
			if self._rebuild:
				self._fen_build()
			_fen_tree = self._fen_tree
			idx = -1
			for d in reversed(range(len(_fen_tree).bit_length())):
				right_idx = idx + (1 << d)
				if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
					idx = right_idx
					k -= _fen_tree[idx]
			return (idx + 1, k)

		def _delete(self, pos, idx):
			_lists = self._lists
			_mins = self._mins
			_list_lens = self._list_lens
			self._len -= 1
			self._fen_update(pos, -1)
			del _lists[pos][idx]
			_list_lens[pos] -= 1
			if _list_lens[pos]:
				_mins[pos] = _lists[pos][0]
			else:
				del _lists[pos]
				del _list_lens[pos]
				del _mins[pos]
				self._rebuild = True

		def _loc_left(self, value):
			if not self._len:
				return (0, 0)
			_lists = self._lists
			_mins = self._mins
			(lo, pos) = (-1, len(_lists) - 1)
			while lo + 1 < pos:
				mi = lo + pos >> 1
				if value <= _mins[mi]:
					pos = mi
				else:
					lo = mi
			if pos and value <= _lists[pos - 1][-1]:
				pos -= 1
			_list = _lists[pos]
			(lo, idx) = (-1, len(_list))
			while lo + 1 < idx:
				mi = lo + idx >> 1
				if value <= _list[mi]:
					idx = mi
				else:
					lo = mi
			return (pos, idx)

		def _loc_right(self, value):
			if not self._len:
				return (0, 0)
			_lists = self._lists
			_mins = self._mins
			(pos, hi) = (0, len(_lists))
			while pos + 1 < hi:
				mi = pos + hi >> 1
				if value < _mins[mi]:
					hi = mi
				else:
					pos = mi
			_list = _lists[pos]
			(lo, idx) = (-1, len(_list))
			while lo + 1 < idx:
				mi = lo + idx >> 1
				if value < _list[mi]:
					idx = mi
				else:
					lo = mi
			return (pos, idx)

		def add(self, value):
			_load = self._load
			_lists = self._lists
			_mins = self._mins
			_list_lens = self._list_lens
			self._len += 1
			if _lists:
				(pos, idx) = self._loc_right(value)
				self._fen_update(pos, 1)
				_list = _lists[pos]
				_list.insert(idx, value)
				_list_lens[pos] += 1
				_mins[pos] = _list[0]
				if _load + _load < len(_list):
					_lists.insert(pos + 1, _list[_load:])
					_list_lens.insert(pos + 1, len(_list) - _load)
					_mins.insert(pos + 1, _list[_load])
					_list_lens[pos] = _load
					del _list[_load:]
					self._rebuild = True
			else:
				_lists.append([value])
				_mins.append(value)
				_list_lens.append(1)
				self._rebuild = True

		def discard(self, value):
			_lists = self._lists
			if _lists:
				(pos, idx) = self._loc_right(value)
				if idx and _lists[pos][idx - 1] == value:
					self._delete(pos, idx - 1)

		def remove(self, value):
			_len = self._len
			self.discard(value)
			if _len == self._len:
				raise ValueError('{0!r} not in list'.format(value))

		def pop(self, index=-1):
			(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
			value = self._lists[pos][idx]
			self._delete(pos, idx)
			return value

		def bisect_left(self, value):
			(pos, idx) = self._loc_left(value)
			return self._fen_query(pos) + idx

		def bisect_right(self, value):
			(pos, idx) = self._loc_right(value)
			return self._fen_query(pos) + idx

		def count(self, value):
			return self.bisect_right(value) - self.bisect_left(value)

		def __len__(self):
			return self._len

		def __getitem__(self, index):
			(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
			return self._lists[pos][idx]

		def __delitem__(self, index):
			(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
			self._delete(pos, idx)

		def __contains__(self, value):
			_lists = self._lists
			if _lists:
				(pos, idx) = self._loc_left(value)
				return idx < len(_lists[pos]) and _lists[pos][idx] == value
			return False

		def __iter__(self):
			return (value for _list in self._lists for value in _list)

		def __reversed__(self):
			return (value for _list in reversed(self._lists) for value in reversed(_list))

		def __repr__(self):
			return 'SortedList({0})'.format(list(self))
	n = N()
	a = lis()
	b = lis()
	temp = [b[i] - a[i] for i in range(n)]
	s = SortedList(temp)
	ans = 0
	for i in range(n):
		s.remove(b[i] - a[i])
		t = a[i] - b[i]
		k = s.bisect_left(t)
		ans += k
	print(ans)
solve()


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ab = []
for i in range(n):
	ab.append(a[i] - b[i])
ab.sort()
ans = 0
(i, j) = (n - 1, 0)
while i >= 0 and j <= n - 1:
	while j <= n - 1 and ab[i] + ab[j] <= 0:
		j += 1
	ans += max(0, i - j)
	i -= 1
print(ans)


def CountPairs(arr, n):
	arr.sort()
	count = 0
	l = 0
	r = n - 1
	while l < r:
		if arr[l] + arr[r] > 0:
			count += r - l
			r -= 1
		else:
			l += 1
	return count
N = int(input())
array1 = [int(x) for x in input().split()]
array2 = [int(x) for x in input().split()]
differences = []
for i in range(N):
	differences.append(array1[i] - array2[i])
print(CountPairs(differences, N))


from bisect import bisect_right
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
D = [a - b for (a, b) in zip(A, B)]
D.sort()
s = 0
for (i, d) in enumerate(D):
	if d > 0:
		s += len(D) - i - 1
	else:
		j = bisect_right(D, -d)
		s += len(D) - j
print(s)


from sys import stdin, stdout
(_input, _print) = (stdin.readline, stdout.write)
(_range, _int, _list, _len, _str) = (range, int, list, len, str)

def solution():
	n = _int(_input())
	a = [_int(i) for i in _input().split()]
	b = [_int(i) for i in _input().split()]
	c = sorted([a[i] - b[i] for i in _range(n)])

	def binary_search(arr, l, r, elem):
		while l < r:
			mid = (l + r) // 2
			if elem < arr[mid]:
				r = mid
			else:
				l = mid + 1
		return r
	first = n
	for i in _range(n):
		if c[i] > 0:
			first = i
			break
	summary = 0
	for i in _range(n):
		if c[i] < 0:
			search = -c[i]
			j = binary_search(c, first, n, search)
			summary += n - j
		if c[i] == 0:
			summary += n - first
		if c[i] > 0:
			summary += n - i - 1
	print(summary)
solution()


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
(cnt_e, diff_g, diff_l) = (0, [], [])
for i in range(n):
	if a[i] == b[i]:
		cnt_e += 1
	if a[i] < b[i]:
		diff_l.append(b[i] - a[i])
	if a[i] > b[i]:
		diff_g.append(a[i] - b[i])
res = 0
res += cnt_e * len(diff_g)
res += len(diff_g) * (len(diff_g) - 1) // 2
diff_g.sort()
diff_l.sort()
for i in diff_g:
	(l, r) = (0, len(diff_l) - 1)
	while l <= r:
		m = l + r >> 1
		if diff_l[m] >= i:
			r = m - 1
		else:
			l = m + 1
	res += l
print(res)


from sys import stdin

def inp():
	return (ss.rstrip() for ss in stdin).__next__()

def itg():
	return int(stdin.buffer.readline())

def mpint():
	return map(int, stdin.buffer.readline().split())
from bisect import bisect_right
n = itg()
a = mpint()
b = mpint()
c = [ai - bi for (ai, bi) in zip(a, b)]
c.sort()
ans = 0
for i in range(n):
	upper_bound = bisect_right(c, -c[i])
	ans += n - upper_bound
	if upper_bound <= i:
		ans -= 1
print(ans // 2)


def search(i):
	l = 0
	r = i - 1
	best = 0
	while l <= r:
		m = (l + r) // 2
		if c[m] + c[i] >= 1:
			best = m + 1
			l = m + 1
		else:
			r = m - 1
	return best
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [a[i] - b[i] for i in range(n)]
c.sort(reverse=True)
ans = 0
for i in range(1, n):
	ans += search(i)
print(ans)


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log2, ceil
from collections import defaultdict
from bisect import bisect_left as bl, bisect_right as br
from collections import Counter
from collections import deque
ip = lambda : int(stdin.readline())
inp = lambda : map(int, stdin.readline().split())
ips = lambda : stdin.readline().rstrip()
t = 1
for _ in range(t):
	n = ip()
	a = list(inp())
	b = list(inp())
	ch = []
	for i in range(n):
		ch.append(b[i] - a[i])
	ch.sort()
	ans = 0
	for i in range(n):
		val = a[i] - b[i]
		ct = bl(ch, val)
		if b[i] - a[i] < val:
			ct -= 1
		ans += ct
	ans = ans // 2
	print(ans)


am = int(input())
teach = list(map(int, input().split()))
stud = list(map(int, input().split()))
newArr = []
for i in range(am):
	newArr.append(teach[i] - stud[i])
newArr.sort()
pairs = 0
iter = am - 1
total = 0
now = newArr[iter]
sliced = 0
while True:
	if now <= 0:
		break
	else:
		for i in range(sliced, am):
			if newArr[i] + now <= 0:
				sliced += 1
			else:
				pairs += am - sliced - 1 - total
				break
		iter -= 1
		if iter < 0:
			break
		now = newArr[iter]
		total += 1
print(pairs)


from sys import stdin
from bisect import bisect_left

def get_int_input():
	return int(stdin.readline())

def get_str_input():
	return input()

def multiple_input():
	return map(int, stdin.readline().split())

def list_input():
	return list(map(int, stdin.readline().split()))
n = get_int_input()
a = list_input()
b = list_input()
diff = []
for i in range(n):
	diff.append(a[i] - b[i])
diff.sort()
pair = 0
(l, r) = (0, n - 1)
while l < r:
	if diff[l] + diff[r] > 0:
		pair += r - l
		r -= 1
	else:
		l += 1
print(pair)


from bisect import bisect_left as bl
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = []
for i in range(n):
	c.append(a[i] - b[i])
c.sort()
ans = 0
for i in range(n):
	if c[i] < 1:
		continue
	pos = bl(c, -c[i] + 1)
	ans += i - pos
print(ans)


import bisect
n = int(input())
l = [int(x) for x in input().split()]
m = [int(x) for x in input().split()]
c = []
for i in range(n):
	c.append(l[i] - m[i])
c.sort()
i = 1
ans = 0
while i < n:
	if c[i] > 0:
		a = -c[i] + 1
		j = bisect.bisect_left(c, a, 0, i)
		ans += i - j
	i += 1
print(ans)


import sys
a = int(sys.stdin.readline())
X = sys.stdin.readline().split()
Y = sys.stdin.readline().split()
Z = []
for i in range(a):
	Z.append(int(X[i]) - int(Y[i]))
c = 0
Z.sort()
for i in range(a - 1, -1, -1):
	z = Z[i]
	(l, r) = (0, i)
	while l < r:
		m = (l + r) // 2
		if z + Z[m] > 0:
			r = m
		else:
			l = m + 1
	c += i - l
print(c)


from bisect import bisect_left
n = int(input())
list_1 = input().split()
list_2 = input().split()
list_1 = list(map(int, list_1))
list_2 = list(map(int, list_2))
good_pair = 0
list_3 = []
for i in range(len(list_1)):
	list_3.append(list_1[i] - list_2[i])
list_3.sort()
for i in range(len(list_3)):
	if list_3[i] <= 0:
		continue
	else:
		index = bisect_left(list_3, -1 * list_3[i] + 1)
		good_pair += i - index
print(good_pair)


import bisect
num_cases = int(input())
a = [int(i) for i in input().split(' ')]
b = [int(j) for j in input().split(' ')]
differences = [elem_a - elem_b for (elem_a, elem_b) in zip(a, b)]
differences.sort()
total_pairs = 0
deduct = 0
for difference in differences:
	pair = 0
	if difference > 0:
		pair = len(differences) - bisect.bisect_left(differences, -1 * difference + 1)
		total_pairs += pair
		total_pairs -= 1
	elif difference == 0:
		pair = len(differences) - bisect.bisect_left(differences, 1)
		total_pairs += pair
	else:
		pair = len(differences) - bisect.bisect_left(differences, -1 * difference + 1)
		total_pairs += pair
print(int(total_pairs / 2))


def lower_bound(l, r, x):
	while r - l > 1:
		m = (l + r) // 2
		if c[m] + x > 0:
			r = m
		else:
			l = m
	return r
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(a[i] - b[i]) for i in range(n)]
c.sort()
cnt = 0
for i in range(n):
	if c[i] > 0:
		idx = lower_bound(-1, i, c[i])
		if idx != -1:
			cnt += i - idx
print(cnt)


from sys import stdin
from bisect import bisect_left
try:
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().rstrip().split()))
	b = list(map(int, stdin.readline().rstrip().split()))
	arr = [a[i] - b[i] for i in range(n)]
	arr.sort()
	count = 0
	for i in range(n - 1):
		if arr[i] <= 0:
			ind = bisect_left(arr, abs(arr[i]) + 1)
			count += n - ind
		else:
			count += n - i - 1
	print(count)
except:
	pass


import os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def getpos(v):
	v = -1 * v
	l = 0
	h = n
	while l < h:
		m = (l + h) // 2
		if c[m] == v:
			while m < n and c[m] == v:
				m += 1
			return m
		elif c[m] < v:
			l = m + 1
		else:
			h = m
	return l
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = sorted([i - j for (i, j) in zip(a, b)])
zeros = 0
gzeros = 0
lz = 0
for i in c:
	if i == 0:
		zeros += 1
	elif i > 0:
		gzeros += 1
	else:
		lz += n - getpos(i)
output = lz + zeros * gzeros + gzeros * (gzeros - 1) // 2
print(output)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
delta = sorted([ai - bi for (ai, bi) in zip(a, b)], reverse=True)
(l, r) = (0, n - 1)
cnt = 0
ct = n - 1
while l < r:
	if delta[l] + delta[r] > 0:
		cnt += ct
		ct -= 1
		l += 1
	else:
		ct -= 1
		r -= 1
print(cnt)


def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] > k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater
for _ in range(1):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	aa = []
	for i in range(n):
		aa.append(a[i] - b[i])
	aa.sort()
	ans = 0
	for i in range(n):
		t = aa[i]
		aa[i] = -10 ** 18
		ans += countGreater(aa, n, -t)
	print(ans)


from bisect import bisect_left

def solve(arr, n):
	ans = 0
	ls = sorted(arr)
	(L, R) = (0, n - 1)
	while L < R:
		while L < R and ls[L] + ls[R] <= 0:
			L += 1
		ans += R - L
		R -= 1
	return ans
n = int(input())
arr = list(map(int, input().split()))
brr = list(map(int, input().split()))
print(solve(list([arr[x] - brr[x] for x in range(n)]), n))


import sys
input = sys.stdin.readline

def getInt():
	return int(input())

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

def getList():
	return list(map(int, input().split()))

def getStr():
	return input().strip()
n = getInt()
a = getList()
b = getList()
d_pol = {}
d_otr = {}
pol = 0
for i in range(n):
	r = a[i] - b[i]
	if r > 0:
		if r not in d_pol:
			d_pol[r] = 0
		d_pol[r] += 1
		pol += 1
	else:
		if r not in d_otr:
			d_otr[r] = 0
		d_otr[r] += 1
keys_pol = list(d_pol.keys())
keys_pol.sort()
keys_otr = list(d_otr.keys())
keys_otr.sort(reverse=True)
res = pol * (pol - 1) // 2
kk = 0
r2 = 0
for k1 in range(len(keys_pol)):
	res += d_pol[keys_pol[k1]] * r2
	k = kk
	for k2 in range(k, len(keys_otr)):
		if keys_pol[k1] + keys_otr[k2] > 0:
			r2 += d_otr[keys_otr[k2]]
			res += d_pol[keys_pol[k1]] * d_otr[keys_otr[k2]]
			kk = k2 + 1
		else:
			break
print(res)


def f(n, a, b):
	c = [a[i] - b[i] for i in range(n)]
	c.sort()
	counter = 0
	for i in range(n):
		if c[i] > 0:
			left = 0
			right = i
			while left < right:
				mid = (left + right) // 2
				if c[i] + c[mid] <= 0:
					left = mid + 1
				else:
					right = mid
			counter += i - left
	return counter
n = int(input())
a = list(map(int, input().rstrip().split()))
b = list(map(int, input().rstrip().split()))
print(f(n, a, b))


from collections import Counter
import bisect
n = int(input())
a = [int(x) for x in input().split(' ')]
b = [int(x) for x in input().split(' ')]
c = []
for i in range(n):
	c.append(a[i] - b[i])
c = sorted(c)
answer = 0
for i in range(n - 1, -1, -1):
	j = bisect.bisect_right(c, -c[i])
	if i > j:
		answer += i - j
print(answer)


import bisect

def findPairs(arr, n, x):
	l = 0
	r = n - 1
	result = 0
	while l < r:
		if arr[l] + arr[r] < x:
			result += r - l
			l += 1
		else:
			r -= 1
	return result
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = []
for i in range(len(a)):
	c.append(a[i] - b[i])
c = sorted(c)
l = findPairs(c, len(c), 1)
n = len(c)
print(n * (n - 1) // 2 - l)


import sys
input = sys.stdin.readline

def fastio():
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()
INF = 10 ** 20
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br
(n,) = I()
a = I()
b = I()
s = []
ans = 0
p = z = 0
for i in range(n):
	s.append(a[i] - b[i])
	p += a[i] - b[i] > 0
	z += a[i] - b[i] == 0
s.sort()
ans += p * (p - 1) // 2 + z * p
for i in range(n):
	if s[i] < 0:
		ans += n - br(s, -s[i])
print(ans)


n = int(input())
l1 = [int(x) for x in input().split()]
l2 = [int(x) for x in input().split()]
t = []
for i in range(n):
	t += [l1[i] - l2[i]]
t.sort()
i = 0
j = n - 1
ans = 0
while i < j:
	if t[j] + t[i] > 0:
		ans += j - i
		j -= 1
	else:
		i += 1
print(ans)


import sys
input = sys.stdin.readline
from bisect import bisect_right
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = [a - b for (a, b) in zip(A, B)]
C.sort()
ans = 0
for (i, c) in enumerate(C):
	ind = bisect_right(C, -c)
	ans += min(N - ind, N - i - 1)
print(ans)


from bisect import *
n = int(input())
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
a = [b[i] - c[i] for i in range(n)]
a.sort()
ans = 0
for i in range(len(a)):
	ans += min(len(a) - bisect_right(a, -a[i]), len(a) - i - 1)
print(ans)


from bisect import bisect_left, bisect_right
from typing import List
import collections
import bisect
import itertools
import functools
from fractions import gcd
import heapq
from math import ceil, sqrt, floor
import sys
sys.setrecursionlimit(50000)
import collections
from collections import defaultdict, deque
import collections
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
diff = [B[i] - A[i] for i in range(n)]
diff.sort()
ret = 0
for i in range(n):
	d = A[i] - B[i]
	idx = bisect.bisect_right(diff, d - 1) - 1
	if idx >= 0:
		ret += idx + 1
		if d > 0:
			ret -= 1
print(ret // 2)


n = int(input())
diff = [int(a) - int(b) for (a, b) in zip(input().split(), input().split())]
diff.sort()
total = 0
for i in range(n - 1):
	l = i
	r = n
	if diff[i] <= 0:
		while r - l > 1:
			p = (r + l) // 2
			if diff[i] + diff[p] > 0:
				r = p
			else:
				l = p
	else:
		r = i + 1
	total += n - r
print(total)


from sys import stdin
from bisect import bisect_left, bisect_right
input = stdin.buffer.readline
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [a[i] - b[i] for i in range(n)]
c.sort()
index = bisect_right(c, 0)
ans = 0
for i in range(index, n):
	temp = bisect_right(c, -c[i])
	ans += n - temp - 1
ans -= (n - index) * (n - index - 1) // 2
print(ans)


import bisect as bi
n = int(input())
l = list(map(int, input().split()))
r = list(map(int, input().split()))
ar = []
for i in range(n):
	ar.append(l[i] - r[i])
	c = 0
ar.sort()
ans = 0
d = n - bi.bisect(ar, 0)
ans += d * (d - 1) // 2
dd = ar.count(0)
ans += dd * d
temp = ar[bi.bisect(ar, 0):]
for i in ar:
	if i >= 0:
		break
	gg = len(temp) - bi.bisect(temp, abs(i))
	ans += gg
print(ans)


from sys import stdin, stdout
import bisect
n = int(stdin.readline())
topic = list(map(int, stdin.readline().split()))
student = list(map(int, stdin.readline().split()))
for i in range(n):
	topic[i] -= student[i]
topic.sort()
ans = 0
for i in range(len(topic) - 1, -1, -1):
	if topic[i] <= 0:
		break
	else:
		j = bisect.bisect_left(topic, 1 - topic[i])
		ans += i - j
stdout.write(str(ans))


from bisect import bisect_left as bl, bisect_right as br, insort
import sys
import heapq
from collections import defaultdict as dd, deque

def data():
	return sys.stdin.readline().strip()

def mdata():
	return map(int, data().split())

def conv(x):
	return bin(x).replace('0b', '')
n = int(data())
A = list(mdata())
B = list(mdata())
dp = [0] * n
for i in range(n):
	dp[i] = A[i] - B[i]
dp.sort()
ans = 0
for i in range(n - 1, -1, -1):
	if dp[i] <= 0:
		break
	t = -1 * dp[i]
	k = br(dp, -dp[i])
	if dp[i] == -dp[k]:
		k -= 1
	ans += i - k
print(ans)


def solve(n, a, d):
	diffs = []
	for i in range(n):
		diffs.append(a[i] - d[i])
	diffs.sort()
	pairs = 0
	lb = 0
	rb = n - 1
	while lb < rb:
		if diffs[rb] + diffs[lb] > 0:
			pairs += rb - lb
			rb -= 1
		else:
			lb += 1
	return pairs

def main():
	n = int(input())
	d = input()
	d = [int(i) for i in d.split()]
	e = input()
	e = [int(i) for i in e.split()]
	ans = solve(n, d, e)
	print(ans)
main()


from bisect import bisect_left
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [0] * n
for i in range(n):
	c[i] = a[i] - b[i]
c.sort()
i = 0
ans = 0
now = 0
tmp = 0
flag = bisect_left(c, 1)
while c[i] <= 0:
	tmp = -c[i] + 1
	if c[i] < 0:
		now = bisect_left(c, tmp)
	elif c[i] == 0:
		now = flag
	ans += n - now
	i += 1
	if i >= n:
		break
print(ans + (n - i) * (n - i - 1) // 2)


n = int(input())
a = [int(i) for i in input().split(' ')]
b = [int(i) for i in input().split(' ')]
s = [i - j for (i, j) in zip(a, b)]
s.sort(reverse=True)
goods = 0
(i, j) = (-1, n)
for index in range(1, n):
	if s[index] > 0:
		goods += index
	else:
		j = index
		i = index - 1
		break
while i >= 0 and j < n:
	if s[i] + s[j] > 0:
		goods += i + 1
		j += 1
	else:
		i -= 1
print(goods)


debug = False
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [a[i] - b[i] for i in range(n)]
if debug:
	print('c', c)
c.sort()
from bisect import bisect_right
i = n - 1
ans = 0
while c[i] > 0 and i >= 0:
	key = -c[i]
	ind = bisect_right(c, key)
	ans += i - ind
	i -= 1
print(ans)


import bisect
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
diff = [i - j for (i, j) in zip(a, b)]
diff.sort()
ans = 0
for i in range(n):
	if diff[i] <= 0:
		continue
	j = bisect.bisect_left(diff, -diff[i] + 1)
	ans += i - j
print(ans)


def to_list(s):
	return list(map(lambda x: int(x), s.split(' ')))

def C_n_2(n):
	return int(n * (n - 1) / 2)

def solve(a, b):
	c = [0] * len(a)
	for i in range(len(a)):
		c[i] = a[i] - b[i]
	pos_len = sum([int(item > 0) for item in c])
	neg_len = len(c) - pos_len
	sum_ = C_n_2(pos_len)
	sort_c = sorted(c, reverse=True)
	dict_ = {}
	for i in range(pos_len):
		dict_[sort_c[i]] = 0
	if neg_len > 0:
		j = pos_len
		neg_subarr_len = 0
		for i in range(pos_len - 1, -1, -1):
			pos_num = sort_c[i]
			while j < len(c):
				if -sort_c[j] < pos_num:
					neg_subarr_len += 1
					j += 1
				else:
					break
			dict_[pos_num] += neg_subarr_len
	sum_ += sum(dict_.values())
	return sum_
n = int(input())
a = to_list(input())
b = to_list(input())
print(solve(a, b))


import math
t = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
arr = [a[i] - b[i] for i in range(t)]
arr.sort()
p = 0
ans = 0
j = t - 1
for ii in range(t):
	i = arr[ii]
	if i > 0:
		p += t - ii
		break
	while arr[j] + i > 0:
		j -= 1
	ans += t - j - 1
print(math.comb(p, 2) + ans)


import math
from bisect import bisect_left, bisect_right
from sys import stdin, stdout
from collections import Counter
input = lambda : stdin.readline().strip()
print = stdout.write
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = {}
for i in range(n):
	try:
		d[a[i] - b[i]] += 1
	except:
		d[a[i] - b[i]] = 1
diffs = []
for (k, v) in d.items():
	diffs.append(k)
diffs.sort()
cnts = [d[i] for i in diffs]
for i in range(len(cnts) - 2, -1, -1):
	cnts[i] += cnts[i + 1]
s = 0
for i in range(n):
	index = bisect_right(diffs, b[i] - a[i])
	try:
		s += cnts[index]
	except:
		s += 0
	if b[i] < a[i]:
		s -= 1
print(str(s // 2) + '\n')


from bisect import bisect_left as bisect
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [a[i] - b[i] for i in range(n)]
c.sort()
cu = 0
for i in c:
	x = 1 - i
	z = bisect(c, x)
	if x <= 0:
		cu += n - z - 1
	else:
		cu += n - z
print(cu // 2)


n = int(input())
num1 = list(map(int, input().split()))
num2 = list(map(int, input().split()))
p = n * [0]
q = n * [0]
ans = 0
for i in range(n):
	p[i] = num1[i] - num2[i]
	q[i] = -p[i]
	if num1[i] - num2[i] > num2[i] - num1[i]:
		ans -= 1
p.sort()
q.sort()
u = 0
for i in range(n):
	while u < n and p[i] > q[u]:
		u += 1
	ans += u
print(int(ans / 2))


from sys import stdin
import bisect
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
B = [int(x) for x in stdin.readline().rstrip().split()]
C = []
for i in range(N):
	C.append(A[i] - B[i])
C.sort()
ans = 0
nonzero = len([i for i in C if i > 0])
cnt = 0
for (ind, i) in enumerate(C):
	if i < 0:
		ans += N - bisect.bisect_right(C, abs(i))
	elif i == 0:
		ans += nonzero
	else:
		cnt += 1
		ans += nonzero - cnt
print(ans)


import sys
input = sys.stdin.readline
import bisect
from collections import deque
n = int(input())
a = [int(item) for item in input().split()]
b = [int(item) for item in input().split()]
c = []
for (aa, bb) in zip(a, b):
	c.append(aa - bb)
c.sort()
c = deque(c)
ans = 0
while c:
	item = c.popleft()
	val = len(c) - bisect.bisect_right(c, -item)
	ans += val
print(ans)


from bisect import bisect_right

def main():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = []
	for i in range(n):
		c.append(a[i] - b[i])
	c.sort()
	ans = 0
	for (i, v) in enumerate(c):
		ans += n - bisect_right(c, -v, lo=i + 1)
	print(ans)
main()


t = int(input())
x = []
aa = input().split()
bb = input().split()
for i in range(len(aa)):
	a = int(aa[i])
	b = int(bb[i])
	x.append(a - b)
x.sort()
x.reverse()
j = len(x) - 1
sum = 0
for i in range(len(x)):
	if x[i] <= 0 or i > j:
		break
	while j > i and x[i] + x[j] <= 0:
		j = j - 1
	sum += j - i
print(sum)


from collections import defaultdict

def solve(x, pos):
	l = 0
	r = pos
	while l < r:
		mid = l + r >> 1
		if a[mid] + x > 0:
			r = mid
		else:
			l = mid + 1
	return pos - l
IA = lambda : map(int, input().split())
n = int(input())
a = list(IA())
b = list(IA())
for i in range(0, n):
	a[i] = a[i] - b[i]
a = sorted(a)
l = 0
r = n - 1
ans = 0
for i in range(0, n):
	ans += solve(a[i], i)
print(ans)


import sys, bisect
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
p = []
for i in range(n):
	p.append(a[i] - b[i])
p.sort()
res = 0
for i in range(n):
	k = bisect.bisect_right(p, -p[i])
	res += n - max(k, i + 1)
print(res)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
res = 0
for i in range(n):
	a[i] = a[i] - b[i]
a.sort()
res = 0
i = n - 1
j = 0
while i >= 0 and a[i] > 0:
	a[i]
	while j < n and a[i] <= -a[j]:
		j += 1
	res += max(i - j, 0)
	i -= 1
print(res)


n = int(input())
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
l3 = []
for i in range(n):
	l3.append(l1[i] - l2[i])
l3.sort()
count = 0
for i in range(n - 1):
	store = -l3[i]
	k = i + 1
	j = n
	index = i
	while k < j:
		mid = (k + j) // 2
		if l3[mid] <= store:
			index = mid
			k = mid + 1
		else:
			j = mid
	count += n - (index + 1)
print(count)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
now = []
for i in range(n):
	now.append([a[i] - b[i], a[i], b[i]])
now.sort()
ans = 0
i = 0
j = n - 1
while i < j:
	if now[i][0] + now[j][0] > 0:
		ans += j - i
		j -= 1
	else:
		i += 1
print(ans)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
diff = [0] * n
for i in range(n):
	diff[i] = a[i] - b[i]
diff.sort()
sol = 0
j = n - 1
good = 0
for i in range(n):
	while j > i and diff[i] + diff[j] > 0:
		j -= 1
		good += 1
	if j < i:
		good = n - i - 1
	sol += good
print(sol)


def bsg(n, arr, hi=None, lo=0):
	if hi is None:
		hi = len(arr)
	if not arr:
		return None
	mid = (hi + lo) // 2
	if arr[mid] > n >= arr[mid - 1]:
		return mid
	if mid == lo or hi == mid:
		return None
	if arr[mid] > n:
		return bsg(n, arr, mid, lo)
	return bsg(n, arr, hi, mid)
n = int(input())
tarr = list(map(int, input().split()))
sarr = list(map(int, input().split()))
arr = []
for i in range(n):
	arr.append(tarr[i] - sarr[i])
arr.sort()
cnt = 0
for (i, x) in enumerate(arr):
	if x < 1:
		idx = bsg(-x, arr)
		if idx is not None:
			cnt += n - idx
	else:
		cnt += n - i - 1
print(cnt)


class Solution:

	def __init__(self):
		self.n = int(input())
		self.a = [int(x) for x in input().split()]
		self.b = [int(x) for x in input().split()]

	def solve_and_print(self):
		good_pairs = 0
		c = sorted((self.a[i] - self.b[i] for i in range(self.n)))
		for j in range(self.n):
			if c[j] > 0:
				(left, right) = (0, j)
				while left < right:
					mid = left + (right - left >> 1)
					if c[j] + c[mid] <= 0:
						left = mid + 1
					else:
						right = mid
				good_pairs += j - left
		print(good_pairs)
Solution().solve_and_print()


import sys

def solv():
	sol = pos * (pos - 1) // 2 + (n - pos - neg) * pos
	dfnce.sort()
	ed = neg - 1
	for bg in range(neg, n):
		while ed >= 0 and -dfnce[ed] < dfnce[bg]:
			ed -= 1
		sol += neg - ed - 1
	return sol
n = int(input())
tchr = list(map(int, input().split()))
stdnt = list(map(int, input().split()))
dfnce = []
neg = 0
pos = 0
for i in range(0, n):
	curr = tchr[i] - stdnt[i]
	dfnce.append(curr)
	if curr < 0:
		neg += 1
	if curr > 0:
		pos += 1
print(solv())


from collections import Counter, defaultdict, deque
from heapq import heapify, heappush, heappop, heappushpop
from bisect import bisect
from sys import stdin
int_inp = lambda : int(stdin.readline().strip())
lst_inp = lambda : [int(i) for i in stdin.readline().strip().split(' ')]
str_inp = lambda : stdin.readline().strip()
n = int_inp()
a = lst_inp()
b = lst_inp()
c = [i - j for (i, j) in zip(a, b)]
c.sort()
count = 0
for i in range(n - 1):
	j = bisect(c, -c[i])
	count += n - j
	if j <= i:
		count -= i - j + 1
print(count)


from heapq import *
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
X = [A[i] - B[i] for i in range(N)]
Y = [B[i] - A[i] for i in range(N)]
hq = []
iter = [(Y[i], X[i]) for i in range(N)]
iter.sort()
ans = 0
for (y, x) in iter:
	while hq and hq[0] <= y:
		heappop(hq)
	ans += len(hq)
	heappush(hq, x)
print(ans)


n = int(input())
l = list(map(int, input().split()))
l1 = list(map(int, input().split()))
diff = [0] * n
for i in range(n):
	diff[i] = l[i] - l1[i]
diff.sort(reverse=True)
i = 0
j = n - 1
count = 0
while i < j:
	if diff[i] + diff[j] <= 0:
		j -= 1
	else:
		count += j - i
		i += 1
print(count)


from sys import stdin
from collections import deque
from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin

def ii():
	return int(stdin.readline())

def fi():
	return float(stdin.readline())

def mi():
	return map(int, stdin.readline().split())

def fmi():
	return map(float, stdin.readline().split())

def li():
	return list(mi())

def lsi():
	x = list(stdin.readline())
	x.pop()
	return x

def si():
	return stdin.readline()
n = ii()
a = li()
b = li()
s = []
for i in range(n):
	s.append(a[i] - b[i])
s.sort()
c = 0
r = -1
for i in range(n):
	if s[i] > 0:
		r = i
		break
if r == -1:
	print(0)
	exit()
l = r - 1
for i in range(r, n):
	while l > -1 and s[i] + s[l] > 0:
		l -= 1
	c += i - (l + 1)
print(c)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(n):
	a[i] -= b[i]
a.sort()
last = n - 1
start = 0
ans = 0
while last > start:
	if a[start] + a[last] > 0:
		ans += last - start
		last -= 1
	else:
		start += 1
print(ans)


def binary_search(array, elem):
	left = -1
	right = len(array)
	while left < right - 1:
		middle = (left + right) // 2
		if array[middle] >= elem:
			right = middle
		else:
			left = middle
	return right
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = []
ans = 0
for i in range(len(a)):
	c.append(a[i] - b[i])
c.sort()
for i in range(len(a)):
	count = -1 * (a[i] - b[i] - 1)
	d = binary_search(c, count)
	if a[i] > b[i]:
		d += 1
	if d != -1:
		ans += len(c) - d
print(ans // 2)


t = int(input())
a = input().split(' ')
b = input().split(' ')
negativo = []
positivo = []
cero = []
tot = 0
for i in range(0, t):
	resta = int(a[i]) - int(b[i])
	if resta > 0:
		positivo.append(resta)
	elif resta < 0:
		negativo.append(resta)
	else:
		cero.append(resta)
positivo.sort()
negativo.sort()
largop = len(positivo)
largoc = len(cero)
largon = len(negativo)
tot += largoc * largop
if largop > 0 and largon > 0:
	tot += int(largop * (largop - 1) / 2)
	i = largon - 1
	j = 0
	while i >= 0 and j < largop:
		if positivo[j] + negativo[i] > 0:
			tot += largop - j
			i -= 1
		else:
			j += 1
elif largon == 0 and largop > 0:
	tot += int(largop * (largop - 1) / 2)
else:
	tot += 0
print(tot)


t = int(input())
pairs = []
cnt = 0
teach = input().split()
stud = input().split()
for i in range(0, t):
	teach[i] = int(teach[i])
	stud[i] = int(stud[i])
for i in range(0, t):
	x = teach[i] - stud[i]
	pairs.append(x)
pairs.sort()
k = 0

def fact(a):
	fc = 1
	for i in range(1, a):
		fc = fc * i
	return fc
l = cnt = 0
r = t - 1
while l < r:
	if pairs[l] + pairs[r] > 0:
		cnt += r - l
		r -= 1
	elif pairs[l] <= 0 and pairs[r] <= 0:
		r -= 1
		l += 1
	elif pairs[r] < 0:
		r -= 1
	elif pairs[l] < 0:
		l += 1
print(cnt)


import bisect
n = int(input())
l = input().split()
li = [int(i) for i in l]
l = input().split()
li1 = [int(i) for i in l]
lif = [0 for i in range(n)]
for i in range(n):
	lif[i] = li[i] - li1[i]
lif.sort()
count = 0
for i in range(n):
	count1 = bisect.bisect(lif, -1 * lif[i])
	count += n - count1
	if lif[i] > -1 * lif[i]:
		count -= 1
print(count // 2)


from math import *
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
l = []
c = 0
for i in range(n):
	k = a[i] - b[i]
	l.append(k)
l.sort()
(i, j) = (0, n - 1)
while i < j:
	if l[i] + l[j] > 0:
		c = c + j - i
		j = j - 1
	else:
		i = i + 1
print(c)


import sys

def answer(n, a, b):
	d = []
	for i in range(n):
		d.append(a[i] - b[i])
	d.sort(reverse=True)
	ngr0 = 0
	neq0 = 0
	for i in range(n):
		if d[i] > 0:
			ngr0 += 1
		elif d[i] == 0:
			neq0 += 1
		else:
			break
	nlt0 = n - ngr0 - neq0
	cnt = 0
	if ngr0 >= 2:
		cnt = ngr0 * (ngr0 - 1) // 2
	if neq0 > 0:
		cnt += neq0 * ngr0
	lptr = 0
	rptr = n - 1
	while lptr <= rptr and d[rptr] < 0:
		while d[lptr] + d[rptr] > 0:
			lptr += 1
		cnt += lptr
		rptr -= 1
	return cnt

def main():
	n = int(input())
	a = [int(i) for i in sys.stdin.readline().split()]
	b = [int(i) for i in sys.stdin.readline().split()]
	print(answer(n, a, b))
	return
main()


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
modified = []
for i in range(0, n):
	modified.append(a[i] - b[i])
modified = sorted(modified)
modified = modified[::-1]
start = 0
end = n - 1
flag = 0
ans = 0
while flag == 0:
	if modified[start] + modified[end] > 0:
		ans = ans + (end - start)
		start = start + 1
	else:
		end = end - 1
	if end == start:
		flag = 1
print(ans)


import math
import itertools
gh = lambda : map(int, input().split())
mod = 998244353
mod = int(mod)

def main():
	n = int(input())
	a = list(gh())
	b = list(gh())
	d = []
	ans = 0
	for i in range(n):
		x = a[i] - b[i]
		d.append(x)
	d.sort(reverse=True)
	for i in range(n):
		l = 0
		r = len(d) - 1
		x = d[i]
		if x > 0:
			while l < r:
				m = (l + r) // 2 + 1
				if d[m] + x > 0:
					l = m
				else:
					r = m - 1
			ans += r - i
	print(ans)
main()


def bs(new, k):
	low = 0
	high = len(new)
	while low < high:
		mid = (low + high) // 2
		if new[mid] <= k:
			low = mid + 1
		elif new[mid] > k:
			high = mid - 1
	if low != len(new) and new[low] <= k:
		low += 1
	return len(new) - low
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
new = []
temp = []
for i in range(n):
	new.append(a[i] - b[i])
	temp.append((a[i], b[i]))
new.sort()
count = 0
for i in range(n):
	temp = bs(new, -1 * new[i])
	if n - temp < i:
		temp -= 1
	count += temp
print(count // 2)


n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = sorted((a[i] - b[i] for i in range(n)))
cou = 0
l = 0
r = n - 1
while l < r:
	if c[l] + c[r] > 0:
		cou += r - l
		r -= 1
	else:
		l += 1
print(cou)


from sys import stdin
T = int(input())
a = list(map(int, stdin.readline().split()))
b = list(map(int, stdin.readline().split()))
A = [a[i] - b[i] for i in range(T)]
count = [0]

def merge_compare(p, r):
	if p < r:
		q = (r + p) // 2
		merge_compare(p, q)
		merge_compare(q + 1, r)
		merge(p, q, r)

def merge(p, q, r):
	n_1 = q - p + 1
	n_2 = r - q
	temp = []
	L = A[p:q + 1]
	alt = [-x for x in L][::-1]
	R = A[q + 1:r + 1]
	i = 0
	j = 0
	while i < n_1 and j < n_2:
		if alt[i] < R[j]:
			count[0] += n_2 - j
			i += 1
		else:
			j += 1
	(i, j) = (0, 0)
	while i < n_1 and j < n_2:
		if L[i] >= R[j]:
			temp.append(R[j])
			j += 1
		else:
			temp.append(L[i])
			i += 1
	if i == n_1:
		temp += R[j:]
	else:
		temp += L[i:]
	A[p:r + 1] = temp
merge_compare(0, T - 1)
print(count[0])


from sys import stdin
from collections import defaultdict
import bisect
n = int(stdin.readline())
alist = list(map(int, stdin.readline().strip().split()))
blist = list(map(int, stdin.readline().strip().split()))
d = defaultdict(int)
dposkeys = set()
dnegkeys = set()
poscount = 0
for i in range(n):
	t = alist[i] - blist[i]
	d[t] += 1
	if t > 0:
		poscount += 1
		dposkeys.add(t)
	else:
		dnegkeys.add(t)
if len(d.keys()) == len(dposkeys):
	print(n * (n - 1) // 2)
	exit()
del alist, blist
visited = set()
dposkeys = sorted(list(dposkeys))
pref = [0]
t = 0
for k in dposkeys:
	t += d[k]
	pref.append(t)
pref[0] = t
for i in range(1, len(pref)):
	pref[i] = t - pref[i]
nmpairs = 0
for k1 in dnegkeys:
	ind = bisect.bisect_left(dposkeys, -k1 + 1)
	nmpairs += d[k1] * pref[ind]
print(nmpairs + poscount * (poscount - 1) // 2)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = []
for i in range(n):
	c.append(a[i] - b[i])
c.sort()
x = 0
y = n - 1
count = 0
while c[y] > 0 and x < y:
	if c[x] + c[y] >= 1:
		count += y - x
		y -= 1
	else:
		x += 1
print(count)


import bisect
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
z = [a[i] - b[i] for i in range(n)]
z.sort()
t = 0
for (i, d) in enumerate(z[:-1]):
	h = bisect.bisect(z, -d, i + 1)
	t += n - h
print(t)


n = int(input())
s1 = input()
s2 = input()
l1 = s1.split()
l2 = s2.split()
l3 = list()
for i in range(0, n):
	l3.append(int(l1[i]) - int(l2[i]))
l3.sort(reverse=True)
i = 0
j = n - 1
sol = 0
while i < j:
	if l3[i] + l3[j] > 0:
		sol = sol + j - i
		i += 1
	else:
		j -= 1
print(sol)


from bisect import bisect_left
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
diff = []
for i in range(n):
	diff.append(a[i] - b[i])
diff.sort()
occ = {}
for i in range(n):
	occ[diff[i]] = occ.get(diff[i], 0) + 1
final = 0
for i in range(n):
	pos = bisect_left(diff, -diff[i])
	big = n - pos
	if diff[i] > 0:
		big -= 1
	big -= occ.get(-diff[i], 0)
	final += big
print(int(final / 2))


n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = []
for i in range(n):
	c.append(a[i] - b[i])
c.sort()
pos = n
for i in range(n):
	if c[i] > 0:
		pos = i
		break
i = 0
j = n - 1
ans = 0
while c[i] < 0 and i < j:
	while c[i] + c[j] > 0 and i < j:
		j -= 1
	ans = ans + (n - 1 - j)
	i += 1
while i < n:
	if c[i] != 0:
		break
	ans = ans + (n - pos)
	i += 1
val = n - i
ans = ans + val * (val - 1) // 2
print(ans)


n = int(input())
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))
arr = []
for i in range(n):
	m = arr1[i] - arr2[i]
	arr.append(m)
arr = sorted(arr)
l = 0
r = n - 1
ans = 0
while l < r:
	if arr[l] + arr[r] > 0:
		ans += r - l
		r -= 1
	else:
		l += 1
print(ans)


n = int(input())
a = [int(x) for x in input().split()]
diff = sorted((a[i] - int(x) for (i, x) in enumerate(input().split())), reverse=True)
cnt = 0
limit = diff[-1]
ans = 0
for (i, val) in enumerate(diff, 1):
	if val > 0 and val + limit > 0:
		ans += n - i - cnt
	elif val > 0:
		for j in range(n - cnt):
			if diff[-1 - j - cnt] < 0 and diff[-1 - j - cnt] + val <= 0:
				limit = diff[-1 - j - cnt]
			else:
				cnt += j
				break
		ans += n - i - cnt
	else:
		break
print(ans)


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

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

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0 and x != 2 or x == 0:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = True
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)
n = int(z())
l1 = zzz()
l2 = zzz()
arr = []
for (i, j) in zip(l1, l2):
	arr.append(i - j)
arr = sorted(arr)
ans = 0
for i in range(n):
	x = bsl(arr, -arr[i] + 1)
	if i > x:
		ans += n - 1 - x
	else:
		ans += n - x
print(ans // 2)


import math
n = int(input())
teach = [int(i) for i in input().split(' ')]
stud = [int(i) for i in input().split(' ')]
diffs = []
for i in range(n):
	diffs.append(teach[i] - stud[i])
diffs.sort()
right = n - 1
left = 0
sm = 0
while left < right:
	while left < right and diffs[right] + diffs[left] <= 0:
		left += 1
	sm += right - left
	right -= 1
print(sm)


n = int(input())
ch = input()
L = [int(j) for j in ch.split()]
ch = input()
L2 = [int(j) for j in ch.split()]
L3 = [0] * n
for i in range(n):
	L3[i] = L[i] - L2[i]
L3.sort()
i = 0
j = n - 1
nb = 0
while True:
	if i == j:
		break
	if L3[j] > -L3[i]:
		nb += j - i
		j -= 1
	else:
		i += 1
print(nb)


def binHigherBound(a, lo, hi, x):
	if lo > hi:
		return lo
	mid = int(lo + (hi - lo) // 2)
	if a[mid] == x:
		return binHigherBound(a, mid + 1, hi, x)
	elif a[mid] > x:
		return binHigherBound(a, lo, mid - 1, x)
	else:
		return binHigherBound(a, mid + 1, hi, x)
topics = int(input())
teachers = [int(_) for _ in input().split()]
students = [int(_) for _ in input().split()]
assert len(teachers) == len(students) == topics, 'Invalid Test Case'
diff = [teachers[i] - students[i] for (i, _) in enumerate(teachers)]
ordered_neg_diff = sorted([teachers[i] - students[i] for (i, _) in enumerate(teachers) if teachers[i] - students[i] <= 0])
ordered_pos_diff = sorted([teachers[i] - students[i] for (i, _) in enumerate(teachers) if teachers[i] - students[i] > 0])
if len(ordered_pos_diff) == 0:
	print(0)
else:
	memoize = {}
	max_pos = ordered_pos_diff[-1]
	min_pos = ordered_pos_diff[0]
	search_until = len(ordered_pos_diff) - 1
	ans = 0
	for neg in ordered_neg_diff:
		if neg in memoize:
			ans = ans + memoize[neg]
		elif neg + max_pos <= 0:
			continue
		else:
			i = binHigherBound(ordered_pos_diff, 0, search_until, -1 * neg)
			if neg + ordered_pos_diff[i] > 0:
				valid_neg_pairs = len(ordered_pos_diff) - i
				ans = ans + valid_neg_pairs
				memoize[neg] = valid_neg_pairs
				search_until = i
	n = len(ordered_pos_diff)
	pos_pairs = n * (n - 1) // 2
	ans = ans + pos_pairs
	print(int(ans))


from sys import stdin
from bisect import *

def inp():
	return stdin.readline().strip()
n = int(inp())
a = [int(x) for x in inp().split()]
b = [int(x) for x in inp().split()]
c = []
for (i, j) in zip(a, b):
	c.append(i - j)
c.sort()
count = 1
total = 0
x = -1
for i in range(n):
	offset = 0
	if c[i] <= 0:
		offset = 1
	x = bisect_left(c, abs(c[i]) + offset)
	if i != 0 and c[i] != c[i - 1]:
		count = 1
	if c[i] > 0:
		x += count
		count += 1
	total += n - x
print(total)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [0 for i in range(n)]
for i in range(n):
	c[i] = a[i] - b[i]
c.sort()
g = n - 1
for i in range(n):
	if c[i] > 0:
		g = i
		break
q = (n - g - 1) * (n - g) // 2
l = 0
r = n - 1
while l < g and r >= g:
	if c[l] + c[r] > 0:
		q = q + g - l
		r = r - 1
	else:
		l = l + 1
print(q)


def lower_bound(array, x, low=0, high=None):
	if len(array) == 0:
		return 0
	if high == None:
		high = len(array)
	while low < high:
		mid = (low + high) // 2
		if x < array[mid]:
			high = mid
		else:
			low = mid + 1
	return low
n = int(input())
ass = list(map(int, input().split()))
bss = list(map(int, input().split()))
for i in range(n):
	ass[i] -= bss[i]
ass = sorted(ass)
negs = lower_bound(ass, -0.5)
zeros = ass.count(0)
ans = (n - negs - zeros) * (n - negs - 1 - zeros) // 2
for i in ass:
	if i >= 0:
		break
	req = abs(i) + 0.9
	k = lower_bound(ass, req)
	this = n - k + 1
	if ass[k - 1] != req:
		this -= 1
	ans += this
print(ans + zeros * (n - negs - zeros))


n = int(input())
teacher = [int(x) for x in input().split()]
student = [int(x) for x in input().split()]
pos = []
neg = []
arr = []
zeros = 0
for i in range(n):
	arr.append(teacher[i] - student[i])
arr.sort()
for num in arr:
	if num < 0:
		neg.append(abs(num))
	elif num > 0:
		pos.append(num)
	else:
		zeros += 1
p = len(pos)
ans = p * (p - 1) // 2
if zeros:
	ans += zeros * p
i = len(neg) - 1
cnt = 0
for pnum in pos:
	while i >= 0 and neg[i] < pnum:
		cnt += 1
		i -= 1
	ans += cnt
print(ans)


import collections
import bisect
local = False
if local:
	file = open('A.txt', 'r')

def IN():
	if local:
		return file.readline().rstrip()
	else:
		return input().rstrip()

def solve(a, b):
	diffs = [x[0] - x[1] for x in zip(a, b)]
	diffs.sort()
	ans = 0
	for i in range(len(diffs)):
		if diffs[i] <= 0:
			pos = bisect.bisect_left(diffs, -diffs[i] + 1)
			ans += len(diffs) - pos
		else:
			ans += len(diffs) - i - 1
	return ans
n = int(IN())
a = [int(_) for _ in IN().split()]
b = [int(_) for _ in IN().split()]
print(solve(a, b))


n = int(input())
a = map(int, input().split())
b = map(int, input().split())
c = list(map(lambda x, y: x - y, a, b))
c.sort()
c = c[::-1]
sol = 0
j = n - 1
for i in range(n - 1):
	if j <= i:
		j = i + 1
	while j > i and c[i] + c[j] <= 0:
		j -= 1
	if j <= i:
		break
	sol += j - i
print(sol)


n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
d = [a[i] - b[i] for i in range(n)]
d.sort()
i = 0
j = n - 1
r = 0
while i != j:
	if d[i] + d[j] > 0:
		j -= 1
		r += 1
	else:
		i += 1
		r += n - 1 - j
r += (n - 1 - i) * (n - 2 - i) // 2
print(r)


import sys
import bisect
input = sys.stdin.readline

def main():
	N = int(input())
	A = [int(x) for x in input().split()]
	B = [int(x) for x in input().split()]
	x = []
	for (a, b) in zip(A, B):
		x.append(a - b)
	x.sort()
	ans = 0
	for v in x:
		if v > 0:
			ans += N - bisect.bisect_right(x, -v) - 1
		else:
			ans += N - bisect.bisect_right(x, -v)
	print(ans // 2)
main()


def upper_bound(arr, target, i, j):
	while i < j:
		mid = int(i + (j - i) / 2)
		if target >= arr[mid]:
			i = mid + 1
		else:
			j = mid
	if arr[i] > target:
		return i
	else:
		return i + 1
L = int(input())
A = list(map(int, input().strip().split()))
B = list(map(int, input().strip().split()))
C = [i - k for (i, k) in zip(A, B)]
C.sort()
ret = 0
for i in range(len(C)):
	pos = upper_bound(C, -C[i], 0, len(C) - 1)
	ret += len(C) - pos
for i in range(len(C)):
	if C[i] > 0:
		ret -= 1
print(ret // 2)


import bisect
import io, os
import sys
input = sys.stdin.readline
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
z = [a[i] - b[i] for i in range(n)]
z.sort()
t = 0
for (i, d) in enumerate(z[:-1]):
	h = bisect.bisect(z, -d, i + 1)
	t += n - h
print(t)


def bada(ls, num, ln):
	i = 0
	h = ln - 1
	res = ln
	while i <= h:
		m = (i + h) // 2
		if ls[m] > num:
			res = m
			h = m - 1
		else:
			i = m + 1
	return res
g = {}
l = {}
lg = 0
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
neg = []
pos = []
z_c = 0
for i in range(n):
	x = a[i] - b[i]
	if x > 0:
		pos.append(x)
	elif x == 0:
		z_c += 1
	else:
		neg.append(x)
ln_pos = len(pos)
count = ln_pos * z_c + (ln_pos - 1) * ln_pos // 2
pos = sorted(pos)
for num in neg:
	count += ln_pos - bada(pos, abs(num), ln_pos)
print(count)


from sys import stdin
import bisect

def main():
	readline = stdin.readline
	n = int(readline())
	a = list(map(int, readline().split()))
	b = list(map(int, readline().split()))
	s = [0] * n
	for i in range(n):
		s[i] = a[i] - b[i]
	s.sort()
	t = [-x for x in s]
	zero_ika = 0
	for i in range(n):
		if t[i] <= 0:
			zero_ika += 1
		else:
			break
	count = 0
	for i in range(n - 1):
		l = i
		r = n
		if l == r - 1:
			if s[i] > t[l]:
				count += 1
		else:
			while l < r - 1:
				m = (l + r) // 2
				if t[m] >= s[i]:
					l = m
				else:
					r = m
			count += n - r
	print(count)
main()


from bisect import bisect_left
import os
import sys
from io import BytesIO, IOBase
from collections import Counter, defaultdict
from collections import deque
from functools import cmp_to_key
import math

def sin():
	return input()

def ain():
	return list(map(int, sin().split()))

def sain():
	return input().split()

def iin():
	return int(sin())
MAX = float('inf')
MIN = float('-inf')
MOD = 1000000007

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
	s = set()
	for p in range(2, n + 1):
		if prime[p]:
			s.add(p)
	return s

def readTree(n, m):
	adj = [deque([]) for _ in range(n + 1)]
	for _ in range(m):
		(u, v) = ain()
		adj[u].append(v)
		adj[v].append(u)
	return adj

def solve(c1, c2, maxi1, maxi2):
	for i in range(1, maxi1 + 1):
		if i not in c1:
			return False
	for i in range(1, maxi2 + 1):
		if i not in c2:
			return False
	return True

def main():
	n = iin()
	a = ain()
	b = ain()
	d1 = deque()
	d2 = deque()
	for i in range(n):
		d1.append(a[i] - b[i])
		d2.append(b[i] - a[i])
	d2 = sorted(d2)
	ans = 0
	for i in d1:
		ans += bisect_left(d2, i)
		if i > 0:
			ans -= 1
	print(ans // 2)
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')
if os.getcwd() == 'D:\\code':
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
	input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
diffs = []
for i in range(n):
	diffs.append(a[i] - b[i])
diffs.sort()
mp = {}
res = 0
for i in range(n):
	lo = i + 1
	hi = n - 1
	best = n
	while lo <= hi:
		mid = lo + hi >> 1
		if diffs[i] + diffs[mid] > 0:
			best = min(best, mid)
			hi = mid - 1
		else:
			lo = mid + 1
	res += n - best
print(res)


import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub
sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2 ** 62 - 1

def read_int():
	return int(input())

def read_int_n():
	return list(map(int, input().split()))

def read_float():
	return float(input())

def read_float_n():
	return list(map(float, input().split()))

def read_str():
	return input().strip()

def read_str_n():
	return list(map(str, input().split()))

def error_print(*args):
	print(*args, file=sys.stderr)

def mt(f):
	import time

	def wrap(*args, **kwargs):
		s = time.time()
		ret = f(*args, **kwargs)
		e = time.time()
		error_print(e - s, 'sec')
		return ret
	return wrap

@mt
def slv(N, A, B):
	C = [a - b for (a, b) in zip(A, B)]
	C.sort()
	ans = 0
	for (i, c) in enumerate(reversed(C)):
		j = bisect.bisect_right(C, -c, 0, N - i - 1)
		ans += N - i - 1 - j
	return ans

def main():
	N = read_int()
	A = read_int_n()
	B = read_int_n()
	print(slv(N, A, B))
main()


from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
from itertools import permutations, combinations, groupby
import functools
import sys
import bisect
import string
import math
import time
import random

def Golf():
	(*a,) = map(int, open(0))

def I():
	return int(input())

def S_():
	return input()

def IS():
	return input().split()

def LS():
	return [i for i in input().split()]

def LI():
	return [int(i) for i in input().split()]

def LI_():
	return [int(i) - 1 for i in input().split()]

def NI(n):
	return [int(input()) for i in range(n)]

def NI_(n):
	return [int(input()) - 1 for i in range(n)]

def StoLI():
	return [ord(i) - 97 for i in input()]

def ItoS(n):
	return chr(n + 97)

def LtoS(ls):
	return ''.join([chr(i + 97) for i in ls])

def GI(V, E, Directed=False, index=0):
	org_inp = []
	g = [[] for i in range(n)]
	for i in range(E):
		inp = LI()
		org_inp.append(inp)
		if index == 0:
			inp[0] -= 1
			inp[1] -= 1
		if len(inp) == 2:
			(a, b) = inp
			g[a].append(b)
			if not Directed:
				g[b].append(a)
		elif len(inp) == 3:
			(a, b, c) = inp
			aa = (inp[0], inp[2])
			bb = (inp[1], inp[2])
			g[a].append(bb)
			if not Directed:
				g[b].append(aa)
	return (g, org_inp)

def GGI(h, w, search=None, replacement_of_found='.', mp_def={'#': 1, '.': 0}):
	mp = [1] * (w + 2)
	found = {}
	for i in range(h):
		s = input()
		for char in search:
			if char in s:
				found[char] = (i + 1) * (w + 2) + s.index(char) + 1
				mp_def[char] = mp_def[replacement_of_found]
		mp += [1] + [mp_def[j] for j in s] + [1]
	mp += [1] * (w + 2)
	return (h + 2, w + 2, mp, found)

def TI(n):
	return GI(n, n - 1)

def bit_combination(k, n=2):
	rt = []
	for tb in range(n ** k):
		s = [tb // n ** bt % n for bt in range(k)]
		rt += [s]
	return rt

def show(*inp, end='\n'):
	if show_flg:
		print(*inp, end=end)
YN = ['YES', 'NO']
Yn = ['Yes', 'No']
mo = 10 ** 9 + 7
inf = float('inf')
l_alp = string.ascii_lowercase
input = lambda : sys.stdin.readline().rstrip()

def ran_input():
	n = random.randint(4, 16)
	(rmin, rmax) = (1, 10)
	a = [random.randint(rmin, rmax) for _ in range(n)]
	return (n, a)
show_flg = False
show_flg = True
for _ in range(1):
	n = I()
	a = LI()
	b = LI()
	c = [(a[i] - b[i], b[i] - a[i]) for i in range(n)]
	c = sorted(c, key=lambda x: x[1])
	x = [i for (i, j) in c]
	y = [j for (i, j) in c]
	ans = 0
	for i in range(n):
		f = x[i]
		z = bisect.bisect_left(y, f)
		z = max(z - i - 1, 0)
		if x[i] == 0:
			0
		ans += z
	print(ans)


from math import *
from copy import *
from string import *
from random import *
from bisect import *
from sys import stdin
from sys import maxsize
from operator import *
from itertools import *
from collections import Counter
from collections import defaultdict

def solve(A, B):
	n = len(A)
	diff = [0] * n
	for i in range(n):
		diff[i] = A[i] - B[i]
	diff = sorted(diff)
	ans = 0
	for i in range(n - 1):
		zz = 0
		if diff[i] <= 0:
			zz = bisect_left(diff, abs(diff[i]) + 1, i + 1)
		else:
			zz = bisect_left(diff, 0, i + 1)
		ans += n - zz
	return ans
N = int(input())
a = list(map(int, stdin.readline().rstrip().split()))
b = list(map(int, stdin.readline().rstrip().split()))
print(solve(a, b))


import sys
import os
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))
input = lambda : sys.stdin.readline().rstrip('\r\n')
mod = 10 ** 9 + 7

def lcm(x, y):
	return x * y / gcd(x, y)

def fact(x, mod=mod):
	ans = 1
	for i in range(1, x + 1):
		ans = ans * i % mod
	return ans

def arr2D(n, m, default=0):
	return [[default for j in range(m)] for i in range(n)]

def arr3D(n, m, r, default=0):
	return [[[default for k in range(r)] for j in range(m)] for i in range(n)]

def sortDictV(x):
	return {k: v for (k, v) in sorted(x.items(), key=lambda item: item[1])}

class DSU:

	def __init__(self, length):
		self.length = length
		self.parent = [-1] * self.length

	def getParent(self, node, start):
		if node >= self.length:
			return False
		if self.parent[node] < 0:
			if start != node:
				self.parent[start] = node
			return node
		return self.getParent(self.parent[node], start)

	def union(self, node1, node2):
		parent1 = self.getParent(node1, node1)
		parent2 = self.getParent(node2, node2)
		if parent1 == parent2:
			return False
		elif self.parent[parent1] <= self.parent[parent2]:
			self.parent[parent1] += self.parent[parent2]
			self.parent[parent2] = parent1
		else:
			self.parent[parent2] += self.parent[parent1]
			self.parent[parent1] = parent2
		return True

	def getCount(self, node):
		return -self.parent[self.getParent(node, node)]
from bisect import bisect_left as bs

def solve(n, a, b):
	diff = [a[i] - b[i] for i in range(n)]
	diff = sorted(diff)
	cnt = 0
	for i in range(n):
		ind = bs(diff, b[i] - a[i] + 1)
		if a[i] - b[i] >= b[i] - a[i] + 1:
			cnt -= 1
		cnt += n - ind
	return cnt // 2
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
print(solve(n, a, b))


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
p = []
o = []
for i in range(n):
	d = a[i] - b[i]
	if d > 0:
		p.append(d)
	else:
		o.append(d)
ne = len(p)
ans = 0
if ne > 1:
	ans += (ne - 1) * ne // 2
pp = ne
ne = len(o)
if ne == n:
	print(0)
	exit()
p.sort()
o.sort(reverse=True)
lst = 0
n = ne
for i in range(n):
	f = False
	for j in range(lst, pp):
		lst = j
		if p[j] > abs(o[i]):
			f = True
			break
	ne = pp - lst
	if ne > 0 and f:
		ans += ne
print(ans)


from bisect import bisect_left
n = int(input())
t1 = list(map(int, input().split()))
t2 = list(map(int, input().split()))
t = []
w = 0
count = n
for x in range(0, n):
	t.append(t1[x] - t2[x])
t = sorted(t)
for x in range(0, n):
	if t[x] <= 0:
		szuk = abs(t[x]) + 1
	else:
		count = x
		break
	w += n - bisect_left(t, szuk)
w += (n - count) * (n - count - 1) // 2
print(w)


def lowermax(low, high, key, c):
	ans = high + 1
	while low <= high:
		mid = (low + high) // 2
		if c[mid] >= key:
			ans = mid
			high = mid - 1
		else:
			low = mid + 1
	return ans
n = int(input())
for ii in range(1):
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	c = [b[i] - a[i] for i in range(0, len(a))]
	ans = 0
	c.sort()
	for i in range(0, len(a)):
		end = lowermax(i + 1, len(a) - 1, -c[i], c)
		if end != -100:
			ans += end - 1 - i
	print(ans)


n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
arr = []
for i in range(n):
	arr.append(a[i] - b[i])
arr.sort()
ans = 0
(l, r) = (0, n - 1)
while l < r:
	if arr[l] + arr[r] > 0:
		ans += r - l
		r -= 1
	else:
		l += 1
print(ans)


def binarysearch(arr, end, key):
	l = 0
	r = end - 1
	leftGreater = end
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] > key:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return end - leftGreater
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = []
for k in range(n):
	c.append(a[k] - b[k])
c.sort()
ans = 0
for i in range(n):
	if c[i] <= 0:
		continue
	key = c[i] - 2 * c[i]
	ind = binarysearch(c, i, key)
	ans = ans + ind
print(ans)


x = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
pos = []
neg = []
zer = 0

def bns(s, x):
	hi = len(s) - 1
	lo = 0
	res = 0
	while hi >= lo:
		mid = (hi + lo) // 2
		if s[mid] <= x:
			res = mid + 1
			lo = mid + 1
		else:
			hi = mid - 1
	return res
for n in range(x):
	d = a[n] - b[n]
	if d == 0:
		zer += 1
	elif d > 0:
		pos.append(d)
	else:
		neg.append(abs(d))
neg.sort()
res = len(pos) * (len(pos) - 1) // 2
res += zer * len(pos)
for n in pos:
	res += bns(neg, n - 1)
print(res)


import math
from sys import stdin
input = stdin.readline
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
d = []
for i in range(n):
	d.append(a[i] - b[i])
d.sort(reverse=True)
c = 0
l = -1
for i in range(n):
	if d[i] > 0:
		while d[l] + d[i] <= 0:
			l = l - 1
		c = c + (n - i + l)
	else:
		break
print(c)


import sys
from bisect import bisect_left
x0 = sys.stdin.readline()
n = int(x0)
x1 = sys.stdin.readline()
x2 = sys.stdin.readline()
l1 = [int(x) for x in x1.split(' ')]
l2 = [int(x) for x in x2.split(' ')]
l3 = [l1[i] - l2[i] for i in range(n)]
l3 = sorted(l3)
cnt = 0
for i in range(n):
	if l3[i] > 0:
		cnt += i - bisect_left(l3, -(l3[i] - 1))
print(cnt)


import bisect
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for j in range(n):
	a[j] -= b[j]
a.sort()
total = 0
for j in range(n):
	if a[j] > 0:
		count = n - j
		total += count * (count - 1) // 2
		break
	else:
		element = abs(a[j]) + 1
		pos = bisect.bisect_left(a, element)
		total += n - pos
print(total)


import bisect

def f(n):
	return n * (n + 1) // 2
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [a[i] - b[i] for i in range(n)]
c.sort()
ans = 0
for i in range(n):
	x = 1 - c[i]
	j = bisect.bisect_left(c, x, i + 1, n)
	ans += n - j
print(ans)


n = int(input())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
cl = []
for (a, b) in zip(al, bl):
	cl.append(a - b)
import bisect
ans = 0
cl = sorted(cl)
for c in cl:
	idx = bisect.bisect(cl, -c)
	if c > 0:
		ans -= 1
	ans += n - idx
print(ans // 2)


n = int(input())
a = list(map(lambda x: int(x), input().split()))
b = list(map(lambda x: int(x), input().split()))
diff = [b[x] - a[x] for x in range(n)]
diff.sort()
left = 0
right = n - 1
ret = 0
while left <= right:
	while left <= right and diff[left] + diff[right] < 0:
		ret += right - left
		left += 1
	while left <= right and diff[left] + diff[right] >= 0 and (left <= right):
		right -= 1
print(ret)


n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
a = [x[i] - y[i] for i in range(n)]
a.sort()
ans = 0
i = 0
j = n - 1
while i != j:
	if a[i] + a[j] > 0:
		ans += j - i
		j -= 1
	else:
		i += 1
print(ans)


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

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

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0 and x != 2 or x == 0:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = True
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)
n = int(z())
lst1 = zzz()
lst2 = zzz()
lst = []
for i in range(n):
	lst.append(lst1[i] - lst2[i])
lst = sorted(lst)
cnt = 0
(l, r) = (0, n - 1)
while l < r:
	if lst[l] + lst[r] > 0:
		cnt += r - l
		r -= 1
	else:
		l += 1
print(cnt)


n = int(input())
As = [int(i) for i in input().split(' ')]
Bs = [int(i) for i in input().split(' ')]
ds = [As[i] - Bs[i] for i in range(n)]
ds.sort()
ans = 0
i = 0
j = len(ds) - 1
while i < j:
	if ds[j] <= 0:
		break
	ubi = j
	lbi = i
	c = 0
	while lbi < ubi:
		mid = (lbi + ubi) // 2
		if ds[mid] + ds[j] > 0:
			ubi = mid
		else:
			if lbi == mid:
				break
			lbi = mid
	i = ubi
	ans += max(j - ubi, 0)
	j -= 1
print(ans)


from operator import sub
from bisect import bisect_right

def main():
	nTopics = int(input())
	differencesInInterest = list(map(sub, map(int, input().split()), map(int, input().split())))
	differencesInInterest.sort()
	return nGoodPairsOfTopics(nTopics, differencesInInterest)

def nGoodPairsOfTopics(nTopics, differencesInInterest):
	if differencesInInterest[-1] < 1:
		return 0
	iLast = bisect_right(differencesInInterest, 0) - 1
	return sum((i - bisect_right(differencesInInterest, -differencesInInterest[i]) for i in range(nTopics - 1, iLast, -1)))
print(main())


def go():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	dif = sorted((aa - bb for (aa, bb) in zip(a, b)))
	j = n - 1
	res = 0
	for (i, d) in enumerate(dif):
		while j > -1 and d + dif[j] > 0:
			j -= 1
		res += n - 1 - j
		if j < i:
			res -= 1
	return res // 2
for _ in range(1):
	print(go())