from heapq import * def main(): n = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) i = ans = 0 while i < n: j = i while j < n-1: if A[j]+B[j] < A[j+1]+B[j+1] and A[j]+B[j+1] < A[j+1]+B[j]: j += 1 else: break c = j-i+1 ans += c*(c-1)//2 i = j+1 return ans 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())