N=int(input())
SO=[int(input().replace(' ',''), 2) for i in range(N)]
PT=[list(map(int,input().split())) for i in range(N)]
ret=-10**7*N
for sp in range(1,2**10):
  r=0
  for i in range(N):
    r+=PT[i][bin(SO[i] & sp).count('1')]
  ret=max(ret,r)
print(ret)