import sys
def 解():
    input = sys.stdin.readline
    iN = int(input())
    aF = [0]*iN
    aP = [0]*iN
    for i in range(iN):
        aF[i] = int(input().rstrip().replace(' ',''),2)
    for i in range(iN):
        aP[i] = [int(_) for  _ in input().split()]
    iD = 2**10
    iMax = -1*(10**8)
    for i in range(1,iD):
        iM = 0
        for j in range(iN):
            iM += aP[j][bin(aF[j] & i).count("1")]
        if iMax < iM:
            iMax = iM
    print(iMax)
解()
