# -*- coding: utf-8 -*-

def main(N,F,P):
    inf = float("INF")
    ans = -inf
    print(F,P)
    
    for i in range(1,1<<10):
        count = [0]*N
        tmp = 0
        for j in range(10):
            if((i>>j)&1):
                for k in range(N):
                    if F[k][j]==1:
                        count[k] += 1
            else:
                continue
            
        for l in range(N):
            tmp += P[l][count[l]]
        ans = max(ans,tmp)
    print(ans)

if __name__ == '__main__':
    N = int(input())
    F,P = [],[]
    for i in range(N):
        F.append([int(j) for j in input().split()])
    for i in range(N):
        P.append([int(j) for j in input().split()])
    main(N,F,P)