N = int(raw_input())
F = []
for n in range(N):
    F.append([int(val) for val in raw_input().split(" ")])
P = []
for n in range(N):
    P.append([int(val) for val in raw_input().split(" ")])

print N
print F
print P

max_val = None
for i_X in xrange(1, 2**10):
    c_i = [0]*N
    for i_pos in range(10):
        X_ijk = (i_X/(2**i_pos))%2
        for i_n in xrange(N):
            c_i[i_n] += F[i_n][i_pos] * X_ijk
    score = sum([P[i_n][c_i[i_n]] for i_n in xrange(N)])
    if (type(max_val) == type(None)) or (score > max_val):
        max_val = score

print max_val