def count_bits(num)
  mask = 1
  count = 0
  while mask != 0
    break if mask == 1024 
    count += 1 if (num & mask) != 0
    mask <<= 1
  end
  count
end

N = gets.chomp.to_i
F = []
N.times do
  F << gets.chomp.split(' ').map(&:to_i).join
end

P = []
N.times do
  P << gets.chomp.split(' ').map(&:to_i)
end

profit = -100000000
(1..1023).each do |pattern|
  c = []
  F.each do |fi|
    c << count_bits(fi.to_i(2) & pattern)
  end

  temp = 0
  c.each.with_index do |ci, i|
    temp += P[i][ci]
  end
  profit = temp if profit < temp
end

puts profit