n=int(input())
f=[list(map(int,input().split())) for _ in range(n)]
p=[list(map(int,input().split())) for _ in range(n)]
ans=-float('inf')
for i in range(1,2**10):
    tmp=list(map(int,list(format(i, '08b'))))
    p_tmp=[0 for _ in range(n)]
    for i in range(n):
        cnt=0
        for j in range(len(tmp)):
            if tmp[j]==1 and f[i][j]==tmp[j]:
                cnt+=1
        p_tmp[i]=cnt
    P=0
    for k in range(n):
        P+=p[k][p_tmp[k]]
    ans=max(ans,P)
print(ans)