import scala.io.StdIn

object Main extends App {

  val n = StdIn.readLine().toInt

  val shops = (0 until n).map { _ =>
    StdIn.readLine().split(' ').map(_.toInt)
  }.toArray

  val p = (0 until n).map { _ =>
    StdIn.readLine().split(' ').map(_.toInt)
  }.toArray

  var res = Int.MinValue
  for (b <- 1 until (1 << 10)) {
    //println(b.toBinaryString)
    var cc = 0
    (0 until n).foreach { i =>
      var c = 0
      (0 until 10).foreach { k =>
        //println("::" + ((b >> k) & 1).toBinaryString)
        c += (if (((b >> k) & 1) == 1 && shops(i)(k) == 1) 1 else 0)
      }
      cc += p(i)(c)
    }
    res = if (res < cc) cc else res
  }

  println(res)
}