import numpy as np
l = 10
f = 2 ** l - 1
ans = -float("inf")
n = int(input())
j = np.array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0] for j in range(n)])
for i in range(n):
    j[i] = (np.array(list(map(int, input().split()))))
costs = np.array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] for j in range(n)])
for i in range(n):
    costs[i] = (np.array(list(map(int, input().split()))))
for i in range(2**l):
    ff = np.array(list(map(int, list(format(f, "b").zfill(l)))))
    tmp = 0
    for h in range(n):
        tmp += costs[0][np.sum(ff == j[h])]
    ans = max(ans, tmp)
    f -= 1
print(ans-1)
