I=input;n=int(I());f=[int(I()[::2],2)for _ in[0]*n];p=[I().split()for _ in[0]*n];print((max(sum(int(q[bin(i&g).count('1')])for g,q in zip(f,p))for i in range(1,1024))))
I=input;n=int(I());f=eval('int(I()[::2],2),'*n);p=eval('I().split(),'*n);print((max(sum(int(q[bin(i&g).count('1')])for g,q in zip(f,p))for i in range(1,1024))))
I = input
n = int(I())
f = [int(I()[::2], 2) for _ in [0] * n]
p = [I().split() for _ in [0] * n]
print(
    (
        max(
            sum(int(q[bin(i & g).count("1")]) for g, q in zip(f, p))
            for i in range(1, 1024)
        )
    )
)

I = input
n = int(I())
f = eval("int(I()[::2],2)," * n)
p = eval("I().split()," * n)
print(
    (
        max(
            sum(int(q[bin(i & g).count("1")]) for g, q in zip(f, p))
            for i in range(1, 1024)
        )
    )
)

-f = [int(I()[::2], 2) for _ in [0] * n] -p = [I().split() for _ in [0] * n] +f = eval("int(I()[::2],2)," * n) +p = eval("I().split()," * n)