fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val fs = Array(n, { readLine()!!.replace(" ", "").toInt(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 x.toString(2).filter { it == '1' }.length
}