n=int(eval(input()))

f=[0]*n

for i in range(n):

  x=list(map(int,input().split()))

  for j in range(len(x)):

    if x[j]==1:

      f[i]+=1<<j

  

p=[[0 for j in range(10)] for i in range(n)]



for i in range(n):

  p[i]=list(map(int,input().split()))



ans=10**9*(-1)-1

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

  pro=0

  for j in range(len(f)):

    open=0

    for k in range(10):

      if (i>>k)&1==1 and (f[j]>>k)&1==1:

        open+=1

    pro+=p[j][open]

  if ans<pro:

    ans=pro

print(ans)

# 曜日と時間帯の組み合わせを1111111111の10ビットで全探索



import sys

readline = sys.stdin.readline



N = int(readline())

F = [None] * N

for i in range(N):

  F[i] = int(readline().rstrip().replace(" ",""),2)

    

P = [None] * N

for i in range(N):

  P[i] = list(map(int,readline().split()))

  

ans = -(10 ** 10)

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

  # joisinoが営業する時間帯の文字列11011101

  # 各店について、店jとANDを取って、1ビットの数を数えるとCが分かる

  point = 0

  for j in range(N):

    # 店j

    debug = False

    c = bin(i & F[j])[2:].count("1")

    point += P[j][c]

  if ans < point:

    ans = point

  

print(ans)

n = int(eval(input()))
f = [0] * n
for i in range(n):
    x = list(map(int, input().split()))
    for j in range(len(x)):
        if x[j] == 1:
            f[i] += 1 << j
p = [[0 for j in range(10)] for i in range(n)]
for i in range(n):
    p[i] = list(map(int, input().split()))
ans = 10**9 * (-1) - 1
for i in range(1, 2**10):
    pro = 0
    for j in range(len(f)):
        open = 0
        for k in range(10):
            if (i >> k) & 1 == 1 and (f[j] >> k) & 1 == 1:
                open += 1
        pro += p[j][open]
    if ans < pro:
        ans = pro
print(ans)

# 曜日と時間帯の組み合わせを1111111111の10ビットで全探索
import sys

readline = sys.stdin.readline
N = int(readline())
F = [None] * N
for i in range(N):
    F[i] = int(readline().rstrip().replace(" ", ""), 2)
P = [None] * N
for i in range(N):
    P[i] = list(map(int, readline().split()))
ans = -(10**10)
for i in range(1, 2**10):
    # joisinoが営業する時間帯の文字列11011101
    # 各店について、店jとANDを取って、1ビットの数を数えるとCが分かる
    point = 0
    for j in range(N):
        # 店j
        debug = False
        c = bin(i & F[j])[2:].count("1")
        point += P[j][c]
    if ans < point:
        ans = point
print(ans)

-n = int(eval(input())) -f = [0] * n -for i in range(n): -    x = list(map(int, input().split())) -    for j in range(len(x)): -        if x[j] == 1: -            f[i] += 1 << j -p = [[0 for j in range(10)] for i in range(n)] -for i in range(n): -    p[i] = list(map(int, input().split())) -ans = 10**9 * (-1) - 1 +# 曜日と時間帯の組み合わせを1111111111の10ビットで全探索 +import sys + +readline = sys.stdin.readline +N = int(readline()) +F = [None] * N +for i in range(N): +    F[i] = int(readline().rstrip().replace(" ", ""), 2) +P = [None] * N +for i in range(N): +    P[i] = list(map(int, readline().split())) +ans = -(10**10) -    pro = 0 -    for j in range(len(f)): -        open = 0 -        for k in range(10): -            if (i >> k) & 1 == 1 and (f[j] >> k) & 1 == 1: -                open += 1 -        pro += p[j][open] -    if ans < pro: -        ans = pro +    # joisinoが営業する時間帯の文字列11011101 +    # 各店について、店jとANDを取って、1ビットの数を数えるとCが分かる +    point = 0 +    for j in range(N): +        # 店j +        debug = False +        c = bin(i & F[j])[2:].count("1") +        point += P[j][c] +    if ans < point: +        ans = point