
def binarize(txt):
    xs = txt.split(' ')
    xs = [int(x) for x in xs]
    b = 0
    for i in range(10):
        b += xs[i] * (2 ** i)
    return b


def count1(b):
    b = b[2:]
    count = 0
    for i in range(len(b)):
        if b[i] == '1':
            count += 1
    return count


N = input()
N = int(N)

F = [0 for i in range(N)]

for i in range(N):
    txt = input()
    F[i] = binarize(txt)


P = [[] for i in range(N)]

for i in range(N):
    xs = input().split(' ')
    P[i] = [int(x) for x in xs]


m = - 10 ** 11

for i in range(1, 2**10-1):

    score = 0

    for j in range(N):
        b = bin(i & F[j])
        count = count1(b)
        score += P[j][count]

    if score > m:
        m = score

print(m)