import itertools
n = int(input())
f = []
p = []
res = -10**7
for i in range(n):
    f.append(list(map(int,input().split())))
for i in range(n):
    p.append(list(map(int,input().split())))
l = [0,1]
q = list(itertools.product(l,repeat=10))
del q[0]
for i in q:
    r = 0
    for j in range(n):
        c = 0
        for k in range(10):
            if i[k] and f[j][k]:
                c += 1
        r += p[j][c]
    res = r if res<r else res
print(res)