import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] aArr = new int[n]; for (int i = 0; i < n; i++) { aArr[i] = sc.nextInt(); } Arrays.sort(aArr); int[] bArr = new int[n]; for (int i = 0; i < n; i++) { bArr[i] = sc.nextInt(); } ArrayList used = new ArrayList<>(); used.add(Integer.MIN_VALUE); used.add(Integer.MAX_VALUE); long point = 0; for (int i = 0; i < n; i++) { int left = 0; int right = used.size(); while (right - left > 1) { int m = (left + right) / 2; if (used.get(m) < bArr[i]) { left = m; } else { right = m; } } used.add(right, bArr[i]); int min = 0; int max = used.size(); while (max - min > 1) { int m = (min + max) / 2; if (used.get(m) < aArr[i]) { min = m; } else { max = m; } } point += min; } System.out.println(point); } }