#from collections import Counter
N=int(input())
F=list(int(input().replace(" ",""),2) for i in range(N))
P=list(list(map(int,input().split())) for i in range(N))
ans=-(1<<40)
for bit in range(1,1<<10):
    tmp = 0
    for i in range(N):
        tmp+=P[i][bin(bit&F[i]).count('1')]
    ans = max(ans,tmp)
print(ans)