fun main() {
    val n = readLine()!!.toInt()
    val a = readInts()
    val b = readInts()
    if (profile(a) != profile(b)) {
        println(-1)
        return
    }
    val ops = solve(a, b).toList()
    println(ops.size)
    println(ops.joinToString(separator = " ") { "${it + 1}" })
}

fun profile(a: List<Int>) = (0 until a.lastIndex).map { a.indexOf(it) < a.indexOf(it + 1) }

fun solve(a: MutableList<Int>, b: MutableList<Int>): Sequence<Int> = sequence {
    if (a == b) {
        return@sequence
    }
    val n = a.size
    val startValue = n - 1
    val pos = a.indexOf(startValue)
    val posNext = a.indexOf(startValue - 1)
    val finalPos = b.indexOf(startValue)

    a.removeAt(pos)
    b.removeAt(finalPos)

    if (pos < posNext) {
        yieldAll(moveLeft(pos, 0))
        yieldAll(solve(a, b).map { it + 1 })
        yieldAll(moveRight(0, finalPos))
    } else {
        yieldAll(moveRight(pos, n - 1))
        yieldAll(solve(a, b))
        yieldAll(moveLeft(n - 1, finalPos))
    }
}

fun moveLeft(pos: Int, left: Int) = (pos - 1 downTo left).toList()
fun moveRight(pos: Int, right: Int) = (pos..right - 1).toList()

fun readInts() = readLine()!!.split(" ").map { it.toInt() - 1 }.toMutableList()