from itertools import product
from operator import and_
N = int(input())
F = [tuple(map(lambda s: s=="1", input().split())) for _ in range(N)]
P = [tuple(map(int, input().split())) for _ in range(N)]
print(max(sum(P[i][sum(map(and_, F[i], prod))] for i in range(N)) for prod in product((True, False), repeat=10) if sum(prod)))