import sys
import numpy as np
from itertools import product

input = sys.stdin.readline

N = int(input())

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

f = np.array(F)
p = np.array(P)

def cal(f, p, v):
    total = 0
    max_total = -10**8
    c = np.dot(f, v.T)
    for ci in c.T:
        total = sum([p[i,cii] for i, cii in enumerate(ci)])
        max_total = max(total, max_total)
    return max_total

v = np.array(list(product([0,1],repeat=10)))
v[0] = np.array([0,0,0,0,0,0,0,0,0,1])

print(cal(f, p, v))
