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

ans = -100000000
for i in range(1, 2 ** 10):
    sum = 0
    for j, f in enumerate(F):
        cover = i & f
        cnt = 0
        while cover != 0:
            if cover % 2 == 1:
                cnt += 1
            cover //= 2
        sum += P[j][cnt]
    ans = max(sum, ans)

print(ans)
