N = int(eval(input()))

F = []

P = []

for i in range(N):

    F.append(list(map(int, input().split())))

for i in range(N):

    P.append(list(map(int, input().split())))



TIME = 10

prof_cand = []



for bit in range(1,1<<TIME):

    onBiz = []

    with_n = []

    for t in range(TIME):

        if bit & (1<<t):

            onBiz.append(1)

        else:

            onBiz.append(0)

            

    for n in range(N):

        with_n.append(sum([F[n][i]*onBiz[i] for i in range(TIME)]))

    

    prof = sum([P[i][with_n[i]] for i in range(N)])

    prof_cand.append(prof)

    

print((max(prof_cand)))
import sys

stdin = sys.stdin



sys.setrecursionlimit(10**5) 

 

def li(): return list(map(int, stdin.readline().split()))

def li_(): return [int(x)-1 for x in stdin.readline().split()]

def lf(): return list(map(float, stdin.readline().split()))

def ls(): return stdin.readline().split()

def ns(): return stdin.readline().rstrip()

def lc(): return list(ns())

def ni(): return int(stdin.readline())

def nf(): return float(stdin.readline())



def dfs(depth:int, inbis:str, f:list, p:list):

    if depth != 10:

        return max(dfs(depth+1, inbis+"1",f,p),

                   dfs(depth+1, inbis+"0",f,p))

        

    else:

        if inbis.count("1") == 0:

            return -10**10

        else:

            biz = [int(i) for i in inbis]

            ans = 0

            for i in range(len(f)):

                common = [biz[j]*f[i][j] for j in range(10)]

                ans += p[i][sum(common)]

                

            return ans



n = ni()

f = []

p = []

for _ in range(n):

    f.append(list(li()))

for _ in range(n):

    p.append(list(li()))

    

print((dfs(0,"",f,p)))
N = int(eval(input()))
F = []
P = []
for i in range(N):
    F.append(list(map(int, input().split())))
for i in range(N):
    P.append(list(map(int, input().split())))
TIME = 10
prof_cand = []
for bit in range(1, 1 << TIME):
    onBiz = []
    with_n = []
    for t in range(TIME):
        if bit & (1 << t):
            onBiz.append(1)
        else:
            onBiz.append(0)
    for n in range(N):
        with_n.append(sum([F[n][i] * onBiz[i] for i in range(TIME)]))
    prof = sum([P[i][with_n[i]] for i in range(N)])
    prof_cand.append(prof)
print((max(prof_cand)))

import sys

stdin = sys.stdin
sys.setrecursionlimit(10**5)


def li():
    return list(map(int, stdin.readline().split()))


def li_():
    return [int(x) - 1 for x in stdin.readline().split()]


def lf():
    return list(map(float, stdin.readline().split()))


def ls():
    return stdin.readline().split()


def ns():
    return stdin.readline().rstrip()


def lc():
    return list(ns())


def ni():
    return int(stdin.readline())


def nf():
    return float(stdin.readline())


def dfs(depth: int, inbis: str, f: list, p: list):
    if depth != 10:
        return max(dfs(depth + 1, inbis + "1", f, p), dfs(depth + 1, inbis + "0", f, p))
    else:
        if inbis.count("1") == 0:
            return -(10**10)
        else:
            biz = [int(i) for i in inbis]
            ans = 0
            for i in range(len(f)):
                common = [biz[j] * f[i][j] for j in range(10)]
                ans += p[i][sum(common)]
            return ans


n = ni()
f = []
p = []
for _ in range(n):
    f.append(list(li()))
for _ in range(n):
    p.append(list(li()))
print((dfs(0, "", f, p)))

-N = int(eval(input())) -F = [] -P = [] -for i in range(N): -    F.append(list(map(int, input().split()))) -for i in range(N): -    P.append(list(map(int, input().split()))) -TIME = 10 -prof_cand = [] -for bit in range(1, 1 << TIME): -    onBiz = [] -    with_n = [] -    for t in range(TIME): -        if bit & (1 << t): -            onBiz.append(1) +import sys + +stdin = sys.stdin +sys.setrecursionlimit(10**5) + + +def li(): +    return list(map(int, stdin.readline().split())) + + +def li_(): +    return [int(x) - 1 for x in stdin.readline().split()] + + +def lf(): +    return list(map(float, stdin.readline().split())) + + +def ls(): +    return stdin.readline().split() + + +def ns(): +    return stdin.readline().rstrip() + + +def lc(): +    return list(ns()) + + +def ni(): +    return int(stdin.readline()) + + +def nf(): +    return float(stdin.readline()) + + +def dfs(depth: int, inbis: str, f: list, p: list): +    if depth != 10: +        return max(dfs(depth + 1, inbis + "1", f, p), dfs(depth + 1, inbis + "0", f, p)) +    else: +        if inbis.count("1") == 0: +            return -(10**10) -            onBiz.append(0) -    for n in range(N): -        with_n.append(sum([F[n][i] * onBiz[i] for i in range(TIME)])) -    prof = sum([P[i][with_n[i]] for i in range(N)]) -    prof_cand.append(prof) -print((max(prof_cand))) +            biz = [int(i) for i in inbis] +            ans = 0 +            for i in range(len(f)): +                common = [biz[j] * f[i][j] for j in range(10)] +                ans += p[i][sum(common)] +            return ans + + +n = ni() +f = [] +p = [] +for _ in range(n): +    f.append(list(li())) +for _ in range(n): +    p.append(list(li())) +print((dfs(0, "", f, p)))