import java.util.*
import kotlin.math.max


fun intList() = readLine()?.split(" ")?.map(String::toInt) ?: TODO()
fun bitFullSearch(n: Int): List<BitSet> = (0 until (1 shl n)).map { bit ->
    BitSet(n).apply {
        repeat(n) { i ->
            set(i, bit and (1 shl i) > 0)
        }
    }
}

fun main() {
    val n = readLine()?.toInt() ?: return
    val ff = mutableListOf<List<Int>>()
    repeat(n) {
        val f = intList()
        ff.add(f)
    }
    val pp = mutableListOf<List<Int>>()
    repeat(n) {
        val p = intList()
        pp.add(p)
    }
    val bit = bitFullSearch(10)
    var m = Long.MIN_VALUE
    bit.drop(1).forEach { b ->
        var t = 0L
        ff.forEachIndexed { i, fff ->
            var c = 0
            fff.forEachIndexed { j, ffff ->
                if (b.get(j) && ffff == 1) {
                    c++
                }
            }
            t += pp[i][c]
        }
        m = max(m, t)
    }
    println(m.toString())
}