N=int(input())
F=[]
for i in range(N):
    tem = list(map(int,input().split()))
    F.append(tem)
P=[]
for i in range(N):
    tem = list(map(int,input().split()))
    P.append(tem)


max_benef =-float("inf")

for d in range(1,2**10):
    op = ["-"] * 10  # あらかじめ ["-", "-", "-"] というリストを作っておく
    for j in range(10):
        if ((d >> j) & 1):
            op[10 - 1 - j] = "+"  # フラグが立っていた箇所を "+" で上書き
    
    m =0
    count=[0 for t in range(10)]
    for t in range(10):
        if op[t]=="+":
            for s in range(10):
                if F[s][t]==1:
                    count[s]+=1
        for s in range(10):
            m += P[s][count[s]]
        ans = max(m,ans)
    
    print(ans)




