import numpy as np
n = int(input())
f = np.zeros((n, 10))
p = np.zeros((n, 11))
for i in range(n):
    f[i] = np.array(list(map(int, input().split())))

for i in range(n):
    p[i] = np.array(list(map(int, input().split())))

l = 10
f_n = 2**l-1
ans = (-10**7)*10*n
for i in range(2**l-1):
    ff = np.array(list(map(int,list(format(f_n,'b').zfill(l)))))
    print (ff)
    c = np.sum(ff*f, dtype=np.int64, axis=1)
    c = np.eye(11)[c]
    tmp = np.sum(c*p)
    if ans < tmp:
        ans = tmp
    f_n -= 1
    
print (int(ans))
