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):
n = int(input())
f = [list(map(int,input().split())) for _ in range(n)]
p = [list(map(int,input().split())) for _ in range(n)]
mise = []

ans = -10**9

for i in range(1,2 ** 10):
	kari = []
	ii = i
	for j in range(10):
		kari.append(ii%2)
		ii = ii//2	
	mise.append(kari)

mise.pop(0)

for i in range(len(mise)):
	rieki = 0
	for j in range(n):
		counter = 0
		for k in range(10):
			counter += f[j][k]*mise[i][k]
		rieki += p[j][counter]
	ans = max(rieki,ans)
		
print(ans)

Solution (Python):

import math
import heapq
import bisect
import numpy as np
from collections import Counter


INF = 10**9

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 = -INF
for i in range(1,1<<10):
    tmp = 0
    for j in range(N):
        b_hours = 0
        for k in range(10):
            if i&(1<<k) and F[j][k]:
                b_hours += 1
        tmp += P[j][b_hours]
    ans = max(ans, tmp)

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 = -float('inf')

o = []
for i in range(2 ** 10):
    op = [0] * 10
    for j in range(10):
        if ((i >> j) & 1):
            op[9-j] = 1
    o.append(op)
o.remove([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
for openinfo in o:
    
    tmp = 0
    for i in range(n):
        cnt = 0
        for j in range(10):
            if openinfo[j] == 1 and f[i][j] == 1:
                cnt += 1
        tmp += p[i][cnt]
    ans = max(ans,tmp)
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):
    l=[]
    for j in range(10):
        if (i>>j)&1:
            l.append(1)
        else:
            l.append(0)
    res=0       
    for j in range(n):
        res+=p[j][sum([f[j][k]*l[k] for k in range(10)])]
    ans=max(ans,res)
    
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 = - float('inf')
for flag in range(1, 2 ** 10):  
    tmp = 0
    for shop in range(n):  
        op = 0  
        for i in range(10):  
            if flag & (1 << i):  
                c = 1  
            else:
                c = 0  
            if F[shop][i] * c == 1:  
                op += 1  
        tmp += P[shop][op]  
    ans = max(ans, tmp)  
print(ans)

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

result = []
for i in range(1, 2**10):
    b = format(i, "010b")
    r = 0
    for j in range(n):
        c = [1 for I in range(10) if b[I]==f[j][I]=="1"]
        r += p[j][len(c)]
    result.append(r)
print(max(result))

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

result = []
for i in range(1, 2**10):
    b = format(i, "010b")
    r = 0
    for j in range(n):
        c = 0
        for s in range(10):
            if b[s]=="1" and f[j][s]=="1":
                c += 1
        r += p[j][c]
    result.append(r)
print(max(result))

Solution (Python):
import sys
import numpy as np

input = sys.stdin.readline


n = int(input())


f = [input().replace(" ", "") for i in range(n)]


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



p_max = -999999999999999

for i in range(1, 1024):
    
    f_b = format(i, '010b')
    
    p_10 = 0
    for f_1, p_1 in zip(f, p):
        
        
        p_cnt = 0
        for j in range(10):
            
            if f_1[j] == '1' and f_b[j] == '1':
                
                p_cnt += 1
        
        p_10 += p_1[p_cnt]
    if p_10 > p_max:
        
        p_max = p_10

print(p_max)

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)]
print(max(sum([p[bin(f&i).count("1")] for f,p in zip(F,P)]) for i in range(1,2**10)))

Solution (Python):

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
mod=10**9+7
import itertools

def main():
    N=I()
    F=[[] for _ in range(N)]
    P=[[] for _ in range(N)]
    
    for i in range(N):
        F[i]=LI()
        
    for i in range(N):
        P[i]=LI()
    
    def calc(L):
        temp=0
        for i in range(N):
            cnt=0
            for j in range(10):
                cnt+=L[j]*F[i][j]
            temp+=P[i][cnt]
            
        return temp
    
    ans=-1*(10**10)
    for ite in itertools.product([0,1], repeat=10):
        if sum(ite)!=0:
            ans=max(ans,calc(ite))

    print(ans)

main()

Solution (Python):
n = int(input())
f = []
for i in range(n):
	ff = list(map(int, input().split()))
	f.append(ff)
p = []
for i in range(n):
	pp = list(map(int, input().split()))
	p.append(pp)
ans = -10**10
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[j][k] == 1:
				c += 1
		tmp += p[j][c]
	ans = max(ans, tmp)
print (ans)

Solution (Python):
n = int(input())
f = []
a = ["0","1"]
for i in range(n):
	ff = list(map(int, input().split()))
	f.append(ff)

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

def calc(t):
	y = list(t)
	tmp = 0
	flg = False
	for k in range(n):
		c = 0
		for b in range(10):
			if y[b] == "1" and f[k][b]:
				c += 1
				flg = True
		tmp += p[k][c]
	if flg == True:
		return tmp
	else:
		return -10**10

x = []
def dfs(i, s):
	for j in a:
		if i == 10:
			x.append(calc(s))
			return
		else:
			dfs(i+1, s+j)
dfs(0, "")
print (max(x))

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

Solution (Python):

n = int(input())
f = [[0]*10 for _ in range(n)]
p = [[0]*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()))
ans = - 10**9 -1 
for i in range(1,1024):
    rev = 0
    for j in range(n):
        cnt = 0
        for k in range(10):
            if 2**k & i and f[j][k]:
                cnt  += 1
        
        rev += p[j][cnt]
    ans = max(rev,ans)
print(ans)

Solution (Python):
def main():
    n=int(input())
    fre=[int(''.join(input().split()),2) for i in range(n)]
    pay=[list(map(int,input().split())) for i in range(n)]
    
    ans=-10**9
    for bit in range(1,1<<10):
        money=0
        for i in range(n):
            cnt=format(bit&fre[i],'b').count('1')
            money+=pay[i][cnt]
        ans=max(money,ans)
    print(ans)
if __name__=='__main__':
    main()

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 = float('-inf')
for i in range(1, 2**10):
    flags = [0] * 10
    for i, c in enumerate(bin(i)[2:][::-1]):
        if c == "1":
            flags[i] = 1

    res = 0
    for f, p in zip(F, P):
        cnt = 0
        for x, y in zip(f, flags):
            if x & y:
                cnt += 1
        res += p[cnt]
    ans = max(ans, res)
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)]
ans=-10**10
for sp in range(1, 1024):
  total = 0
  for i in range(n):
    b = bin(F[i] & sp)
    total += P[i][b.count('1')]
  ans = max(ans, total)
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)]
ans=-10**7*n
for sp in range(1, 2**10):
  total = 0
  for i in range(n):
    total += P[i][bin(F[i] & sp).count('1')]
  ans = max(ans, total)
print(ans)

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

ans = -10**9

for bit in range(1 << 10):
  if bit == 0:
    continue

  total = 0

  for n in range(N):
    count = 0

    for i in range(10):
      if bit & (1 << i):
        count += F[n][i]
    total += P[n][count]

  if total > ans:
    ans = total

print(ans)

Solution (Python):
N=int(input())
SO=[int(input().replace(' ',''), 2) for i in range(N)]
PT=[list(map(int,input().split())) for i in range(N)]
ret=-10**7*N
for sp in range(1,2**10):
  r=0
  for i in range(N):
    r+=PT[i][bin(SO[i] & sp).count('1')]
  ret=max(ret,r)
print(ret)

Solution (Python):
def main():
    import sys
    
    sys.setrecursionlimit(10000000)

    from collections import Counter
    from collections import deque

    
    
    

    n = int(input())
    F = [input().split() for _ in range(n)]
    P = [list(map(int, input().split())) for _ in range(n)]
    ans = -10**10
    for i in range(1, 1033):
        a = list(str(format(i, '010b')))
        total = 0
        for j in range(n):
            cnt = 0
            for k in range(10):
                if F[j][k]=='1' and a[k]=='1':
                    cnt += 1
            total += P[j][cnt]
        if total>ans:
            ans = total
    print(ans)




if __name__ == '__main__':
    main()

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

from itertools import *
first=True
ans=-10**12
for tmp in list(product([0,1], repeat=10)):
    if first:
        first=False
        continue
    sm=0
    for i in range(n):
        cnt=0
        for j in range(10):
            cnt+= tmp[j] & f[i][j]
        sm+=p[i][cnt]
    if ans < sm:
        ans=sm
print(ans)

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

from itertools import *
first=True
ans=-10**12
for tmp in list(product([0,1], repeat=10)):
    if first:
        first=False
        continue

    ona=[]
    for mise in f:
        cnt=0
        for j in range(10):
            cnt+= tmp[j] & mise[j]
        ona.append(cnt)

    sm=0
    for i in range(len(p)):
        sm+=p[i][ona[i]]
    if ans < sm:
        ans=sm
print(ans)

Solution (Python):
import sys
import numpy as np

def read():
    return sys.stdin.readline().rstrip()

def main():
    n = int(read())
    f = np.array([[int(i) for i in read().split()] for _ in range(n)])
    p = [[int(i) for i in read().split()] for _ in range(n)]
    pf = -float("inf")
    for i in range(1, 2**10):
        t = 0
        g = np.array([i >> j & 1 for j in range(10)])
        for j in range(n):
            t += p[j][(f[j] & g).sum()]
        pf = max(t, pf)
    print(pf)

if __name__ == '__main__':
    main()

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**18
for i in range(1,2**10):
  d=0
  for j in range(n):
    cnt=0
    for k in range(10):
      if i>>k&1==f[j][k]==1:
        cnt+=1
    d+=p[j][cnt]
  ans=max(ans,d)
print(ans)

Solution (Python):
import itertools
j_shop = list(set(itertools.product(*[[0, 1]]*10)) - set([tuple([0]*10)]))

n = int(input())

D = [[] for _ in range(10)]
from collections import defaultdict
profit = defaultdict(int)


for i in range(n):
    f = list(map(int, input().split()))
    for j in range(10):
        if f[j] == 1:
            D[j].append(i)
            
for i in range(n):
    p = list(map(int, input().split()))
    for j in range(11):
        profit[(i, j)] = p[j]
        
ans = float('-INF')
for js in j_shop:
    temp = [0]*n
    for i in range(10):
        if js[i] == 1:
            for d in D[i]:
                temp[d] += 1
    p = 0
    for k, v in enumerate(temp):
        p += profit[(k, v)]
    ans = max(ans, p)
print(ans)

Solution (Python):
import numpy as np
from itertools import product

n,*fp = map(int,open(0).read().split())
f = np.array([fp[i*10:(i+1)*10] for i in range(n)])
p = np.array([fp[(n*10+i*11):(n*10+(i+1)*11)] for i in range(n)])

op_list  = np.array(list(product([0,1],repeat=10)))[1:]
op_count = np.dot(op_list,f.T)
ans = p[np.arange(n),op_count].sum(axis=1).max()
print(ans)

Solution (Python):
n=int(input())
f=[]
p=[]
for i in range(n):
    f_i=list(map(int,input().split()))
    f.append(f_i)
for i in range(n):
    p_i=list(map(int,input().split()))
    p.append(p_i)
ans=-10000000*n
for i in range(1,1024):
    i_bin=((bin(i))[2:]).zfill(10)
    temp=0
    for j in range(n):
        buf=0
        for k in range(10):
            if f[j][k]==1 and i_bin[k]=="1":
                buf+=1
        temp+=p[j][buf]
    if ans<temp:
        ans=temp
print(ans)

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)]
print(max(sum([p[bin(f&i).count('1')] for f,p in zip(F,P)]) for i in range(1,2**10)))

Solution (Python):
def main():
    SHOP_NUM = int(input())
    open_info = [input().split() for _ in range(SHOP_NUM)]
    profit = [list(map(int, input().split())) for _ in range(SHOP_NUM)]
    answer = -float("inf")
    for i in range(1, 1024):
        open = str(format(i, '10b'))
        now_profit = 0
        for shop in range(SHOP_NUM):
            tmp = 0
            for j in range(10):
                if open[j] == "1" and open_info[shop][j] == "1":
                    tmp += 1
            now_profit += profit[shop][tmp]
        answer = max(answer, now_profit)
    print(answer)


if __name__ == '__main__':
    main()

Solution (Python):
import numpy as np
import sys
sys.setrecursionlimit(3000)
n = int(input())
f = np.array([list(map(int, input().split())) for _ in range(n)])
p = np.array([list(map(int, input().split())) for _ in range(n)])


def dfs(a):
    if len(a) == 10:
        if sum(a) == 0:
            return -10**9
        else:
            profit = 0
            for i in range(n):
                c = int(np.dot(a, f[i]))
                profit += p[i][c]
            return profit

    ret1 = dfs(np.append(a, 1))
    ret2 = dfs(np.append(a, 0))
    return max(ret1, ret2)


start = np.array([])
print(dfs(start))

Solution (Python):





N = int(input())    
F_list = []
for _ in range(N):
    f = list(map(int, input().split()))
    F_list.append(f)

P_list = []
for _ in range(N):
    p = list(map(int, input().split()))
    P_list.append(p)











def benefit(i, c):
    return P_list[i][c]

is_joisino_shop_open_list = [False] * 10
benefit_joisino_list = []

def dfs(j):
    if j >= 10:

        
        if True in is_joisino_shop_open_list:
            
            benefit_joisino = 0
            for n in range(N):
                
                count_n_open = 0                
                shop_n_list = F_list[n]

                for i in range(10):    
                    if shop_n_list[i] == 1 and is_joisino_shop_open_list[i] == True:
                        count_n_open += 1

                benefit_n_joisino = P_list[n][count_n_open]
                benefit_joisino += benefit_n_joisino

            benefit_joisino_list.append(benefit_joisino)

        return

    
    
    is_joisino_shop_open_list[j] = True
    dfs(j+1)

    
    is_joisino_shop_open_list[j] = False
    dfs(j+1)


dfs(0)
max_benefit_joisino = max(benefit_joisino_list)
print(max_benefit_joisino)

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


INF = 1<<60
ans = -INF
for st in range(1,1<<10):
    t = st
    state = [0]*10
    for i in range(10):
        state[i] = t%2
        t >>= 1
    
    cur = 0
    for k in range(N):
        tmp = 0
        for i in range(10):
            if F[k][i] == 1 and state[i] == 1:
                tmp += 1
        cur += P[k][tmp]
    
    ans = max(ans,cur)

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

f2 = []
ans = -10**10

for i in f:
    f_tmp = ''
    for j in i:
        f_tmp += str(j)
    f2.append(f_tmp)

li = []

def bfs():
    global li
    if len(li) == 10:
        hantei()
    else:
        li.append(0)
        bfs()
        li.pop(-1)
        li.append(1)
        bfs()
        li.pop(-1)

def hantei():
    global li,ans
    if 1 not in li:
        pass
    else:
        li_tmp = ''
        ans_tmp = 0
        for i in li:
            li_tmp += str(i)
        tmp = format(int(li_tmp, 2) & int(f2[0], 2), 'b')

        for i in range(n):
            tmp = format(int(li_tmp, 2) & int(f2[i], 2), 'b')
            ans_tmp += p[i][tmp.count('1')]

        ans = max(ans, ans_tmp)

bfs()

print(ans)

Solution (Python):
N=int(input())
SO=[int(input().replace(' ',''), 2) for i in range(N)]
PT=[list(map(int,input().split())) for i in range(N)]
ret=-10**7*N
for sp in range(1,2**10):
  r=0
  for i in range(N):
    r+=PT[i][bin(SO[i] & sp).count('1')]
  ret=max(ret,r)
print(ret)

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

for i in range(1,2**10):
    total=0
    bit=[0]*10
    for j in range(10):
        if(i>>j&1):
            bit[j]=1
    for j in range(N):
        tmp=0
        for k in range(10):
            if(bit[k]==1 and bit[k]==F[j][k]):
                tmp+=1
        total+=P[j][tmp]
    ans=max(ans,total)

print(ans)

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

for i in range(N):
    P[i]=list(map(int,input().split()))
SUM=[["" for i in range(10)] for i in range(N)]
for i in range(N):
    tm=0
    for j in range(10):
        tm+=P[i][j]
        SUM[i][j]=tm


for i in range(1,2**10):
    total=0
    bit=[0]*10
    for j in range(10):
        if(i>>j&1):
            bit[j]=1
    for j in range(N):
        tmp=0
        for k in range(10):
            if(bit[k]==1 and bit[k]==F[j][k]):
                tmp+=1
        total+=P[j][tmp]
    ans=max(ans,total)

print(ans)

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

ans = -10000000000
for i in range(1, 2 ** 10):
    sum = 0
    for j, f in enumerate(F):
        cover = i & f
        cnt = 0
        while cover != 0:
            if cover % 2 == 1:
                cnt += 1
            cover //= 2
        sum += P[j][cnt]
    ans = max(sum, ans)

print(ans)

Solution (Python):
import itertools
n = int(input())
f = [list(map(int,input().split())) for _ in range(n)]
p = [list(map(int,input().split())) for _ in range(n)]
INF = float("inf")
ans = -INF
for i in list(itertools.product([0,1],repeat=10)):
  tmp = 0
  if sum(i)==0: continue
  for j in range(n):
    open_s = sum([1 for p,q in zip(i,f[j]) if p+q==2])
    tmp += p[j][open_s]
  ans = max(tmp,ans)
print(ans)

Solution (Python):
import sys
import numpy as np


n = int(input())


f = [input().replace(" ", "") for i in range(n)]


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

p_max = -999999999999999
for i in range(1, 1024):
    f_b = format(i, '010b')
    p_10 = 0
    for f_1, p_1 in zip(f, p):
        p_cnt = 0
        for j in range(10):
            if f_1[j] == '1' and f_b[j] == '1':
                p_cnt += 1
        p_10 += p_1[p_cnt]
    if p_10 > p_max:
        if p_10 == 0:
            print(str(i))
            break
        p_max = p_10

print(p_max)

Solution (Python):
from itertools import product

def solve(n, FF, PP):
    return max(
        sum(P[sum(i & f for i, f in zip(I, F))] for F, P in zip(FF, PP))
        for I in list(product(range(2), repeat=10))[1:]
    )

_n = int(input())
_FF = [list(map(int, input().split())) for _ in range(_n)]
_PP = [list(map(int, input().split())) for _ in range(_n)]
print(solve(_n, _FF, _PP))

Solution (Python):
n = int(input())

f = list()
for i in range(n):
    temp = list(map(str, input().split()))
    bin_str = ''
    for j in range(10):
        bin_str = bin_str + temp[j]

    f.append(int(bin_str, 2))

p = list()
for i in range(n):
    p.append(list(map(int, input().split())))

max_sell = -10**10
open = 0
for i in range(2**10):
    temp_sell = 0

    open_list = '{:010b}'.format(open)
    open_flag = False
    check = 0
    for j in range(5):
        check = int(open_list[j * 2]) + int(open_list[j * 2 + 1])
        if(check > 0):
            open_flag = True
            break

    if(open_flag):
        for j in range(n):
            res_temp = open & f[j]
            count = bin(res_temp).count('1')

            temp_sell += p[j][count]

        if(temp_sell > max_sell):
            max_sell = temp_sell

    open += 1

print(max_sell)

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


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

ans = -(10**9)

"""
自分の店が開く時間帯の組み合わせを用意する.itertools?
その組み合わせの時間帯に営業している店を調べる。for文
店ごとにciをカウントしていく.for文
最後にansに店ごとのPを加算していき、マックスの値を調べる。ans = max(ans,~)
"""

for i in range(2**10):
    check = [0]*10
    tmp = 0
    for j in range(10):
        if (i>>j)&1: 
            check[j] = 1
    if any(check)==False:
        continue
    for k in range(N):
        cnt = 0 
        for l in range(10):
            if F[k][l] == 1 and check[l] == 1:
                cnt += 1
        tmp += P[k][cnt]
    ans = max(ans,tmp)

print(ans)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n = int(readline())
lst1 = [list(map(int,readline().split())) for i in range(n)]

lst2 = [list(map(int,readline().split())) for i in range(n)]


lst3 = [[] for _ in range(10)]
for i in range(n):
    for j in range(10):
        if lst1[i][j] == 1:
            lst3[j].append(i)


def bit_search(lst):
    keta = len(lst)
    bit_lst = []
    for i in range(2**keta):
        sub = [0]*n
        for j in range(keta):
            if ((i>>j) &1):
                for k in lst3[j]:
                    sub[k] += 1
        bit_lst.append(sub)
    return bit_lst


dummy = [0]*(10)
all_lst = bit_search(dummy)

ans = -10**9
for i in all_lst[1:]:
    res = 0
    for j in range(n):
        res += lst2[j][i[j]]
    ans = max(res,ans)

print(ans)

Solution (Python):
n=int(input())
a=[[int(i) for i in input().split()] for i in range(n)]
b=[[int(i) for i in input().split()] for i in range(n)]
maxi=-10**9
check=[0]*10
for i in range(2**10):
    check=[0]*10
    tmp=0
    for j in range(10):
        if (i>>j)&1:
            check[j]=1
    if any(check)==False:
        continue
    for i in range(n):
        cnt=0
        for j in range(10):
            if a[i][j]==1 and check[j]==1:
                cnt+=1
        tmp+=b[i][cnt]
    if tmp>maxi:
        maxi=tmp
print(maxi)

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

import itertools as it

stat = [i for i in it.product([0, 1], repeat=10)]
stat.pop(0)
ans = -10**9
for t_stat in stat:
    x = 0
    for i in range(n):
        tmp=[min(j, k) for j, k in zip(t_stat, s[i])]
        lll=tmp.count(1)
        x+=p[i][lll]
    ans = max(ans, x)
print(ans)

Solution (Python):
N=int(input())
A=[list(map(int,input().split())) for i in range(N)]
B=[list(map(int,input().split())) for i in range(N)] 

import itertools
D=list(itertools.product([0,1],repeat=10))

ans=(-1)*9999999999
for i in D:
  a=0
  if i!=(0,0,0,0,0,0,0,0,0,0):
    for j in range(N):
      b=0
      for k in range(10):
        if i[k]==1 and A[j][k]==1:
          b+=1
      a+=B[j][b]
    ans=max(ans,a)
print(ans)

Solution (Python):
n = int(input())
f = []
p = []
ans = []
for i in range(n):
    f.append(list(map(int, input().split())))
for i in range(n):
    p.append(list(map(int, input().split())))
for i in range(1, 2**10):
    b = format(i, '
    s = 0
    for j in range(n):
        s2 = 0
        for k in range(10):
            s2 += int(b[k])*f[j][k]
        s += p[j][s2]
    ans.append(s)
print(max(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 = -float('inf')
for i in range(1, 1024):
    t = 0
    for j in range(N):
        c = 0
        for k in range(10):
            c += (i >> k & 1) & F[j][k]
        t += P[j][c]
    result = max(result, t)
print(result)

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 = -float('inf')
for i in range(1, 1024):
    t = 0
    for j in range(N):
        t += P[j][sum((i >> k & 1) & F[j][k] for k in range(10))]
    if t > result:
        result = t
print(result)

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

Solution (Python):
TIMEZONE_NUM = 10

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 = -float('inf')
for i in range(1, 2 ** TIMEZONE_NUM):
    tmp_ans = 0
    for n in range(N):
        both_open_num = 0
        for flag_j, flag_f in zip(bin(i)[2:].zfill(TIMEZONE_NUM), F[n]):
            if int(flag_j) == flag_f == 1:
                both_open_num += 1
        tmp_ans += P[n][both_open_num]
    ans = max(ans, tmp_ans)

print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
F = []
for _ in range(N):
    F.append([str(x) for x in input().split()])
P = []
for _ in range(N):
    P.append([int(x) for x in input().split()])
ans = -10 ** 10
for i in range(1, 2 ** 10):
    bini = "0b" + format(i, 'b').zfill(10)
    ans_ = 0
    for j in range(N):
        shop = "0b" + "".join(F[j])
        cnt = bin((int(shop, 2) & int(bini, 2))).count("1")
        ans_ += P[j][cnt]
    ans = max(ans, ans_)
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
F = []
for _ in range(N):
    F.append([int(x) for x in input().split()])
P = []
for _ in range(N):
    P.append([int(x) for x in input().split()])
ans = -10 ** 10
import numpy as np
for i in range(1, 2 ** 10):
    bini = format(i, 'b').zfill(10)
    bini = np.array([int(x) for x in list(bini)])
    ans_ = 0
    for j in range(N):
        shop = np.array(F[j])
        cnt = np.count_nonzero(shop * bini)
        ans_ += P[j][cnt]
    ans = max(ans, ans_)
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)]
d = 10
status = []
for mask in range(1 << d):
    tmp = []
    for i in range(d):
        tmp.append((mask >> i) & 1)
    status.append(tmp)

ans = -10**12
for i in range(1, 1 << d):
    tmp = 0
    
    
    for j in range(N):
        cnt = 0
        for shop_status, joisino_status in zip(F[j], status[i]):
            if shop_status == 1 and joisino_status == 1:
                cnt += 1
        tmp += P[j][cnt]
    ans = max(ans, tmp)
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30
from itertools import permutations

def main():
    n = int(input().strip())
    f = [0] * n
    p = [[] for _ in range(n)]
    for i in range(n):
        tmp = list(map(int, input().strip().split()))
        for j in range(10):
            f[i] += tmp[9-j] << j
    for i in range(n):
        p[i] = list(map(int, input().strip().split()))
    ans = -INF
    for b in range(1, 2**10):
        m = 0
        for j in range(n):
            v = fun(f[j], b)
            m += p[j][v]
        ans = max(ans, m)
    print(ans)

def fun(f, q):
    ans = 0
    r = f & q
    for i in range(10):
        ans += (r >> i) & 0x1
    return ans

if __name__ == '__main__':
    main()