import sys
r=sys.stdin.readline
N=int(r())
F=[int(r().replace(' ',''),2)for _ in[0]*N]
P=[list(map(int,r().split()))for _ in[0]*N]
print(max(sum([p[bin(f&i).count('1')]for f,p in zip(F,P)])for i in range(1,2**10)))