N = int(input())
F = [''.join(list(map(str, input().split()))) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]
ans = [0]*((1<<10)-1)
for i in range(1, 1<<10):
    count = 0
    for j in range(N):
        count += P[j][format(int(F[j], 2)&i, 'b').count('1')]
    ans[i-1] = count
print(max(ans))