import scala.io.StdIn

object Main extends App {

  val n = StdIn.readInt
  val f = Iterator.continually(StdIn.readLine)
    .take(n)
    .map(_.split(" ").map(_.toInt))
    .toArray
  val p = Iterator.continually(StdIn.readLine)
    .take(n)
    .map(_.split(" ").map(_.toInt))
    .toArray

  val MIN = Int.MinValue

  val ans =
    (1 until 1 << 10)./:(MIN)((ans,key) => {
      val itp = p.iterator
      val score = 
        f./:(0)((fac,fe) => {
          val itf = fe.iterator
          val arr = itp.next
          val d = (0 until 10)./:(0)((acc,i) => {
            if(((key>>i & 1) & itf.next) == 1) acc + 1
            else acc
          })
          fac + arr(d)
        })
      math.max(ans, score)
    })

  println(ans)
}