from itertools import product


def BothAreOpen(arrange1, arrange2):
    counter = 0
    for element in zip(arrange1, arrange2):
        if element == (1, 1):
            counter += 1
    return counter


N = int(input())
OpeningHours = [list(map(int, input().split())) for i in range(N)]
Profits = [list(map(int, input().split())) for i in range(N)]

ans = -100000000

for MyShop in product([0, 1], repeat=10):
    if MyShop == tuple([0] * 10):
        continue

    chofuku = []
    for OtherStore in OpeningHours:
        chofuku.append(BothAreOpen(MyShop, OtherStore))

    x = sum([Profits[i][chofuku[i]] for i in range(N)])
    if x > ans:
        ans = x

print(ans)
