N = int(input())
FF = [list(map(int, input().split())) for _ in range(N)]
PP = [list(map(int, input().split())) for _ in range(N)]

from itertools import combinations

mm = None
for i in range(1, 11):
  for ss in combinations(range(0, 10), i):
    m = 0
    for j in range(N):
      c = sum(f for k, f in enumerate(FF[j]) if k in ss)
      m += PP[j][c]
      if mm is None:
        mm = m
      else:
        mm = max(mm, m)
print(mm)