n = int(input())
F = [int("".join(input().split()), 2) for _ in range(n)]
P = [list(map(int, input().split())) for _ in range(n)]

max_ans = -float("inf")

for i in range(1, 1024):
	ans = 0
	for j in range(n):
		ans += P[j][list(str(bin(i & F[j]))).count("1")]
	if ans > max_ans:
		max_ans = ans

print(max_ans)