def main():

    import sys

    #input = sys.stdin.readline

    sys.setrecursionlimit(10000000)



    from collections import Counter

    from collections import deque



    #dxy = [[0,1],[0,-1],[1,0],[-1,0]]

    #dxy = [[0,1],[0,-1],[1,0],[-1,0],[1,1],[1,-1],[-1,1],[-1,-1]]

    #mod = 1000000007



    n = int(eval(input()))

    F = [input().split() for _ in range(n)]

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

    ans = -10**10

    for i in range(1, 1033):

        a = list(str(format(i, '010b')))

        total = 0

        for j in range(n):

            cnt = 0

            for k in range(10):

                if F[j][k]=='1' and a[k]=='1':

                    cnt += 1

            total += P[j][cnt]

        if total>ans:

            ans = total

    print(ans)









if __name__ == '__main__':

    main()
N=int(eval(input()))

SO=[int(input().replace(' ',''), 2) for i in range(N)]

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

ret=-10**7*N

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

  r=0

  for i in range(N):

    r+=PT[i][bin(SO[i] & sp).count('1')]

  ret=max(ret,r)

print(ret)
def main():
    import sys

    # input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter
    from collections import deque

    # dxy = [[0,1],[0,-1],[1,0],[-1,0]]
    # dxy = [[0,1],[0,-1],[1,0],[-1,0],[1,1],[1,-1],[-1,1],[-1,-1]]
    # mod = 1000000007
    n = int(eval(input()))
    F = [input().split() for _ in range(n)]
    P = [list(map(int, input().split())) for _ in range(n)]
    ans = -(10**10)
    for i in range(1, 1033):
        a = list(str(format(i, "010b")))
        total = 0
        for j in range(n):
            cnt = 0
            for k in range(10):
                if F[j][k] == "1" and a[k] == "1":
                    cnt += 1
            total += P[j][cnt]
        if total > ans:
            ans = total
    print(ans)


if __name__ == "__main__":
    main()

N = int(eval(input()))
SO = [int(input().replace(" ", ""), 2) for i in range(N)]
PT = [list(map(int, input().split())) for i in range(N)]
ret = -(10**7) * N
for sp in range(1, 2**10):
    r = 0
    for i in range(N):
        r += PT[i][bin(SO[i] & sp).count("1")]
    ret = max(ret, r)
print(ret)

-def main(): -    import sys - -    # input = sys.stdin.readline -    sys.setrecursionlimit(10000000) -    from collections import Counter -    from collections import deque - -    # dxy = [[0,1],[0,-1],[1,0],[-1,0]] -    # dxy = [[0,1],[0,-1],[1,0],[-1,0],[1,1],[1,-1],[-1,1],[-1,-1]] -    # mod = 1000000007 -    n = int(eval(input())) -    F = [input().split() for _ in range(n)] -    P = [list(map(int, input().split())) for _ in range(n)] -    ans = -(10**10) -    for i in range(1, 1033): -        a = list(str(format(i, "010b"))) -        total = 0 -        for j in range(n): -            cnt = 0 -            for k in range(10): -                if F[j][k] == "1" and a[k] == "1": -                    cnt += 1 -            total += P[j][cnt] -        if total > ans: -            ans = total -    print(ans) - - -if __name__ == "__main__": -    main() +N = int(eval(input())) +SO = [int(input().replace(" ", ""), 2) for i in range(N)] +PT = [list(map(int, input().split())) for i in range(N)] +ret = -(10**7) * N +for sp in range(1, 2**10): +    r = 0 +    for i in range(N): +        r += PT[i][bin(SO[i] & sp).count("1")] +    ret = max(ret, r) +print(ret)