N = int(input())
run = [input().replace(" ","") for _ in range(N)]
pro = [list(map(int,input().split())) for _ in range(N)]
ans = -99999999
total_pro = 0
cal = ["0","1"]
for i in cal:
  for j in cal:
    for k in cal:
      for l in cal:
        for m in cal:
          for n in cal:
            for o in cal:
              for p in cal:
                for q in cal:
                  for r in cal:
                    if i==j==k==l==m==n==o==p==q==r=="0":
                      pass
                    else:
                      joi = int(i+j+k+l+m+n+o+p+q+r,2)
                      for x in range(N):
                         store = int(run[x],2)
                         total_pro += pro[x][bin(joi&store).count("1")]
                      ans = max(ans,total_pro)
                      total_pro = 0
print(ans) 