N=int(input())
F=[int(input().replace(" ", ""), 2) for _ in range(N)]
P=[[int(x) for x in input().split()] for _ in range(N)]
C=[sum(map(int, format(i, "b"))) for i in range(2**10)]
print(max([sum([p[C[f&i]] for f,p in zip(F, P)]) for i in range(1, 2**10)]))
