object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt()
  val m = 10
  val f = Array.fill(n * m)(sc.nextInt())
  val p = Array.fill(n * (m+1))(sc.nextInt())

  var ans = Long.MinValue
  for (s <- 1 until 1 << m) {
    var ansSub = 0L
    for (i <- 0 until n) {
      val count = (0 until m).count(j => ((s >> j) & f(i*m + j)) == 1)
      ansSub += p(i*(m+1) + count)
    }

    ans = ans.max(ansSub)
  }

  println(ans)
}