fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val fs = Array(n, { readLine()!!.replace(" ", "").let { Integer.parseInt(it, 2) } })
    val pMat = Array(n, { readLine()!!.split(" ").map(String::toInt) })
    val ans = (1 until 1024).map { x -> (0 until n).map { pMat[it][bitCount(x.and(fs[it]))] }.sum() }.max()
    println(ans)
}

fun bitCount(x: Int): Int {
    return Integer.toString(x, 2).filter { it == '1' }.length
}
