from itertools import product

def solve(n, FF, PP):
    return max(
        sum(P[sum(i & f for i, f in zip(I, F))] for F, P in zip(FF, PP))
        for I in list(product(range(2), repeat=10))[1:]
    )

_n = int(input())
_FF = [list(map(int, input().split())) for _ in range(_n)]
_PP = [list(map(int, input().split())) for _ in range(_n)]
print(solve(_n, _FF, _PP))
