#region Header #!/usr/bin/env python3 # from typing import * import sys import io import math import collections import decimal import itertools import bisect import heapq def input(): return sys.stdin.readline()[:-1] sys.setrecursionlimit(1000000) #endregion # _INPUT = """3 # 2 2 2 # 1 5 3 # """ # sys.stdin = io.StringIO(_INPUT) # Range Add Query に対応 class BIT_RAQ: """ Binary Indexed Tree (Fenwick Tree), 1-indexed """ def __init__(self, n): """ Parameters ---------- n : int 要素数。index は 0..n になる。 """ self.size = n self.data = [[0]*(n+1) for _ in range(2)] self.depth = n.bit_length() def _add(self, p, i, x): assert p in [0, 1] assert 1 <= i <= self.size+1, 'i: out of range' while i <= self.size: self.data[p][i] += x i += i & -i def add(self, i, x): """ index i に add """ assert 1 <= i <= self.size+1, 'i: out of range' self._add(0, i, x) def radd(self, l, r, x): """ [l, r) に add """ assert 1 <= l <= self.size, 'l: out of range' assert l <= r <= self.size+1, 'r: out of range' self._add(0, l, -x * (l-1)) self._add(0, min(r+1, self.size+1), x * r) self._add(1, l, x) self._add(1, min(r+1, self.size+1), -x) def _get_sum(self, p, i): assert p in [0, 1] assert 0 <= i <= self.size+1, 'i: out of range' s = 0 while i > 0: s += self.data[p][i] i -= i & -i return s def get_sum(self, i): """ [1,i) の sum """ assert 0 <= i <= self.size+1, 'i: out of range' return self._get_sum(0, i) + self._get_sum(1, i) * i def get_rsum(self, l, r): """ [l, r) の sum """ assert 1 <= l <= self.size, 'l: out of range' assert l <= r <= self.size+1, 'r: out of range' return self.get_sum(r) - self.get_sum(l-1) def get_value(self, i): """ index i の値 """ assert 1 <= i <= self.size+1, 'i: out of range' return self.get_sum(i) - self.get_sum(i-1) def lower_bound(self, x): """ 累積和が x 以上になる最小の index """ sum_ = 0 pos = 0 for i in range(self.depth, -1, -1): k = pos + (1 << i) if k <= self.size and sum_ + self.data[k] < x: sum_ += self.data[k] pos += 1 << i return pos + 1 def main(): N = int(input()) A = sorted(list(map(int, input().split()))) B = list(map(int, input().split())) bit = BIT_RAQ(N+1) for i in range(N): j = max(bisect.bisect_right(A, B[i]), i) bit.radd(j+1, N+1, 1) ans = bit.get_sum(N) print(ans) if __name__ == '__main__': main()