n = int(input())
f=[]
for i in range(n):
    tmp = list(map(int,input().split()))
    f.append(tmp)
p=[]
for i in range(n):
    tmp = list(map(int,input().split()))
    p.append(tmp)

from itertools import *
first=True
ans=-10**12
for tmp in list(product([0,1], repeat=10)):
    if first:
        first=False
        continue

    for i in range(n):
        cnt=0
        for j in range(10):
            cnt+= tmp[j] & mise[j]
        sm=0
        for i in range(n):
            sm+=p[i][cnt]
        if ans < sm:
            ans=sm
print(ans)