from operator import mul

n = int(input())
cof = [1 << x for x in range(10)]
fs = [sum(map(mul, map(int, input().split()), cof)) for _ in range(n)]
ps = [list(map(int, input().split())) for _ in range(n)]
print(max(sum(p[bin(f & g).count('1')] for f, p in zip(fs, ps)) for g in range(1, 1024)))
