N = int(input())
F = []
P = []
for i in range(N):
    temp = [int(i) for i in input().split()]
    tt = 0b0
    for j in range(len(temp)):
        tt += 2 ** j * temp[j]
    print(bin(tt))
    F.append(tt)
    
for i in range(N):
    temp = [int(i) for i in input().split()]
    P.append(temp)

def bene(bit):
    res = 0
    for i in range(N):
        a = bit & F[i]
        cc = 0
        for j in str(bin(a)):
            if j == "1":
                cc += 1
        res += P[i][cc]
    return res

benes = [bene(i) for i in range(1,1024)]
benes.sort()
print(benes[-1])