n=int(input())
f=[list(map(str,input().split()))for i in range(n)]
p=[list(map(int,input().split()))for i in range(n)]
d=[]
for i in range(n):
    c=""
    for j in range(10):
        c+=f[i][j]
    else:
        d.append(int(c,2))
ans=float("-inf")
for i in range(1,1025):
    k=0
    for j in range(n):
        k+=p[j][bin(d[j]&i).count("1")] 
    else:
        ans=max(k,ans)
print(ans)