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

# for i in range(N):
#     print(bin(F[i]))

ans = -10**9
for bit in range(1, 1<<10):
    money = 0
    for i in range(N):
        cnt = format(bit&F[i], 'b').count('1')
        money += P[i][cnt]
    ans = max(money, ans)
 
print(ans)
