fun make(candidate: List<Int>, perm: List<Int>): List<Int> {
    if (candidate.isEmpty()) {
        return listOf(perm.reduce { a, b ->
            a * 10 + b
        })
    }
    return candidate.indices.map { i ->
        val p = perm.toMutableList()
        val c = candidate.toMutableList()
        p.add(c[i])
        c.removeAt(i)
        make(c, p)
    }.flatten()
}

fun main(args: Array<String>) {
    val n = readLine()?.toInt() ?: return
    val p = readLine()?.replace(" ", "")?.toInt() ?: return
    val q = readLine()?.replace(" ", "")?.toInt() ?: return

    val data = 1.until(n + 1).map { it }
    val list = make(data, mutableListOf()).sortedDescending()
    val pi = list.indexOf(p)
    val qi = list.indexOf(q)
    val result = Math.abs(pi - qi)
    println(result)
}
