N = int(input())
F_list = [int(input().replace(' ', ''), 2) for _ in range(N)]
P_list = [list(map(int, input().split())) for _ in range(N)]

max_p = float('-inf')
for i in range(1,1024):
    p = 0
    for j in range(len(F_list)):
        c = format(i & F_list[j], 'b').count('1')
        p += P_list[j][c]
    if p > max_p:
        max_p = p
print(max_p)
