using System; public class BIT { private int[] data; private int n; public BIT(int n) { this.n = n; data = new int[n + 1]; } public int getSum(int i) { var s = 0; while (i > 0) { s += data[i]; i -= i & -i; } return s; } public void addix(int i, int x) { while (i <= n) { data[i] += x; i += i & -i; } } } public class hello { static void Main() { var n = int.Parse(Console.ReadLine().Trim()); string[] line = Console.ReadLine().Trim().Split(' '); var a = Array.ConvertAll(line, int.Parse); line = Console.ReadLine().Trim().Split(' '); var b = Array.ConvertAll(line, int.Parse); getAns(n, a, b); } static void getAns(int n, int[] a, int[] b) { var rb = new int[n + 1]; for (int i = 0; i < n; i++) rb[b[i]] = i + 1; var c = new int[n]; for (int i = 0; i < n; i++) c[i] = rb[a[i]]; getINV(n, c); } static void getINV(int n, int[] a) { var bit = new BIT(n); var ans = 0L; bit.addix(a[0], 1); for (int i = 1; i < n; i++) { bit.addix(a[i], 1); ans += i + 1 - bit.getSum(a[i]); } Console.WriteLine(ans); } }