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

Difficulty: introductory

Starter code:

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


def __starting_point():
    main()

__starting_point()

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)


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()))]
#print(y)
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)

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)


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)

#!/usr/bin/env python3
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 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 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


# t = int(input())
for _ in range(1):
    print(go())


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)


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)


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)

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)

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

def __starting_point():
    solve()
__starting_point()

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()))
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
    # print(ans)
    p1 -= 1
print(ans)