N=int(input())
F=[int(input().replace(' ',''),2) for _ in range(N)]
P=[tuple(map(int,input().split())) for _ in range(N)]

ans=-(10**7*N)
for o in range(1,1<<10):
    p=0
    for i in range(N):
        p+=P[i][bin(F[i]&o).count('1')]
    ans=max(ans,p)
print(ans)