n=int(input())
f=[list(map(int,input().split())) for _ in [0]*n]
p=[list(map(int,input().split())) for _ in [0]*n]
s=-float('inf')
for i in range(1,2**10):
    l=list(map(int,'0'*(12-len(bin(i)))+bin(i)[2:]))
    s=max(s,sum(p[j][sum(l[i] and f[j][i] for i in range(10))] for j in range(n)))
print(s)