fun main(args:Array<String>?): Unit {
    readLine()
    val wise = readLine()!!.trim().split(' ').map{it == "0"}
    val hate = readLine()!!.trim().split(' ').map(String::toInt)
    val rights = wise.indices.filter{wise[it]}.map{hate[it]}
    val lefts = wise.indices.filterNot{wise[it]}.map{hate[it]}
    val fromRight = rights.min() ?: 0
    val fromLeft = lefts.min() ?: 0
    println(
            if (rights.isEmpty() || lefts.isEmpty()) 0 else fromRight + fromLeft
    )
}
