import itertools
N=input()
F=[]
for i in range(N):
	F.append(map(int,raw_input().split()))
#print F

P=[]
for i in range(N):
	P.append(map(int,raw_input().split()))
#print P


l=list(itertools.product(range(2), repeat=10))
#l=[(1, 1, 1, 1, 1, 0, 0, 0, 0, 0),(0, 0, 0, 0, 0, 1, 1, 1, 1, 1),(0, 0, 0, 0, 0, 1, 1, 1, 1, 1)]
l.remove((0, 0, 0, 0, 0, 0, 0, 0, 0, 0))

b=[[] for i in range(2**10-1)]


for ind_i,i in enumerate(l):
	for j in F:
		#print [min(t) for t in zip(i, j)]
		#print sum([min(t) for t in zip(i, j)])
		b[ind_i].append(sum([min(t) for t in zip(i, j)]))
#print b

b_sum=0
ans=float("-inf")
for ind_i,i in enumerate(b):
	b_sum=0
	for ind_j,j in enumerate(i):
		#print ind_i, ind_j,j
		b_sum+=P[ind_j][j]
	#print sum
	ans=max(ans,b_sum)

print ans