n = int(input())
fs = [list(map(int, input().split())) for _ in range(n)]
ps = [list(map(int, input().split())) for _ in range(n)]
res = -float('inf')
for i in range(1, 2**10):
    s = list(map(int, list(bin(i)[2:])))
    val = 0
    for f, p in zip(fs, ps):
        count = 0
        for a, b in zip(s, f):
            if a == 1 and b == 1:
                count += 1
        val += p[count]
    res = max(res, val)
print(res)