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

x = [int(v, 2) for v in F]
rev = []
for i in range(1, 2 ** 10):
    cnt = [list(bin(i & v)[2:]).count('1') for v in x]
    rev.append(sum([P[j][cnt[j]] for j in range(N)]))
print(max(rev))