N=int(input())
F=[list(map(int,input().split())) for i in range(2*N)]
F,P=F[:N],F[N:]
from itertools import product
r=-10**9
for i in range(1,1024):
  x=[(i>>(9-j))%2 for j in range(10)]
  r=max(r,sum([P[j][sum([F[j][i]*x[i] for i in range(10)])] for j in range(N)]))
print(r)