from itertools import product

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

max_res = -10**8

for i,j in enumerate(product("01",repeat=10)):
    if i != 0:
        res = [0 for _ in range(N)]
        for k, flag in enumerate(j):
            if flag == "1":
                for l,f in enumerate(F):
                    if f[k] == "1":
                        res[l] += 1
        buf = 0
        for m in range(N):
            buf += int(P[m][res[m]])
        max_res = max(buf,max_res)

print(max_res)