from sys import stdin

n = int(stdin.readline().rstrip())
f = [list(map(int,stdin.readline().rstrip().split())) for _ in range(n)]
p = [list(map(int,stdin.readline().rstrip().split())) for _ in range(n+1)]

def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)

ma = 0
for i in range(1,1024):
    s = Base_10_to_n(i,2).zfill(10)
    total = 0
    for j in range(n):
        point = 0
        for k in range(10):
            if int(s[k]) == 1 and f[j][k] == 1:
                point += 1
        total += p[j][point]
    ma = max(ma,total)
    
print(ma)