N = int(input())
F = []
for _ in range(N):
    f = [int(s) for s in input().split()]
    b = sum([v * (1 << i) for i, v in enumerate(f)])
    F.append(b)
P = []
for _ in range(N):
    p = [int(s) for s in input().split()]
    P.append(p)
ans = max([sum([P[j][bin(i & F[j]).count("1")] for j in range(N)])
           for i in range(1, 2 ** 10)])
print(ans)
