N = int(input())

F=[int(input().replace(" ",""),2) for i in range(N)]
#f = [list(map(int, input().split())) for _ in range(n)]
P = [list(map(int, input().split())) for _ in range(N)]
ans = - 10**18
for i in range(1, 2**10):
    s = 0
    for f,p in zip(F,P):
        s += p[bin(f&i).count("1")]
    ans = max(ans, s)
print(ans)