n = int(input())
f = []
for _ in range(n):
    f.append(list(map(int, input().split())))

p = []
for _ in range(n):
    p.append(list(map(int, input().split())))


def dfs(day, state):
    if 5 == day:
        if 0 == sum(state):
            return -10 ** 7
        counts = [0 for _ in range(n)]
        for i in range(5):
            for j in range(n):
                if 1 == state[2 * i] and 1 == f[j][2 * i]:
                    counts[j] += 1
                if 1 == state[2 * i + 1] and 1 == f[j][2 * i + 1]:
                    counts[j] += 1
        profit = 0
        for i in range(n):
            profit += p[i][counts[i]]
        return profit
    canddiates = []
    state[2 * day] = 0
    canddiates.append(dfs(day + 1, state))
    state[2 * day] = 1
    canddiates.append(dfs(day + 1, state))
    state[2 * day + 1] = 0
    canddiates.append(dfs(day + 1, state))
    state[2 * day + 1] = 1
    canddiates.append(dfs(day + 1, state))
    return max(canddiates)


state = [0 for _ in range(10)]
print(dfs(0, state))
