Problem:
 Score : 300 points    Problem Statement Joisino is planning to open a shop in a shopping street.  Each of the five weekdays is divided into two periods, the morning and the evening. For each of those ten periods, a shop must be either open during the whole period, or closed during the whole period. Naturally, a shop must be open during at least one of those periods.  There are already N stores in the street, numbered 1 through N .  You are given information of the business hours of those shops, F_{i,j,k} . If F_{i,j,k}=1 , Shop i is open during Period k on Day j (this notation is explained below); if F_{i,j,k}=0 , Shop i is closed during that period. Here, the days of the week are denoted as follows. Monday: Day 1 , Tuesday: Day 2 , Wednesday: Day 3 , Thursday: Day 4 , Friday: Day 5 . Also, the morning is denoted as Period 1 , and the afternoon is denoted as Period 2 .  Let c_i be the number of periods during which both Shop i and Joisino's shop are open. Then, the profit of Joisino's shop will be P_{1,c_1}+P_{2,c_2}+...+P_{N,c_N} .  Find the maximum possible profit of Joisino's shop when she decides whether her shop is open during each period, making sure that it is open during at least one period.      Constraints  1≤N≤100  0≤F_{i,j,k}≤1  For every integer i such that 1≤i≤N , there exists at least one pair (j,k) such that F_{i,j,k}=1 .  -10^7≤P_{i,j}≤10^7  All input values are integers.         Input Input is given from Standard Input in the following format:  N  F_{1,1,1}  F_{1,1,2}  ...  F_{1,5,1}  F_{1,5,2}  :  F_{N,1,1}  F_{N,1,2}  ...  F_{N,5,1}  F_{N,5,2}  P_{1,0}  ...  P_{1,10}  :  P_{N,0}  ...  P_{N,10}       Output Print the maximum possible profit of Joisino's shop.        Sample Input 1 1
1 1 0 1 0 0 0 1 0 1
3 4 5 6 7 8 9 -2 -3 4 -2      Sample Output 1 8  If her shop is open only during the periods when Shop 1 is opened, the profit will be 8 , which is the maximum possible profit.       Sample Input 2 2
1 1 1 1 1 0 0 0 0 0
0 0 0 0 0 1 1 1 1 1
0 -2 -2 -2 -2 -2 -1 -1 -1 -1 -1
0 -2 -2 -2 -2 -2 -1 -1 -1 -1 -1      Sample Output 2 -2  Note that a shop must be open during at least one period, and the profit may be negative.       Sample Input 3 3
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
-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      Sample Output 3 23

Solution (Python):
import sys

def main():
	n = int(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())))
	ans = -sys.maxsize
	for x10 in range(1,2**10):
		x2 = base_10_to_n(x10,2)
		for _ in range(10-len(x2)):	
			x2 = '0' + x2
		benefit = 0
		for j in range(n):
			count = 0
			for k in range(10):
				if(f[j][k] == 1 and x2[k] == '1'):
					count+=f[j][k]
			benefit+=p[j][count]
		if(ans<benefit): ans = benefit
	print(ans)

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

main()

Solution (Python):
N = int(input())
F = []
for n in range(N):
  F.append([k for k, x in enumerate(input().split()) if x=="1"])
P = []
for n in range(N):
  P.append([int(p) for p in input().split()])

PROFIT = []
for i in range(1, 2**10):
  i = format(i, "b")
  if len(i) < 10:
    i = "0"*(10-len(i)) + i
  OPEN_joisino = [k for k, x in enumerate(i) if x=="1"]
  profit = 0
  for n in range(N):
    together_time = 0
    for t in OPEN_joisino:
      if t in F[n]:
        together_time += 1
    profit += P[n][together_time]
  PROFIT.append(profit)
ans = max(PROFIT)
print(ans)

Solution (Python):

N = input()
N = int(N)
Fs =  [list(map(int,input().split(" "))) for _ in range(N)]
Ps =  [list(map(int,input().split(" "))) for _ in range(N)]
ans = -(10**10)
for flag in range(1,2 ** 10): 
    temp = 0
    for shop in range(N):
        op = 0

        for i in range(10): 
            if flag & (1 << i):
                c = 1
            else:
                c = 0
            if Fs[shop][i] * c == 1:
                op += 1

        temp +=Ps[shop][op]
    if temp > ans:
        ans =temp
print(ans)

Solution (Python):
N = int(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())))

ans = -10 ** 12
for i in range(1, 1024):
    chk = list(str(bin(i+1024)))[3:]
    profit = 0
    for n in range(N):
        total = 0
        for j, c in enumerate(chk):
            if c == "1":
                total += F[n][j]
        profit += P[n][total]
    if profit > ans:
        ans = profit

print(ans)

Solution (Python):
N = int(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**9)
for i in range(1,2**10):
  S = [0]*N
  tmp = 0
  for j in range(10):
    for k in range(N):
      if (i >> j) & 1 and F[k][j] == 1:
        S[k] += 1
  for m in range(N):
    tmp += P[m][S[m]]
  ans = max(ans,tmp)
print(ans)

Solution (Python):
N = int(input())
F = [[int(f) for f in input().split()] for _ in range(N)]
P = [[int(p) for p in input().split()] for _ in range(N)]

saidai_rieki = -1*(10**10)
for i in range(1,2**10):
    C = [0]*N
    for time in range(10):
        if (i>>time)%2==1:
            for j in range(N):
                C[j] += F[j][time]    
    saidai_rieki = max(saidai_rieki,sum([P[j][C[j]] for j in range(N)]))
print(saidai_rieki)

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

ans = -(10 ** 9)
for i in range(1, 2 ** 10):
    tmp = 0
    for j in range(N):
        f = int('0b' + ''.join(F[j]), 0)
        tmp += P[j][bin(i & f).count('1')]
    ans = max(ans, tmp)

print(ans)

Solution (Python):
import sys

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)]






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

print(max_profit)

Solution (Python):
import sys

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)]






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

print(max_profit)

Solution (Python):
import numpy as np


N = int(input())

F = np.zeros((N, 10), dtype = int)
for i in range(N):
    F_i = list(map(int, input().split()))
    F[i] = [val for j, val in enumerate(F_i)]

P = np.zeros((N, 11), dtype = int)
for i in range(N):
    P[i] = list(map(int, input().split()))

matrix_pattern = np.zeros((2**10 - 1, 10), dtype = int)
for x in range(10):
    for y in range(0, 2**(10 - x), 2):
        matrix_pattern[(2**x * y):(2**x * (y + 1)), x] = 1

list_profit = []

for pattern in matrix_pattern:
    
    profit = 0
    
    for i in range(N):
        
        c_i = sum(F[i] * pattern)
        
        profit += P[i, c_i]
    list_profit.append(profit)

print(max(list_profit))

Solution (Python):
n = int(input())
f = [list(map(int, input().split())) for _ in range(n)]
p = [list(map(int, input().split())) for _ in range(n)]
res = -10**10
for i in range(1, 1<<10):
    count = [0 for _ in range(n)]
    for j in range(10):
        for k in range(n):
            if (i>>j)&1 == 1 and f[k][10-j-1] == 1:
                count[k] += 1
    total = 0
    for k in range(n):
        total += p[k][count[k]]
    res = max(res, total)
print(res)

Solution (Python):
def inner_prod(vec_a, vec_b):
    ans = 0
    for a, b in zip(vec_a, vec_b):
        ans += a * b
    return ans


N = int(input())
F = [list(map(int, input().split())) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]
ans = -float("inf")
for i in range(1, 1024):
    flags = [(i & (2 ** b)) // (2 ** b) for b in range(10)]
    benefit = 0
    for j, f in enumerate(F):
        benefit += P[j][inner_prod(flags, f)]
    ans = max(ans, benefit)
print(ans)

Solution (Python):
N = int(input())
f = [int(input().replace(' ',''),2) for _ in range(N)]
p = [list(map(int,input().split())) for _ in range(N)]
g = -9999999999
for i in range(1,1024):
    gg = 0
    for j in range(N):
        s = (format(i & f[j],'b').zfill(10))
        c = s.count('1')
        gg += p[j][c]
    g = max(g,gg)
print(g)

Solution (Python):



from operator import itemgetter
import collections

n = int(input())
f = [list(map(int,input().split())) for _ in range(n)]
p = [list(map(int,input().split())) for _ in range(n)]

ma = -float('inf')
for i in range(1,2**10):
    b = [0]*10
    s = 0
    sum = 0
    for j in range(10):
        if (i>>j) & 1:
            b[j] = 1
    for j in range(n):
        for k in range(10):
            if f[j][k] & b[k]:
                s += 1
        sum += p[j][s]
        s = 0
    ma = max(ma,sum)
print(ma)

Solution (Python):
def larger(x, y):
	if x > y:
		return x
	return y

def openshop(n):
	lst = []
	m = n
	for i in range(0, 10):
		lst.append(m%2)
		m //= 2
	return lst

N = int(input())
F = []
for i in range(0, N):
	F.append(list(map(int, input().split())))
P = []
for i in range(0, N):
	P.append(list(map(int, input().split())))
max = -5000000000000000
for i in range(1, 1024):
	joisino = openshop(i)
	opencounter = []
	for j in range(0, N):
		opencounter.append(0)
	for j in range(0, 10):
		if joisino[j] == 1:
			for k in range(0, N):
				opencounter[k] += F[k][j]
	sum = 0
	for j in range(0, N):
		sum += P[j][opencounter[j]]
	max = larger(max, sum)
print(max)

Solution (Python):
n = int(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, 1<<10):
    tmp_ans = 0
    for j in range(n):
        c = 0
        for k in range(10):
            if f[j][k] == 1 and (i >> k) & 1 == 1:
                c += 1
        tmp_ans += p[j][c]
    ans = max(ans, tmp_ans)

print(ans)

Solution (Python):
n=int(input())
f=[]
p=[]
for i in range(n):
    q=[int(j) for j in input().split()]
    f.append(q)
for i in range(n):
    q=[int(j) for j in input().split()]
    p.append(q)

def base(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out.rjust(10,'0')
ans=-10**100
for i in range(1,1024):
    i=base(i,2)
    res=0
    for j in range(n):
        c=0
        for k in range(10):
            if f[j][k]==1 and int(i[k])==1:
                c+=1
        res+=p[j][c]
    ans=max(ans,res)
print(ans)

Solution (Python):
N = int(input())
lst_F = [list(map(int, input().split())) for _ in range(N)]
lst_P = [list(map(int, input().split())) for _ in range(N)]
n_timetable = 10
lst_joisino = [None] * n_timetable


def score(src, F, P):
    cnt = 0
    for i, j in zip(src, F):
        if i == j == 1:
            cnt += 1
    return P[cnt]


def dfs(pos):
    if pos == n_timetable:
        ret = 0
        for i in range(N):
            if lst_joisino == [0] * n_timetable:
                return -float("INF")
            p = score(lst_joisino, lst_F[i], lst_P[i])
            ret += p
        return ret
    lst_joisino[pos] = 0
    ret0 = dfs(pos + 1)
    lst_joisino[pos] = 1
    ret1 = dfs(pos + 1)
    return max(ret0, ret1)


print(dfs(0))

Solution (Python):
N=int(input())
F=[int(input().replace(" ",""),2) for _ in [0]*N]
P=[list(map(int,input().split())) for _ in [0]*N]
print(max([sum([P[j][bin(i&F[j]).count("1")] for j in range(N)]) for i in range(1,1024)]))

Solution (Python):
n = int(input())
open_list = [ [ int(v) for v in  input().split() ] for i in range(n)]
profit_list = [ [ int(v) for v in  input().split() ] for i in range(n)]

ans = -10**9
for i in range(1,1024):
    total_profit = 0
    shop = [ int(v) for v in bin(i)[2:].zfill(10) ]
    for j in range(n):
        total_profit += profit_list[j][sum([shop[k] & open_list[j][k] for k in range(10)])]
    ans = max(ans,total_profit)

print(ans)

Solution (Python):
n=int(input())
F=[[] for i in range(10)]
for i in range(n):
    for j,f in enumerate(list(map(int,input().split()))):
        if f:
            F[j].append(i)
P=[list(map(int,input().split())) for i in range(n)]
ans=-float("inf")
for i in range(1,1024):
    l=[0]*n
    for j in range(10):
        if i>>j&1:
            for k in F[j]:
                l[k]+=1
    t=0
    for j,k in enumerate(l):
        t+=P[j][k]
    ans=max(ans,t)
print(ans)

Solution (Python):
n=int(input())
F=[[] for i in range(10)]
for i in range(n):
    for j,f in enumerate(list(map(int,input().split()))):
        if f:
            F[j].append(i)
P=[list(map(int,input().split())) for i in range(n)]
ans=-float("inf")
for i in range(1,1024):
    l=[0]*n
    for j in range(10):
        if i>>j&1:
            for k in F[j]:
                l[k]+=1
    t=0
    for j,k in enumerate(l):
        t+=P[j][k]
    ans=max(ans,t)
print(ans)

Solution (Python):
n=int(input())
F=[]
for i in range(n):
    sub_list=list(map(int,input().split()))
    F.append(sub_list)
P=[]
for i in range(n):
    sub_list=list(map(int,input().split()))
    P.append(sub_list)
Ans=-10**10
for i in range(1,1024):
    i_list=[]
    for j in range(10):
        i_list.append((i>>j)&1)
    ans=0
    for j in range(n):
        count=0
        for k in range(10):
            count+=F[j][k]*i_list[k]
        ans+=P[j][count]
    Ans=max(Ans,ans)
print(Ans)

Solution (Python):
n = int(input())
f = []
p = []
for i in range(n):
    f.append([int(_) for _ in input().split()])
for i in range(n):
    p.append([int(_) for _ in input().split()])

ans = 0
for i in range(1, 2**10):
    pat = format(i, "010b")
    score = 0
    for j in range(n):
        cnt = 0
        for k in range(10):
            if pat[k]=="1" and f[j][k] == 1:
                cnt += 1
        score += p[j][cnt]
    if i == 1:
        ans = score
    ans = max(score, ans)

print(ans)

Solution (Python):
N = int(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))
ans = -float('inf')
for i in range(1023):
    b = bin(1024+i+1)[3:]
    pp = [0]*N
    for j in range(N):
        for k in range(10):
            if F[j][k] == 1 and b[k] == "1":
                pp[j] += 1
    hoge = 0
    for j in range(N):
        hoge += P[j][pp[j]] 
    ans = max(ans,hoge)

print(ans)

Solution (Python):
n=int(input())
f=[[int(i) for i in input().split()] for _ in range(n)]
p=[[int(i) for i in input().split()] for _ in range(n)]
ans=-10000000000000
All=[[] for _ in range(2**10)]
count=0
for bit in range(1<<10):
    pattarn = []
    for j in range(10):
        if (bit & (1<<j)):
            pattarn.append(j)
    All[count]=pattarn
    count+=1

for i in range(len(All)):
    All[i]=tuple(All[i])
All=sorted(list(set(All)),key=len)[1:]
for i in All:
    result=0
    for j in range(n):
        s=0
        for num in i:
            s+=f[j][num]
        res=p[j][s]
        result+=res
    ans=max(ans,result)
print(ans)

Solution (Python):
n=int(input())
f=[list(map(int,input().split())) for i in range(n)]
p=[list(map(int,input().split())) for i in range(n)]



ans=-2**(31-1)

for i in range(1,2**10):
    list=[0]*n
    earn=0
    for j in range(10):
        for k in range(n):
            if i&(1<<j) and f[k][j]==1:
                list[k]+=1
    
    for k in range(n):
        earn+=p[k][list[k]]
    
    ans=max(ans, earn)
print(ans)

Solution (Python):

N = int(input())

F = []

for i in range(N):

    f = list(map(int,input().split()))

    F.append( [f[0],f[1] ,f[2],f[3] , f[4],f[5] , f[6],f[7] , f[8],f[9] ] )

P = []

for i in range(N):

    p = list(map(int,input().split()))

    P.append(p)

ans = -N * (10 ** 7)

for i in range(2 ** 10):
    
    nt = format(i,"b")
    nt = nt.zfill(10)

    

    now = 0

    for j in range(N):

        both = 0
        for k in range(10):

            if F[j][k] == 1 and nt[k] == "1":
                both += 1

        now += P[j][both]
        

    if i != 0:
        ans = max(now,ans)

print (ans)

Solution (Python):
n = int(input())
f = [int(input().replace(' ',''),2) for _ in range(n)]
p = [list(map(int,input().split())) for _ in range(n)]
prof = - 10 ** 10
for i in range(1,1 <<10):
	prof1 = 0
	for j,time in enumerate(f):
		prof1 += p[j][bin(i & time).count('1')]
	prof = max(prof,prof1)
print(prof)

Solution (Python):
n = int(input())
f = [int(input().replace(' ',''),2) for i in range(n)]
p = [list(map(int,input().split())) for i in range(n)]
prof = - 10 ** 10
for i in range(1,1 <<10):
	prof1 = 0
	for j,time in enumerate(f):
		prof1 += p[j][bin(i & time).count('1')]
	prof = max(prof,prof1)
print(prof)

Solution (Python):
n = int(input())
f = [int(input().replace(' ',''),2) for i in range(n)]
p = [list(map(int,input().split())) for i in range(n)]
prof = - 10 ** 10
for i in range(1,1 <<10):
	prof1 = 0
	for j,time in enumerate(f):
		same = bin(i & time).count('1')
		prof1 += p[j][same]
	prof = max(prof,prof1)
print(prof)

Solution (Python):
N=int(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):
    prof=0
    for j,f in enumerate(F):
        prof+=P[j][bin(i&f).count("1")]
    ans=max(ans,prof)

print(ans)

Solution (Python):
N = int(input())
F = [list(map(int,input().split())) for _ in range(N)]
P = [list(map(int,input().split())) for _ in range(N)]
ans = -10**9

for i in range(1,2**10):
    bit = format(i,"010b")
    C = [0]*(N)
    temp = 0
    for b in range(10):
        if bit[b] == "1":
            for j in range(N):
                if F[j][b] == 1:
                    C[j] += 1
    for p,c in zip(P,C):
        temp += p[c]
    if temp > ans:
        ans = temp
print(ans)

Solution (Python):
N=int(input())
F=[int(input().replace(' ',''),2) for _ in range(N)]
P=[list(int(i) for i in input().split()) for _ in range(N)]

ans=-10**10
for i in range(1,1<<10):
    prof=0
    for j,f in enumerate(F):
        prof+=P[j][bin(i&f).count("1")]
    ans=max(ans,prof)

print(ans)

Solution (Python):
n = int(input())
f=[]
p=[]
for _ in range(n):
    f.append(list(map(int,input().split())))
for _ in range(n):
    p.append(list(map(int,input().split())))
ans = -(10**10)
for i in range(1,2**10):
    x=0
    binary=format(i,"010b")
    for j in range(n):
        cnt=0
        for k in range(10):
            if binary[k]=="1" and f[j][k]==1:
                cnt+=1
        x += p[j][cnt]
    ans = max(ans,x)
print(ans)

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

result = -10**9
for b in range(1, 1 << 10):
    c = [0 for _ in range(N)]
    for t in range(10):
        if (b & (1 << t)) != 0:
            
            for i in range(N):
                if F[i][t] == 1:
                    c[i] += 1
    profit = 0
    for i in range(N):
        profit += P[i][c[i]]
    result = max(result, profit)
print(result)

Solution (Python):
INF = float("inf")
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N = n()
opens = []
for i in range(N):
    opens.append(nl())
profits = []
for i in range(N):
    profits.append(nl())

max_profit = -INF

import itertools
for p in itertools.product([0, 1], repeat=10):
    if all([i == 0 for i in p]):
        continue
    profit = 0
    for i in range(N):
        count = 0
        for j in range(10):
            count += opens[i][j] * p[j]
        profit += profits[i][count]
    if profit > max_profit:
        max_profit = profit

print(max_profit)

Solution (Python):
n= int(input())
f=[[int(x) for x in input().split()] for _ in range(n)]
p=[[int(x) for x in input().split()] for _ in range(n)]

ans = -1*10**9
for i in range(1,2**10):
    ls = []
    for j in range(10):
        if (i>>j)&1:
            ls.append(1)
        else:
            ls.append(0)
    cnt = []
    for k in range(n):
        cn = 0
        for l in range(10):
            if ls[l]==f[k][l]==1:
                cn+=1
            else:
                pass
        cnt.append(cn)
    can =0    
    for m in range(n):
        can += p[m][cnt[m]]
    
    ans = max(ans,can)

print(ans)

Solution (Python):

import itertools

def solve(N, F, P):
    max_prof = -1 * float('inf')
    for seq in itertools.product([True,False], repeat = 10):
        if not any(seq):
            continue

        prof = 0
        for f,p in zip(F,P):
            prof += p[sum(itertools.compress(f, seq))]
        max_prof = max(prof,max_prof)
    print(max_prof)



def main():
    N = int(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())))

    solve(N, F, P)



if __name__ == '__main__':
    main()

Solution (Python):
N=int(input())
F,P,F0=[],[],[]
ans=-10**9
for b in range(1,2**10):
    F0.append(format(b,'010b'))
for _ in range(N):
    F.append(list(input().split()))
for _ in range(N):
    P.append(list(map(int,input().split())))

for c in F0:
    benefit=0
    for i in range(N):
        counter=0
        for j in range(10):
            if c[j]=="1" and F[i][j]=="1":counter+=1
        benefit+=P[i][counter]
    ans=max(ans,benefit)

print(ans)

Solution (Python):
n = int(input())
flist = []
for _ in range(n):
    flist.append([int(f) for f in input().split()])

plist = []
for _ in range(n):
    plist.append([int(p) for p in input().split()])

def commonSum(a_l, b_l):
    """共通要素を返す"""
    cnt = 0
    for a, b in zip(a_l, b_l):
        if a == b and a == 1:
            cnt += 1
    return cnt


profit = -10**15
for open in range(1, 2**10):
    openlist = [int(i) for i in format(open, 'b').zfill(10)]

    
    prof = 0
    for i in range(n):
        common = commonSum(flist[i], openlist)
        prof += plist[i][common]
    if profit < prof:
      profit = prof
print(profit)

Solution (Python):
n=int(input())
store=[]
for i in range(n):
    store.append(list(map(int,input().split())))
score=[]
for i in range(n):
    score.append(list(map(int,input().split())))

A=[]
for i in range(1,2**10):
    ans=0
    for s in range(n):
        count=0
        for j in range(10):
            if ((i>>j)&1) and store[s][j]==1:
                count+=1
        ans+=score[s][count]
    A.append(ans)
print(max(A))

Solution (Python):
import numpy as np
N = int(input())
F = [[int(x) for x in input().split()] for _ in range(N)]
P = [[int(x) for x in input().split()] for _ in range(N)]

import itertools
answer = -(10 ** 18)
for a in itertools.product([0,1], repeat = 10):
  if sum(a) == 0:
    continue
  profit = 0
  for shop in range(N):
    profit += P[shop][sum(a[i]*F[shop][i] for i in range(10))]
  if answer < profit:
    answer = profit

print(answer)

Solution (Python):
n = int(input())
f_matrix = [[0]*10]*n
p_matrix = [[0]*11]*n
f_matrix = [[int(i) for i in input().split()] for _ in range(n)]
p_matrix = [[int(i) for i in input().split()] for _ in range(n)]

ans = -10**20
for i in range(1, 2**10):
  tmp = 0
  for j in range(n):
    c = 0
    for k in range(10):
      if i>>k&1 and f_matrix[j][k] is 1:
        c += 1
    tmp += p_matrix[j][c]
  ans = max(ans, tmp)
print(ans)

Solution (Python):
import sys
import numpy as np
INF = 10000000000
M = 10


def main():
    n = int(input())
    fveclist = [np.array([int(e) for e in input().split()]) for _ in range(n)]
    plist = [[int(e) for e in input().split()] for _ in range(n)]
    ans = -INF
    for b in range(1, pow(2, M)):
        joisino = np.array([b >> i & 1 for i in range(M)])
        subans = 0
        for i in range(n):
            subans += plist[i][(fveclist[i] * joisino).sum()]
        ans = max(ans, subans)
    print(ans)


main()

Solution (Python):
N=int(input())
F=[[int(i) for i in input().split()] for j in range(N)]
P=[[int(i) for i in input().split()] for j in range(N)]
print(max([(sum([P[shop][sum([i*j for i,j in zip([i>>k & 1 for k in range(10)],F[shop])])] for shop in range(N)])) for i in range(1,1024)]))

Solution (Python):
N=int(input())
F=[[int(i) for i in input().split()] for j in range(N)]
P=[[int(i) for i in input().split()] for j in range(N)]
R=[]
for i in range(1,1024):
    opentime = [i>>k & 1 for k in range(10)]
    R.append(sum([P[shop][sum([i*j for i,j in zip(opentime,F[shop])])] for shop in range(N)]))
print(max(R))

Solution (Python):







import sys
sys.setrecursionlimit(10**7)
from itertools import combinations, permutations 
from math import factorial
def combinations_count(n, r):
    
    
    
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n
    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]
    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot
    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])
    return result
def combination_with_repetition_count(n, r):
    return combinations_count(n + r - 1, r)
from collections import deque, Counter 
from heapq import heapify, heappop, heappush, heappushpop, heapreplace,nlargest,nsmallest 
from copy import deepcopy, copy 
from operator import itemgetter 
from functools import reduce
from fractions import gcd 
def gcds(numbers):
    return reduce(gcd, numbers)
def lcm(x, y):
    return (x * y) // gcd(x, y)
def lcms(numbers):
    return reduce(lcm, numbers, 1)



INF = 10 ** 18
MOD = 10 ** 6 + 3
modpow = lambda a, n, p = MOD: pow(a, n, p) 
def modinv(a, p = MOD):
    
    
    return modpow(a, p-2, p)
def modinv_list(n, p = MOD):
    if n <= 1:
        return [0,1][:n+1]
    else:
        inv_t = [0,1]
        for i in range(2, n+1):
            inv_t += [inv_t[p % i] * (p - int(p / i)) % p]
        return inv_t
def modfactorial_list(n, p = MOD):
    if n == 0:
        return [1]
    else:
        l = [0] * (n+1)
        tmp = 1
        for i in range(1, n+1):
            tmp = tmp * i % p
            l[i] = tmp
        return l
def modcomb(n, k, fac_list = [], p = MOD):
    
    
    from math import factorial
    if n < 0 or k < 0 or n < k: return 0
    if n == 0 or k == 0: return 1
    if len(fac_list) <= n:
        a = factorial(n) % p
        b = factorial(k) % p
        c = factorial(n-k) % p
    else:
        a = fac_list[n]
        b = fac_list[k]
        c = fac_list[n-k]
    return (a * modpow(b, p-2, p) * modpow(c, p-2, p)) % p
def modadd(a, b, p = MOD):
    return (a + b) % MOD
def modsub(a, b, p = MOD):
    return (a - b) % p
def modmul(a, b, p = MOD):
    return ((a % p) * (b % p)) % p
def moddiv(a, b, p = MOD):
    return modmul(a, modpow(b, p-2, p))




    
    

    
    
    
    
    



r = lambda: sys.stdin.readline().strip() 
R = lambda: list(map(int, r().split())) 
Rmap = lambda: map(int, r().split())

N = int(r())
F = [R() for _ in range(N)]
P = [R() for _ in range(N)]
A = [0] * N

    
    
maxans = -INF
ans = 0
for i in range(1, 11):
    for j in combinations(range(10), i):
        point = 0
        for l in range(N):
            tmp = 0
            for k in j:
                tmp += F[l][k]
            point += P[l][tmp]
        maxans = max(maxans, point)
print(maxans)

Solution (Python):







import sys
sys.setrecursionlimit(10**7)
from itertools import combinations, permutations 
from math import factorial
def combinations_count(n, r):
    
    
    
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n
    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]
    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot
    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])
    return result
def combination_with_repetition_count(n, r):
    return combinations_count(n + r - 1, r)
from collections import deque, Counter 
from heapq import heapify, heappop, heappush, heappushpop, heapreplace,nlargest,nsmallest 
from copy import deepcopy, copy 
from operator import itemgetter 
from functools import reduce
from fractions import gcd 
def gcds(numbers):
    return reduce(gcd, numbers)
def lcm(x, y):
    return (x * y) // gcd(x, y)
def lcms(numbers):
    return reduce(lcm, numbers, 1)



INF = 10 ** 18
MOD = 10 ** 6 + 3
modpow = lambda a, n, p = MOD: pow(a, n, p) 
def modinv(a, p = MOD):
    
    
    return modpow(a, p-2, p)
def modinv_list(n, p = MOD):
    if n <= 1:
        return [0,1][:n+1]
    else:
        inv_t = [0,1]
        for i in range(2, n+1):
            inv_t += [inv_t[p % i] * (p - int(p / i)) % p]
        return inv_t
def modfactorial_list(n, p = MOD):
    if n == 0:
        return [1]
    else:
        l = [0] * (n+1)
        tmp = 1
        for i in range(1, n+1):
            tmp = tmp * i % p
            l[i] = tmp
        return l
def modcomb(n, k, fac_list = [], p = MOD):
    
    
    from math import factorial
    if n < 0 or k < 0 or n < k: return 0
    if n == 0 or k == 0: return 1
    if len(fac_list) <= n:
        a = factorial(n) % p
        b = factorial(k) % p
        c = factorial(n-k) % p
    else:
        a = fac_list[n]
        b = fac_list[k]
        c = fac_list[n-k]
    return (a * modpow(b, p-2, p) * modpow(c, p-2, p)) % p
def modadd(a, b, p = MOD):
    return (a + b) % MOD
def modsub(a, b, p = MOD):
    return (a - b) % p
def modmul(a, b, p = MOD):
    return ((a % p) * (b % p)) % p
def moddiv(a, b, p = MOD):
    return modmul(a, modpow(b, p-2, p))




    
    

    
    
    
    
    



r = lambda: sys.stdin.readline().strip() 
R = lambda: list(map(int, r().split())) 
Rmap = lambda: map(int, r().split())

N = int(r())
F = [R() for _ in range(N)]
P = [R() for _ in range(N)]
A = [0] * N

    
    
maxans = -INF
ans = 0
for i in range(1, 11):
    for j in combinations(range(10), i):
        point = 0
        for l in range(N):
            tmp = 0
            for k in j:
                tmp += F[l][k]
            point += P[l][tmp]
        maxans = max(maxans, point)
print(maxans)

Solution (Python):
N = int(input())
F = [[int(_) for _ in input().split()] for _ in range(N)]
P = [[int(_) for _ in input().split()] for _ in range(N)]
store = [0] * N
ans = -float('inf')

for i in range(N):
    tmp = 0
    for j in range(10):
        tmp += F[i][j] << j
    store[i] = tmp

for i in range(1, 2**10):
    bene = 0
    for j in range(N):
        bene += P[j][bin(i & store[j]).count('1')]
    
    if bene > ans:
        ans = bene

print(ans)