import sys
input = sys.stdin.readline
N = int(input())
def inputs():return [int(x) for x in input().split()]
f = [inputs() for _ in range(N)]
p = [inputs() for _ in range(N)]
cnt =[0]*(N)
ans = -10**8
for bit in range(1,1<<10):
    ans1 = 0
    cnt =[0]*(N)
    for j in range(10):
        for i in range(N):
            if bit&1<<j and f[i][j]==1:
                cnt[i] +=1
    ans1 += sum([p[i][cnt[i]] for i in range(N)])
    ans = max(ans1,ans)
print(ans)
