N=int(input())
F=[int(input().replace(" ",""),2) for _ in [0]*N]
P=[list(map(int,input().split())) for _ in [0]*N]
print(max([sum([P[j][bin(i&F[j]).count("1")] for j in range(N)]) for i in range(1,1024)]))