import java.util.*

fun main(args: Array<String>) {
    abc080c()
}

fun abc080c() {
    val n = readLine()!!.toInt()
    val fList = (1..n).map { readLine()!!.split(" ").map { it[0] == '1' }.toBooleanArray() }.toTypedArray()
    val pList = (1..n).map { readLine()!!.split(' ').map { it.toLong() }.toLongArray() }.toTypedArray()

    var answer = Long.MIN_VALUE / 10

    for (i in 1L until bits(10)) {
        val bitSet = BitSet.valueOf(longArrayOf(i))

        val sum = fList.mapIndexed { index, f ->
            val count = f.withIndex().count { it.value && bitSet[it.index] }
            pList[index][count]
        }.sum()

        answer = Math.max(answer, sum)
    }

    println(answer)
}

private fun bits(x: Int): Int {
    var ret = 1
    repeat(x) { ret *= 2 }
    return ret - 1
}
