n = gets.to_i
f = []
p = []
max = -10**8
n.times do
	f.push(gets.split.map(&:to_i))
end
n.times do
	p.push(gets.split.map(&:to_i))
end

1023.times do |i|
	total = 0
	open = []
	10.times do |j|
		open[j] = ((i+1) >> j) & 1
	end
	n.times do |j|
		c = 0
		10.times do |k|
			c += f[j][k] * open[k]
		end
		total += p[j][c]
		#p c
	end
	max = total if max < total
	#p open
end
puts max
