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

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

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

ans = -float('inf')
for i in range(1,1 << 10):
    g = [0] * N
    for j in range(10):
        if i >> j & 1:
            for k in range(N):
                g[k] += F[k][j]
    sub = 0
    for i in range(N):
        sub += P[i][g[i]]
    ans = max(ans, sub)
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())))

ans = -10**18
for ci in range(1, 2**10):
    score = 0
    for cn in range(n):
        cnt = 0
        for cj in range(10):
            x = ci >> cj & 1
            if x and f[cn][cj]:
                cnt += 1
        score += p[cn][cnt]
    ans = max(ans, score)
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())))

ans = -10**18
for ci in range(1, 2**10):
    score = 0
    for cn in range(n):
        cnt = 0
        for cj in range(10):
            x = ci >> cj & 1
            if x and f[cn][cj]:
                cnt += 1
        score += p[cn][cnt]
    ans = max(ans, score)
print(ans)

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



def main():
    n = int(input().strip())
    timetable = []
    profites = []
    ans = -(10**9)

    for _ in range(n):
        timetable.append([int(i) for i in input().strip().split()])
    for _ in range(n):
        profites.append([int(i) for i in input().strip().split()])

    for i in range(1, 2**10):
        on_service = [0] * 10
        overlaps = [0] * n
        for j in range(10):
            if i >> j & 1:
                on_service[j] = 1
                for k, table in enumerate(timetable):
                    if table[j] == 1:
                        overlaps[k] += 1
        _tmp = 0
        for m in range(n):
            ptr = overlaps[m]
            _tmp += profites[m][ptr]
        ans = max(ans, _tmp)
    print(ans)
    return


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

from itertools import product
bits_l=list(product([0,1], repeat=10))
bits_l.remove((0,0,0,0,0,0,0,0,0,0))

ans=-float("inf")
for bits in bits_l:
    tmp_ans=0
    for shop in range(n):
        tmp_cnt=0
        for i, bit in enumerate(bits):
            if bit==1 and f[shop][i]==1:
                tmp_cnt+=1
        tmp_ans+=p[shop][tmp_cnt]
    ans=max(ans, 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)]

from itertools import product
bits_l=list(product([0,1], repeat=10))
bits_l.remove((0,0,0,0,0,0,0,0,0,0))

ans=-float("inf")
for bits in bits_l:
    tmp_ans=0
    for shop in range(n):
        tmp_cnt=0
        for i, bit in enumerate(bits):
            if bit==1 and f[shop][i]==1:
                tmp_cnt+=1
        tmp_ans+=p[shop][tmp_cnt]
    ans=max(ans, tmp_ans)

print(ans)

Solution (Python):
A=int(input())
shop_l=[list(map(int,input().split())) for i in range(A)]
shop_count_l=[list(map(int,input().split())) for i in range(A)]
ans=-1*10**10
for i in range(1,1024):
   tmp=0
   l=[0]*A
   for j in range(10):
      if (i>>j)&1:
         for k in range(A):
            if shop_l[k][j] == 1:
               l[k]+=1
   for i in range(A):
      tmp+=shop_count_l[i][l[i]]
   ans=max(ans,tmp)
print(ans)

Solution (Python):
import sys
import itertools

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


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


if __name__ == '__main__':
    main()

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

schejule_list = list(product([0, 1], repeat=10))
ans = - float("inf")
for schedule in schejule_list:
    if schedule == (0,0,0,0,0,0,0,0,0,0):
        continue
    res = 0
    for i in range(n):
        kaburi = 0
        for j in range(10):
            kaburi += f[i][j] * schedule[j]
        res += p[i][kaburi]
    ans = max(ans, res)
print(ans)

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

schejule_list = set(product([0, 1], repeat=10))
ans = - float("inf")
for schedule in schejule_list:
    if schedule == (0, 0, 0, 0, 0, 0, 0, 0, 0, 0):
        continue
    res = 0
    for i in range(n):
        kaburi = 0
        for j in range(10):
            kaburi += f[i][j] * schedule[j]
        res += p[i][kaburi]
    ans = max(ans, res)
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):
import sys
from heapq import heappush, heappop
def input(): return sys.stdin.readline().rstrip()
def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return list(mi())


def main():
    n = ii()
    F = []
    P = []
    for _ in range(n):
        F.append(li())
    for _ in range(n):
        P.append(li())
    
    inf = 10 ** 18
    ans = -inf
    for i in range(1, 1<<10):
        c = [0]*(n)
        tmp = 0
        for j in range(10):
            if (i>>j)&1:
                for k in range(n):
                    c[k] += F[k][j]
        for k in range(n):
            tmp += P[k][c[k]]
        ans = max(ans, tmp)
    print(ans)
            
            
        
    




if __name__ == '__main__':
    main()

Solution (Python):
def ForBaseConvert(Roop,MaxD,Base):
    if all(type(TT) is int for TT in [Roop,MaxD,Base]):
        if Base>=2 and MaxD>=1:
            ConvertN = []
            while Roop>0:
                ConvertN.append(Roop%Base)
                Roop = Roop//Base

            BaseConv = [0]*(MaxD-len(ConvertN))+ConvertN[::-1]
            BaseSInd = [[] for TB in range(0,Base)]
            for TB in range(0,Base):
                BaseSInd[TB] = [SInd for SInd,SNum in enumerate(BaseConv) if SNum==TB]
            return BaseConv,BaseSInd
        else:
            return []
    else:
        return []
      
N = int(input())
F = [[] for TF in range(0,N)]
for TF in range(0,N):
    F[TF] = [int(T) for T in input().split()]
P = [[] for TP in range(0,N)]
for TP in range(0,N):
    P[TP] = [int(T) for T in input().split()]
    
MAXB = -10**9
for TB in range(1,2**10):
    BaseConv,BaseSInd = ForBaseConvert(TB,10,2)
    Benefit = 0
    for TN in range(0,N):        
        Count = sum(1 if F[TN][TT]==1 else 0 for TT in BaseSInd[1])
        Benefit += P[TN][Count]
    if MAXB<Benefit:
        MAXB = Benefit
print(MAXB)

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

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**12
from itertools import product
for i in range(1, 2**10):
    pattern = [(i>>j)&1 for j in range(10)]
    rieki = 0
    for ff, pp in zip(F, P):
        count = sum([f and p for f, p in zip(ff, pattern)])
        rieki += pp[count]

    ans = max(ans, rieki)
print(ans)

Solution (Python):
from itertools import product

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

MAX=-10**12
for p in product(range(2),repeat=10):
  if p==(0,)*10:continue
  SUM=0
  for i in range(N):
    count=0
    for j in range(10):
      if p[j]==1 and F[i][j]==1:
        count+=1
    SUM += P[i][count]
  MAX = max(MAX,SUM)
print(MAX)

Solution (Python):
n=int(input())
import numpy as np
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())))
x=np.asarray(f)
mx=-10**9
for i in range(1,2**10):
    y=np.asarray([int(x) for x in list(format(i,'010b'))])
    z=x*y
    can=np.sum(z,axis=1)
    c=0
    for j in range(n):
        c += p[j][can[j]]
    mx=max(c,mx)
print(mx)

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

import itertools

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

print(ans)

Solution (Python):
N = int(input())
F = [int(''.join(list(input().split())), 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):
    res = 0
    for k in range(N):
        p = i & F[k]
        cnt = 0
        for j in range(10):
            if (p >> j) & 1:
                cnt += 1
        res += P[k][cnt]
    ans = max(ans, res)

print(ans)

Solution (Python):
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    F = [LI() for _ in range(N)]
    P = [LI() for _ in range(N)]

    ans = -INF
    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:
                    cnt += F[j][k]
            tmp += P[j][cnt]
        ans = max(tmp, ans)

    print(ans)

if __name__ == '__main__':
    resolve()

Solution (Python):
import numpy as np
N = int(input())
schedules = [list(map(int, input().split())) for _ in range(N)]
prices = [list(map(int, input().split())) for _ in range(N)]


ans = -1 * float('inf')
for i in range(1, 1 << 10):
    my_schedule = list(map(int, bin(i)[2:].zfill(10)))
    score = 0
    for j, schedule in enumerate(schedules):
        count = 0
        for k in range(10):
            if my_schedule[k] == schedule[k] and schedule[k] == 1:
                count += 1
        score += prices[j][count]
    ans = max(ans, score)
print(ans)

Solution (Python):
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
f = []
for i in range(n):
    f.append(LIST())
p = []
for i in range(n):
    p.append(LIST())

ans = -inf
for x in product([0, 1], repeat=10):
    if sum(x) != 0:
        tmp = 0
        for j in range(n):
            count = 0
            for k in range(10):
                count += f[j][k]*x[k]
            tmp += p[j][count]
        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)]

bh=[0]*n
c=[0]*n
for i,s in enumerate(f):
  for j,h in enumerate(s):
    bh[i]|=h<<j

maxp=-float('inf')
for mbh in range(1,2**10):
  for i in range(n):
    intsect=mbh&bh[i]
    c[i]=sum(intsect>>k&1 for k in range(10))
  maxp=max(maxp,sum(p[i][c[i]] for i in range(n)))
print(maxp)

Solution (Python):
import sys
from collections import defaultdict, deque, Counter
import math


from bisect import bisect_left, bisect_right
import heapq

sys.setrecursionlimit(1000000)


input = sys.stdin.readline

getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = 10 ** 20
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)


def nck(n, k, kaijyo):
    return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD


def npk(n, k, kaijyo):
    if k == 0 or k == n:
        return n % MOD
    return (kaijyo[n] * divide(kaijyo[n-k])) % MOD


def fact_and_inv(SIZE):
    inv = [0] * SIZE  
    fac = [0] * SIZE  
    finv = [0] * SIZE  
    inv[1] = 1
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    for i in range(2, SIZE):
        inv[i] = MOD - (MOD // i) * inv[MOD % i] % MOD
        fac[i] = fac[i - 1] * i % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD

    return fac, finv

def kaijyo(n):
    ret = [1]
    for i in range(1, n + 1):
        ret.append((ret[-1] * i)% MOD)
    return ret

def warshall_floyd(d, n):
    
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d

class TwoDimGrid:
    
    def __init__(self, h, w, wall="
        self.h = h
        self.w = w
        self.size = (h+2) * (w+2)
        self.wall = wall
        self.get_grid()

    def get_grid(self):
        grid = [self.wall * (self.w + 2)]
        for i in range(self.h):
            grid.append(self.wall + getS() + self.wall)

        grid.append(self.wall * (self.w + 2))
        self.grid = grid

    def pos(self, x, y):
        return y * (self.w + 2) + x + 1

    def search(self):
        grid = self.grid
        move = [(0, 1), (0, -1), (1, 0), (-1, 0)]
        move_eight = [(0, 1), (0, -1), (1, 0), (-1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]

        ans = 0
        for i in range(1, self.h + 1):
            for j in range(1, self.w + 1):
                pass 
def bc(bi):
    
    ret = 0
    while(bi > 0):
        if bi & 1 == 1:
            ret += 1
        bi //= 2
    return ret

def judge(bi, fnums, pnums):
    ret = 0
    for i, fnum in enumerate(fnums):
        tmp = bi & fnum

        ret += pnums[i][bc(tmp)]
    
    return ret

def solve():
    n = getN()
    fnums = []
    for i in range(n):
        fnums.append(getList())
    fnums = [int("".join(list(map(str, fnum))), 2) for fnum in fnums]
    
    pnums = []
    for i in range(n):
        pnums.append(getList())
    ans = -INF
    for bi in range(1, 1 << 10):
        ans = max(ans, judge(bi, fnums, pnums))

    print(ans)

def main():
    n = getN()
    for _ in range(n):
        solve()


if __name__ == "__main__":
    
    solve()

Solution (Python):

import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial
from bisect import bisect_left, bisect_right 
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

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

res = -10**12
for i in range(1, 2**10):
    tres = 0
    cnts = [0]*N
    for j in range(10):
        bo = (i>>j) & 1
        for k in range(N):
            cnts[k] += F[k][j] & bo
    for k in range(N):
        tres += P[k][cnts[k]] 
    if res < tres:
        res = tres
print(res)

Solution (Python):
import math


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def dec(digits):
    answer = 0
    for d in digits:
        answer = (answer<<1) + d
    return answer

def bitcount(n):
    answer = 0
    while n != 0:
        answer += n&1
        n >>= 1
    return answer

def solve():
    N = read_int()
    F = []
    P = []
    for _ in range(N):
        F.append(dec(read_ints()))
    for _ in range(N):
        P.append(read_ints())
    max_profit = -math.inf
    for day in range(1, 1<<10):
        profit = 0
        for i in range(N):
            profit += P[i][bitcount(F[i]&day)]
        max_profit = max(max_profit, profit)
    return max_profit


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

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 = -(1 << 30)
for bit in range(1, 1 << 10):
    cnt = 0
    for i in range(n):
        cnt2 = 0
        for j in range(10):
            if (bit >> j & 1) and f[i][j]:
                cnt2 += 1
        cnt += p[i][cnt2]
    if ans < cnt:
        ans = cnt
print(ans)

Solution (Python):
import sys

N = int(input())
Bs = 2**10

Fs = []
Ps = []
l1 = []
for _ in range(N):
  s = int(input().replace(' ', ''), 2)
  Fs.append(s)
for _ in range(N):
  Ps.append(list(map(int, input().split())))

rlt = -sys.maxsize
for b in range(1,Bs):
  tmp = 0
  for i in range(N):
    t = b&Fs[i]
    t = bin(t)[2:]
    c = t.count('1')
    tmp += Ps[i][c]
  rlt = max(rlt, tmp)
  
print(rlt)

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


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

    ans = -INF
    for bits in range(1, 1 << 10):
        res = 0
        for i in range(N):
            c = 0
            for j in range(10):
                if F[i][j] and (bits & (1 << j)):
                    c += 1
            res += P[i][c]
        if ans < res:
            ans = res

    print(ans)
    return


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

Solution (Python):

from itertools import product

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

ret = -10 ** 18


itr = product([0, 1], repeat=10)
itr.__next__()
for bit in itr:
    cand = sum((P[i][sum((f*b for f, b in zip(F[i], bit)))] for i in range(N)))
    ret = max(ret, cand)

print(ret)

Solution (Python):

from collections import deque

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

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

ret = None
for bit in range(1, 2**10):
    nWork = [0] * N
    for i in range(10):
        if (bit >> i) & 1:
            for shop in range(N):
                if F[shop][i] == 1:
                    nWork[shop] += 1

    cand = 0
    for i in range(N):
        cand += P[i][nWork[i]]
    if ret == None or cand > ret:
        ret = cand
print(ret)

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)]
A = [0, 1]
M = -10**18
Pr = list(product(A, repeat=10))
Pr.remove((0,0,0,0,0,0,0,0,0,0))
for I in Pr:
  s = 0
  for i in range(N):
    s += P[i][sum(i*f for i, f in zip(I, F[i]))]
  M = max(M, s)
print(M)

Solution (Python):
import numpy as np
N = int(input())
F = np.array([list(map(int, input().split())) for i in range(N)])
P = np.array([list(map(int, input().split())) for i in range(N)])
ans = -10**18
for i in range(2**10):
    box = []
    for k in range(10):
        if ((i>>k)&1):
            box = [1]+ box
        else:
            box = [0]+ box
    if all(i == 0 for i in box):
        continue
    
    
    G = np.sum(F*box, axis=1)
    a = 0
    for x,y in zip(G,P):
        a += y[x]
    ans = max(ans, a)
    
print(ans)

Solution (Python):


n = int(input())

shops = []
for _ in range(n):
    s = [int(i) for i in input().split()]
    shops.append(s)

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

ans = -1 * float('inf')
for i in range(1, 2 ** 10):
    revenue = 0
    for j in range(n):
        c = 0
        s = shops[j]
        for k in range(10):
            if s[k] and (i >> k) & 1:
                c += 1
        revenue += profits[j][c]
    ans = max(ans, revenue)
print(ans)

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

f = [[] for _ in range(n)]
a = [[] for _ in range(n)]

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

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

ans = -float("inf")
for times in range(1, 1 << 10):
    profit = 0
    for i in range(n):
        cnt = 0
        for j in range(10):
            if times >> j & 1 and f[i][j]:
                cnt += 1
        profit += a[i][cnt]

    ans = max(ans, profit)

print(ans)

Solution (Python):
import sys
import itertools

import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


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

ans = -INF
for i in range(1, 1 << 10):
    profit = 0
    for k in range(N):
        cnt = 0
        for j in range(10):
            if i & 1 << j > 0 and F[k][j] == 1:
                cnt += 1
        profit += P[k][cnt]
    ans = max(ans, profit)
print(ans)

Solution (Python):
n=int(input())
f=[]
for i in range(n):
    fn=[int(x) for x in input().rstrip().split()]
    f.append(fn)

p=[]
for i in range(n):
    pn=[int(x) for x in input().rstrip().split()]
    p.append(pn)

ans=-float('inf')
for i in range(1,2**10):
    now=0
    for s in range(n):
        cnt=0
        for j in range(10):
            if ((i>>j) & 1) and f[s][j]==1:
                cnt+=1
        now+=p[s][cnt]
    ans=max(ans,now)
print(ans)

Solution (Python):
from itertools import combinations

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 ** 18
for i in range(1, 11):
    for pat in combinations(range(10), i):
        cnt = [0] * n
        for e in pat:
            for j in range(n):
                cnt[j] += f[j][e]

        score = 0
        for i, e in enumerate(cnt):
            score += p[i][e]

        ans = max(ans, score)

print(ans)

Solution (Python):
import sys
from itertools import product

input = sys.stdin.readline


def main():
    N = int(input())
    F = [None] * N
    for i in range(N):
        F[i] = tuple(map(int, input().split()))
    P = [None] * N
    for i in range(N):
        P[i] = tuple(map(int, input().split()))

    ans = -float("inf")
    for comb in product(range(2), repeat=10):
        if sum(comb) == 0:
            continue
        c = [0] * N
        for j, is_open in enumerate(comb):
            if is_open:
                for i in range(N):
                    c[i] += F[i][j]
        profit = sum(P[i][c[i]] for i in range(N))
        ans = max(ans, profit)

    print(ans)


if __name__ == "__main__":
    main()

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


def main():
    n = int(input())
    F = [[] for _ in range(n)]
    for w in range(n):
        l = list(map(int, input().split()))
        for i in range(5):
            F[w].append(l[i * 2: i * 2 + 2])
    P = [list(map(int, input().split())) for _ in range(n)]

    ans = -10**10
    for case in range(1, 1 << 10):
        profit = 0
        for i in range(n):
            c = 0
            for t in range(10):
                if F[i][t // 2][t % 2] and case & (1 << t): c += 1
            profit += P[i][c]
        ans = max(ans, profit)
    print(ans)



if __name__ == "__main__":
    main()

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, 1 << (10)):
    C = [0]*n
    for j in range(10):
        if i & 2**j:
            for k in range(n):
                if F[k][j]:
                    C[k] += 1
    current = 0
    for k in range(n):
        current += P[k][C[k]]
    ans = max(current, ans)
print (ans)

Solution (Python):
from math import inf

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

ans = -inf
for bit in range(1,1024):
    res = 0
    for j in range(n):
        c = 0
        for k in range(10):
            mask = 1 << k
            if f[j][k] and bit&mask:
                c+=1
        res += p[j][c]
    ans = max(ans, res)
print(ans)

Solution (Python):
from itertools import product

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

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

ite = product(range(2),repeat=10)
ans = -1*(10**9)
for it in ite:
    pattern = list(it)
    if 1 not in pattern: continue
    each_cnt = [0]*n
    for i,v in enumerate(pattern):
        if v == 1:
            for j,f in enumerate(fl):
                if f[i] == 1:
                    each_cnt[j] += 1
    val = 0
    for i, c in enumerate(each_cnt):
        val += pl[i][c]
    ans = max(ans,val)

print(ans)

Solution (Python):
import sys
n = int(input())
F = [list(map(int, sys.stdin.readline().split())) for _ in range(n)]
P = [list(map(int, sys.stdin.readline().split())) for _ in range(n)]
ans = -pow(10,9)-7
for i in range(1,pow(2,10)):
    b = bin(i)[2:].zfill(10)
    t = 0
    for j in range(n):
        c = 0
        for k in range(10):
            if int(b[k]) and F[j][k]:
                c += 1
        t += P[j][c]
    ans = max(ans, t)
print(ans)

Solution (Python):
N = int(input())
F = [int("".join(input().split()),2) for n in range(N)]
P = [list(map(int,input().split())) for n in range(N)]
print(max(sum(p[bin(n&f).count("1")]for f,p in zip(F,P)) for n in range(1,1024)))

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

for i in range(1,1024):
  p = 0
  for j in range(N):
    c = 0
    for k in range(10):
      if (i>>k&1) & F[j][k]:
        c+=1
    p+=P[j][c]
  ans+=[p]
    
print(max(ans))

Solution (Python):
from itertools import product
n=int(input())
fs=[list(map(int,input().split())) for _ in range(n)]
ps=[list(map(int,input().split())) for _ in range(n)]
ans=-float('inf')
for b in product((0,1),repeat=10):
    if sum(b)==0:
        continue
    v=0
    for f,p in zip(fs,ps):
        cnt=sum([a&b for a,b in zip(b,f)])
        v+=p[cnt]
    ans=max(ans,v)
print(ans)