from math import sqrt,sin,cos,tan,ceil,radians,floor,gcd,exp,log,log10,log2,factorial,fsum from heapq import heapify, heappop, heappush from bisect import bisect_left, bisect_right from copy import deepcopy import copy import random from random import randrange from collections import deque,Counter,defaultdict from itertools import permutations,combinations from decimal import Decimal,ROUND_HALF_UP #tmp = Decimal(mid).quantize(Decimal('0'), rounding=ROUND_HALF_UP) from functools import lru_cache, reduce #@lru_cache(maxsize=None) from operator import add,sub,mul,xor,and_,or_,itemgetter import sys #input = sys.stdin.readline # .rstrip() INF = 10**18 mod1 = 10**9+7 mod2 = 998244353 #DecimalならPython #再帰ならPython!!!!!!!!!!!!!!!!!!!!!!!!!! ''' Bi < Bj 交換した結果、逆転するといくない 荷物が重いといくない 今までの区間で一番大きい値を持っておく 荷物が軽いほうが良い 体重は重いほうがよくて、荷物は軽いほうがいい 体重-荷物がでかいやつ 二分探索が必要か? 単調増加 2 4 5 8 2 1 6 2 [1,2],[3,4] 右のほうがでかくなるはずなんだよな 絶対に ただの尺取じゃね ''' N = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) i = 0 j = 1 ans = 0 while i < N: while j < N: b1 = max(B[i],B[j]) b2 = min(B[i],B[j]) if A[i]+b1 < A[j]+b2: ans += j-i else: break j += 1 if j <= i: j += 1 else: i += 1 print(ans)