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):
from itertools import product
N = int(input())
lsF = [[]]
for i in range(N):
    lsF.append(list(map(int,input().split())))
lsP = [[]]
for i in range(N):
    lsP.append(list(map(int,input().split())))
bita = list(product(range(2),repeat=10))
bita.pop(0)
ans = -10**10
for bit in bita:
    count = [0 for i in range(N+1)]
    for i in range(10):
        for j in range(1,N+1):
            count[j] += bit[i]*lsF[j][i]
    benifit = 0
    for i in range(1,N+1):
        benifit += lsP[i][count[i]]
    ans = max(ans,benifit)
print(ans)

Solution (Python):
import itertools
n=int(input())
f=[list(map(int,input().split())) for _ in range(n)]
p=[list(map(int,input().split())) for _ in range(n)]
ans=-(10**12)
for i in range(1,11):
    num=list(itertools.combinations(range(10),i))
    for j in range(len(num)):
        cnt=[0]*n
        cnt2=0
        for k in range(i):
            for l in range(n):
                if f[l][num[j][k]]==1:
                    cnt[l]+=1
        for k in range(n):
            cnt2+=p[k][cnt[k]]
        ans=max(cnt2,ans)
print(ans)

Solution (Python):
import itertools
n=int(input())
f=[list(map(int,input().split())) for _ in range(n)]
p=[list(map(int,input().split())) for _ in range(n)]
ans=-(10**12)
for i in range(1,11):
    num=list(itertools.combinations(range(10),i))
    for j in range(len(num)):
        cnt=[0]*n
        cnt2=0
        for k in range(i):
            for l in range(n):
                if f[l][num[j][k]]==1:
                    cnt[l]+=1
        for k in range(n):
            cnt2+=p[k][cnt[k]]
        ans=max(cnt2,ans)
print(ans)

Solution (Python):

import numpy as np
from itertools import product
import sys
sys.setrecursionlimit(10**6)

n = int(input())

data = np.zeros((10, n), dtype=int)
for i in range(n):
    f = np.array(list(map(int, input().split())))
    data[:, i] = f



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


ans = -10**10

for j, i in enumerate(product([0, 1], repeat=10)):
    if j == 0:
        continue

    indices = [x for x, y in enumerate(i) if y == 1]
    

    data_tmp = data[indices]
    data_tmp = np.sum(data_tmp, axis=0)
    ans_tmp = sum([p[a][b] for a, b in enumerate(data_tmp)])
    ans = max(ans, ans_tmp)
print(ans)

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

def solve(out_list):
  ans = 0
  for fi, pi in zip(f, p):
    c = 0
    for o in out_list:
      if fi[o] == 1:
        c += 1
    ans += pi[c]
  return ans

ans = -float("inf")
for i in range(2 ** 10):
  out_list = []
  
  for j in range(10):
    
    if (i >> j) & 1:
      out_list.append(j)
  if len(out_list) != 0:
    ans = max(ans, solve(out_list))
print(ans)

Solution (Python):
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()))
 
ans = -float("Inf")
for i in range(1,2**10):
    L = []
    b = 0
    for j in range(10):
        if (i>>j)&1:
            L.append(j)
    for j in range(n):
        c = 0
        for x in L:
            if F[j][x] == 1:
                c += 1
        b += P[j][c]
        
    ans = max(ans, b)
 
 
print(ans)

Solution (Python):
N = int(input())
F = [list(map(int,input().split())) for i in range(N)]
P = [list(map(int,input().split())) for i in range(N)]
 
ans = -10**9
for i in range(2**10-1):
  Bit = [1]*10
  for j in range(10):
    if (i>>j)&1:
      Bit[j]=0
  count = 0
  for k in range(N):
    op = sum(b&f for b,f in zip(Bit,F[k]))
    count+=P[k][op]
  ans = max(ans,count)
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**10

for a in range(2**10):
    t = [(a>>b)&1 for b in range(10)]
    if 1 not in t:
        continue
    
    p = 0
    for i in range(N):
        p += P[i][sum(t[j] and F[i][j] for j in range(10))]

    ans = max(p, ans)

print(ans)

Solution (Python):
import itertools

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

ans = -10 ** 10
flg = True
for lst in itertools.product(range(2), repeat = 10):
    if flg:
        flg = False
        continue
    ans_sub = 0
    for i in range(n):
        cnt = sum(j * k for j, k in zip(lst, F_s[i]))
        ans_sub += P_s[i][cnt]
    ans = max(ans, ans_sub)
print(ans)

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

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

ans = -10**32
 
for k in range(1,1<<10):
    sc = 0
    
    for i in range(n):
        cnt = 0
        for j in range(10):
            if L[i][j] and k>>j&1:
                cnt +=1
        
        sc += score[i][cnt]
            
    ans = max(ans,sc)

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

max_prof = -float('inf')

for s in range(1, 1 << 10):

    sum_prof = 0
    for store_no in range(N):
        state = s

        time_zone = 0
        both_open_cnt = 0
        while state > 0:
            if (state & 1) and F[store_no][time_zone]:
                both_open_cnt += 1

            state >>= 1
            time_zone += 1

        sum_prof += P[store_no][both_open_cnt]

    max_prof = max(max_prof, sum_prof)


print(max_prof)

Solution (Python):
from itertools import combinations

def getval():
    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)]
    return n,f,p

def main(n,f,p):
    ans = 0
    for i in range(n):
        temp = 0
        for j in f[i]:
            temp += j
        ans += p[i][temp]

    for i in range(1,10):
        for c in combinations(range(10),i):
            pro = 0
            for j in range(n):
                temp = 0
                for k in c:
                    temp += f[j][k]
                pro += p[j][temp]
            ans = max(ans,pro)

    print(ans)

if __name__=="__main__":
    n,f,p = getval()
    main(n,f,p)

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=-1000000000
for i in range(1,1<<10):
    cnt=[0 for _ in range(N)]
    for j in range(10):
        if (i>>j)%2==1:
            for k in range(N):
                cnt[k]+=F[k][j]
    A=[P[j][cnt[j]] for j in range(N)]
    ans=max(ans,sum(A))
print(ans)

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

ans = -100000000000
for k in range(1, 2 ** 10):
    val = 0
    for i in range(N):
        c = bin(k & F[i]).count("1")
        val += P[i][c]
    ans = max(ans, val)
print(ans)

Solution (Python):
import sys
from sys import exit
from collections import deque
from copy import deepcopy
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod=MOD):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x,mode='counter'):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    if mode=='counter':
        return C
    S = set([1])
    for k in C:
        T = deepcopy(S)
        for x in T:
            for i in range(1,C[k]+1):
                S.add(x*(k**i))
    if mode=='set':
        return S
    if mode=='list':
        return sorted(list(S))



N=intput()
F=[lint() for _ in range(N)]
P=[lint() for _ in range(N)]
ans=-INF
for c in product([0,1],repeat=10):
    if c==(0,0,0,0,0,0,0,0,0,0):
        continue
    tmp=0
    for i in range(N):
        count=0
        for j in range(10):
            count+=c[j]&F[i][j]
        tmp+=P[i][count]
    ans=max(ans,tmp)
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)]
num = 1 << 10
ans = -(10 ** 10)


def popcnt(n):
    c = (n & 0x5555555555555555) + ((n >> 1) & 0x5555555555555555)
    c = (c & 0x3333333333333333) + ((c >> 2) & 0x3333333333333333)
    c = (c & 0x0F0F0F0F0F0F0F0F) + ((c >> 4) & 0x0F0F0F0F0F0F0F0F)
    c = (c & 0x00FF00FF00FF00FF) + ((c >> 8) & 0x00FF00FF00FF00FF)
    c = (c & 0x0000FFFF0000FFFF) + ((c >> 16) & 0x0000FFFF0000FFFF)
    c = (c & 0x00000000FFFFFFFF) + ((c >> 32) & 0x00000000FFFFFFFF)
    return c




for i in range(1, num):
    temp = 0
    for j in range(n):
        temp += P[j][popcnt(i & F[j])]
    ans = max(temp, ans)
print(ans)

Solution (Python):
import numpy as np

def main():
    with open(0) as f:
        N = int(f.readline())
        F = np.array([list(map(int, f.readline().split())) for _ in range(N)])
        P = [list(map(int, f.readline().split())) for _ in range(N)]

    max_profit = -np.inf
    for i in range(1,2**10):
        Open = np.array([(i>>j)&1 for j in range(10)])
        conflict = np.dot(F, Open.T)
        profit = sum(P[i][v] for i,v in enumerate(conflict))
        max_profit = max(max_profit, profit)
    print(max_profit)

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())))
a=0
ans=-(10**10)
for k in range(1,1024):
    a=0
    x=bin(k)
    y=[0]*10
    for i in range(2,len(x)):
        y[10-len(x)+i]+=int(x[i])
    for i in range(n):
        m=0
        t=0
        for j in range(10):
            if y[j]+f[i][j]==2:
                t+=1
        m+=p[i][t]
        a+=m
    ans=max(a,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**9
for i in range(1,2**10):
    s = i
    b = [0]*10
    for j in range(10):
        if s >= (2**(10-j-1)):
            s -= 2**(10-j-1)
            b[j] = 1
    a = 0
    for j in range(N):
        c = 0
        for k in range(10):
            if b[k] == 1 and F[j][k] == 1:
                c += 1
        a += P[j][c]
    ans = max(ans,a)
print(ans)

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

ans=-10**9
for i in range(2**10-1):
    Bit=[1]*10
    for j in range(10):
        if (i>>j)&1:
            Bit[j]=0
    count=0
    for k in range(N):
        op=sum(b&f for b,f in zip(Bit,F[k]))
        count+=P[k][op]
    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)]
ans = -float("inf")
for i in range(1, 2**10):
    tf = [False]*10
    for j in range(10):
        if (i>>j)&1:
            tf[j] = True
    cnt1 = 0
    for j in range(n):
        cnt2 = 0
        for k in range(10):
            if tf[k] and f[j][k]:
                cnt2 += 1
        cnt1 += p[j][cnt2]
    ans = max(ans, cnt1)
print(ans)

Solution (Python):
def bitcount(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f 
    x = x + (x >> 8) 
    x = x + (x >> 16) 
    x = x + (x >> 32) 
    return x & 0x0000007f

def binary_to_int(x):
    temp = 0
    for i in range(len(str(x))):
        temp += 2**(len(str(x))-i-1) * int(str(x[i]))
    return temp

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

for i in range(1, 2**10):
    temp = 0
    for j in range(n):
        temp += p[j-1][bitcount(i & shops[j-1])]
    if i == 1:
        ans = temp
    elif temp > ans:
        ans = temp

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**10
for i in range(1,1<<10):
    c = [0] * n 
    for j in range(10):
        if i & (1<<j):
            for k,F in enumerate(f):
                if F[j]:
                    c[k] += 1
    profit = 0
    for j in range(n):
        profit += p[j][c[j]]
    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)]

li = []

for i in range(2**10):
    if i == 0:
        continue
    ans = 0
    co = [0]*n
    for j in range(10):
        if (i>>j &1)==1:
            for k in range(n):
                if f[k][j]==1:
                    co[k] +=1
    
    for l in range(n):
        ans += p[l][co[l]]
    li += [ans]
print(max(li))

Solution (Python):
from itertools import product

ans = -10**9 - 1

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

all_x = True
for ox in product((0, 1), repeat=10):
  if all_x:
    all_x = False
  else:
    temp = 0
    for n in range(N):
      cnt = 0
      for i, j in zip(F[n], ox):
        cnt += i*j
      temp += P[n][cnt]
    ans = max(ans, temp)

print(ans)

Solution (Python):
import sys, math
from functools import lru_cache
from collections import defaultdict
from decimal import Decimal
sys.setrecursionlimit(10**9)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    N = ii()
    F = [list(mi()) for i in range(N)]
    P = [list(mi()) for i in range(N)]

    m = -math.inf

    for ptn in range(1, 2**10):
        r = 0
        for i in range(N):
            cnt = 0
            for j in range(10):
                if F[i][j] and (ptn>>j)&1:
                    cnt += 1
            r += P[i][cnt]
        m = max(m, r)

    print(m)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
import math

input = sys.stdin.readline
N = int(input())
F = []
for _ in range(N):
    f = 0
    for i, k in enumerate(input().split()):
        f += pow(2, i) * int(k)
    F.append(f)

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


def cal_prof(bit_flg):
    ret = 0
    for i in range(N):
        f = bin(F[i] & bit_flg).count('1')
        ret += P[i][f]
    return ret

ans = -math.inf
for i in range(1, pow(2, 10)):
    ans = max(ans, cal_prof(i))
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())))
  
ans = -(10**9)
for i in range(1, 2**10):
  l = [0] * N
  for j in range(10):
    if (i>>j) & 1:
      for k in range(N):
        if F[k][j] == 1:
          l[k] += 1
  tmp = 0
  for m in range(N):
    n = l[m]
    tmp += P[m][n]
  ans = max(tmp, ans)
print(ans)

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

ans = -float('inf')
for i in range(1, 2**10):
    t = [1 if i & (1 << j) != 0 else 0 for j in range(10)]
    b = 0
    for j in range(N):
        c = 0
        for k in range(10):
            if t[k] == 1 and f[j][k] == 1:
                c += 1
        b += p[j][c]
    ans = max(ans, b)
print(ans)

Solution (Python):
import sys
mod=10**9+7 ; inf=float("inf")
from math import sqrt, ceil
from collections import deque, Counter, defaultdict 
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from decimal import ROUND_HALF_UP,Decimal  
  
from functools import lru_cache
from bisect import bisect_left as bileft, bisect_right as biright






n=int(input());ans=-inf
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())))

for bit in range(1,1<<10):
    L=[(bit>>i)&1 for i in range(10)]
    now=0
    for i in range(n):
        cnt=0
        for cc in range(10):
            if (F[i][cc]==1 and L[cc]==1) : cnt+=1
        now+=P[i][cnt]
    ans=max(ans,now)
print(ans)

Solution (Python):
import itertools

N = int(input())
M = 10
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 s in itertools.product([0, 1], repeat=M):
    if max(s) == 0:
        continue
    score = 0
    for i in range(N):
        cnt = 0
        for j in range(M):
            if s[j] and F[i][j]:
                cnt += 1
        score += P[i][cnt]
    ans = max(ans, score)
print(ans)

Solution (Python):
n=int(input())
f=[[] for i in range(n)]
for i in range(n):
    f[i]=list(map(int,input().split()))
p=[[] for i in range(n)]
for i in range(n):
    p[i]=list(map(int,input().split()))
ans=-10000000000
for i in range(1,1024):
    x=[]
    pro=0
    for j in range(10):
        x.append(i%2)
        i=i//2
    for j in range(n):
        c=0
        for k in range(10):
            if x[k]==f[j][k]==1:
                c+=1
        pro+=p[j][c]
    ans=max(ans,pro)
print(ans)

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

p = []
for i in range(n):
    line = [int(j) for j in input().split()]
    p.append(line)

res = - 10 ** 11
for i in range(1, 1 << 10):
    tmp_res = 0
    for j in range(n):
        counter = 0
        for k in range(10):
            if i >> k & f[j][k]:
                counter += 1
        tmp_res += p[j][counter]
    res = max(res, tmp_res)

print(res)

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 pattern in range(1, 2 ** 10):
    _ans = 0
    for shop in range(n):
        match_cnt = 0
        for i in range(10):
            if F[shop][i] == 0:
                continue
            if (pattern >> i) & 1:
                match_cnt += 1
        _ans += P[shop][match_cnt]
    ans = max(ans, _ans)
print(ans)

Solution (Python):
def main():
    from sys import stdin
    def input():
        return stdin.readline().strip()

    def str_to_bool(i):
        if i == '0':
            return False
        else:
            return True

    n = int(input())
    f = [[str_to_bool(i) for i in input().split()] for _ in range(n)]
    p = [[int(i) for i in input().split()] for _ in range(n)]

    
    from itertools import product

    ans = -float('inf')
    flag = True
    for iterator in product([False, True], repeat=10):
        if flag:
            flag = False
            continue

        profit = 0
        for store_ind in range(n):
            num = 0
            for i in range(10):
                if iterator[i] and f[store_ind][i]:
                    num += 1
            profit += p[store_ind][num]
        
        if ans < profit:
            ans = profit

    print(ans)

main()

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 bit in product([0, 1], repeat=10):
    if sum(bit) == 0:
        continue
    gain = 0
    for pi, fi in zip(p, f):
        tmp = sum(bitj & fij for bitj, fij in zip(bit, fi))
        gain += pi[tmp]
    ans = max(ans, gain)
print(ans)

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

for i in range(1, 2**10):
    ans = max(ans, sum(p[bin(i & f).count('1')] for f, p in zip(F, P)))
print(ans)

Solution (Python):
N=int(input())
F = []
for _ in range(N):
    s = input().split()
    F.append(int("".join(s), base=2))
P = [list(map(int, input().split())) for _ in range(N)]
ans = -float("inf")
for bit in range(1, 2**10):
    gain = 0
    for i in range(N):
        ci = 0
        for j in range(10):
            if ((bit>>j) & 1) and ((F[i]>>j) & 1):
                ci += 1
        gain += P[i][ci]
    ans = max(ans, gain)
print(ans)

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

Profit = []
for i in range(1,2**10): 
    Open = np.array([int(x) for x in format(i, '010b')]).T 
    c = np.dot(F, Open) 
    hq.heappush(Profit, -sum(P[i, c[i]] for i in range(N))) 
print(-Profit[0])

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

total = -10**9
for i in range(1,2**10):
    pgain = 0
    for f,p in zip(F,P):
        pgain += p[bin(f&i).count("1")]
    if total < pgain:
        total = pgain
        k = i
print(total)

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

Profit = []
for i in range(1,2**10): 
    Open = np.array([int(x) for x in format(i, '010b')]) 
    prf = 0
    for f, p in zip(F, P):
        cnt = np.dot(Open, f)
        prf += p[cnt]
    hq.heappush(Profit, -prf)
print(-Profit[0])

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

Profit = []
for i in range(1,2**10):
    Open = np.array([int(x) for x in format(i, '010b')])
    prf = 0
    for f, p in zip(F, P):
        cnt = np.dot(Open, f)
        prf += p[cnt]
    hq.heappush(Profit, -prf)
print(-Profit[0])

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

maxi = -10**10

for i in range(1,2**10):
    num = [0]*n
    for j in range(10):
        if ((i >> j) & 1):
            for k in range(n):
                num[k] += l[k][j]
    benefit = 0
    for m in range(n):
        benefit += p[m][num[m]]
    maxi = max(maxi,benefit)
print(maxi)

Solution (Python):
def dfs(s,N):
    if len(s)==10:
        if "1" in s:
            cal(s,N)
        return
    dfs(s+"0",N)
    dfs(s+"1",N)

def cal(s,N):
    p = 0
    for i in range(N):
        c=0
        for j in range(10):
            c+=F[i][j]*int(s[j])
        p+=P[i][c]
    profit.append(p)
    return

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

dfs("",N)
print(max(profit))

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

for j in range(1, 1024):
    ss = 0
    for i in range(N):
        b = format(j, "010b")
        bb = [0] * 10
        for k in range(10):
            bb[k] = F[i][k] * int(b[k])
        ss += P[i][sum(bb)]
    ans = max(ans, ss)

print(ans)

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

ans=[]
for i in range(1,2**10):
    tmp=0
    for j in range(N):
        b=''.join(F[j])
        ct=0
        for k in range(10):
            if (i>>k)&int(b[k]):
                ct+=1
        tmp+=P[j][ct]
    ans.append(tmp)
print(max(ans))

Solution (Python):
N=int(input())
F=[list(map(int,input().split())) for _ in range(N)]
P=[list(map(int,input().split())) for _ in range(N)]
import math
profit=-math.inf
for i in range(1,2**10):
  temp=0
  i=format(i,'b').rjust(10,'0')
  e=[]
  for j in range(10):
    if i[j]=='1':
      e.append(j)
  for k in range(N):
    count=0
    for l in range(len(e)):
      if F[k][e[l]]==1:
        count+=1
    temp+=P[k][count]
  profit=max(temp,profit)
print(profit)

Solution (Python):
def pad_zero(s, n):
	s = str(s)
	return ("0" * n + s)[-n:]

def main():
	N = int(input())
	F = [[int(f) for f in input().split(" ")] for i in range(N)]
	P = [[int(p) for p in input().split(" ")] for i in range(N)]

	total_profit = []
	for b in range(1, 2 ** 10):
		sale_bit = list(pad_zero(format(b, 'b'), 10))
		profit = 0
		for i in range(len(F)):
			f = F[i]
			p = P[i]
			profit += p[sum([fjk * int(s) for (fjk, s) in zip(f, sale_bit)])]
		total_profit.append(profit)
	print(max(total_profit))


main()

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

F=[set() for _ in range(N)]
for i in range(N):
    G=list(map(int,input().split()))
    for j in range(J):
        if G[j]:
            F[i].add(j)

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

Ans=-float("inf")
for x in range(1,2**J):
    S=set()
    for t in range(J):
        if x%2:
            S.add(t)
        x>>=1

    Score=0
    for i in range(N):
        Score+=P[i][len(F[i]&S)]
    Ans=max(Ans,Score)
    assert 1

print(Ans)

Solution (Python):
import sys
readline = sys.stdin.readline

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

ans = -10**18
for S in range(1, 1<<10):
    res = 0
    for i in range(N):
        cnt = 0
        for j in range(10):
            if (1<<j) & S and F[i][j]:
                cnt += 1
        res += P[i][cnt]

    ans = max(ans, res)

print(ans)

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

Solution (Python):
import sys
import itertools
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


n = int(readline())
fs = [list(map(int, readline().split())) for _ in range(n)]
ps = [list(map(int, readline().split())) for _ in range(n)]

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

ans = -10**9
for p in pat:
    if sum(list(p)) == 0:
        continue
    money = 0
    for i in range(n):
        cnt = 0
        for j in range(10):
            if fs[i][j] == 1 and p[j] == 1:
                cnt += 1
        money += ps[i][cnt]
    if ans < money:
        ans = max(ans, money)
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 = -float('inf')
for i in range(1, 2 ** 10):
  sum = 0
  for j in range(n):
    sum += p[j][bin(i & f[j]).count('1')]
  ans = max(ans, sum)
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**10
for status in range(1,2**10):
    c=[0]*n
    cur=0
    for t in range(10):
        for i in range(n):
            if (status>>t)&1==1 and f[i][t]==1:
                c[i]+=1
    
    for i in range(n):
        cur+=p[i][c[i]]
    
    ans=max(ans,cur)

print(ans)