CodeEff/ECCO huggingface dataset:
# Original solution
n = int(eval(input()))
F = [list(map(int, input().split())) for _ in range(n)]#F[i]は(i+1)番目の店の営業の有無のリスト
P = [list(map(int, input().split())) for _ in range(n)]#P[i]は(i+1)番目の店との同時開店数に応じた利益のリスト

ans = (-1) * 10 ** 9
for i in range(2 ** 10):
    if sum(map(int, list(str(i)))) == 0:
        continue
    cnt_lst = [0 for _ in range(n)]
    for d in range(5):
        for t in range(2):
            dt = 2 * d + t
            if i & (2 ** dt) != 0:
                for j in range(n):
                    cnt_lst[j] += F[j][dt]
    buf = 0
    for j in range(n):
        buf += P[j][cnt_lst[j]]
    ans = max(buf, ans)
print(ans)

# Optimized solution
def main():
    from itertools import combinations

    N = int(eval(input()))
    F = []
    for _ in range(N):
        t = 0
        for j, b in enumerate(map(int, input().split())):
            if b:
                t |= (1 << j)
        F.append(t)
    # F[i]:=店舗iの営業時間情報
    P = [list(map(int, input().split())) for _ in range(N)]
    # P[i]:=店舗iと営業時間が重なる個数に対する利益

    ans = -10 ** 9 - 1
    for open_ in range(1, 10 + 1):
        for comb in combinations(list(range(10)), r=open_):
            t = 0
            for j in comb:
                t |= (1 << j)

            p = 0
            for i, f in enumerate(F):
                x = bin(t & f).count('1')
                p += P[i][x]

            ans = max(ans, p)

    print(ans)


if __name__ == '__main__':
    main()
# Original solution
#!/mnt/c/Users/moiki/bash/env/bin/python
# N,M = map(int, input().split())
N = int(eval(input()))
F = [list(map(int, input().split())) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]

ans = - 10**10

for i in range(1,1<<10):
    score = 0
    for n in range(N):
        f = "".join(map(str,F[n])) 
        b = "{:010b}".format(i)
        c = [int(f[i]) & int(b[i]) for i in range(10)]
        cnt = len(list([x for x in c if x]))
        score += P[n][cnt]
    ans = max(ans, score)
print(ans)


# Optimized solution
N = int(eval(input()))
F = [ int(input().replace(" ", ""), 2) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]
ans = - 10**10

for i in range(1,1<<10):
    ans = max(ans, sum(P[n][bin(i&F[n]).count('1')] for n in range(N)))
print(ans)
# Original solution
icase=0
if icase==0:
    n=int(eval(input()))

    f=[]
    for i in range(n):
        fi=list(map(int,input().split()))
        f.append(fi)
    p=[]
    for i in range(n):
        pi=list(map(int,input().split()))
        p.append(pi)
elif icase==1: 
    n=1
    f=[[1, 1, 0, 1, 0, 0, 0, 1, 0, 1]]
    p=[[3, 4, 5, 6, 7, 8, 9, -2, -3, 4, -2]]
elif icase==2: 
    n=2
    f=[[1, 1, 1, 1, 1, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 1, 1, 1, 1, 1]]
    p=[[0, -2, -2, -2, -2, -2, -1, -1, -1, -1, -1],
       [0, -2, -2, -2, -2, -2, -1, -1, -1, -1, -1]]
elif icase==3: 
    n=3
    f=[[1, 1, 1, 1, 1, 1, 0, 0, 1, 1],
       [0, 1, 0, 1, 1, 1, 1, 0, 1, 0],
       [1, 0, 1, 1, 0, 1, 0, 1, 0, 1]]
    p=[[-8, 6, -2, -8, -8, 4, 8, 7, -6, 2, 2],
       [-9, 2, 0, 1, 7, -5, 0, -2, -6, 5, 5],
       [6, -6, 7, -9, 6, -5, 8, 0, -9, -7, -7]]
    
import itertools
sumpmax=-10**11
for i in itertools.product([0,1], repeat=10):
    r=list(i)
    sump=0
    if sum(r)!=0:
        for jj in range(n):
            ci=0
            for j in range(10):
                ci=ci+r[j]*f[jj][j]
            sump=sump+p[jj][ci]
#            print(sump,r)
        sumpmax=max(sump,sumpmax)
print(sumpmax)

# Optimized solution
import itertools

n=int(eval(input()))
f=[[]]*n
for i in range(n):
    fij=list(map(int,input().split()))
#    f[i].append(fij)
    f[i]=fij
p=[[]]*n
for i in range(n):
    pij=list(map(int,input().split()))
    p[i]=pij
    
pmax=-10**11
for a in itertools.product([0,1], repeat=10):
    if sum(a)==0:
        continue
    psum=0
    for ni in range(n):
        k=0
        for i in range(10):
            if f[ni][i]==1 and a[i]==1:
                k+=1
        psum=psum+p[ni][k] 
    pmax=max(pmax,psum)   

print(pmax)
# Original solution
# -*- coding: utf-8 -*-

import itertools

N = int(eval(input()))
F = []
for i in range(N):
    F.append(list(map(int, input().split())))
P = []
for i in range(N):
    P.append(list(map(int, input().split())))

# 重複順列で自分の店の全パターンを出す
me_list = list(itertools.product([0, 1], repeat=10))

# 初期値は利益の最小値
me_p = -1000000000
# 自分の店の全パターンループ
for i in range(len(me_list)):

    # 一度も営業しないパターンを除く
    if i == 0:
        continue

    tmp_p = 0
    # 他店の数でループ
    for j in range(N):

        cnt = 0
        # 月～金のAMPMループ
        for k in range(10):

            # 他店との営業重複カウント
            if me_list[i][k] == 1 and F[j][k] == 1:
                cnt += 1
        
        # 各店舗との重複数に応じた利益を合算していく
        tmp_p += P[j][cnt]

    # 合算した利益を現状の最高値と比較して置き換えていく
    me_p = max(me_p, tmp_p)   

print(me_p)

# Optimized solution
# -*- coding: utf-8 -*-

import itertools

N = int(eval(input()))
F = []
for i in range(N):
    F.append(list(map(int, input().split())))
P = []
for i in range(N):
    P.append(list(map(int, input().split())))

# 重複順列で自分の店の全パターンを出す
me_list = list(itertools.product([0, 1], repeat=10))

# 初期値は利益の最小値
me_p = -float("inf")
# 自分の店の全パターンループ
for i in range(len(me_list)):

    # 一度も営業しないパターンを除く
    if i == 0:
        continue

    tmp_p = 0
    # 他店の数でループ
    for j in range(N):

        cnt = 0
        # 月～金のAMPMループ
        for k in range(10):

            # 他店との営業重複カウント
            if me_list[i][k] == 1 and F[j][k] == 1:
                cnt += 1
        
        # 各店舗との重複数に応じた利益を合算していく
        tmp_p += P[j][cnt]

    # 合算した利益を現状の最高値と比較して置き換えていく
    me_p = max(me_p, tmp_p)   

print(me_p)
# Original solution
import itertools
mylist = [0, 1]
n = int(input().rstrip())

mise = [list(map(int, input().rstrip().split())) for i in range(n)]
mine = [list(map(int, input().rstrip().split())) for i in range(n)]

maxnum = - float('inf')
for i in itertools.product(mylist, repeat = 10):
    if sum(i) == 0:
        continue
    sell = 0
    for j, k in zip(mise, mine):
        temp = 0
        for l in range(10):
            if j[l] == i[l] and j[l] == 1:
                temp += 1
        sell += k[temp]
    maxnum = max(maxnum, sell)
print(maxnum)

# Optimized solution
MAX_TIME = 10
n = int(input().rstrip())
#２進法を
P = [sum(int(i) << MAX_TIME-k-1 for k, i in enumerate(input().rstrip().split())) for j in range(n)]
S = [list(map(int, input().rstrip().split())) for i in range(n)]
#予め2進数をカウントしておく
    # 予めビットをカウントしておく
pattern = [sum(i >> j & 1 for j in range(MAX_TIME)) for i in range(2 ** MAX_TIME)]
result = -float('inf')


for i in range(1, 2**MAX_TIME):
    temp = 0
    for l, j in zip(P, S):
        temp += j[pattern[l & i]]
    result = max(result, temp)
print(result)
# Original solution
N = int(eval(input()))
F = [list(map(int, input().split())) for k in range(N)]
P = [list(map(int, input().split())) for k in range(N)]
B = [format(k,'b').zfill(10) for k in range(1,1024)]
ans = -10**9

for d in B:
    t = 0
    E = [0 for k in range(N)]
    for l in range(N):
        for k in range(10):
            E[l] += int(d[k])*F[l][k]
    for k in range(N):
        t += P[k][E[k]]
    ans = max(t,ans)

print(ans)

# Optimized solution
N = int(eval(input()))
F = [list(map(int,input().split())) for k in range(N)]
P = [list(map(int,input().split())) for k in range(N)]
ans = -float("inf")
for k in range(2**10):
    temp = 0
    S = [0 for l in range(N)]
    for s in range(N):
        for d in range(10):
            if (k>>d)&1 == 1:
                if F[s][d] == 1:
                    S[s] += 1
    if sum(S) > 0:
        for l in range(N):
            temp += P[l][S[l]]
        ans = max(ans,temp)

print(ans)
# Original solution
import itertools
N=eval(input())
F=[]
for i in range(N):
	F.append(list(map(int,input().split())))
#print F

P=[]
for i in range(N):
	P.append(list(map(int,input().split())))
#print P


l=list(itertools.product(list(range(2)), repeat=10))
#l=[(1, 1, 1, 1, 1, 0, 0, 0, 0, 0),(0, 0, 0, 0, 0, 1, 1, 1, 1, 1),(0, 0, 0, 0, 0, 1, 1, 1, 1, 1)]
l.remove((0, 0, 0, 0, 0, 0, 0, 0, 0, 0))

b=[[] for i in range(2**10-1)]


for ind_i,i in enumerate(l):
	for j in F:
		#print [min(t) for t in zip(i, j)]
		#print sum([min(t) for t in zip(i, j)])
		b[ind_i].append(sum([min(t) for t in zip(i, j)]))
#print b

b_sum=0
ans=float("-inf")
for ind_i,i in enumerate(b):
	b_sum=0
	for ind_j,j in enumerate(i):
		#print ind_i, ind_j,j
		b_sum+=P[ind_j][j]
	#print sum
	ans=max(ans,b_sum)

print(ans)

# Optimized solution
# -*- coding: utf-8 -*-
import sys

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

D=[]    #各店の状態を10進数で表示
for f in F: #各店の状態を10進数に置き換え
    n=0
    for i,x in enumerate(f):
        if x==1:
            n+=2**(9-i)
    D.append(n)


def count_one(n):
    cnt=0
    for i in range(10):
        cnt+=n>>i&1
    return cnt

ans=float("-inf")
for i in range(1,2**10):
    t=0 #temporary
    for j,d in enumerate(D):
        c=count_one(d&i)    #両方の店が営業している時間帯の個数
        t+=P[j][c]
    ans=max(ans,t)

print(ans)
# Original solution
N=int(eval(input()))
F=[int(input().replace(' ',''),2)for _ in[0]*N]
P=[list(map(int,input().split()))for _ in[0]*N]
ans = -float('inf')
for i in range(1,2**10):
    sum = 0
    for k in range(N):
        sum += P[k][bin(F[k]&i).count('1')]
    if ans < sum:
        ans = sum
print(ans)

# Optimized solution
N=int(eval(input()))
F=[int(input().replace(' ',''),2)for _ in[0]*N]
P=[list(map(int,input().split()))for _ in[0]*N]
print((max(sum([p[bin(f&i).count('1')]for f,p in zip(F,P)])for i in range(1,2**10))))
# Original solution
N=int(eval(input()))
F=[list(map(int,input().split())) for _ in range(N)]
P=[list(map(int,input().split())) for _ in range(N)]

ans=-10**18
for i in range(1,2**10):
  tmp=0
  for j in range(N):
    cnt=0
    for k in range(10):
      if i&(1<<k) and F[j][k]:
        cnt+=1
    tmp+=P[j][cnt]
  ans=max(ans,tmp)
print(ans)

# Optimized solution
import sys
input=sys.stdin.readline
N=int(eval(input()))
F=[int(input().replace(' ',''),2) for _ in range(N)]
P=[list(map(int,input().split())) for _ in range(N)]

ans=-10**18
for i in range(1,2**10):
  cnt=0
  for j in range(N):
    cnt+=P[j][bin(F[j] & i).count('1')]
  ans=max(ans,cnt)
print(ans)
# Original solution
n = int(eval(input()))
F = [[] * 10 for _ in range(n)]
P = [[] * 10 for _ in range(n)]

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

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


res = -1<<30
for item in range(1, 1 << 10):
	fund = 0
	for i in range(n):
		cnt = 0
		for x in range(10):
			if item >> x & 1 and F[i][x] == 1:
				cnt += 1
		fund += P[i][cnt]
	res = max(res, fund)

print(res)

# Optimized solution
from itertools import product

bit = [0, 1]

lst = list(product(bit, repeat=10))

n = int(eval(input()))
F = [list(map(int, input().split())) for i in range(n)]
P = [list(map(int, input().split())) for j in range(n)]

res = -1 << 30
for v in lst:
	if v.count(0) == 10: continue
	fund = 0
	for i in range(n):
		cnt = 0
		for x in range(10):
			if F[i][x] == 1 and v[x] == 1:
				cnt += 1
		fund += P[i][cnt]
	res = max(res, fund)

print(res)
# Original solution
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)))

# Optimized solution
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)))
# Original solution
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)))

# Optimized solution
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())

n = ni()
f = [int("".join(ls()), 2) for _ in range(n)]      
p = [list(li()) for _ in range(n)]

# bit全探索
ans = -float("inf")
for bit in range(1, 1<<10):
    profit = 0
    
    for i,fi in enumerate(f):
        both = bin(bit&fi).count("1")
        profit += p[i][both]
    
    ans = max(ans, profit)
    
print(ans)
# Original solution
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())

n = ni()
f = [int("".join(ls()), 2) for _ in range(n)]      
p = [list(li()) for _ in range(n)]

# bit全探索
ans = -float("inf")
for bit in range(1, 1<<10):
    profit = 0
    
    for i,fi in enumerate(f):
        both = 0
        
        for mask in range(10):
            if bit&(1<<mask) and fi&(1<<mask):
                both += 1
        
        profit += p[i][both]
    
    ans = max(ans, profit)
    
print(ans)

# Optimized solution
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())

n = ni()
f = [int("".join(ls()), 2) for _ in range(n)]      
p = [list(li()) for _ in range(n)]

def dfs(cur:int, depth:int):
    if depth == 10:
        if cur == 0:
            return -float("inf")
        else:
            return sum([p[i][bin(cur&fi).count("1")] for i, fi in enumerate(f)])
    
    else:
        return max(dfs(cur+(1<<depth), depth+1),
                   dfs(cur, depth+1))
        
print((dfs(0,0)))
# Original solution
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

import itertools

n = int(readline())
f = [list(map(int, readline().split())) for _ in range(n)]
p = [list(map(int, readline().split())) for _ in range(n)]
bit = list(itertools.product([0, 1], repeat=10))
ans = -float('inf')
bit.pop(0)
for i in range(2 ** 10 - 1):
    memo = 0
    flag = False
    for j in range(n):
        cnt = 0
        for k in range(10):
            if bit[i][k] == f[j][k] == 1:
                cnt += 1
        if cnt != 0:
            flag = True
        memo += p[j][cnt]
    if flag:
        ans = max(ans, memo)
print(ans)


# Optimized solution
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from itertools import product

n = int(readline())
f = [list(map(int, readline().split())) for _ in range(n)]
p = [list(map(int, readline().split())) for _ in range(n)]
ans = -float('inf')
for bit in list(product([0, 1], repeat=10))[1:]:
    v = 0
    for ff, pp in zip(f, p):
        cnt = 0
        for i, check in enumerate(ff):
            if bit[i] == check == 1:
                cnt += 1
        v += pp[cnt]
    if ans < v:
        ans = v
print(ans)
# Original solution
import sys

input = sys.stdin.readline

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

# 各曜日時間帯に開くか開かないかは2**10=1024通りしかないので
# O(N*2**10) = O(10**5)で間に合う
# 長さ10の配列に0 or 1を格納するbit全探索を行う。
# F[i][j]: 店i, jは曜日と時間帯を表す0~9

n = 10
max_profit = - float("inf")
for bit in range(1, 1<<n):  # 2**10まで2進数で(1つ以上の時間帯で営業しないといけないから000000000を除くため、1スタート)
    profit = 0
    for i in range(N):  # 店の数
        count = 0
        for j in range(n):  # bit（10桁）のどこに1があるか調べる
            if F[i][j] == 1 and (bit>>j) & 1:  # 右シフトしたbitの最後の桁が1ならTrue
                    # 10回シフトして最後の桁が1か調べる == bitのj桁目に1があればTrue
                count += 1
        profit += P[i][count]
    max_profit = max(max_profit, profit)

print(max_profit)

# Optimized solution
N = int(eval(input()))
F = []
for _ in range(N):
    F.append(list(map(int, input().split())))
P = []
for _ in range(N):
    P.append(list(map(int, input().split())))

n = 10
answer = -float("inf")
for bit in range(1, 1<<n):
    ans = 0
    for i in range(N):
        count = 0
        for j in range(n):
            if F[i][j] and (bit>>j & 1):
                count += 1
        ans += P[i][count]
    answer = max(ans, answer)

print(answer)
# Original solution
I=input;n=int(I());f=[int(I()[::2],2)for _ in[0]*n];p=[I().split()for _ in[0]*n];print((max(sum(int(q[bin(i&g).count('1')])for g,q in zip(f,p))for i in range(1,1024))))

# Optimized solution
I=input;n=int(I());f=eval('int(I()[::2],2),'*n);p=eval('I().split(),'*n);print((max(sum(int(q[bin(i&g).count('1')])for g,q in zip(f,p))for i in range(1,1024))))
# Original solution
# coding:utf-8

INF = float('inf')


def inpl(): return list(map(int, input().split()))


N = int(eval(input()))

F = [inpl() for _ in range(N)]
P = [inpl() for _ in range(N)]

ans = -INF
for i in range(1, 1 << 10):

    score = 0
    for shop in range(N):

        both_open = 0
        for period in range(10):
            if i >> period & F[shop][period] == 1:
                both_open += 1

        score += P[shop][both_open]

    ans = max(ans, score)

print(ans)

# Optimized solution
# coding:utf-8

import sys

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return eval(input())


n = II()
F = [LI() for _ in range(n)]
P = [LI() for _ in range(n)]

ans = -INF
for bit in range(1, 1024):
    profit = 0
    for shop in range(n):
        cnt = 0
        for shift in range(10):
            if not bit >> shift & 1:
                continue

            if F[shop][shift]:
                cnt += 1

        profit += P[shop][cnt]

    ans = max(ans, profit)

print(ans)
# Original solution
n = int(eval(input()))
f = [list(map(int,input().split())) for i in range(n)]
p = [list(map(int,input().split())) for i in range(n)]
ans = -10**10
for i in range(1,2**10):
    a = 0
    for j in range(n):
        a += p[j][sum(i>>k&1 and f[j][k] for k in range(10))]
    ans = max(ans,a)
print(ans)


# Optimized solution
n = int(eval(input()))
f = [list(map(int,input().split())) for i in range(n)]
p = [list(map(int,input().split())) for i in range(n)]
print((max(sum(p[j][sum(i>>k&1 and f[j][k] for k in range(10))] for j in range(n)) for i in range(1,2**10))))
# Original solution
N = int(eval(input()))
F = [list(map(int,input().split())) for n in range(N)]
P = [list(map(int,input().split())) for n in range(N)]
ans = []

for i in range(1,1024):
  p = 0
  for j in range(N):
    c = 0
    for k in range(10):
      if (i>>k&1) & F[j][k]:
        c+=1
    p+=P[j][c]
  ans+=[p]
    
print((max(ans)))

# Optimized solution
N = int(eval(input()))
F = [int("".join(input().split()),2) for n in range(N)]
P = [list(map(int,input().split())) for n in range(N)]
print((max(sum(p[bin(n&f).count("1")]for f,p in zip(F,P)) for n in range(1,1024))))
# Original solution
#N,A,B=map(int, input().split())
 
#A=list(map(int, input().split()))
 
N=int(eval(input()))
 
F=[]
P=[]
 
for i in range(N):
    tmp=list(map(int, input().split()))
    F.append(tmp)
 
for i in range(N):
    tmp=list(map(int, input().split()))
    P.append(tmp)
 
max_sum=-1000000001
 
for i in range(1,1024):
    bin=[0]*10
    now=i
    for j in range(10):
        bin[j]=now%2
        now=now//2
    ans_sum=0
    for j in range(N):
        ans=0
        for h in range(10):
            if F[j][h]*bin[h]==1:
                ans+=1
        ans_sum+=P[j][ans]
    if max_sum<ans_sum:
        max_sum=ans_sum
 
print(max_sum)

# Optimized solution
#-*-coding:utf-8-*-

def main():
    n = int(eval(input()))
    f_list = [list(map(int, input().split())) for i in range(n)]
    p_list = [list(map(int, input().split())) for i in range(n)]

    max_profit = -1000000001
    
    for i in range(1, 2 ** 10):
        binary=[0]*10
        now=i
        for j in range(10):
            binary[j]=now%2
            now=now//2
        profit = 0
        for j in range(n):
            one_cnt = 0
            for h in range(10):
                if f_list[j][h]*binary[h]==1:
                    one_cnt += 1
            profit += p_list[j][one_cnt]
        if max_profit < profit:
            max_profit = profit
 
    print(max_profit)
    
if __name__ == '__main__':
    main()
# Original solution
N = int(eval(input()))
isopen = [list(map(int,input().split())) for i in range(N)]
gain = [list(map(int,input().split())) for i in range(N)]

ans = -float('inf')
for i in range(1,2**10):
    tmp = 0
    for n in range(N):
        c = 0
        for b in range(10):
            if ((i >> b)&1) & isopen[n][b]:
                c += 1
        tmp += gain[n][c]
    ans = max(ans, tmp)
print(ans)


# Optimized solution
N = int(eval(input()))
F = [list(map(int,input().split())) for i in range(N)]
P = [list(map(int,input().split())) for i in range(N)]

ans = -float('inf')
for b in range(1,2**10):
    tmp = 0
    for i in range(N):
        c = 0
        for k in range(10):
            if b&(1<<k) and F[i][k]:
                c += 1
        tmp += P[i][c]
    ans = max(ans,tmp)
print(ans)