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

res = []
for i in range(1, 2**10 + 1):
    index = list(map(int, list(bin(i))[2:]))
    kaburi = [sum([i * f for i, f in zip(index, F[n])]) for n in range(N)]
    res.append(sum([P[n][k] for n, k in zip(range(N), kaburi)]))

print(max(res))
