fun main(arr:Array<String>) {
    val n = readLine()!!.toInt()
    val mise = (1..n).map { readLine()!!.replace(" ", "").toInt(2) }
    val rieki = (1..n).map { readLine()!!.split(" ").map { it.toLong() } }
    val prc = Proc(n, mise, rieki)
    val ans = prc.getAns(0,0)
    println(ans)
}

class Proc(val miseCount:Int, val miseOpen:List<Int>, val rieki:List<List<Long>>) {
    fun getAns(idx:Int, subTotal:Int):Long {
        if(idx >= 10) {
            if(subTotal == 0) {
                return Long.MIN_VALUE
            }
            val ret = (0 until miseCount).map {msIndex ->
                val kyotsu = (miseOpen[msIndex] and subTotal).toString(2)
                val kyotsuCount = kyotsu.count { it == '1' }
                val r = rieki[msIndex][kyotsuCount]
                r
            }.sum()
            return ret
        }
        var ans = getAns(idx + 1, subTotal)
        ans = Math.max(ans, getAns(idx + 1, subTotal + (1 shl idx)))
        return ans
    }
}
