N=int(input())
H=['']*N
W=['']*N
x=[]
for i in range(N):
    H[i]=list(map(int,input().split()))
for j in range(N):
    W[j]=list(map(int,input().split()))
for k in range(1024):
    t=[]
    for ii in range(10):
        if k&(1<<ii):
            t+=[1]
        else:
            t+=[0]
            ans=0
    for jj in range(N):
        s=0
        for kk in range(10):
            s+=H[jj][kk]*t[kk]
        ans+=W[jj][s]
    x.append(ans)
print(max(x))    
