import numpy as np
N = int(input())
F = np.array(tuple(tuple(map(int, input().split())) for _ in range(N)), dtype=np.int8)
P = np.array(tuple(tuple(map(int, input().split())) for _ in range(N)), dtype=np.int8)
arrange = np.arange(N)
print(max(P[arrange, F[:, list(map(lambda n: n == "1",format(n, "010b")))].sum(axis=1)].sum() for n in range(1, 1 << 10)))