n = int(eval(input()))

shops = [list(input().split()) for i in range(n)]

profits = [list(input().split()) for i in range(n)]



l = []

ans = -10000000000000000000000000000

def f(now, i):

  if i >= 10:

    l.append(list(now))

    return

  

  f(now+"1", i+1)

  f(now+"0", i+1)

f("", 0)



for i in range(len(l)-1):

  temp = 0

  for j in range(len(shops)):

    count = 0

    for k in range(10):

      if shops[j][k] == "1" and l[i][k] == "1":

        count += 1

    temp += int(profits[j][count])

  if temp > ans:

    ans = temp



print(ans)
import itertools

n = int(eval(input()))

F = [list(map(int, input().split())) for i in range(n)]

P = [list(map(int, input().split())) for i in range(n)]

combos = sorted(list(itertools.product([0, 1], repeat=10)))

ans = -float('inf')



for combo in combos[1:]:

  total = 0



  for i in range(len(F)):

    count = 0      

    for a, b in zip(combo, F[i]):

      if a == 1 and b == 1:

        count += 1

    total += P[i][count]

  

  ans = max(ans, total)



print(ans)
n = int(eval(input()))
shops = [list(input().split()) for i in range(n)]
profits = [list(input().split()) for i in range(n)]
l = []
ans = -10000000000000000000000000000


def f(now, i):
    if i >= 10:
        l.append(list(now))
        return
    f(now + "1", i + 1)
    f(now + "0", i + 1)


f("", 0)
for i in range(len(l) - 1):
    temp = 0
    for j in range(len(shops)):
        count = 0
        for k in range(10):
            if shops[j][k] == "1" and l[i][k] == "1":
                count += 1
        temp += int(profits[j][count])
    if temp > ans:
        ans = temp
print(ans)

import itertools

n = int(eval(input()))
F = [list(map(int, input().split())) for i in range(n)]
P = [list(map(int, input().split())) for i in range(n)]
combos = sorted(list(itertools.product([0, 1], repeat=10)))
ans = -float("inf")
for combo in combos[1:]:
    total = 0
    for i in range(len(F)):
        count = 0
        for a, b in zip(combo, F[i]):
            if a == 1 and b == 1:
                count += 1
        total += P[i][count]
    ans = max(ans, total)
print(ans)

+import itertools + -shops = [list(input().split()) for i in range(n)] -profits = [list(input().split()) for i in range(n)] -l = [] -ans = -10000000000000000000000000000 - - -def f(now, i): -    if i >= 10: -        l.append(list(now)) -        return -    f(now + "1", i + 1) -    f(now + "0", i + 1) - - -f("", 0) -for i in range(len(l) - 1): -    temp = 0 -    for j in range(len(shops)): +F = [list(map(int, input().split())) for i in range(n)] +P = [list(map(int, input().split())) for i in range(n)] +combos = sorted(list(itertools.product([0, 1], repeat=10))) +ans = -float("inf") +for combo in combos[1:]: +    total = 0 +    for i in range(len(F)): -        for k in range(10): -            if shops[j][k] == "1" and l[i][k] == "1": +        for a, b in zip(combo, F[i]): +            if a == 1 and b == 1: -        temp += int(profits[j][count]) -    if temp > ans: -        ans = temp +        total += P[i][count] +    ans = max(ans, total)