fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val F = mutableListOf<IntArray>()
    val P = mutableListOf<IntArray>()
    (1..N).forEach {
        F.add(readLine()!!.split(" ").map { it.toInt() }.toIntArray())
    }
    (1..N).forEach {
        P.add(readLine()!!.split(" ").map { it.toInt() }.toIntArray())
    }


    var benefit = Int.MIN_VALUE
    (1..(1.shl(10) - 1)).forEach { bit ->
        var localBenefit = 0
        val myOpenInfo = (0..9).map {
            val isIthOpen = bit.shr(it).and(1)
            isIthOpen
        }

        (0..(N-1)).forEach { shopIndex ->
            val shopOpenInfo = F[shopIndex]
            var c = 0
            (0..9).forEach {
                if (myOpenInfo[it] == 1 && shopOpenInfo[it] == 1) {
                    c++
                }
            }

            localBenefit += P[shopIndex][c]
        }
        benefit = Math.max(benefit, localBenefit)
    }

    println(benefit)
}