from bisect import bisect_left N = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) a.sort() t0 = [] t1 = [] result = 0 for i in range(N): j = bisect_left(t1, b[i]) t1 = t1[:j] + [b[i]] + t1[j:] result += bisect_left(t0, a[i]) result += bisect_left(t1, a[i]) if len(t1) == 100: t0.extend(t1) t0.sort() t1 = [] print(result)