N = int(eval(input()))



F = [[int(i) for i in input().split()] for i in range(N)]

P = [[int(i) for i in input().split()] for i in range(N)]



ans = - 10 ** 16

for i in range(1 << 10):

    output = [0] * 10

    for j in range(10):

        if (i>>j) & 1:

            output[j] = 1

    if output.count(0) == 10:

        continue

    tmp_sum = 0

    for n in range(N):

        cnt = 0

        for m in range(10):

            if F[n][m] == output[m] == 1:

                cnt += 1

        tmp_sum += P[n][cnt]

    ans = max(ans, tmp_sum)

print(ans)
def main():

    N = int(eval(input()))

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

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

    ans = -(10**15)

    for i in range(2**10):

        tmp = []

        for j in range(10):

            if ((i >> j) & 1):

                tmp.append(j)

        if not tmp:

            continue

        score = 0

        for k in range(N):

            cnt = 0

            for l in range(10):

                if F[k][l] == 1 and l in tmp:

                    cnt += 1

            score += P[k][cnt]



        ans = max(ans, score)



    print(ans)

if __name__ == "__main__":

    main()
N = int(eval(input()))
F = [[int(i) for i in input().split()] for i in range(N)]
P = [[int(i) for i in input().split()] for i in range(N)]
ans = -(10**16)
for i in range(1 << 10):
    output = [0] * 10
    for j in range(10):
        if (i >> j) & 1:
            output[j] = 1
    if output.count(0) == 10:
        continue
    tmp_sum = 0
    for n in range(N):
        cnt = 0
        for m in range(10):
            if F[n][m] == output[m] == 1:
                cnt += 1
        tmp_sum += P[n][cnt]
    ans = max(ans, tmp_sum)
print(ans)

def main():
    N = int(eval(input()))
    F = [list(map(int, input().split())) for _ in range(N)]
    P = [list(map(int, input().split())) for _ in range(N)]
    ans = -(10**15)
    for i in range(2**10):
        tmp = []
        for j in range(10):
            if (i >> j) & 1:
                tmp.append(j)
        if not tmp:
            continue
        score = 0
        for k in range(N):
            cnt = 0
            for l in range(10):
                if F[k][l] == 1 and l in tmp:
                    cnt += 1
            score += P[k][cnt]
        ans = max(ans, score)
    print(ans)


if __name__ == "__main__":
    main()

-N = int(eval(input())) -F = [[int(i) for i in input().split()] for i in range(N)] -P = [[int(i) for i in input().split()] for i in range(N)] -ans = -(10**16) -for i in range(1 << 10): -    output = [0] * 10 -    for j in range(10): -        if (i >> j) & 1: -            output[j] = 1 -    if output.count(0) == 10: -        continue -    tmp_sum = 0 -    for n in range(N): -        cnt = 0 -        for m in range(10): -            if F[n][m] == output[m] == 1: -                cnt += 1 -        tmp_sum += P[n][cnt] -    ans = max(ans, tmp_sum) -print(ans) +def main(): +    N = int(eval(input())) +    F = [list(map(int, input().split())) for _ in range(N)] +    P = [list(map(int, input().split())) for _ in range(N)] +    ans = -(10**15) +    for i in range(2**10): +        tmp = [] +        for j in range(10): +            if (i >> j) & 1: +                tmp.append(j) +        if not tmp: +            continue +        score = 0 +        for k in range(N): +            cnt = 0 +            for l in range(10): +                if F[k][l] == 1 and l in tmp: +                    cnt += 1 +            score += P[k][cnt] +        ans = max(ans, score) +    print(ans) + + +if __name__ == "__main__": +    main()