n = int(input())
f = [int(input()[::2], 2) for i in range(n)]
p = [list(map(int, input().split())) for l in range(n)]
ans = -float("inf")
for h in range(1, 1024):
    ans = max(ans, sum(p[g][sum(list(map(int, bin(f[g] & h)[2:])))] for g in range(n)))
print(ans)
