N = int(input())
F, P = [], []
for _ in range(N):
    F.append(int(''.join(list(map(str, input().split()))), 2))
for _ in range(N):
    P.append(list(map(int, input().split())))

ans = -1e10
for i in range(1,2**10):
    temp = 0
    for j in range(N):
        temp += P[j][bin(i&F[j]).count("1")]
    if temp > ans:
        ans = temp
print(ans)