n = int(input())
f = [list(map(int,input().split())) for _ in range(n)]
p = [list(map(int,input().split())) for _ in range(n)]

a     = []
count = 0
point = []
PP = []

for _ in range(1024,2048):
    a.append(list(map(int,list(bin(_)[3:]))))
    
for k in range(1024):
    for i in range(n):
        for j in range(10):
            if f[i][j] == a[k][j]:
                count += 1
        point.append(p[i][count])
        count = 0
    PP.append(sum(point))
    point = []
print (max(PP))