import sys

input = sys.stdin.readline

N = int(input())
F = [int(input().replace(' ', ''), 2) for _ in range(N)]
P = [[int(x) for x in input().split()] for _ in range(N)]

ans = float('-inf')
for i in range(1, 2**10):
    res = 0
    for f, p in zip(F, P):
        cnt = bin(i & f).count('1')
        res += p[cnt]
    ans = max(ans, res)
print(ans)