import itertools
import numpy as np

N = int(input())
F = list()
P = list()
for i in range(N):
	f = list(map(int, input().split()))
	#F.append([f[0:2],f[2:4],f[4:6],f[6:8],f[8:10]])
	F.append(f)
for i in range(N):
	p = list(map(int, input().split()))
	P.append(p)

F = np.array(F)

count = [0] * N

n_range = []
for val in list(itertools.product([0,1], repeat=10)):
	indices = [i for i,j in enumerate(val) if j == 1]
	f = [sum(list(F[i][indices])) for i in range(N)]
	n_range.append(f)

score = list()
for n in n_range:
	s = sum([P[i][c] for i,c in enumerate(n)])
	score.append(s)

if score.index(max(score)) == 0:
	s = [P[i][1] for i in range(N)]
	print(max(s))
else:
	print(max(score))