n=int(input())
F=[int(input().replace(' ',''),2) for i in range(n)]
P=[list(map(int,input().split())) for i in range(n)]
ans=-10**9
for i in range(1,1<<10):
    r=0
    for j in range(n):
        r+=P[j][str(bin(i&F[j])).count('1')]
    ans=max(ans,r)
print(ans)