N = int(input())
F = [list(map(int,input().split())) for _ in range(N)]
P = [list(map(int,input().split())) for _ in range(N)]
ans = -(10**9)
for i in range(1,2**10):
    a = [(i>>j)&1 for j in range(10)]
    tmp = 0
    for j in range(N):
        tmp += P[j][sum(a[k]*F[j][k] for k in range(10))]
    ans = max(ans,tmp)
print(ans)