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

  var ans = Int.MinValue
  val a = Array.ofDim[Int](10)

  def evaluate():Unit = {
    if(!a.forall(_ == 0)) {
      val itp = p.iterator
      val score = 
        f./:(0)((fcc,fe) => {
          val itf = fe.iterator
          val arr = itp.next
          val s = a./:(0)((acc, e) => {
            if((e & itf.next) == 1) acc+1
            else acc
          })
          fcc + arr(s)
        })
      ans = math.max(ans, score)
    }
  }

  def dfs(pos:Int):Unit = {
    if(pos == 10) evaluate()
    else {
      a(pos) = 0; dfs(pos+1)
      a(pos) = 1; dfs(pos+1)
    }
  }

  dfs(0)
  println(ans)
}