import java.io.BufferedReader import java.io.InputStream import java.io.InputStreamReader import java.io.PrintWriter import java.util.* fun compress(a: Array): Array { val n = a.count() val b = a.sorted().distinct().toTypedArray() val c = Array(n) { 0 } for (i in 0 until n) { c[i] = Arrays.binarySearch(b, a[i]) } return c } class BIT(private val n: Int) { private val data = LongArray(n) { 0 } fun add(i: Int, x: Long) { var p = i + 1 while (p <= n) { data[p - 1] += x p += p and -p } } fun sum(l: Int, r: Int): Long { return sum(r) - sum(l) } private fun sum(i: Int): Long { var r = i var s = 0L while(r > 0) { s += data[r - 1] r -= r and -r } return s } } fun inversionNumber(a: Array): Long { val b = compress(a) val n = a.count() val bit = BIT(n) var ans = 0L for (i in 0 until n) { ans += i - bit.sum(0, b[i]) bit.add(b[i], 1) } return ans } fun PrintWriter.solve(sc: FastScanner) { val n = sc.nextInt() val a = Array(n) { sc.nextInt() } val b = Array(n) { sc.nextInt() } val new = Array(n + 1) { 0 } for (i in 0 until n) { new[b[i]] = i + 1 } for (i in 0 until n) { a[i] = new[a[i]] } println(inversionNumber(a)) } fun main() { val writer = PrintWriter(System.out, false) writer.solve(FastScanner(System.`in`)) writer.flush() } class FastScanner(s: InputStream) { private var st = StringTokenizer("") private val br = BufferedReader(InputStreamReader(s)) fun next(): String { while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine()) return st.nextToken() } fun nextInt() = next().toInt() fun nextLong() = next().toLong() fun nextLine() = br.readLine() fun nextDouble() = next().toDouble() fun ready() = br.ready() }