import itertools
import numpy as np
N = int(input())
F = [[int(x) for x in input().split()] for _ in range(N)]
P = [[int(x) for x in input().split()] for _ in range(N)]

f = np.array(F)
ans = min(itertools.chain(*P))
for n in range(1, 2**10):
    a = np.array([int(x) for x in bin(n)[2:].rjust(10, '0')])
    p = sum([P[i][x] for i,x in enumerate(np.sum(f * a, axis=1))])
    ans = max(ans, p)
print(ans)