import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.Arrays; import java.util.TreeMap; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); int n2 = n * 2; String[] sa = br.readLine().split(" "); int[] a = new int[n2]; for (int i = 0; i < n; i++) { a[i] = Integer.parseInt(sa[i]); } sa = br.readLine().split(" "); for (int i = 0; i < n; i++) { a[n + i] = Integer.parseInt(sa[i]); } br.close(); int[] b = zaatu(a); int[] c = Arrays.copyOf(b, n); Arrays.sort(c); BIT bit = new BIT(n2); long ans = 0; for (int i = 0; i < n; i++) { bit.add(b[n + i], 1); ans += bit.sum(c[i] - 1); } System.out.println(ans); } static int[] zaatu(int[] a) { TreeMap map = new TreeMap<>(); for (int i = 0; i < a.length; i++) { map.put(a[i], null); } Integer[] arr = map.keySet().toArray(new Integer[0]); int cnt = 0; for (Integer i : arr) { cnt++; map.put(i, cnt); } int[] b = new int[a.length]; for (int i = 0; i < a.length; i++) { b[i] = map.get(a[i]); } return b; } static class BIT { int n; long[] arr; public BIT(int n) { this.n = n; arr = new long[n + 1]; } void add(int idx, long val) { for (int i = idx; i <= n; i += i & -i) { arr[i] += val; } } long sum(int idx) { long sum = 0; for (int i = idx; i > 0; i -= i & -i) { sum += arr[i]; } return sum; } } }