import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val f = IntArray(n) {
        (1..10).map { sc.nextInt() }
                .reduce { acc, i -> acc.shl(1) + i }
    }

    val p = Array(n) { IntArray(11) { sc.nextInt() } }

    println(p.joinToString { it.joinToString() })

    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)
}