from itertools import product

n = int(input())
fs = [[int(x) for x in input().split()] for _ in range(n)]
ps = [[int(x) for x in input().split()] for _ in range(n)]

xs = product((0, 1), repeat=10)
next(xs)
print(max(sum(p[sum(a==b==1 for a, b in zip(f, x))] for f, p in zip(fs, ps)) for x in xs))