import itertools

N=eval(input())

F=[]

for i in range(N):

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

#print F



P=[]

for i in range(N):

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

#print P





l=list(itertools.product(list(range(2)), repeat=10))

#l=[(1, 1, 1, 1, 1, 0, 0, 0, 0, 0),(0, 0, 0, 0, 0, 1, 1, 1, 1, 1),(0, 0, 0, 0, 0, 1, 1, 1, 1, 1)]

l.remove((0, 0, 0, 0, 0, 0, 0, 0, 0, 0))



b=[[] for i in range(2**10-1)]





for ind_i,i in enumerate(l):

	for j in F:

		#print [min(t) for t in zip(i, j)]

		#print sum([min(t) for t in zip(i, j)])

		b[ind_i].append(sum([min(t) for t in zip(i, j)]))

#print b



b_sum=0

ans=float("-inf")

for ind_i,i in enumerate(b):

	b_sum=0

	for ind_j,j in enumerate(i):

		#print ind_i, ind_j,j

		b_sum+=P[ind_j][j]

	#print sum

	ans=max(ans,b_sum)



print(ans)
# -*- coding: utf-8 -*-

import sys



N=eval(input())

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

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



D=[]    #各店の状態を10進数で表示

for f in F: #各店の状態を10進数に置き換え

    n=0

    for i,x in enumerate(f):

        if x==1:

            n+=2**(9-i)

    D.append(n)





def count_one(n):

    cnt=0

    for i in range(10):

        cnt+=n>>i&1

    return cnt



ans=float("-inf")

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

    t=0 #temporary

    for j,d in enumerate(D):

        c=count_one(d&i)    #両方の店が営業している時間帯の個数

        t+=P[j][c]

    ans=max(ans,t)



print(ans)
import itertools

N = eval(input())
F = []
for i in range(N):
    F.append(list(map(int, input().split())))
# print F
P = []
for i in range(N):
    P.append(list(map(int, input().split())))
# print P
l = list(itertools.product(list(range(2)), repeat=10))
# l=[(1, 1, 1, 1, 1, 0, 0, 0, 0, 0),(0, 0, 0, 0, 0, 1, 1, 1, 1, 1),(0, 0, 0, 0, 0, 1, 1, 1, 1, 1)]
l.remove((0, 0, 0, 0, 0, 0, 0, 0, 0, 0))
b = [[] for i in range(2**10 - 1)]
for ind_i, i in enumerate(l):
    for j in F:
        # print [min(t) for t in zip(i, j)]
        # print sum([min(t) for t in zip(i, j)])
        b[ind_i].append(sum([min(t) for t in zip(i, j)]))
# print b
b_sum = 0
ans = float("-inf")
for ind_i, i in enumerate(b):
    b_sum = 0
    for ind_j, j in enumerate(i):
        # print ind_i, ind_j,j
        b_sum += P[ind_j][j]
    # print sum
    ans = max(ans, b_sum)
print(ans)

# -*- coding: utf-8 -*-
import sys

N = eval(input())
F = [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
P = [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
D = []  # 各店の状態を10進数で表示
for f in F:  # 各店の状態を10進数に置き換え
    n = 0
    for i, x in enumerate(f):
        if x == 1:
            n += 2 ** (9 - i)
    D.append(n)


def count_one(n):
    cnt = 0
    for i in range(10):
        cnt += n >> i & 1
    return cnt


ans = float("-inf")
for i in range(1, 2**10):
    t = 0  # temporary
    for j, d in enumerate(D):
        c = count_one(d & i)  # 両方の店が営業している時間帯の個数
        t += P[j][c]
    ans = max(ans, t)
print(ans)

-import itertools +# -*- coding: utf-8 -*- +import sys -F = [] -for i in range(N): -    F.append(list(map(int, input().split()))) -# print F -P = [] -for i in range(N): -    P.append(list(map(int, input().split()))) -# print P -l = list(itertools.product(list(range(2)), repeat=10)) -# l=[(1, 1, 1, 1, 1, 0, 0, 0, 0, 0),(0, 0, 0, 0, 0, 1, 1, 1, 1, 1),(0, 0, 0, 0, 0, 1, 1, 1, 1, 1)] -l.remove((0, 0, 0, 0, 0, 0, 0, 0, 0, 0)) -b = [[] for i in range(2**10 - 1)] -for ind_i, i in enumerate(l): -    for j in F: -        # print [min(t) for t in zip(i, j)] -        # print sum([min(t) for t in zip(i, j)]) -        b[ind_i].append(sum([min(t) for t in zip(i, j)])) -# print b -b_sum = 0 +F = [list(map(int, sys.stdin.readline().split())) for _ in range(N)] +P = [list(map(int, sys.stdin.readline().split())) for _ in range(N)] +D = []  # 各店の状態を10進数で表示 +for f in F:  # 各店の状態を10進数に置き換え +    n = 0 +    for i, x in enumerate(f): +        if x == 1: +            n += 2 ** (9 - i) +    D.append(n) + + +def count_one(n): +    cnt = 0 +    for i in range(10): +        cnt += n >> i & 1 +    return cnt + + -for ind_i, i in enumerate(b): -    b_sum = 0 -    for ind_j, j in enumerate(i): -        # print ind_i, ind_j,j -        b_sum += P[ind_j][j] -    # print sum -    ans = max(ans, b_sum) +for i in range(1, 2**10): +    t = 0  # temporary +    for j, d in enumerate(D): +        c = count_one(d & i)  # 両方の店が営業している時間帯の個数 +        t += P[j][c] +    ans = max(ans, t)