N = gets.to_i
f = Array.new(N){Array.new(10)}
N.times do |i|
  f[i] = gets.chomp.split(" ").map(&:to_i)
end
p = Array.new(N){Array.new(10)}
N.times do |i|
  p[i] = gets.chomp.split(" ").map(&:to_i)
end
max = -1000000000
[0,1].repeated_permutation(10).each do |x|
  next if !x.include?(1)
  num = Array.new(10,0)
  sum = 0
  N.times do |i|
    10.times do |j|
      num[i] += 1 if x[j] == f[i][j] && x[j] == 1
    end
    sum += p[i][num[i]]
  end
  max = sum if max < sum
end
puts max