n = int(input())
f = [[int(x) for x in input().split()] for i in range(n)]
p = [input().split() for i in range(n)]
for i in range(n):
  p[i] = [int(x) for x in p[i]]
ans=min((min(x) for x in p))
b=format(i, "010b")
for i in range(1,2**10):
  d, t={j:0 for j in range(n)},0
  for j in range(n):
    for k in range(10):
      if (i>>k)%2*f[j][k]==1: d[j]+=1
    t+=p[j][d[j]]
  if ans<t: ans=t
print(ans)