from heapq import * def main(): n = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) r = 0 ans = 0 hq0 = [] hq0_ = [] hq1 = [] hq1_ = [] for l in range(n): while l == r or (r < n and hq0[0] > -A[r]-B[r] and hq1[0] > -A[r]+B[r]): heappush(hq0, -A[r]-B[r]) heappush(hq1, -A[r]+B[r]) r += 1 ans += r-l-1 heappush(hq0_, -A[l]-B[l]) heappush(hq1_, -A[l]+B[l]) while hq0_ and hq0[0] == hq0_[0]: heappop(hq0) heappop(hq0_) while hq1_ and hq1[0] == hq1_[0]: heappop(hq1) heappop(hq1_) return ans print(main())