inline fun CharSequence.countIndexed(predicate: (index: Int, Char) -> Boolean): Int {
    var count = 0
    var index = 0
    for (element in this) if (predicate(index++, element)) ++count
    return count
}

fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val ff = Array(n) { readLine()!!.split(' ').map { it == "1" } }
    val pp = Array(n) { readLine()!!.split(' ').map(String::toInt) }
    var ans = Int.MIN_VALUE
    for (i in 1..1023) {
        val ot = Integer.toString(i, 2)
        var ur = 0
        for (j in 0 until n) {
            val f = ff[j]
            val p = pp[j]
            val cnt = ot.countIndexed { k, c -> c == '1' && f[k] }
            ur += p[cnt]
        }
        ans = Math.max(ans, ur)
    }
    println(ans)
}
