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)]



ans = -(10**7) * 10 * 100



for i in range(1,2**10):  

  counter = [0]*N #店iとjoisinoのかぶっている数

  tmp = 0 #  

  for j in range(10):    

    if (i>>j) & 1:

      for k in range(N):

        if F[k][j] ==1:

          counter[k] += 1

  for l in range(N):

    tmp += P[l][counter[l]]

      #tmp += P[k][counter[k]]

  ans = max(tmp,ans)

print(ans)
n = int(eval(input()))



bits = []

for i in range(n):

  bit = int(input().replace(" ", ""), 2)

  bits.append(bit)

p = [[int(item) for item in input().split()] for _ in range(n)]



ans = - 10**9

for i in range(1,2**10):

  val = 0

  for j,mise in enumerate(p):

    val += mise[bin(i & bits[j]).count("1")]

  ans = max(ans, val)

print(ans)
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)]
ans = -(10**7) * 10 * 100
for i in range(1, 2**10):
    counter = [0] * N  # 店iとjoisinoのかぶっている数
    tmp = 0  #
    for j in range(10):
        if (i >> j) & 1:
            for k in range(N):
                if F[k][j] == 1:
                    counter[k] += 1
    for l in range(N):
        tmp += P[l][counter[l]]
        # tmp += P[k][counter[k]]
    ans = max(tmp, ans)
print(ans)

n = int(eval(input()))
bits = []
for i in range(n):
    bit = int(input().replace(" ", ""), 2)
    bits.append(bit)
p = [[int(item) for item in input().split()] for _ in range(n)]
ans = -(10**9)
for i in range(1, 2**10):
    val = 0
    for j, mise in enumerate(p):
        val += mise[bin(i & bits[j]).count("1")]
    ans = max(ans, val)
print(ans)

-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)] -ans = -(10**7) * 10 * 100 +n = int(eval(input())) +bits = [] +for i in range(n): +    bit = int(input().replace(" ", ""), 2) +    bits.append(bit) +p = [[int(item) for item in input().split()] for _ in range(n)] +ans = -(10**9) -    counter = [0] * N  # 店iとjoisinoのかぶっている数 -    tmp = 0  # -    for j in range(10): -        if (i >> j) & 1: -            for k in range(N): -                if F[k][j] == 1: -                    counter[k] += 1 -    for l in range(N): -        tmp += P[l][counter[l]] -        # tmp += P[k][counter[k]] -    ans = max(tmp, ans) +    val = 0 +    for j, mise in enumerate(p): +        val += mise[bin(i & bits[j]).count("1")] +    ans = max(ans, val)