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

Solution (Python):
import sys

input = sys.stdin.readline


def main():
    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):
        c = [0] * N
        for j in range(10):
            if i >> j & 1:
                for k in range(N):
                    if F[k][j] == 1:
                        c[k] += 1

        tmp = 0
        for k in range(N):
            tmp += P[k][c[k]]

        ans = max(ans, tmp)

    print(ans)




if __name__ == '__main__':
    main()

Solution (Python):
from operator import mul

n = int(input())
cof = [1 << x for x in range(10)]
fs = [sum(map(mul, map(int, input().split()), cof)) for _ in range(n)]
ps = [list(map(int, input().split())) for _ in range(n)]

ans = float('-inf')
for g in range(1, 1024):
   ans = max(ans, sum(p[bin(f & g).count('1')] for f, p in zip(fs, ps)))

print(ans)

Solution (Python):
import sys
bbn=1000000007
	


class store:
	def __init__(self, is_open):
		ret=0
		for i,v in enumerate(is_open):
			ret += (2**i)*v
		self.is_open=ret
	
	def add_proof_info(self,pl):
		self.ploofs=pl
		
	def get_proof(self, time):
		count=0
		temp=self.is_open
		tt=time
		while temp>0:
			count+=1&tt&temp
			tt=tt>>1
			temp=temp>>1
			

		return self.ploofs[count]
		
def main():
	n = int(input())
	stores=[]
	for i in range(n):
		is_open = list(map(int, input().split()))
		st=store(is_open)
		stores.append(st)
		
	for s in stores:
		pl=list(map(int, input().split()))
		s.add_proof_info(pl)
	
	ret=None
	for i in range(1,(2**10)+0):
		value=sum([s.get_proof(i) for s in stores])
		if ret is None or ret < value:
			ret = value
		
	print(ret)
	
	

isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		
			
	ret = main()
	if ret is not None:
		print(ret)

Solution (Python):
from itertools import product
from operator import and_
N = int(input())
F = [tuple(map(lambda s: s=="1", input().split())) for _ in range(N)]
P = [tuple(map(int, input().split())) for _ in range(N)]
print(max(sum(P[i][sum(map(and_, F[i], prod))] for i in range(N)) for prod in product((True, False), repeat=10) if sum(prod)))

Solution (Python):
n = int(input())
info = [list(map(int, input().split())) for i in range(n)]
profits = [list(map(int, input().split())) for i in range(n)]
ans = -float("inf")

for i in range(1, 2 ** 10):
    tmp = 0
    for j in range(n):
        count = 0
        for k in range(10):
            if ((i >> k) & 1) == 1 and info[j][k] == 1:
                count += 1

        tmp += profits[j][count]
    
    ans = max(ans, tmp)

print(ans)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

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

def main():
  n=I()
  a=[LI() for _ in range(n)]
  b=[LI() for _ in range(n)]

  ans=-inf
  for i in range(1,1<<10):
    _ans=0
    for _i,x in enumerate(a):
      counter=0
      for j in range(10):
        if i&(1<<j) and x[j]==1:
          counter+=1
      _ans+=b[_i][counter]
    ans=max(ans,_ans)
  return ans


print(main())

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_list = [0] * (2 ** 10 - 1)

for i in range(1, 2**10):
    open_day = [0] * 10
    
    for j in range(10):
        if i & (1 << j):
            open_day[j] = 1
    
    for k in range(N):
        count = 0
        for t in range(10):
            if open_day[t] == F[k][t] and F[k][t] == 1:
                count += 1
        ans_list[i-1] += P[k][count]

print(max(ans_list))

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

lst=set()
for i in range(2**10):
    a=(10-len(bin(i)[2:]))*"0"+bin(i)[2:]
    if "1" in a:
        num=0
        for n in range(N):
            count=0
            for m in range(10):
                if F[n][m]==1 and a[m]=="1":
                    count+=1
            num+=P[n][count]
        lst.add(num)


print(max(lst))

Solution (Python):
n = int(input())
arr = [list(map(int, input().split())) for i in range(n)]
arm = [list(map(int, input().split())) for j in range(n)]  
ans = -9999999999  
for item in range(1, (1<<10)):  
    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):
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):
    res = 0
    for j in range(n):
        cnt = sum([(i >> k & 1) & f[j][k] for k in range(10)])
        res += p[j][cnt]
    ans = max(ans, res)

print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
N=int(input())
F=[list(map(int,input().split())) for _ in range(N)]
P=[list(map(int,input().split())) for _ in range(N)]
ans=(-1)*float("INF")
for i in range(1,1<<10):
    p=0
    for j in range(N):
        cnt=0
        for k in range(10):
            if 1&i>>k & F[j][k]:
                cnt+=1
        p+=P[j][cnt]
    ans=max(p,ans)
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)]




ans = -10**10
for v in itertools.product([1,0],repeat=10):
    if v != (0,0,0,0,0,0,0,0,0,0):
        bene = 0
        for i in range(N):
            c = 0
            for j in range(10):
                if v[j] == F[i][j] == 1:
                    c += 1
            bene += P[i][c]
        ans = max(ans,bene)
print(ans)

Solution (Python):
state = [0 for x in range(0, 10)]

def next(state):
    new_state = [x for x in state]
    new_state[9] += 1
    for i in range(0, 9):
        if new_state[9 - i] >= 2:
            new_state[9 - i] = 0
            new_state[9 - i - 1] += 1
        else:
            break

    return new_state


n = int(input())

f = list()
for i in range(0, n):
    tmp = list(map(int, input().split(" ")))
    f.append(tmp)

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

ans = -1000000000
for i in range(0, 2 ** 10 - 1):
    state = next(state)
    v = 0
    for j in range(0, n):
        opens = 0
        for k in range(0, len(state)):
            opens += f[j][k] * state[k]
        v += p[j][opens]
    ans = max(ans, v)

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(2**10):
    if i == 0: 
        continue
    profit = 0
    pattern = [0]*10
    for j in range(10):
        if 1 << j & i:
            pattern[j] = 1
    

    for k in range(N):
        l = sum([pattern[m] == F[k][m] == 1 for m in range(10)])
        
        
        
        

        
        profit += P[k][l]
    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)]
ans = -float('inf')
for i in range(2**10):
    if i == 0: 
        continue
    profit = 0
    pattern = [0]*10
    for j in range(10):
        if 1 << j & i:
            pattern[j] = 1
    

    for k in range(N):
        
        l = 0
        for m in range(10):
            if pattern[m] == F[k][m] == 1:
                l += 1

        
        profit += P[k][l]
    ans = max(ans,profit)
print(ans)

Solution (Python):

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


ans = -float("inf")

for i in range(2**10):
  cnt = [0] * N
  for j in range(10):
    if (i>>j) & 1:
      for k in range(N):
        if F[k][j] == 1:
          cnt[k] += 1
  
  tmp = 0
  valid = False
  for i in range(N):
    if cnt[i] > 0:
      valid = True
    tmp += P[i][cnt[i]]

  if valid:
    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**15
for i in range(1, 2**10):
    tmp = 0
    for k in range(N):
        c = 0
        for j in range(10):
            if (i >> j) & 1 and F[k][j]:
                c += 1
        tmp += P[k][c]
    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 = -(1<<60)
for bit in range(1, 1<<10): 
  tmp = 0
  for i in range(N):
    cnt = 0
    for j in range(10):
      if (bit>>j)&1 and F[i][j]:
        cnt += 1
    tmp += P[i][cnt]
  
  if ans<tmp:
    ans = tmp
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())))

A = []
def dfs(arr):
    if len(arr) == 10:
        if arr != [0,0,0,0,0,0,0,0,0,0]:
            A.append(arr)
        return
    for i in [0,1]:
        dfs(arr + [i])
dfs([])

ans = -(10**18)

for i in range(len(A)):
    tmp = 0
    for j in range(N):
        fac = A[i][0]*F[j][0] + A[i][1]*F[j][1] + A[i][2]*F[j][2] + A[i][3]*F[j][3] + A[i][4]*F[j][4] + A[i][5]*F[j][5] + A[i][6]*F[j][6] + A[i][7]*F[j][7] + A[i][8]*F[j][8] + A[i][9]*F[j][9]
        tmp += P[j][fac]
    ans = max(tmp, ans)
print(ans)

Solution (Python):

import itertools

def main():
    N = int(input())
    F = [int(input().replace(' ',''),2) for _ in range(N)]
    P = [list(map(int,input().split())) for _ in range(N)]
    answer = -float('inf')

    for bit in range(1,1<<10):
        tmp_profit = 0
        for i in range(N):
            count = format(bit&F[i],'b').count("1")
            tmp_profit += P[i][count]
        answer = max(answer,tmp_profit)
    print(answer)
    return 

if __name__ == '__main__':
    main()

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

bitlen = 10


























import numpy as np
F = np.array(F)
P = np.array(P)

bitshifter = np.array([x for x in range(bitlen)])


def ret_score(n: int, F, bitshifter, P):
    bit_arr = (n >> bitshifter) & 1
    F_matched = bit_arr & F
    C = F_matched.sum(axis=1)

    
    ret = 0
    for i, c in enumerate(C):
        ret += P[i, c]
    return ret


ans = -10**10
for n in range(1, 1 << bitlen):
    ans = max(ans, ret_score(n, F, bitshifter, P))
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())))

bitlen = 10


























import numpy as np
F = np.array(F)
P = np.array(P)

bitshifter = np.array([x for x in range(bitlen)])


def ret_score(n: int):
    bit_arr = (n >> bitshifter) & 1
    F_matched = bit_arr & F
    C = F_matched.sum(axis=1)

    
    ret = 0
    for i, c in enumerate(C):
        ret += P[i, c]
    return ret


ans = -10**10
for n in range(1, 1 << bitlen):
    ans = max(ans, ret_score(n))
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())))

bitlen = 10


def ret_score(n: int):
    
    C = []
    for i in range(N):  
        cnt = 0
        for bit in range(bitlen):  
            if ((n >> bit) & 1) and F[i][bit]:  
                cnt += 1
        C.append(cnt)

    
    ret = 0
    for i, c in enumerate(C):
        ret += P[i][c]
    return ret


ans = -10**10
for n in range(1, 1 << bitlen):
    ans = max(ans, ret_score(n))
print(ans)

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

opening_status = []
for _ in range(n):
    F = input().replace(' ', '')
    opening_status.append(int(F, 2))

scores = []
for _ in range(n):
    score = list(map(int, input().split()))
    scores.append(score)


ans = -float('INF')
for pattern in range(1, 2**10):
    candidate = 0
    for idx, status in enumerate(opening_status):
        together = pattern & status
        count = sum([1 if together >> i & 1 else 0 for i in range(10)])
        candidate += scores[idx][count]

    ans = max(ans, candidate)

print(ans)

Solution (Python):
import itertools 

n = int(input())

shopData = []

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

data = list(itertools.product(range(2), repeat = 10))
del data[0]
max_point = - (10 ** 9)
for shop in data:
    cand = 0
    for i in range(len(shopData)):
        count = 0
        for j in range(10):
            if shop[j] == 1 and shopData[i][j] == 1:
                count += 1
        cand += point[i][count]
    max_point = max(max_point, cand)
print(max_point)

Solution (Python):

def calc_money(open_time,F,P):
    money = 0
    for i in range(len(F)):
        overlap_time=0
        for j in range(len(open_time)):
            overlap_time+= open_time[j]*F[i][j]
        
        money+=P[i][overlap_time]
    return money


        


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

    max_money=0
    for i in range(1024):
        if i==0: continue
        num=str(bin(i))[2:]
        open_time = []

        for j in range(10-len(num)):
            open_time.append(0)
        for j in range(len(num)):
            open_time.append(int(num[j]))
        money = calc_money(open_time,F,P)
        if i==1:
            max_money=money
        elif max_money<money:
            max_money=money
    print(max_money)
            


main()

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

ans=-(10**7*N)
for o in range(1,1<<10):
    p=0
    for i in range(N):
        p+=P[i][bin(F[i]&o).count('1')]
    ans=max(ans,p)
print(ans)

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

ans=-(10**7*N)

for o in range(1,1<<10):
    
    C=[0]*N
    for t in range(10):
        
        if o&1:
            for i in range(N):
                if F[i][t]==1:
                    C[i]+=1
        o>>=1
    
    p=0
    for i in range(N):
        p+=P[i][C[i]]
    ans=max(ans,p)

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())))
pmax=0
cnt=1024
for i in range(1023):
    cnt+=1
    tmpp=[]
    oc=str(bin(cnt))[3:]
    for j in range(n):
        c=0
        for k in range(10):
            if f[j][k]==1 and oc[k]=="1":
                c+=1
        tmpp.append(p[j][c])
    if i==0:
        pmax=sum(tmpp)
    else:
        if sum(tmpp)>pmax:
            pmax=sum(tmpp)
print(pmax)

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

ans = -float("inf")
n = 10  
for i in range(2 ** n):
   if i == 0:
      continue
   bit = [0] * n
   for j in range(n):
       if ((i >> j) & 1):
           bit[j] = 1
   tmp = 0
   for idx,f in enumerate(fl):
      point = 0
      for j in range(n):
         if f[j] == 1 and bit[j] == 1:
            point += 1
      tmp += pl[idx][point] 
   ans = max(ans, tmp)
print(ans)

Solution (Python):
import sys
from itertools import combinations as combi
input = sys.stdin.readline
N = int(input())
f = [list(map(int, input().split())) for _ in range(N)]
p = [list(map(int, input().split())) for _ in range(N)]
days = [i for i in range(10)]
res = -float("inf")
for x in range(1, 11):
  for c in combi(days, x):
    t = 0
    y = [0] * N
    for i in range(N):
      for j in c:
        if f[i][j]:
          y[i] += 1
      t += p[i][y[i]]
    
    res = max(res, t)
print(res)

Solution (Python):
N = int(input())
F = []
P = []
for i in range(N):
    a = list(map(int,input().split()))
    c = 0
    for i in range(10):
        c += a[i]*(2**(9-i))
    F.append(c)
for i in range(N):
    P.append(list(map(int,input().split())))
ans = []
for i in range(1,2**10):
    an = 0
    for j in range(len(F)):
        count = 0
        for k in range(10):
            if ((i&F[j]) >> k) & 1 == 1:
                count += 1
        an += P[j][count]
    ans.append(an)
print(max(ans))

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

def count_one(bit):
    n = 0
    while bit:
        n += (1 & bit)
        bit = bit >> 1
    return n

def main():
    N = I()
    F_bit = []
    P = []
    ans = -inf
    for i in range(N):
        f = LS()
        f_bit = int(''.join(f), base=2)
        F_bit.append(f_bit)

    for _ in range(N):
        p = LI()
        P.append(p)

    for bit in range(1, 1<<10):
        cur_ans = 0
        for i in range(N):
            i_bit = F_bit[i]
            ci = count_one(bit & i_bit)
            cur_ans += P[i][ci]
        ans = max(ans, cur_ans)
    print(ans)

    '''
    for i in range(N):
        n_open = n_open_time[i]
        i_max_prof = -1
        ix_max_prof = 0
        for j in range(n_open+1):
            if i_max_prof <= P[i][j]:
                i_max_prof = P[i][j]
                ix_max_prof = j
        cur_ans += i_max_prof
        selected_ix.add(ix_max_prof)
        if n_open > 0:
            least_ans = max(least_ans, max(P[i][1:n_open+1]))
    if len(selected_ix) == 1 and 0 in selected_ix:
        print(least_ans)
    else:
    '''

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

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

print(ans)

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

for i in range(N):
  f = list(map(int,input().split()))
  F.append(f)
  
for i in range(N):
  p = list(map(int,input().split()))
  P.append(p)
  
value = 0

ans = - (10 ** 9)

def recur(list):
  con = len(list)
  
  if con == 10:
    
    if list.count(1) == 0:
      return
    value = 0
    
    for n,shop in enumerate(F):
      con = 0
      for j in range(10):
          
          if list[j] == 1 and shop[j] == 1:
              con += 1
      
      
      value += P[n][con]
 
    global ans
  
    ans = max(ans, value)
    
  else:
    
    recur(list + [0])
    
    recur(list + [1])
    
recur([])
    
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)]

answer = []
for i in range(1, 2 ** 10):
  tmp = 0
  for j in range(N):
    cnt = 0
    for k in range(10):
      if (i >> k) & 1 and F[j][k]:
        cnt += 1
    tmp += P[j][cnt]
  answer.append(tmp)
  
print(max(answer))

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

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

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


num = 2**10
max_ans = -100000000000
for i in range(1, num):
    a = format(i, 'b').zfill(10)
    common_list = [0] * n
    ans = 0
    for j in range(n):
        count = 0
        for k in range(10):
            if list_1[j][k] == int(a[k]) and int(a[k]) == 1:
                count += 1
        ans += list_2[j][count]
    if ans > max_ans:
        max_ans = ans

print(max_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)]

def naiseki(a, b):
  na=len(a)
  nb=len(b)
  if na==nb:
    return sum([a[i]*b[i] for i in range(na)])
  else:
    return None

cand=[]
for i in range(1, 2**10):
  temp=list(map(int, list(format(i, '010b'))))
  rieki=0
  for j in range(N):
    c=naiseki(temp, F[j])
    rieki+=P[j][c]
  cand.append(rieki)
  
print(max(cand))

Solution (Python):


import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
A = list2d(N, 10, 0)
for i in range(N):
    A[i] = LIST()
B = list2d(N, 11, 0)
for i in range(N):
    B[i] = LIST()

ans = -INF

for S in range(1, 1<<10):
    sm = 0
    for i in range(N):
        cnt = 0
        for j in range(10):
            if S & 1<<j and A[i][j]:
                cnt += 1
        sm += B[i][cnt]
    ans = max(ans, sm)
print(ans)

Solution (Python):


import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
A = list2d(N, 10, 0)
for i in range(N):
    A[i] = LIST()
B = list2d(N, 11, 0)
for i in range(N):
    B[i] = LIST()

ans = -INF

for S in range(1, 1<<10):
    sm = 0
    for i in range(N):
        cnt = 0
        for j in range(10):
            if S & 1<<j and A[i][j]:
                cnt += 1
        sm += B[i][cnt]
    ans = max(ans, sm)
print(ans)

Solution (Python):
import sys

*I, = map(int, sys.stdin.read().split())
n = I[0]
f = list(zip(*[iter(I[1:1+10*n])] * 10))
p = list(zip(*[iter(I[1+10*n:])] * 11))

def main():
    res = -float('inf')
    for i in range(1, 2**10):
        cnt = [0] * n
        for j in range(10):
            if i >> j & 1:
                for k in range(n):
                    cnt[k] += f[k][j]
        profit = 0
        for k in range(n):
            profit += p[k][cnt[k]]
        res = max(res, profit)

    return res
        
if __name__ == '__main__':
    ans = main()
    print(ans)

Solution (Python):
import sys
import numpy as np 

I = np.array(sys.stdin.read().split(), dtype=np.int64)
n = I[0]
f = I[1:1+10*n].reshape(n, 10)
p = I[1+10*n:].reshape(n, 11)

def main():
    schedules = np.arange(1, 2**10)[:, None] >> np.arange(10) & 1

    res = f & schedules[:, None]
    res = np.sum(res, axis=2)

    res = p[np.arange(n), res]
    res = np.sum(res, axis=1)

    ans = np.amax(res)
    return ans
    
if __name__ == '__main__':
    ans = main()
    print(ans)

Solution (Python):
N = int(input())
A=[0]*N
P=[0]*N


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

MAX=-1*(10**9)
for i in range(1,1024):
    t=format(i,"b")
    l=10-len(t)
    t="0"*l+t
    a=[0]*N
    for j in range(10):
        
        if(t[j]=="1"):
            for k in range(N):
                
                if(int(A[k][j])==int(t[j])):
                    a[k]+=1
    T=0
    for j in range(N):
        T+=P[j][a[j]]
    MAX=max(T,MAX)

print(MAX)

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

for pattern_i in range(1, 2**10):
  op_num = [0]*n
  for pos_i in range(10):
    if pattern_i & 1<<pos_i:
      for n_i in range(n):
        op_num[n_i] += F[n_i][pos_i]
        
  max_score = max(max_score, sum([p_i[op_num_i] for p_i, op_num_i in zip(P, op_num)]))

print(max_score)

Solution (Python):

import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf')
ans = 0 ;count = 0 ;pro = 1

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 bit in range(1,2**10):
    count=[0]*n
    for k in range(10):
        if (bit>>k & 1):
            for i,Fi in enumerate(F):
                count[i]+=Fi[k]
    tmp=0
    for i,Pi in enumerate(P):
        tmp+=Pi[count[i]]
    ans=max(ans,tmp)
print(ans)

Solution (Python):
def calc(days):
    if sum(days) == 0:
        return
    profit = 0
    for i in range(N):
        both = 0
        for f, d in zip(F[i], days):
            if f == d == 1:
                both += 1
        profit += P[i][both]
    global ans
    ans = max(ans, profit)


def dfs(days):
    if len(days) == 10:
        calc(days)
        return
    dfs(days + [0])
    dfs(days + [1])


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

dfs([])
print(ans)

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 ** 7) * 100 * 10

def f(a):
    if a.count(1) == 0:
        return
    prof = 0
    for i, fi in enumerate(F):
        c = 0
        for j in range(10):
            if a[j] == 1 and fi[j] == 1:
                c += 1
        prof += P[i][c]

    global ans
    ans = max(ans, prof)

def dfs(a):
    if len(a) == 10:
        f(a)
    else:
        dfs(a + [0])
        dfs(a + [1])

dfs([])
print(ans)

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


    B = []
    
    for i in range(1, 2 ** 10):
        b = format(i, 'b').zfill(10)
        B.append(b)

    
    
    
    

    profits = []
    for bi in B:
        profit = 0
        for i, fi in enumerate(F):
            c = 0
            for j in range(10):
                if bi[j] == '1' and fi[j] == 1:
                    c += 1
            profit += P[i][c]
        profits.append(profit)
    print(max(profits))





if __name__ == "__main__":
    main()

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**10
for i in range(1,2**10):
    tmp_prof = 0
    test = bin(i)[2:].zfill(10)
    for j in range(n):
        tmp_c = 0
        for k in range(10):
            if (f[j][k]==1) & (test[k]=='1'):
                tmp_c+=1
        tmp_prof += p[j][tmp_c]
    if ans < tmp_prof:
        ans = tmp_prof
print(ans)