n = gets.to_i

f = [nil]

for i in 1..n do
  f.push(gets.chomp.split(' ').map(&:to_i).unshift(nil))
end

p = [nil]
for i in 1..n do
  p.push(gets.chomp.split(' ').map(&:to_i))
end


pkiroku = []
nums = [1,2,3,4,5,6,7,8,9,10]
for i in 1..10 do
  num.combination(i).to_a.each do |c|
    misetasu = []
    for j in 1..n do
      count = 0
      c.each{|k|
        count +=1 if f[j][k] == 1
      }
      misetasu.push(p[j][count])
    end
    pkiroku.push(misetasu.inject(:+))
  end
end

puts pkiroku.max