plans = []
def dfs(i, array):
    if i == 10:
        if sum(array) > 0:
            plans.append(list(array))
    else:
        array[i] = 0
        dfs(i+1, array)

        array[i] = 1
        dfs(i+1, array)

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


N = int(input())
Fs = [[int(f) for f in input().split(' ')] for _ in range(N)]
Ps = [[int(f) for f in input().split(' ')] for _ in range(N)]

ans = -10000
for plan in plans:
    price = 0
    for i, F in enumerate(Fs):
        n = sum([1 for f, p in zip(F, plan)
                 if f == 1 and p == 1])
        price += Ps[i][n]

    ans = max(ans, price)

print(ans)


