import sys

input=sys.stdin.readline



def main():

    N = int(eval(input()))

    F = []

    for _ in range(N):

        F.append(list(map(int, input().split())))

    P = []

    for _ in range(N):

        P.append(list(map(int, input().split())))



    ans = -10**7*N

    for i in range(1, 1<<10):

        tmp = 0

        for s,f in enumerate(F):

            c = 0

            for j in range(10):

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

                    c += 1

            tmp += P[s][c]

        ans = max(ans, tmp)

    print(ans)



if __name__ == '__main__':

    main()

import sys

input=sys.stdin.readline



def main():

    N = int(eval(input()))

    F = [int(input().replace(" ", ""), 2) for _ in range(N)]

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



    ans = -10**7*N

    for i in range(1, 1<<10):

        tmp = 0

        for j,f in enumerate(F):

            c = bin(i&f).count("1")

            tmp += P[j][c]

        ans = max(ans, tmp)

    print(ans)



if __name__ == '__main__':

    main()

import sys

input = sys.stdin.readline


def main():
    N = int(eval(input()))
    F = []
    for _ in range(N):
        F.append(list(map(int, input().split())))
    P = []
    for _ in range(N):
        P.append(list(map(int, input().split())))
    ans = -(10**7) * N
    for i in range(1, 1 << 10):
        tmp = 0
        for s, f in enumerate(F):
            c = 0
            for j in range(10):
                if (i >> j) & 1 & f[j]:
                    c += 1
            tmp += P[s][c]
        ans = max(ans, tmp)
    print(ans)


if __name__ == "__main__":
    main()

import sys

input = sys.stdin.readline


def main():
    N = int(eval(input()))
    F = [int(input().replace(" ", ""), 2) for _ in range(N)]
    P = [list(map(int, input().split())) for _ in range(N)]
    ans = -(10**7) * N
    for i in range(1, 1 << 10):
        tmp = 0
        for j, f in enumerate(F):
            c = bin(i & f).count("1")
            tmp += P[j][c]
        ans = max(ans, tmp)
    print(ans)


if __name__ == "__main__":
    main()

-    F = [] -    for _ in range(N): -        F.append(list(map(int, input().split()))) -    P = [] -    for _ in range(N): -        P.append(list(map(int, input().split()))) +    F = [int(input().replace(" ", ""), 2) for _ in range(N)] +    P = [list(map(int, input().split())) for _ in range(N)] -        for s, f in enumerate(F): -            c = 0 -            for j in range(10): -                if (i >> j) & 1 & f[j]: -                    c += 1 -            tmp += P[s][c] +        for j, f in enumerate(F): +            c = bin(i & f).count("1") +            tmp += P[j][c]