#!/usr/bin/env python3

import itertools



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)]

    bit_list = list(itertools.product([0, 1], repeat=10))

    bit_list.pop(0)

    answer = -10**9-1

    for b in bit_list:

        profit = 0

        for i in range(N):

            a = 0 ## 一致してる営業時間の数

            for j in range(10):

                if b[j]==1 and F[i][j]==1:

                    a+=1

            profit+=P[i][a]



        answer = max(answer,profit)



    print(answer)

    return 



if __name__ == '__main__':

    main()



#!/usr/bin/env python3

import itertools



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)]

    answer = -float('inf')



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

        tmp_profit = 0

        for i in range(N):

            count = format(bit&F[i],'b').count("1")

            tmp_profit += P[i][count]

        answer = max(answer,tmp_profit)

    print(answer)

    return 



if __name__ == '__main__':

    main()



#!/usr/bin/env python3
import itertools


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)]
    bit_list = list(itertools.product([0, 1], repeat=10))
    bit_list.pop(0)
    answer = -(10**9) - 1
    for b in bit_list:
        profit = 0
        for i in range(N):
            a = 0  ## 一致してる営業時間の数
            for j in range(10):
                if b[j] == 1 and F[i][j] == 1:
                    a += 1
            profit += P[i][a]
        answer = max(answer, profit)
    print(answer)
    return


if __name__ == "__main__":
    main()

#!/usr/bin/env python3
import itertools


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)]
    answer = -float("inf")
    for bit in range(1, 1 << 10):
        tmp_profit = 0
        for i in range(N):
            count = format(bit & F[i], "b").count("1")
            tmp_profit += P[i][count]
        answer = max(answer, tmp_profit)
    print(answer)
    return


if __name__ == "__main__":
    main()

-    F = [list(map(int, input().split())) for _ in range(N)] +    F = [int(input().replace(" ", ""), 2) for _ in range(N)] -    bit_list = list(itertools.product([0, 1], repeat=10)) -    bit_list.pop(0) -    answer = -(10**9) - 1 -    for b in bit_list: -        profit = 0 +    answer = -float("inf") +    for bit in range(1, 1 << 10): +        tmp_profit = 0 -            a = 0  ## 一致してる営業時間の数 -            for j in range(10): -                if b[j] == 1 and F[i][j] == 1: -                    a += 1 -            profit += P[i][a] -        answer = max(answer, profit) +            count = format(bit & F[i], "b").count("1") +            tmp_profit += P[i][count] +        answer = max(answer, tmp_profit)