n = int(input())
f, p = [], []
scores = []
for i in range(n):
    f.append(int(int("".join(list(input().split())), 2)))
for i in range(n):
    p.append(list(map(int,input().split())))
for i in range(1,1024):
    score = 0
    for j in range(n):
        double = bin(i & f[j]).count("1")
        score += p[j][double]
    scores.append(score)
print(max(scores))