fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val F = Array(N) { readLine()!!.split(" ").map{it.toInt()}}
    val P = Array(N) { readLine()!!.split(" ").map{it.toLong()}}

    var res = -1e16.toLong()

    for (s in 1 until (1 shl 10)) {
        var t = 0L
        val u = Array(10) { (s shr it) and 1 }

        for (i in F.indices) {
            val c = F[i].indices.count { F[i][it] == 1 && F[i][it] == u[it] }
            t += P[i][c]
        }
        res = Math.max(res, t)
    }

    println(res)
}
