n = int(input())
f = []
p = []
for _ in range(n):
  f.append(list(map(int, input().strip().split())))
for _ in range(n):
  p.append(list(map(int, input().strip().split())))

maxt = None
for i in range(1, 2**10):
  total = 0
  for _f, _p in zip(f, p):
    c = 0
    for bi, fi in zip(bin(i)[2:], _f[::-1]):
      if fi==1 and int(bi)==1:
        c += 1
    total += _p[c]
  maxt = max(total, maxt) if maxt is not None else total
print(maxt)