n=gets.chomp.to_i
f=Array.new
p=Array.new
for m in 0..n-1
  f[m]=gets.to_s.split(" ").map{|s| s.to_i}
end
for m in 0..n-1
  p[m]=gets.to_s.split(" ").map{|s| s.to_i}
end


#店i,時間j
benm=-10**7
for b in 1..2**10-1
  count=Array.new
  ben=0

  for i in 0..n-1
    count[i]=0
  end

  for k in 0..9
    if b&2**k==2**k
      for i in 0..n-1
         count[i]+=f[i][k]
      end
    end
  end

  for i in 0..n-1
    ben+=p[i][count[i]]
  end

  if ben>benm
    benm=ben
  end

end

print benm