n=int(input())
F=[]
P=[]
for _ in range(n):
    b="".join(input().split())
    F.append(int(b, 2))
for _ in range(n):
    inp=list(map(int,input().split()))
    P.append(inp)

ans=-10**18
for i in range(1, 1024):
    earn=0
    for j,f in enumerate(F):
        same=bin(i&f)[2:].zfill(10)
        same=same.count("1")
        earn+=P[j][same]
    ans=max(ans, earn)

print(ans)