io = STDIN
$n=io.gets.to_i
$f=[]
$p=[]
$n.times do
  $f<<io.gets.split.join.to_i(2)
end
$n.times do
  $p<<io.gets.split.map(&:to_i)
end
ans=[]
(2**10).times do |sis|
  sum=0
  $f.each_with_index do |mask,j|
    cross=sis & mask
    sum+=$p[j][cross.to_s(2).count('1')]
  end
  ans << sum
end
p ans.reject{|i|i==0}.max
