from itertools import product
def inpl(): return map(int, input().split())

N = int(input())
F = [tuple(inpl()) for _ in range(N)]
P = [tuple(inpl()) for _ in range(N)]

result = -1 * 10**8
for T in product([0, 1], repeat=10):
    if sum(T) == 0:
        continue
    tmp = 0
    for i in range(N):
        c = sum([f*t for f, t in zip(F[i], T)])
        tmp += P[i][c]
    result = max(result, tmp)
print(result)