fun input() = readLine()!!.split(" ")

fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    var F = IntArray(N, {0})
    for (n in 0..N-1) {
        F[n] = readLine()!!.replace(" ", "").reversed().toInt()
    }
    var P = Array(N, { Array(11, { 0 }) })
    for (n in 0..N - 1) {
        for ((id, v) in readLine()!!.split(" ").map { it.toInt() }.withIndex()) {
            P[n][id] = v
        }
    }
    val max = (1 until 1.shl(10))
            .map { state ->
                F.map { it and state }
                        .map { Integer.bitCount(it) }
                        .mapIndexed { index, count -> P[index][count] }
                        .sum()
            }.max()
    println(max)
}