n = int(eval(input()))

F = [list(map(int, input().split())) for _ in range(n)]#F[i]は(i+1)番目の店の営業の有無のリスト

P = [list(map(int, input().split())) for _ in range(n)]#P[i]は(i+1)番目の店との同時開店数に応じた利益のリスト



ans = (-1) * 10 ** 9

for i in range(2 ** 10):

    if sum(map(int, list(str(i)))) == 0:

        continue

    cnt_lst = [0 for _ in range(n)]

    for d in range(5):

        for t in range(2):

            dt = 2 * d + t

            if i & (2 ** dt) != 0:

                for j in range(n):

                    cnt_lst[j] += F[j][dt]

    buf = 0

    for j in range(n):

        buf += P[j][cnt_lst[j]]

    ans = max(buf, ans)

print(ans)
def main():

    from itertools import combinations



    N = int(eval(input()))

    F = []

    for _ in range(N):

        t = 0

        for j, b in enumerate(map(int, input().split())):

            if b:

                t |= (1 << j)

        F.append(t)

    # F[i]:=店舗iの営業時間情報

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

    # P[i]:=店舗iと営業時間が重なる個数に対する利益



    ans = -10 ** 9 - 1

    for open_ in range(1, 10 + 1):

        for comb in combinations(list(range(10)), r=open_):

            t = 0

            for j in comb:

                t |= (1 << j)



            p = 0

            for i, f in enumerate(F):

                x = bin(t & f).count('1')

                p += P[i][x]



            ans = max(ans, p)



    print(ans)





if __name__ == '__main__':

    main()

n = int(eval(input()))
F = [list(map(int, input().split())) for _ in range(n)]  # F[i]は(i+1)番目の店の営業の有無のリスト
P = [
    list(map(int, input().split())) for _ in range(n)
]  # P[i]は(i+1)番目の店との同時開店数に応じた利益のリスト
ans = (-1) * 10**9
for i in range(2**10):
    if sum(map(int, list(str(i)))) == 0:
        continue
    cnt_lst = [0 for _ in range(n)]
    for d in range(5):
        for t in range(2):
            dt = 2 * d + t
            if i & (2**dt) != 0:
                for j in range(n):
                    cnt_lst[j] += F[j][dt]
    buf = 0
    for j in range(n):
        buf += P[j][cnt_lst[j]]
    ans = max(buf, ans)
print(ans)

def main():
    from itertools import combinations

    N = int(eval(input()))
    F = []
    for _ in range(N):
        t = 0
        for j, b in enumerate(map(int, input().split())):
            if b:
                t |= 1 << j
        F.append(t)
    # F[i]:=店舗iの営業時間情報
    P = [list(map(int, input().split())) for _ in range(N)]
    # P[i]:=店舗iと営業時間が重なる個数に対する利益
    ans = -(10**9) - 1
    for open_ in range(1, 10 + 1):
        for comb in combinations(list(range(10)), r=open_):
            t = 0
            for j in comb:
                t |= 1 << j
            p = 0
            for i, f in enumerate(F):
                x = bin(t & f).count("1")
                p += P[i][x]
            ans = max(ans, p)
    print(ans)


if __name__ == "__main__":
    main()

-n = int(eval(input())) -F = [list(map(int, input().split())) for _ in range(n)]  # F[i]は(i+1)番目の店の営業の有無のリスト -P = [ -    list(map(int, input().split())) for _ in range(n) -]  # P[i]は(i+1)番目の店との同時開店数に応じた利益のリスト -ans = (-1) * 10**9 -for i in range(2**10): -    if sum(map(int, list(str(i)))) == 0: -        continue -    cnt_lst = [0 for _ in range(n)] -    for d in range(5): -        for t in range(2): -            dt = 2 * d + t -            if i & (2**dt) != 0: -                for j in range(n): -                    cnt_lst[j] += F[j][dt] -    buf = 0 -    for j in range(n): -        buf += P[j][cnt_lst[j]] -    ans = max(buf, ans) -print(ans) +def main(): +    from itertools import combinations + +    N = int(eval(input())) +    F = [] +    for _ in range(N): +        t = 0 +        for j, b in enumerate(map(int, input().split())): +            if b: +                t |= 1 << j +        F.append(t) +    # F[i]:=店舗iの営業時間情報 +    P = [list(map(int, input().split())) for _ in range(N)] +    # P[i]:=店舗iと営業時間が重なる個数に対する利益 +    ans = -(10**9) - 1 +    for open_ in range(1, 10 + 1): +        for comb in combinations(list(range(10)), r=open_): +            t = 0 +            for j in comb: +                t |= 1 << j +            p = 0 +            for i, f in enumerate(F): +                x = bin(t & f).count("1") +                p += P[i][x] +            ans = max(ans, p) +    print(ans) + + +if __name__ == "__main__": +    main()