numShops = gets.to_i
open = Array.new(numShops) do |i|
  gets.split.map{|s| s == "1"}
end
price = Array.new(numShops) do |i|
  gets.split.map &:to_i
end

res = 0
(1...1024).each do |i|
  o = i.to_s(2).chars.map{|s| s == "1"}
  p = 0
  numShops.times do |s|
    count = 0
    10.times do |d|
      count += 1 if open[s][d] && o[d]
    end
    p += price[s][count]
  end
  
  res = [res, p].max
end

p res