N = int(input())
F = [int(input().replace(' ',''),2) for _ in [0]*N]
P = [[int(x) for x in input().split()] for _ in [0]*N]
print(max([sum([P[j][bin(i&F[j]).count('1')] for j in range(N)])for i in range(1,2**10)]))