N = int(input())
F = [[] for _ in range(N)]
for i in range(N):
    F[i] = list(map(int, input().split()))
P = [[] for _ in range(N)]
for i in range(N):
    P[i] = list(map(int, input().split()))

joisino = [False] * 10


def dfs(i):
    if i == 10:
        score = 0
        for j in range(N):
            G = [(joisino[k] and (F[j][k] == 1)) for k in range(10)]
            count = G.count(True)
            score += P[j][count]
        return score
    else:
        ans1 = dfs(i + 1) if joisino.count(True) > 0 else -float('inf')
        joisino[i] = True
        ans2 = dfs(i + 1)
        joisino[i] = False
        return max(ans1, ans2)


ans = max(-float('inf'), dfs(0))
print(ans)
