N = int(input())
F = []
for i in range(N):
  F.append(list(map(str,input().split())))
P = []
for i in range(N):
  P.append(list(map(int,input().split())))

ans = -float('inf')
for i in range(1,2**10):
  sum = 0
  for idx, j in enumerate(F):
    bin_num = int("".join(j), 2)
    num = bin(i & bin_num)[2:].count('1')
    sum += P[idx][num]
    if (sum > ans):
      ans = sum
print(ans)