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 itertools
N = int(input().split()[0])
f_list_list = []

for _ in range(N):
    f_list_list.append(list(map(int, input().split())))

p_list_list = []

for _ in range(N):
    p_list_list.append(list(map(int, input().split())))

p_gen = itertools.product([0, 1], repeat=10)
max_p = -float('inf')

for pattern in p_gen:  
    if sum(pattern) == 0:
        continue
    counter = {k: 0 for k in range(N)}
    for t_i, is_open in enumerate(pattern):  
        if is_open == 0:
            continue
        for n_i in range(N):  
            if f_list_list[n_i][t_i] == 1:
                counter[n_i] += 1
    total_p = 0
    for k, c in counter.items():  
        total_p += p_list_list[k][c]
    max_p = max(total_p, max_p)

print(max_p)

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 = -1000000000


for i in range(1, 1024):
    tmp = 0
    c = [0] * N
    ii = list(str(format(i, 'b')).zfill(10))
    for j in range(N):
        for k in range(10):
            if str(F[j][k]) == ii[k] and ii[k] == '1':
                c[j] += 1
    for j in range(N):
        tmp += P[j][c[j]]
    if tmp > ans :
        ans = tmp

print(ans)

Solution (Python):
n = int(input())
f = [0] * n
for i in range(n):
    f[i] = list(map(int, input().split()))
p = [0] * n
for i in range(n):
    p[i] = list(map(int, input().split()))
ans = - 10 ** 7 * 10 * n - 1
for i in range(1, 2**10):
    profit = 0
    open_ = [0] * 10
    for j in range(10):
        if ((i >> j) & 1):
            open_[j] = 1
    for k in range(n):
        cnt = 0
        for l in range(10):
            if open_[l] == 1 and f[k][l] == open_[l]:
                cnt += 1
        profit += p[k][cnt]
    ans = max(profit, ans)
print(ans)

Solution (Python):



import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
f = [LI() for _ in range(n)]
p = [LI() for _ in range(n)]
ans = -inf
for i in range(1,2**10):
    b = [0]*10
    for j in range(10):
        if (i >> j) & 1:
            b[j] = 1
    tmp = 0
    for i in range(n):
        cnt = 0
        for j in range(10):
            if b[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 = []
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 = -float('inf')
for i in range(1, 2 ** 10):
	selfF = []
	for j in range(10):
		selfF.append((i >> j) & 1)
	
	benefit = 0
	for j in range(N):
		both = 0
		for k in range(10):
			if F[j][k] == 1 and selfF[k] == 1:
				both += 1
		benefit += P[j][both]
	ans = max(ans, benefit)

print(ans)

Solution (Python):
N = int(input())
Fs = []
for i in range(N):
  F = list(map(int, input().split()))
  Fs.append(F)
Ps = []
for i in range(N):
  P = list(map(int, input().split()))
  Ps.append(P)
rs = []
for i in range(1, 1<<10):
  r = 0
  for j in range(N):
    F = Fs[j]
    P = Ps[j]
    c = 0
    for k in range(10):
      if i&(1<<k) != 0 and F[k] == 1:
        c += 1
    r += P[c]
  rs.append(r)
r = max(rs)
print(r)

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

for i in range(1, 2**10):
    l = [0 for _ in range(10)]
    for j in range(10):
        if i & 2 ** j > 0:
            l[j] = 1
    score = 0
    for j in range(n):
        count = 0
        for k in range(10):
            if f[j][k] == l[k] == 1:
                count += 1
        score += p[j][count]
    ans = max(ans, score)
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 i in range(1, 2 ** 10):
    p = 0
    for k in range(N):
        store = F[k]
        c = 0
        for j in range(10):
            if (i >> j) & 1 and F[k][j] == 1:
                c += 1
        p += P[k][c]
    ans = max(ans, p)
print(ans)

Solution (Python):
def main():
    N = int(input())
    F = []
    for i in range(N):
        F.append([int(f) for f in input().split()])
    P = []
    for i in range(N):
        P.append([int(p) for p in input().split()])
    states = [[]]
    for _ in range(10):
        temp = []
        for s in states:
            temp.append(s + [1])
            temp.append(s + [0])
        states = temp

    max_v = float('-inf')
    for s in states:
        if sum(s) != 0:
            v = 0
            for i in range(N):
                c = 0
                for j in range(10):
                    c += s[j] * F[i][j]
                v += P[i][c]
        max_v = max(max_v, v)
    return max_v


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

Solution (Python):
n = int(input())
f = []
for i in range(n):
    f1 = list(map(int,input().split()))
    f.append(f1)
p = []
for i in range(n):
    p1 = list(map(int,input().split()))
    p.append(p1)
dayl = [0,1,2,3,4,5,6,7,8,9]
ans = []
for i in range(1,2**10):
    day = []
    for j in range(10):
        if ((i >> j) & 1):
            day.append(dayl[j])
    ans1 = 0
    for x in range(n):
        count = 0
        for j in day:
            count += f[x][j]
        ans1 += p[x][count]
    ans.append(ans1)
print(max(ans))

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

ans=-10**18
for i in range(1, 1024):
    earn=0
    for j,f in enumerate(F):
        same=bin(i&f)[2:].zfill(10)
        same=same.count("1")
        earn+=P[j][same]
    ans=max(ans, earn)

print(ans)

Solution (Python):
from itertools import product
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)]
l=list(product(range(2),repeat=10))
del l[0]
a=-10**9
for i in range(1023):
    t=0
    for j in range(N):
        c=0
        for k in range(10):
            c+=F[j][k] and l[i][k]
        t+=P[j][c]
    if t>a:
        a=t
print(a)

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

num = 2 ** 10

act = [0] * 10

ans = -10**100

for i in range(1,num):
    cnt = i
    tmp = 0
    while cnt != 0:
        if cnt % 2 == 0:
            act[tmp] = 0
            cnt = cnt // 2
            tmp += 1
        else:
            act[tmp] = 1
            cnt = cnt // 2
            tmp += 1
    
    tmp_ans = 0   
    for j in range(n):
        open_num = 0
        for k in range(10):
            if act[k] + f[j][k] == 2:
                open_num += 1
        tmp_ans += p[j][open_num]
    ans = max(ans,tmp_ans)
    
print(ans)

Solution (Python):
n = int(input())
shops = [0 for i in range(n)]
for i in range(n):
    s = input()
    s = s.replace(" ","")
    s = int(s,2)
    shops[i] = s

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

ans = -1000000000000
for i in range(1,1024):
    score = 0
    for j in range(n):
        temp = i&shops[j]
        num = bin(temp).count("1")
        score += prof[j][num]
    if score > ans:
        ans = score
print(ans)

Solution (Python):
import itertools
n=int(input())
lf=[list(map(int,input().split())) for _ in range(n)]
lp=[list(map(int,input().split())) for _ in range(n)]
lit=list(itertools.product([0,1],repeat=10))[1:]
ans=-10**9
for i in lit:
    tmp=0
    for num,j in enumerate(lf):
        com=sum([k*l for k,l in zip(i,j)])
        tmp+=lp[num][com]
    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 = []
for i in range(1, 2**10):
    x = list(map(int, (bin(i)[2:].zfill(10))))
    _ans = 0
    for j in range(n):
        c = sum(map(lambda x, y: x*y, x, f[j]))
        _ans += p[j][c]
    ans.append(_ans)
print(max(ans))

Solution (Python):
n=int(input())
F=[int("0b"+"".join(input().split()),0) for _ in range(n)]
P=[list(map(int,input().split())) for _ in range(n)]
ans=-10e9
for i in range(1,2**10):
	m=0
	for f,p in zip(F,P):
		m+=p[bin(i&f).count("1")]
	ans=max(ans,m)
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 = -float("inf")
for i in range(1,1<<10):
    jo = []
    ben = 0
    for j in range(10):
        jo.append(i%2)
        i = i//2
    for j in range(N):
        both = [0 for k in range(10) if F[j][k] == jo[k] == 1]
        ben += P[j][len(both)]
    ans = max(ans,ben)
print(ans)

Solution (Python):
N = int(input())
F = []
for _ in range(N):
    f = [int(s) for s in input().split()]
    b = sum([v * (1 << i) for i, v in enumerate(f)])
    F.append(b)
P = []
for _ in range(N):
    p = [int(s) for s in input().split()]
    P.append(p)
ans = max([sum([P[j][bin(i & F[j]).count("1")] for j in range(N)])
           for i in range(1, 2 ** 10)])
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)]
ans = -10**12
for i in range(1,1024):
    
    temp = 0
    for j in range(n): 
        fi = f[j]
        ci = bin(fi&i).count("1") 
        
        temp += p[j][ci]
    
    
    ans = max(ans,temp)
print(ans)

Solution (Python):
import itertools

N = int(input())
F = [0] * N
P = [0] * 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()))




l = list(itertools.product(range(2), repeat=10))
l.pop(0)

ans = []
for i in range(len(l)):
    tmp = 0
    for j in range(N):
        count = 0
        for k in range(10):
            if l[i][k] == 1 and F[j][k] == 1:
                count += 1
        tmp += P[j][count]
    ans.append(tmp)

ans = max(ans)
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**12
for i in range(1,1024):
    
    temp = 0
    for j in range(n): 
        fi = f[j]
        ci = sum([1 for k in range(10) if (i>>k)&1==1 and fi[9-k]==1])
        temp += p[j][ci]
    
    ans = max(ans,temp)
print(ans)

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

f_vals = []
for i in range(N):
    f_vals.append([int(_) for _ in input().split()])
p_vals = []
for i in range(N):
    p_vals.append([int(_) for _ in input().split()])


def solve():
    ans = -1e12
    for i in range(1, 2 ** 10):
        sumv = 0
        for l in range(N):
            fcnt = 0
            for j in range(10):
                fcnt += ((i >> j) & 1) and f_vals[l][j]
            sumv += p_vals[l][fcnt]

        ans = max(ans, sumv)
    print(ans)


solve()

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

f_vals = []
for i in range(N):
    f_vals.append([int(_) for _ in input().split()])
p_vals = []
for i in range(N):
    p_vals.append([int(_) for _ in input().split()])


def solve():
    ans = -1e12
    for i in range(1, 2 ** 10):
        sumv = 0
        for l in range(N):
            fcnt = 0
            for j in range(10):
                fcnt += ((i >> j) & 1) and f_vals[l][j]
            sumv += p_vals[l][fcnt]

        ans = max(ans, sumv)
    print(ans)


solve()

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

f_vals = []
for i in range(N):
    f_vals.append([int(_) for _ in input().split()])
p_vals = []
for i in range(N):
    p_vals.append([int(_) for _ in input().split()])


def calc(pat):
    ret = 0
    for i in range(N):  
        fcnt = 0
        for j in range(10):
            if pat[j] == 0: continue
            if f_vals[i][j] == 1:
                fcnt += 1
        ret += p_vals[i][fcnt]
    return ret


def solve():
    ans = -1e12
    for i in range(1, 2 ** 10):
        pat = [(i >> j) & 1 for j in range(10)]
        ans = max(ans, calc(pat))
    print(ans)

solve()

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

ans = -10 ** 10
for f in itertools.product([0, 1], repeat=10):
    if f == (0,) * 10:
        continue
    p = 0
    for i in range(N):
        p += P[i][sum([F[i][j] * f[j] for j in range(10)])]
    ans = max(ans, p)

print(ans)

Solution (Python):


n=int(input())
f=[[]]*n
for i in range(n):
    f[i]=int(input().replace(' ',''),2)

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

res=float('-inf')
for i in range(1,2**10):
    cnt=0
    for j in range(n):
        idx=bin(i&f[j]).count('1')
        cnt+=p[j][idx]
    res=max(res,cnt)
print(res)

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 dfs(i, A, ans):
    if i == 10:
        ans.append(A)
        return ans
    B = A[:]
    B.append(0)
    ans = dfs(i+1, B, ans)
    C = A[:]
    C.append(1)
    ans = dfs(i+1, C, ans)
    return ans

def main():
    D = dfs(0, [], [])
    for ind, A in enumerate(D):
        if ind == 0:
            continue
        gain = 0
        for i in range(N):
            c = 0
            for day in range(10):
                c += F[i][day]*A[day]
            gain += P[i][c]
        if ind == 1:
            ans = gain
            continue
        ans = max(ans, gain)

    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
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 = -1000000000
for i in range(1,1024):
    pr = 0
    for j in range(n):
        count = 0
        for k in range(10):
            if i>>k & 1 == 1 and f[j][k] == 1:
                count += 1
        pr += p[j][count]
    ans = max(ans,pr)
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**10)
for i in range(1,1024):
	X = [0]*N
	for j in range(N):
		count = 0
		for k in range(10):
			if (i>>k)&1 == 1 and F[j][k] == 1:
				count += 1
		X[j] = P[j][count]
	ans = max(ans,sum(X))

print(ans)

Solution (Python):

a = int(input())
f = [list(map(int,input().split())) for i in range(a)]
p = [list(map(int,input().split())) for i in range(a)]
joisino_mask = [[0],[1]]
import copy
for _ in range(9):
    temp_joisino_mask = []
    for i in joisino_mask:
        temp_joisino_mask.append(i+[0])
        temp_joisino_mask.append(i+[1])
    joisino_mask = temp_joisino_mask

joisino_mask.pop(0)
cur_max = -1 * float("inf")
for mask in joisino_mask:
    mask_p = 0
    for i,misei in enumerate(f):
        common_time_cnt = sum(list(map(lambda x,y:(x+y)//2,mask,misei)))
        mask_p += p[i][common_time_cnt]
    if mask_p > cur_max:
        cur_max = mask_p
print(cur_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**9
cnt=0
count=0


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

m = -(10 ** 10)
for i in range(1, 1024):
    r = 0
    for f, p in zip(F, P):
        r += p[bin(i & int(''.join(str(_) for _ in f), 2))[2:].count('1')]
    m = max(r, m)
print(m)

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 ** 9)
for i in range(1, 1<<10):
    store = {lll : 0 for lll in range(10)}
    k = "0" * (10 - len(bin(i)) + 2) + bin(i)[2:]
    calc = 0
    for nn in range(n):
        count = 0
        for j, kk in enumerate(k):
            if kk == "1":
                if f[nn][j] == 1:
                    count += 1
        calc += p[nn][count]
    ans = max(ans, calc)
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())))

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

print(answer)

Solution (Python):
N = int(input())
F = [[0 for _ in range(10)] for _ in range(N)]
P = [[0 for _ in range(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 = -float('inf')
for mask in range(1, 2**10) :
    profit = 0
    for shop in range(N) :
        count = 0
        for time in range(10) :
            if (mask & (1 << time) != 0) and F[shop][time] == 1 :
                count += 1
        profit += P[shop][count]
    ans = max(ans, profit)

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

Solution (Python):
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())))
time = [0,0,0,0,0,0,0,0,0,1]
def suc(time):
  point = 10 - 1
  while point >= 0:
    if time[point] == 0:
      time[point] = 1
      return time
      break
    else:
      time[point] = 0
      point -= 1
  else:
    return 'over'
can = []
while time != 'over':
  add = 0
  for i in range(n):
    cnt = 0
    for j in range(10):
      cnt += f[i][j] * time[j]
    add += p[i][cnt]
  can.append(add)
  time = suc(time)
print(max(can))

Solution (Python):


import sys
input = sys.stdin.readline

def main():
    N = int(input())
    F = tuple(int(input().replace(" ", ""), 2) for _ in range(N))  
    P = tuple(tuple(map(int, input().split())) for _ in range(N))
    
    ans = {
        sum(p[bin(i & f).count("1")] for f, p in zip(F, P)) for i in range(1, 2 ** 10)
    }
    print(max(ans))


if __name__ == "__main__":
    main()

Solution (Python):

import sys
input = sys.stdin.readline

def main():
    N = int(input())
    F = tuple(int(input().replace(" ", ""), 2) for _ in range(N))
    P = tuple(tuple(map(int, input().split())) for _ in range(N))
    ans = []
    for i in range(1, 2 ** 10):
        cnt = sum(p[bin(i & f).count("1")] for f, p in zip(F, P))
        ans += [cnt]
    print(max(ans))


if __name__ == "__main__":
    main()

Solution (Python):

import sys
input = sys.stdin.readline

from itertools import product


def main():
    N = int(input())
    F = tuple(int(input().replace(" ", ""), 2) for _ in range(N))
    P = tuple(tuple(map(int, input().split())) for _ in range(N))
    ans = []
    for i in range(1, 2 ** 10):
        cnt = sum(p[bin(i & f).count("1")] for f, p in zip(F, P))
        ans += [cnt]
    print(max(ans))


if __name__ == "__main__":
    main()

Solution (Python):

import sys
input = sys.stdin.readline

from itertools import product

def main():
    N = int(input())
    F = tuple(tuple(map(int, input().split())) for _ in range(N))
    P = tuple(tuple(map(int, input().split())) for _ in range(N))
    ans = []
    for b in product((0, 1), repeat=10):
        if 1 not in b:
            continue
        cnt = 0
        for f, p in zip(F, P):
            opening = sum(i & j for i, j in zip(b, f))
            cnt += p[opening]
        ans += [cnt]
    print(max(ans))


if __name__ == "__main__":
    main()

Solution (Python):

import sys
input = sys.stdin.readline

from itertools import product

def main():
    N = int(input())
    F = tuple(tuple(map(int, input().split())) for _ in range(N))
    P = tuple(tuple(map(int, input().split())) for _ in range(N))
    ans = []
    for b in tuple(product((0, 1), repeat=10))[1:]:
        cnt = 0
        for f, p in zip(F, P):
            opening = sum(i & j for i, j in zip(b, f))
            cnt += p[opening]
        ans += [cnt]
    print(max(ans))


if __name__ == "__main__":
    main()

Solution (Python):

import sys
input = sys.stdin.readline

from itertools import product

def main():
    N = int(input())
    F = tuple(tuple(map(int, input().split())) for _ in range(N))
    P = tuple(tuple(map(int, input().split())) for _ in range(N))
    ans = []
    for b in tuple(product((0, 1), repeat=10))[1:]:
        cnt = 0
        for f, p in zip(F, P):
            opening = sum(b[i] == 1 and b[i] == f[i] for i in range(10))
            cnt += p[opening]
        ans += [cnt]
    print(max(ans))


if __name__ == "__main__":
    main()

Solution (Python):

N = int(input())
F = []
P = []

for _ in range(N):
    F.append([int(x) for x in input().split()])
for _ in range(N):
    P.append([int(x) for x in input().split()])

maxprofit = None
for i in range(1, 2**10):
    schedule = [int(x) for x in "{:010b}".format(i)]
    profit = 0
    for f,p in zip(F, P):
        c = sum(schedule[x] == f[x] and schedule[x] for x in range(10))
        profit += p[c]
    if maxprofit is None:
        maxprofit = profit
    else:
        maxprofit = max(maxprofit, profit)
        
print(maxprofit)

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

F = [[int(i) for i in input().split()] for i in range(N)]
P = [[int(i) for i in input().split()] for i in range(N)]

ans = - 10 ** 16
for i in range(1 << 10):
    output = [0] * 10
    for j in range(10):
        if (i>>j) & 1:
            output[j] = 1
    if output.count(0) == 10:
        continue
    tmp_sum = 0
    for n in range(N):
        cnt = 0
        for m in range(10):
            if F[n][m] == output[m] == 1:
                cnt += 1
        tmp_sum += P[n][cnt]
    ans = max(ans, tmp_sum)
print(ans)

Solution (Python):



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())))
    mx = -1e12
    for i in range(1, 1 << 10):
        benefit = 0
        for j in range(n):
            f = F[j]
            counter = 0
            for k in range(10):
                if (i >> k & f[k]) == 1:
                    counter += 1
            benefit += P[j][counter]
        mx = max(mx, benefit)
    print(mx)

if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
F = []
P = []





for _ in range(N):
    F.append([int(x) for x in input().split()])
for _ in range(N):
    P.append([int(x) for x in input().split()])

maxprofit = None
for i in range(1, 2**10):
    schedule = [int(x) for x in "{:010b}".format(i)]

    profit = 0
    for f,p in zip(F, P):
        c = sum(schedule[x] == f[x] and schedule[x] for x in range(10))
        profit += p[c]
    if maxprofit is None:
        maxprofit = profit
    else:
        maxprofit = max(maxprofit, profit)
        
print(maxprofit)

Solution (Python):
from sys import exit, stdin
N = int(stdin.readline().rstrip())
F = [list(map(int, stdin.readline().rstrip().split())) for _ in range(N)]
P = [list(map(int, stdin.readline().rstrip().split())) for _ in range(N)]

ans = -2000000000
 
for bit in range(1, 1<<10):
    cc = 0
    for i in range(N):
        c = 0
        for j in range(10):
            if bit >> j & 1 and F[i][j]:
                c += 1
        cc += P[i][c]
    if ans < cc:
        ans = cc
print(ans)

Solution (Python):
n=int(input())
f=[list(map(int,input().split())) for _ in [0]*n]
p=[list(map(int,input().split())) for _ in [0]*n]
s=-float('inf')
for i in range(1,2**10):
    l=list(map(int,'0'*(12-len(bin(i)))+bin(i)[2:]))
    s=max(s,sum(p[j][sum(l[i] and f[j][i] for i in range(10))] for j in range(n)))
print(s)

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

max_first, max_second = 0, 0

max_v = -float("inf")
for p in range(1, 1 << 10):
	v = 0
	for n in range(N):
		c = 0
		for m in range(10):
			c += (p & 1 << m != 0) & (F[n][m])
		v += P[n][c]
	max_v = max(max_v, v)

print(max_v)

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

max_first, max_second = 0, 0

max_v = -float("inf")
for p in range(1, 1 << 10):
	v = 0
	for n in range(N):
		c = 0
		for m in range(10):
			c += (p & 1 << m != 0) & (F[n][m])
		v += P[n][c]
	max_v = max(max_v, v)

print(max_v)

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

ans = -(10**9)
for time in range(1, 2**10):
  sum_v = 0
  for idx, open in enumerate(opens):
    open_str = ''.join(open)
    bin_str = format(time, '010b')
    both_open = int(bin_str, 2)&int(open_str, 2)
    cnt = 0
    for char in format(both_open, '010b'):
      if char == '1':
        cnt += 1
    sum_v += values[idx][cnt]
  ans = max(ans, sum_v)
print(ans)

Solution (Python):

import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math






def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N = inputInt()
    F = [[[0 for _ in range(2)] for _ in range(5)] for _ in range(N)]
    for i in range(N):
        tmp = inputList()
        for j,val in enumerate(tmp):
            ind = j // 2
            if j % 2 == 0:
                F[i][ind][0] = val
            else:
                F[i][ind][1] = val
                
    P = []
    for i in range(N):
        tmp = inputList()
        P.append(tmp)
        
    ans = -100000000000000000000000000
    for i in range(1, 2**10):
        ans_tmp = [0 for _ in range(N)]
        for j in [1,2,2**2,2**3,2**4,2**5,2**6,2**7,2**8,2**9]:
            tmp = j & i
            ind = 0
            hi = 0
            
            if tmp == 0:
                ind = -1
                hi = -1
            elif tmp == 1:
                ind = 0
                hi = 0
            elif tmp == 2:
                ind = 0
                hi = 1
            elif tmp == 4:
                ind = 1
                hi = 0
            elif tmp == 8:
                ind = 1
                hi = 1
            elif tmp == 16:
                ind = 2
                hi = 0
            elif tmp == 32:
                ind = 2
                hi = 1
            elif tmp == 64:
                ind = 3
                hi = 0
            elif tmp == 128:
                ind = 3
                hi = 1
            elif tmp == 256:
                ind = 4
                hi = 0
            elif tmp == 512:
                ind = 4
                hi = 1
                
            if ind != -1:
                for k in range(N):
                    tmp2 = F[k][ind][hi]
                    
                        
                    
                        
                    if tmp2 == 1:
                        ans_tmp[k] += 1
                        
        a_tmp = 0
        for j in range(N):
            a_tmp += P[j][ans_tmp[j]]
        if ans < a_tmp:
            ans = a_tmp
        
    print(ans)
            	
if __name__ == "__main__":
	main()