fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val fs = (0 until n).map {
        val f = readLine()!!.split(' ').map { it.toInt() }
        f.mapIndexed { i, v -> v shl i }.sum()
    }.toIntArray()
    val ps = (0 until n).map {
        readLine()!!.split(' ').map { it.toInt() }.toIntArray()
    }.toTypedArray()

    val dp = IntArray((1 shl 10)) { Int.MIN_VALUE }
    for (i in 1 until (1 shl 10)) {
        var p = 0
        for (j in 0 until n) {
            var x = fs[j] and i
            var cnt = 0
            while (x > 0) {
                cnt += x and 1
                x = x shr 1
            }
            p += ps[j][cnt]
        }
        dp[i] = Math.max(p, dp[i - 1])
    }

    println(dp.last())
}
