N = int(input())
F = [[int(f) for f in input().split()] for _ in range(N)]
P = [[int(p) for p in input().split()] for _ in range(N)]

ans = -10**9-7
for i in range(2**10+1, 2**11-1):
    num = 0
    b = bin(i)
    for j in range(N):
        cnt = 0
        for k in range(10):
            if F[j][k] == 1 and b[k+3] == "1":
                cnt += 1
        num += P[j][cnt]
    ans = max(ans, num)
    
print(ans)