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)]
ans = float("-inf")
for g in range(1,1024):
    ans = max(ans, sum(p[bin(f&g).count("1")] for f, p in zip(fs, ps)))
    
print(ans)