def calculate():
    global maxv
    if sum(ans) == 0:
        return
    score = 0
    for f, p in zip(F, P):
        score += p[bin(int(''.join(map(str, ans)), 2)&f).count('1')]
    maxv = max(maxv, score)

def dfs(pos):
    if pos == 10:
        calculate()
        return
    ans[pos] = 0
    dfs(pos+1)
    ans[pos] = 1
    dfs(pos+1)

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

pos = 0
ans = [0] * 10
maxv = -1000000
dfs(pos)
print(maxv)
