hw = STDIN.gets
h = hw.chomp
N = h.to_i
r = 0
st = ""
f = Array.new(N, Array.new(10, 0))
fs = Array.new(N, Array.new(10, 0))
p = Array.new(N, Array.new(11, 0))
ps = Array.new(N, Array.new(11, 0))
e = Array.new(10, 0)
pow = Array.new(10, 0)
for i in 0..(N - 1)
  	s = ""
	s = STDIN.gets
	s.chomp!
	fs[i] = s.split(" ")
  	f[i] = fs[i].map{|a|a.to_i}
end


for i in 0..(N - 2)
	s = STDIN.gets
	s = s.chomp
	ps[i] = s.split(" ")
    p[i] = ps[i].map{|a|a.to_i}
end

s = STDIN.gets
ps[N - 1] = s.split(" ")
p[N - 1] = ps[N - 1].map{|a|a.to_i}

v = 0
c = -10000001

for i in 1..1023
	r = 0
	s = i.to_s(2)
	if s.length == 10
	else
		while(s.length < 10)
			s = "0" + s
		end
	end
	#puts s
	for j in 0..9
		e[j] = s[j].to_i
	end

	for k in 0..(N - 1)
		v = 0
		for j in 0..9
			if e[j] + f[k][j] == 2
				v = v + 1
			end
		end
		r += p[k][v]
	end
	#puts r
	if c < r
		c = r
	end
end

a = c.to_s
puts a