N = int(input())
F = [int(input().replace(" ", ""), 2) for _ in range(N)]
P = [list(map(int,input().split())) for _ in range(N)]
ans = 0

for i in range(1,1024):
    ans = max(ans, sum(P[n][bin(i & F[n]).count('1')]for n in range(N)))

print(ans)