n = gets.to_i
f = n.times.map{gets.split.map(&:to_i)}
p = n.times.map{gets.split.map(&:to_i)}

max1 = -10**9
(2**10).times{|i|
  a = Array.new(n, 0)
  z = 0
  n.times{|k|
    10.times{|j|
      x = (i>>j)&1
      a[k] += f[k][j]&x
    }
    z += p[k][a[k]]
  }
  max1 = z if max1 < z
}

max2 = -10**9
10.times{|i|
  a = Array.new(n, 0)
  z = 0
  n.times{|k|
    a[k] += f[k][i]
    z += p[k][a[k]]
  }
  max2 = z if max2 < z
}

p max1==0? max2:max1