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

fun strTo2Bit(inpt:String):Int {
    var num = 0
    var n = 1
    for(i in (inpt.indices).reversed()) {
        if(inpt[i] == '1') {
            num += n
        }
        n = (n shl 1)
    }
    return num
}

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)
                val kyotsuCount = count1bit(kyotsu)
                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
    }

    fun count1bit(num:Int):Int {
        return (0..11).filter { (num and (1 shl it)) != 0 }.count()
    }
}
