n = int(input())
f = []
p = []
s = [0 for i in range(10)]
for i in range(n):
    f.append(list(int(i) for i in input().split()))
for i in range(n):
    p.append(list(int(i) for i in input().split()))

def count(x):
    cunt = 0
    for i in range(len(openlist)):
        if f[x][i] == openlist[i]==1:
            cunt +=1
    return cunt
max1 = -10000000000000
for i in range(1,1024):
    sum = 0
    open = format(i,'b')
    openlist = [int(j) for j in open]
    for k in range(n):
        sum += p[k][count(k)]
    max1 = max(max1,sum)
print(max1)
