import sys,random,bisect from collections import deque,defaultdict from heapq import heapify,heappop,heappush from itertools import permutations from math import log,gcd input = lambda :sys.stdin.readline().rstrip() mi = lambda :map(int,input().split()) li = lambda :list(mi()) def solve(N,A,B): r = -1 M = [] del_M = [] m = [] del_m = [] res = 0 for l in range(N): if r==l-1: heappush(M,-(A[l]+B[l])) heappush(m,-(A[l]-B[l])) r = l while del_M and M[0]==del_M[0]: heappop(M) heappop(del_M) while del_m and m[0]==del_m[0]: heappop(m) heappop(del_m) while r!=N-1: if -M[0] < A[r+1]+B[r+1] and -m[0] < A[r+1]-B[r+1]: heappush(M,-(A[r+1]+B[r+1])) heappush(m,-(A[r+1]-B[r+1])) r += 1 else: break #print(l,r,M,m) res += r-l heappush(del_M,-(A[l]+B[l])) heappush(del_m,-(A[l]-B[l])) return res def brute(N,A,B): res = 0 for l in range(N): for r in range(l+1,N): if all(A[i]+B[i] < A[i+1]+B[i+1] for i in range(l,r)) and all(A[i]-B[i] < A[i+1]-B[i+1] for i in range(l,r)): res += 1 return res while False: N = 3 A = [random.randint(1,20) for i in range(N)] B = [random.randint(1,20) for i in range(N)] A.sort() print(A) print(B) print(solve(N,A,B),brute(N,A,B)) assert solve(N,A,B)==brute(N,A,B) N = int(input()) A = li() B = li() print(solve(N,A,B))