import sys

input = sys.stdin.readline

N = int(eval(input()))

F = []

for _ in range(N):

    F.append([int(x) for x in input().split()])

P = []

for _ in range(N):

    P.append([int(x) for x in input().split()])

ans = -10 ** 10

import numpy as np

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

    bini = format(i, 'b').zfill(10)

    bini = np.array([int(x) for x in list(bini)])

    ans_ = 0

    for j in range(N):

        shop = np.array(F[j])

        cnt = np.count_nonzero(shop * bini)

        ans_ += P[j][cnt]

    ans = max(ans, ans_)

print(ans)



import sys

input = sys.stdin.readline

N = int(eval(input()))

F = []

for _ in range(N):

    F.append([str(x) for x in input().split()])

P = []

for _ in range(N):

    P.append([int(x) for x in input().split()])

ans = -10 ** 10

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

    bini = "0b" + format(i, 'b').zfill(10)

    ans_ = 0

    for j in range(N):

        shop = "0b" + "".join(F[j])

        cnt = bin((int(shop, 2) & int(bini, 2))).count("1")

        ans_ += P[j][cnt]

    ans = max(ans, ans_)

print(ans)



import sys

input = sys.stdin.readline
N = int(eval(input()))
F = []
for _ in range(N):
    F.append([int(x) for x in input().split()])
P = []
for _ in range(N):
    P.append([int(x) for x in input().split()])
ans = -(10**10)
import numpy as np

for i in range(1, 2**10):
    bini = format(i, "b").zfill(10)
    bini = np.array([int(x) for x in list(bini)])
    ans_ = 0
    for j in range(N):
        shop = np.array(F[j])
        cnt = np.count_nonzero(shop * bini)
        ans_ += P[j][cnt]
    ans = max(ans, ans_)
print(ans)

import sys

input = sys.stdin.readline
N = int(eval(input()))
F = []
for _ in range(N):
    F.append([str(x) for x in input().split()])
P = []
for _ in range(N):
    P.append([int(x) for x in input().split()])
ans = -(10**10)
for i in range(1, 2**10):
    bini = "0b" + format(i, "b").zfill(10)
    ans_ = 0
    for j in range(N):
        shop = "0b" + "".join(F[j])
        cnt = bin((int(shop, 2) & int(bini, 2))).count("1")
        ans_ += P[j][cnt]
    ans = max(ans, ans_)
print(ans)

-    F.append([int(x) for x in input().split()]) +    F.append([str(x) for x in input().split()]) -import numpy as np - -    bini = format(i, "b").zfill(10) -    bini = np.array([int(x) for x in list(bini)]) +    bini = "0b" + format(i, "b").zfill(10) -        shop = np.array(F[j]) -        cnt = np.count_nonzero(shop * bini) +        shop = "0b" + "".join(F[j]) +        cnt = bin((int(shop, 2) & int(bini, 2))).count("1")