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 = [0 for i in range(N)]
P = [0 for i in range(N)]
for i in range(N):
  F[i] = [int(x) for x in input().split()]
for i in range(N):
  P[i] = [int(x) for x in input().split()]
ans = -10 * 10 ** 9
for c in range(1, 2 ** 10):
  pat = ('0' * 9 + bin(c)[2:])[-10:]
  ans = max(sum([P[i][sum([F[i][j] * int(pat[j]) for j in range(10)])] for i in range(N)]), ans)
print(ans)

Solution (Python):

def main():
    n = int(input())
    F = [0 for i in range(n)]
    P = [0 for i 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 = 0
    Flag = "first"

    for z in range(1,1024):
        ans_list = list(map(int,list(format(z,"010b"))))
        pro = 0

        for i in range(n):
            tmp = 0
            for j in range(10):
                if ans_list[j] == 1 and F[i][j]== 1:
                    tmp += 1

            pro += P[i][tmp]

        if Flag == "first":
            ans = pro
            Flag = False

        ans = max(ans, pro)


    print(ans)


if __name__ == "__main__":
        main()

Solution (Python):
import sys
from itertools import product

input = sys.stdin.readline

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 = float('-inf')
for ptn in product([0, 1], repeat=10):
    if sum(ptn) == 0:
        continue

    res = 0
    for i in range(N):
        cnt = 0
        for j in range(10):
            cnt += F[i][j] * ptn[j]
        res += P[i][cnt]
    ans = max(ans, res)
print(ans)

Solution (Python):
N = int(input())
f_list = []
p_list = []

for i in range(N):
    f = input()
    f_list.append(f)
for i in range(N):
    p = list(map(int, input().split()))
    p_list.append(p)

profit = []
for i in range(1, 2**10):
    sum = 0
    for f, p in zip(f_list, p_list):
        f = int(f.replace(" ", ""), 2)
        c = bin(f & i).count("1")
        sum += p[c]
    profit.append(sum)
print(max(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)]

def calcBit(num):
    res = []
    for _ in range(10):
        res.append(num%2)
        num >>= 1
    return res

ans = -float('inf')
for i in range(1,2**10):
    ans_t = 0
    for k,l in enumerate(f):
        tmp = 0
        for (a,b) in zip(l,calcBit(i)):
            if a==1 and b==1:
                tmp += 1
        ans_t += p[k][tmp]
    ans = max(ans,ans_t)

print(ans)

Solution (Python):
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

N = int(input())
FF = [inpl() for i in range(N)]
PP = [inpl() for i in range(N)]

ans = -INF
for flags in itertools.product([0,1], repeat=10):
	if sum(flags) == 0: continue
	tans = 0
	for i in range(N):
		tmp = 0
		for c in range(10):
			if FF[i][c] and flags[c]:
				tmp += 1
		tans += PP[i][tmp]
	ans = max(tans,ans)

print(ans)

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

for i in product([0,1],repeat=10):
  if i==(0,0,0,0,0,0,0,0,0,0):continue
  s=0
  for (idx,j) in enumerate(f):
    s+=p[idx][sum(k*l for (k,l) in zip(i,j))]
  cd.extend([s])
print(max(cd))

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

res = -1e20
for i in range(2**10):
	bs = format(i, "
	
	if bs == "0000000000": continue
	cnt = 0
	
	for j in range(N):
		tmp = 0
		for k in range(10):
			if F[j][k] == 1 and bs[k] == '1':
				tmp+=1
		cnt += P[j][tmp]
	
	res = max(cnt, res)
print(res)

Solution (Python):

from itertools import combinations

n = int(input())

f = []

for _ in range(n):
    line = list(map(lambda n:int(n),input().split(" ")))
    f.append(line)

p = []
for _ in range(n):
    line = list(map(lambda n:int(n),input().split(" ")))
    p.append(line)

def overlap(ary1,ary2):
    ret = 0
    for i in range(len(ary1)):
        if ary1[i]==ary2[i] and ary1[i]==1:
            ret += 1
    return ret

def calcProf(jary):
    
    ret = 0
    for i in range(n):
        lap = overlap(jary, f[i])
        ret += p[i][lap]
    return ret

def conv(ary):
    ret = [0 for _ in range(10)]
    for i in ary:
        ret[i] = 1
    return ret

prof = -1000000000
for e in range(1,11):
    for elem in combinations(range(10), e):
        cp = calcProf(conv(elem))
        if cp>prof:
            prof = cp

print(prof)

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)]
cost=-float("inf")
for i in range(1,1<<10):
    ans=0
    for j in range(n):
        cnt=0
        for k in range(10):
            if i&(1<<k) and f[j][k]==1:
                cnt+=1
        ans+=p[j][cnt]
    cost=max(ans,cost)
print(cost)

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

Solution (Python):
N = int(input())
isopen = []
profit = []

for i in range(N) :
    isopen.append(list(input().split()))
    
for i in range(N) :
    profit.append(list(map(int, input().split())))
    

perms = []
def perm(s, idx) :
    if idx == 10 :
        if s != "0000000000" :
            perms.append(s)
    else :
        perm(s + "0", idx + 1)
        perm(s + "1", idx + 1)
        
perm("", 0)

def doand(s1, s2) :
    cnt = 0
    for i in range(10) :
        if s1[i] == s2[i] == "1" :
            cnt += 1
            
    return cnt 

max_cost = -10**20

for p in perms :
    cost_over = 0
    
    for i in range(N) : 
        
        numsame = doand(p, "".join(isopen[i]))
        
        
        cost_over += profit[i][numsame]
    
    max_cost = max(max_cost, cost_over)
    
print(max_cost)

Solution (Python):
from itertools import product
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**10
for X in product( range(2), repeat = 10):
    if X == tuple([0]*10):
        pass
    else:
        c = 0
        for i in range(N):
            n = 0
            for j in range(10):
                if F[i][j] == 1 and X[j] == 1:
                    n += 1
            c += P[i][n]
        ans = max(ans, c)
print(ans)

Solution (Python):
import sys
r=sys.stdin.readline
N=int(r())
F=[int(r().replace(' ',''),2)for _ in[0]*N]
P=[list(map(int,r().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)))

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

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

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

ans = -(10 ** 9)


for item in range(1, 1024):
    fund = 0
    for i in range(n):
        cou = 0
        for x in range(10):
            if (item >> x) % 2 == 1 and arr[i][x] == 1:
                cou += 1
        fund += arm[i][cou]
    ans = max(ans, fund)
print(ans)

Solution (Python):


def main():
    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)]

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

Solution (Python):

 

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

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 = (-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)

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

f = np.array(F)
ans = float("-inf")
for n in range(1, 2**10):
    a = np.array([int(x) for x in format(n, '010b')])
    p = sum([P[i][x] for i,x in enumerate(np.sum(f * a, axis=1))])
    ans = max(ans, p)
print(ans)

Solution (Python):
from collections import defaultdict
n = int(input())
O = defaultdict(list)
for i in range(n):
    F = list(map(int, input().split()))
    for j in range(10):
        if F[j] == 1:
            O[j].append(i)
P = []
for _ in range(n):
    _P = list(map(int, input().split()))
    P.append(_P)

max_x = -1 * 10 ** 10
for i in range(1, 1024):
    v = i
    K = [] 
    for j in range(10):
        if v % 2 == 1:
            K.extend(O[j])
        v //= 2
    
    x = 0
    for l in range(n):
        k = K.count(l)
        x += P[l][k]
    max_x = max(max_x, x)
print(max_x)

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

f = np.array(F)
ans = float('-inf')
for n in range(1, 2**10):
    a = np.array([int(x) for x in bin(n)[2:].rjust(10, '0')])
    p = sum([P[i][x] for i,x in enumerate(np.sum(f * a, axis=1))])
    ans = max(ans, p)
print(ans)

Solution (Python):
N = int(input())
F, P = [], []
for i in range(N):
    F.append([int(Fi) for Fi in input().split()])
for i in range(N):
    P.append([int(Pi) for Pi in input().split()])

def profit(action):
    p = 0
    for i in range(N):
        ci = sum([int(action[j]) * F[i][j] for j in range(10)])
        p += P[i][ci]
    return p

pmax = -float('inf')
for i in range(1, 1024):
    pmax = max(pmax, profit(format(i, '010b')))
print(pmax)

Solution (Python):
from collections import defaultdict
n = int(input())
O = defaultdict(list)
for i in range(n):
    F = list(map(int, input().split()))
    for j in range(10):
        if F[j] == 1:
            O[j].append(i)
P = []
for _ in range(n):
    _P = list(map(int, input().split()))
    P.append(_P)

max_x = -1 * 10 ** 10
for i in range(1, 1024):
    v = i
    K = [] 
    for j in range(10):
        if v % 2 == 1:
            K.extend(O[j])
        v //= 2
    
    x = 0
    for l in range(n):
        k = K.count(l)
        x += P[l][k]
    max_x = max(max_x, x)
print(max_x)

Solution (Python):
N = int(input())
F = [[int(x) for x in input().split()] for i in range(N)]
P = [[int(x) for x in input().split()] for i in range(N)]
ans = -10 ** 9
for i in range(1, 2 ** 10):
  pat = bin(i)[2:]
  pat = ['0' for i in range(10 - len(pat))] + list(pat)
  benefit = 0
  for j in range(N):
    benefit += P[j][sum([int(pat[k]) * F[j][k] for k in range(10)])]
  ans = max(ans, benefit)
print(ans)

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

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

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

ans = -10000000000
for i in range(1,1024):
    b = []
    a = 0
    for j in range(10):
        if i | (2**j) == i:
            b.append(1)
        else:
            b.append(0)
    for j in range(n):
        count = 0
        for k in range(10):
            if b[k] == 1 and f[j][k] == 1:
                count += 1
        a += p[j][count]
    ans = max(a,ans)
print(ans)

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


l = []

for i in range(1, 1024):
    a = format(i, '010b')
    b = list(a)
    l.append(b)

ans = 0

for i in range(n):
    y = 0

    for j in range(10):
        if l[0][j] == f[i][j] == '1':
            y += 1
    ans += p[i][y]

for x in l:
    z = 0

    for i in range(n):
        y = 0

        for j in range(10):
            if x[j] == f[i][j] == '1':
                y += 1
        z += p[i][y]
    ans = max(ans, z)

print(ans)

Solution (Python):
n = int(input())
ans = float("-INF")
f = [[0 for i in range(10)] for i in range(n)]
p = [[0 for i in range(11)] for i in range(n)]
for i in range(n):
  ft = list(map(int, input().split()))
  for j in range(10):
    f[i][j] = ft[j]
for i in range(n):
  pt = list(map(int, input().split()))
  for j in range(11):
    p[i][j] = pt[j]

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

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

cand = []

def dfs(string, n, f, p):
    global cand
    if len(string) < 10:
        dfs(string + "f", n, f, p)
        dfs(string + "t", n, f, p)
    else:
        tf = list(string)
        booltf = []
        for i in range(10):
            if tf[i] == "t":
                booltf.append(True)
            else:
                booltf.append(False)
        
        c = []
        c_sum = []
        for kth in range(N):
            c = [i*j for i,j in zip(booltf, F[kth])]
            c_sum.append(sum(c))
        
        profit = 0
        for i,c in zip(range(N), c_sum):
            profit += P[i][c]
            
        cand.append(profit)
        
        if len(cand) == 2**10:        
            ans = max(cand[1:])
            
            print(ans)

        

dfs("", N, F, P)

Solution (Python):
from itertools import product

n = int(input())
fs = [[int(x) for x in input().split()] for _ in range(n)]
ps = [[int(x) for x in input().split()] for _ in range(n)]

xs = product((0, 1), repeat=10)
next(xs)
print(max(sum(p[sum(a==b==1 for a, b in zip(f, x))] for f, p in zip(fs, ps)) for x in xs))

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

INF = float('inf')
ans = -INF
for b in range(1,2**10):
    tmp = 0
    for f,p in zip(fs,ps):
        c = 0
        for k in range(10):
            if b&(1<<k)==0: continue
            if f[k]: c += 1
        tmp += p[c]
    ans = max(ans, tmp)
print(ans)

Solution (Python):
N=int(input())
ans=-10**9
s=["".join(list(input().split())) for i in range(N)]
t=[list(map(int,input().split())) for i in range(N)]
for j in range(1,1024):
    q=0
    for i in range(len(s)):
        q+=t[i][(bin(int(s[i],2)&j)).count("1")]
    ans=max(ans,q)
print(ans)

Solution (Python):




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

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)]
res = -10000000000
for b in range(1,1024):
    profit = 0
    for i in range(N):
        c = 0
        for j in range(10):
            if (b >> j) % 2 == 1 and F[i][j] == 1:
                c += 1
        profit += P[i][c]
    res = max(res, profit)
print(res)

Solution (Python):
from itertools import product

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 = float('-inf')
t = [0, 1]
for store in product(t, t, t, t, t, t, t, t, t, t):
    if sum(store) == 0:
        continue

    profit = 0
    for i in range(N):
        c = 0
        for j in range(10):
            if store[j] + F[i][j] == 2:
                c += 1
        profit += P[i][c]
    ans = max(ans, profit)
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 = -999999999999999999
for item in range(1, 1024):
    fund = 0
    for i in range(n): 
        cou = 0
        for x in range(10):
            if (item >> x) % 2 == 1 and f[i][x] == 1:
                cou += 1
        fund += p[i][cou]
    ans = max(ans, fund)

print(ans)

Solution (Python):
import itertools
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)]
max_res = -10**9

me_list = list(itertools.product([0, 1], repeat=10))
for i in range(1, 2**10):
    res = 0
    co = [ 0 for o in range(N)]
    for j in range(10):
        if me_list[i][j] == 1:
            for k in range(N):
                co[k] += F[k][j]
    for j in range(N):
        res += P[j][co[j]]
    if res > max_res:
        max_res = res
            
print(max_res)

Solution (Python):


import itertools

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


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

Solution (Python):


import itertools

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


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

Solution (Python):


import itertools

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


me_list = list(itertools.product([True, False], repeat=10))


me_p = -float("inf")

for i in range(len(me_list)):

    
    if not any(me_list[i]):
        continue

    tmp_p = 0
    
    for j in range(N):

        cnt = 0
        
        for k in range(10):

            
            if me_list[i][k] and F[j][k]:
                cnt += 1
        
        
        tmp_p += P[j][cnt]

    
    me_p = max(me_p, tmp_p)   

print(me_p)

Solution (Python):
import itertools

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

max_gain = -float('inf')
for status in itertools.product([True, False], repeat=10):
    if not any(status):
        continue
    gain = 0
    for i in range(n):
        same_time_cnt = 0
        for j in range(10):
            if status[j] and f[i][j]:
                same_time_cnt += 1
        gain += p[i][same_time_cnt]
    max_gain = max(max_gain, gain)
print(max_gain)

Solution (Python):
N = int(input())
f = []
for i in range(N):
    raw = int(''.join(input().split()),2)
    f.append(raw)
p = []
for i in range(N):
    raw = list(map(int,input().split()))
    p.append(raw)
def lapCount(n,m):
    return bin(n&m).count("1")
ans = -1000000001
for state in range(1,1024):
    cand = 0
    for i in range(N):
        c = lapCount(state,f[i])
        cand += p[i][c]
    ans = max(ans,cand)
print(ans)

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

max_ans = -float("inf")

for i in range(1, 1024):
	ans = 0
	for j in range(n):
		ans += P[j][list(str(bin(i & F[j]))).count("1")]
	if ans > max_ans:
		max_ans = ans

print(max_ans)

Solution (Python):
from itertools import product
N=int(input().strip())
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())))

score=-float('inf')
opt=0
for op in product(*[(0,1) for i in range(10)]):
    if sum(op)==0:
        continue
    sc=0
    for n in range(N):
        c=sum(F[n][i] and op[i] for i in range(10))
        sc+=P[n][c]
    if score<sc:
        score=sc
        opt=op
print(score)

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

    cost = []
    for i in range(1,2**10):
        cost_i = 0
        k = i
        now = ""
        for _ in range(10):
            now += str(k%2)
            k = k//2
        for n in range(N):
            ci = 0
            for j in range(10):
                if int(now[j])==F[n][j]==1:
                    ci += 1
            cost_i += P[n][ci]
        cost.append(cost_i)

    return max(cost)

if __name__ == '__main__':
    print(main())

Solution (Python):
N = int(input())
F = []
P = []
ans = -10**9
def cal_same_num(F,temp):
    num_same = 0
    for i in range(10):
        if temp[i] == "1" and F[i] == 1:
            num_same += 1
    return num_same

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):
    sum_point = 0
    temp = str(format(i,"b")).zfill(10)
    for j in range(N):
        num_same = cal_same_num(F[j],temp)
        point = P[j][num_same]
        sum_point += point
    ans = max(ans,sum_point)
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 = -1e10

for sister in range(1, 1024):
    count = 0
    for i in range(n):
        cost_list = list('{:b}'.format(int(''.join(map(str, F[i])), 2) & sister))
        cost = 0
        for j in range(len(cost_list)):
            cost += int(cost_list[j])
        count += P[i][cost]
    ans = max(ans, count)

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

MAX_ans = pow(10,9)*(-1)
for K in range(1,1024):
    C = [0 for i in range(N)]
    c = 0
    while(K>0):
        if K%2==1:
            for j in range(N):
                if F[j][c] == 1: C[j] += 1
        c += 1
        K //=2
    ans = 0
    for j in range(N):
        ans += P[j][C[j]]
    if ans > MAX_ans: MAX_ans = ans

print(MAX_ans)

Solution (Python):
from itertools import product

N = int(input())
F = []
P = []
for _ in range(N):
    temp = list(map(int, input().split()))
    F.append([temp[:2], temp[2:4], temp[4:6], temp[6:8], temp[8:]])
for _ in range(N):
    P.append(list(map(int, input().split())))

prod = list(product((0, 1), (0, 1), (0, 1), (0, 1), (0, 1),
                    (0, 1), (0, 1), (0, 1), (0, 1), (0, 1)))
MAX = -float("inf")


def compute(pattern):
    x = 0
    for i in range(N):
        c = 0
        for j in range(5):
            for k in range(2):
                if pattern[j][k] == 1 and F[i][j][k] == 1:
                    c += 1
        x += P[i][c]
    return x


del prod[0]
for e in prod:
    pattern = [e[:2], e[2:4], e[4:6], e[6:8], e[8:]]
    MAX = max(compute(pattern), MAX)

print(MAX)

Solution (Python):
N = int(input())
F_list = [int(input().replace(' ', ''), 2) for _ in range(N)]
P_list = [list(map(int, input().split())) for _ in range(N)]

max_p = float('-inf')
for i in range(1,1024):
    p = 0
    for j in range(len(F_list)):
        c = format(i & F_list[j], 'b').count('1')
        p += P_list[j][c]
    if p > max_p:
        max_p = p
print(max_p)

Solution (Python):
from itertools import product
N = int(input())

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

c = product([0,1],repeat=10)
profits = []

for i in c:
    i = list(i)
    if sum(i) == 0:
        continue
    Duplist = []
    profit = 0
    for j in range(N):
        shop = F[j]
        Dup = 0
        for i_,k in enumerate(shop):
            if i[i_] == 1 and k == 1:
                Dup += 1
        Duplist.append(Dup)
    for i_,j in enumerate(Duplist):
        profit += P[i_][j]
    profits.append(profit)
    
print(max(profits))

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

N = int(input())
F = np.array([list(map(int, input().split())) for i in range(N)])
P = np.array([list(map(int, input().split())) for i in range(N)])
O = list(product([0, 1], repeat=10))
del O[0]
O = np.array(O)
ans = -float('inf')
for o in O:
    tmp = 0
    OF = F*o
    K = []
    for of in OF:
        K.append(np.count_nonzero(of, axis=0))
    for i in range(N):
        tmp += P[i][K[i]]
    ans = max(ans, tmp)
print(ans)

Solution (Python):
import itertools

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



def get_kaburi(decide, i):
    kaburi = 0
    for j in range(10):
        if (decide[j] == 1) and (eigyo[i][j] == 1):
            kaburi += 1
    return kaburi

infinity = 10**10

def get_score(decide):
    if sum(decide) == 0:
        return -infinity
    score = 0
    total_kaburi = 0
    for i in range(N):
        kaburi = get_kaburi(decide, i)
        score += uriage[i][kaburi]
    return score

scores = map(get_score, itertools.product([0,1], repeat=10))
print(max(scores))

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

ans = 0
first = True

def get_list(x):
    l = []
    for i in range(10):
        l.append(x%2)
        x//=2
    return l

for z in range(1, 2**10):
    l = get_list(z)
    p = 0
    c = 0
    for i in range(n):
        c = 0
        for j, x in enumerate(l):
            if x == 0:
                continue
            if runs[i][j] == 1:
                c += 1
        p += points[i][c]
    if first:
        ans = p
        first = False
    else:
        ans = max(ans, p)
print(ans)