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

MaxValu = -2147483646
d = 2 ** 10
for i in range(1, d):
  tmp = i
  L = [0 for _ in range(10)]
  for j in range(10):
    L[j] = tmp % 2
    tmp //= 2
  val = 0
  for j in range(N):
    tmp2 = 0
    for m in range(10):
      tmp2 += F[j][m] * L[m]
    val += P[j][tmp2]
  if val > MaxValu:
    MaxValu = val
print(MaxValu)

Solution (Python):
n=int(input())
F=[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):
    cnt=0
    num=format(i,"b").zfill(10)
    for j,k in enumerate(F):
        cnt +=P[j][len([v for v in range(10) if k[v]==num[v]=="1"])]
    ans=max(ans,cnt)
print(ans)

Solution (Python):
n=int(input())
F=[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):
    cnt=0
    num=format(i,"b").zfill(10)
    for j,k in enumerate(F):
        cnt +=P[j][len([v for v in range(10) if k[v]==num[v]=="1"])]
    ans=max(ans,cnt)
print(ans)

Solution (Python):
n=int(input())
F=[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):
    cnt=0
    num=format(i,"b").zfill(10)
    for j,k in enumerate(F):
        cnt +=P[j][len([True for m in range(10) if k[m]==num[m]=="1"])]
    ans=max(ans,cnt)
print(ans)

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

frr = []

for i in range(n):
    frr.append([int(s) for s in input().split(" ")])

prr = []

for i in range(n):
    prr.append([int(s) for s in input().split(" ")])














res = []
for i in range(1,2 ** 10):
    count = [0 for s in range(n)]

    mask = []
    for j in range(10):
        m =  i >> j & 1
        mask.append(m)
        if m == 1:
            for k in range(n):
                if frr[k][j] == 1:
                    count[k] = count[k] + 1

    mm = []
    for index,c in enumerate(count):
        mm.append(prr[index][c])

    res.append(sum(mm))

print(max(res))

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

p=[[0 for i in range(11)] for j in range(n)]
for i in range(n):
  x=list(map(int,input().split()))
  p[i]=x[:]

val=[0 for _ in range(1023)]

zr=[0 for _ in range(n)]
for i in range(1,1024):  
  mx=0
  x=i-1
  opn=zr[:]
  
  for j in range(10):  
    k=i%2
    i=i//2
    if k==1:
      for l in range(n):  
        opn[l]+=f[l][j]
  for l in range(n):
    mx+=p[l][opn[l]]
  val[x]=mx
  






print(max(val))

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):
    bit = i
    profit = 0
    for j in range(N):
        cnt = sum(F[j][k] & (bit >> k) for k in range(10))
        profit += P[j][cnt]
    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(1, 1 << 10):
    bit = [0] * 10
    for d in range(10):
        bit[d] = 1 if (i >> d) & 1 else 0
    profit = 0
    for j in range(N):
        cnt = sum(F[j][k] & bit[k] for k in range(10))
        profit += P[j][cnt]
    ans = max(ans, profit)

print(ans)

Solution (Python):
n = int(input())
max_num = -10**12
stores = {}

for i in range(n):
    stores[i] =[int('0b'+''.join(input().split()), 2)]
for i in range(n):
    stores[i].append(list(map(int, input().split())))
for i in range(1, 1024):
    total_sum = 0
    for j in range(n):
        common_open_time = bin(stores[j][0] & i).count('1')
        total_sum += stores[j][1][common_open_time]
    max_num = max(total_sum, max_num)
print(max_num)

Solution (Python):




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

    result = -10**10
    for i in range(1, 1 << 10):
        count = [0 for _ in range(N)]
        for j in range(10):
            for k in range(N):
                if (i >> j) & 1 == 1 and F[k][10 - j - 1] == 1:
                    count[k] += 1
        total = 0
        for k in range(N):
            total += P[k][count[k]]
        result = max(result, total)
    print(result)


if __name__ == "__main__":
    main()

Solution (Python):
I=input;R=range;n=int(I())
lf=[int(I()[::2],2) for _ in R(n)]
lp=[list(map(int,I().split())) for _ in R(n)]
print(max(sum(p[bin(i&f).count('1')] for f,p in zip(lf,lp)) for i in R(1,1024)))

Solution (Python):
import numpy as np
n = int(input())
F = np.array([])
for i in range(n):
  F = np.append(F,np.array(list(map(int,input().split()))))
F = F.reshape([n,10])
p = [list(map(int,input().split())) for _ in range(n)]

ans = -10**9
for i in range(1,2**10):
  s = 0
  J = np.array([])
  for j in range(10):
    J = np.append(J,(i >> j) & 1)
  s = 0
  for j in range(n):
    s += p[j][int(np.dot(F[j],J))]
  ans = max(ans,s)
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)]
data = list(itertools.product(range(2), repeat = 10))[1:]
ans = -10**9
for d in data:
    a = 0
    for i in range(n):
        c = 0
        for j in range(10):
            if f[i][j] and d[j]: c+=1
        a+=p[i][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
def bfs(x):
    if len(x) == 10:
        if 1 in x:
            global ans
            a = 0
            for i in range(n):
                f,p = F[i],P[i]
                c = 0
                for j in range(10):
                    if x[j] == f[j] == 1: c+=1
                a+=p[c]
            ans = max(ans,a)
    else:
        bfs(x + [0])
        bfs(x + [1])
bfs([])
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**10

for i in range(1,2**10):
    l = []
    ans1 = 0
    for j in range(10):
        if (i>>j) & 1:
            l.append(1)
        else:
            l.append(0)
    for k in range(n):
        count = 0
        for m in range(10):
            if l[m] == 1 and F[k][m] == 1:
                count += 1
        ans1 += P[k][count]
    ans = max(ans,ans1)
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)]
ma=-10000000000000
for i in range(1,2**10):
    check=[0]*n
    for j in range(10):
        if (i>>j) & 1:
            for k in range(n):
                check[k]+=f[k][j]
    ma_sub=0
    for i in range(n):
        ma_sub+=p[i][check[i]]
    ma=max(ma,ma_sub)
print(ma)

Solution (Python):
n=int(input())
F=[[0]*10 for i in range(n)]
for i in range(n):
  F[i]=list(map(int,input().split()))
P=[[0]*11 for i in range(n)]
for i in range(n):
  P[i]=list(map(int,input().split()))
ans=-10**10
for i in range(1,1024):
  s=format(i,"12b")
  A=[]
  for j in range(10):
    if s[-1-j]=="1":
      A.append(j)
  p=0
  for j in range(n):
    c=sum(F[j][A[k]] for k in range(len(A)))
    p=p+P[j][c]
  if p>ans:
    ans=p
print(ans)

Solution (Python):
INF = 100000000000

from itertools import product
N = int(input())
is_opens = []
all_open = [0 for i in range(10)]

for n in range(N):
  l = list(map(int, input().split()))
  for i in range(len(l)):
    all_open[i] = 1 if l[i] == 1 else all_open[i] 
  is_opens.append(l)
must_true = set([i for i in range(len(all_open)) if all_open[i] == 0])

values = []
for n in range(N):
  values.append(list(map(int, input().split())))

patterns = product([0,1], repeat=10)
ans = -INF
for pattern in patterns:
  trues = set([i for i in range(len(pattern)) if pattern[i] == 1])
  if not must_true.issubset(trues) or trues == set():
    continue 

  tmp = 0
  for n in range(N):
    count = sum([1 for i in range(10) if pattern[i] == 1 and pattern[i] == is_opens[n][i]])
    value = values[n][count]
    tmp += value
  ans = max(ans, tmp)

print(ans)

Solution (Python):
icase=0
if icase==0:
    n=int(input())

    f=[]
    for i in range(n):
        fi=list(map(int,input().split()))
        f.append(fi)
    p=[]
    for i in range(n):
        pi=list(map(int,input().split()))
        p.append(pi)
elif icase==1: 
    n=1
    f=[[1, 1, 0, 1, 0, 0, 0, 1, 0, 1]]
    p=[[3, 4, 5, 6, 7, 8, 9, -2, -3, 4, -2]]
elif icase==2: 
    n=2
    f=[[1, 1, 1, 1, 1, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 1, 1, 1, 1, 1]]
    p=[[0, -2, -2, -2, -2, -2, -1, -1, -1, -1, -1],
       [0, -2, -2, -2, -2, -2, -1, -1, -1, -1, -1]]
elif icase==3: 
    n=3
    f=[[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]]
    p=[[-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]]
    
import itertools
sumpmax=-10**11
for i in itertools.product([0,1], repeat=10):
    r=list(i)
    sump=0
    if sum(r)!=0:
        for jj in range(n):
            ci=0
            for j in range(10):
                ci=ci+r[j]*f[jj][j]
            sump=sump+p[jj][ci]

        sumpmax=max(sump,sumpmax)
print(sumpmax)

Solution (Python):
I=input;R=range;n=int(I())
lf=[int(I()[::2],2) for _ in R(n)]
lp=[list(map(int,I().split())) for _ in R(n)]
print(max(sum(p[bin(i&f).count('1')] for f,p in zip(lf,lp)) for i in R(1,1024)))

Solution (Python):
f=lambda:[list(map(int,input().split())) for _ in range(n)]
n=int(input())
llf,llp=f(),f()
a=-10**9
import itertools as it
for t in it.product([0,1],repeat=10):
  if sum(t):
    lc=[sum(t[i]*lf[i] for i in range(10)) for lf in llf]
    a=max(a,sum(llp[i][lc[i]] for i in range(n)))
print(a)

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

F=[int(input().replace(" ",""),2) for i in range(N)]

P = [list(map(int, input().split())) for _ in range(N)]
ans = - 10**18
for i in range(1, 2**10):
    s = 0
    for f,p in zip(F,P):
        s += p[bin(f&i).count("1")]
    ans = max(ans, s)
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**18
for i in range(1,2**10):
  op=[0]*10
  res=0
  for j in range(10):
    if i>>j&1:
      op[j]=1
  for j in range(n):
    cnt=0
    for k in range(10):
      if op[k]&f[j][k]:
        cnt+=1
    res+=p[j][cnt]
  ans=max(ans,res)
print(ans)

Solution (Python):
def solve():
    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 s in range(1, 1 << 10):
        benefit = 0
        for i in range(N):
            cnt = 0
            for j in range(10):
                if s >> j & 1 and F[i][j] == 1:
                    cnt += 1
            benefit += P[i][cnt]
        ans = max(ans, benefit)
    print(ans)


if __name__ == '__main__':
    solve()

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

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

res = -maxsize
for arr in product(range(2), repeat=10):
    if sum(arr) == 0:
        continue
    a = np.array(arr)
    profit = 0
    for i in range(n):
        profit += p[i][np.sum(a*f[i])]
    if profit > res:
        res = profit

print(res)

Solution (Python):
n = int(input())
f = [list(map(int,input().split())) for _ in range(n)]
p = [list(map(int,input().split())) for _ in range(n)]
ans = - 10 ** 9

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

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

Solution (Python):
import sys
sys.setrecursionlimit(114514)

def g(i):
    global m
    if i == 10:
        if not sum(s) == 0:
            x = 0
            for j in range(n):
                c = 0
                for k in range(10):
                    if s[k] == f[j][k] == 1:
                        c += 1
                x += p[j][c]
            if m < x:
                m = x
        return
    g(i + 1)
    s[i] = 1
    g(i + 1)
    s[i] = 0

n = int(input())
f = [list(map(int, input().split())) for _ in range(n)]
p = [list(map(int, input().split())) for _ in range(n)]
s = [0] * 10
m = -10 ** 9
g(0)
print(m)

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

array = []
for i in range(n):
  f = input().replace(' ', '')
  f = int(f, 2)
  array.append(f)
  
p = []
for i in range(n):
  tmp = list(map(int, input().split()))
  p.append(tmp)
  
ans = -sys.maxsize
for i in range(1,2 ** 10):
  profit = 0
  for j in range(len(array)):
    s = bin(array[j] & i).replace('0b', '').replace('0', '')
    profit += p[j][len(s)]
    
  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(1,1024):
    tmp = 0
    for j in range(N):
        cnt = 0
        for k in range(10):
            if (i>>k & 1) & F[j][k]:
                cnt += 1
        tmp += P[j][cnt]
    ans = max(ans,tmp)
print(ans)

Solution (Python):
class Solution:
    def solve(self, N: int, F, P) -> int:

        answer = - 10**10

        def list2int(li) -> int:

            base = 1
            ret = 0
            for b in li:
                ret += base * b
                base *= 2
            return ret

        def int2list(i: int):
            ret = []
            for _ in range(10):
                ret.append(i % 2)
                i //= 2

            return ret

        F_int = [list2int(f) for f in F]

        for j in range(1, 1024):
            s = 0
            for n, f in enumerate(F_int):
                cn = sum(int2list(j & f))
                s += P[n][cn]

            answer = max(answer, s)

        return answer


if __name__ == '__main__':

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

    
    solution = Solution()
    print(solution.solve(N, F, P))

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

ans = -10 ** 10

for i in range(1, 2**10):
    tmp = 0
    for j in range(n):
        cnt = 0
        for z in range(10):
            if ((i>>z)%2 == 1 and f[j][z] == 1):
                cnt += 1
        tmp += p[j][cnt]
    ans = max(ans,tmp)
print(ans)

Solution (Python):
N=int(input())
Flist=[]
for a in range(N):
    list=[]
    F=input().split()
    for b in F:
        list.append(int(b))
    Flist.append(list)
Plist=[]
for a in range(N):
    list=[]
    F=input().split()
    for b in F:
        list.append(int(b))
    Plist.append(list)
FFlist=[]
for a in range(N):
    list=[]
    item = Flist[a]
    n = len(item)
    for i in range(2 ** n):
        bag = []
        for j in range(n):
            if ((i >> j) & 1):
                bag.append(item[j])
        z=sum(bag)
        list.append(z)
    del list[0]
    FFlist.append(list)
goukei=[]
for a in range(2**10-1):
    c=0
    for b in range(N):
        c+=Plist[b][FFlist[b][a]]
    goukei.append(c)
print(max(goukei))

Solution (Python):

import sys,os
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    N = II()
    F = XLMIIS(N)
    P = XLMIIS(N)
    T = 10
    ans = - 10**7*N
    for bit in range(1,2**T):
        c = [0] * N
        for i in range(T):
            if bit & (1<<i):
                for j in range(N):
                    c[j] += F[j][i]
        benefit = 0
        for i in range(N):
            benefit += P[i][c[i]]
        ans = max(ans,benefit)
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):

import sys,os
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    N = II()
    F = XLMIIS(N)
    P = XLMIIS(N)
    def b(i,c,num_both):
        if i == 10:
            if num_both == 0:
                return -(10**7)*N
            benefit = 0
            for j, p in enumerate(P):
                benefit += p[c[j]]
            return benefit
        c_both = c[:]
        num_both_2 = num_both
        for j in range(N):
            c_both[j] += F[j][i]
            num_both_2 += F[j][i]

        return max(b(i+1,c,num_both),b(i+1,c_both,num_both_2))
    print(b(0,[0]*N,0))


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 = -float('inf')
for x in list(itertools.product([0, 1], repeat=10)):
    if x.count(0) == 10:
        continue
    total = 0
    for i in range(N):
        count = 0
        for j in range(10):
            count += x[j] & F[i][j]
        total += P[i][count]
    ans = max(ans, total)
print(ans)

Solution (Python):


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



ans = -(10 ** 7) * 100 - 10
for i in range(1, 2**10):
    eigyou_here = [-1] * 10
    temp = 0
    for digit in range(10):
        eigyou_here[10 - 1 - digit] = int(i & (2 ** digit) > 0)
    for j_shop in range(n):
        import numpy as np
        coincide_time = np.dot(eigyou[j_shop], eigyou_here)
        
        
        temp += profits[j_shop][coincide_time]

    ans = max(ans, temp)

print(ans)

Solution (Python):


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



ans = -(10 ** 7) * 100 - 10
for i in range(1, 2**10):
    eigyou_here = [-1] * 10
    temp = 0
    for digit in range(10):
        eigyou_here[10 - 1 - digit] = int(i & (2 ** digit) > 0)
    for j_shop in range(n):
        coincide_time = 0
        for time in range(10):
            coincide_time += eigyou[j_shop][time] * eigyou_here[time]
        temp += profits[j_shop][coincide_time]

    ans = max(ans, temp)

print(ans)

Solution (Python):

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

for i in range(N):
    row=list(map(int,input().split()))
    P.append(row)

ans=-10**10

for i in range(1,2**10):
    IB=list(format(i,'010b'))
    uriage=0
    for j in range(N):
        cnt=0
        for k in range(10):
            if F[j][k]==int(IB[k])==1:
                cnt+=1
        uriage+=P[j][cnt]
    ans=max(ans,uriage)

print(ans)

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

ans = - 10**10

def cost(i) :
    tem = 0
    for j in range(N) :
        d = bin(i & F2[j]).count("1")
        tem += P[j][d]
    return tem

for i in range(1, 2**10) :
    ans = max(ans, cost(i))

print(ans)

Solution (Python):


N = int(input().strip())
F_list = [list(map(int, input().rstrip().split())) for i in range(N)]
P_list = [list(map(int, input().rstrip().split())) for i in range(N)]


total_profit_list=[]
for x in range(1,2**10):
    bin_str = format(x, 'b').zfill(10)

    profit=0
    for i in range(N):
        c=0
        for j in range(10):
            if int(bin_str[j]) == F_list[i][j] == 1:
                c += 1
        profit += P_list[i][c]
    
    total_profit_list.append(profit)

print(max(total_profit_list))

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




ans = -10**9
for bit in range(1, 1<<10):
    money = 0
    for i in range(N):
        cnt = format(bit&F[i], 'b').count('1')
        money += P[i][cnt]
    ans = max(money, ans)
 
print(ans)

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

ans = -10**9
for i in range(1, 2**10):
    open = []
    for j in range(10):
        if ((i>>j) & 1):
            open.append(1)
        else:
            open.append(0)
    money = 0
    for num in range(N):
        Flist = Flists[num]
        same = sum([int(open[_] and Flist[_]) for _ in range(10)])
        money += Plists[num][same]
    ans = max(ans, money)

print(ans)

Solution (Python):
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


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


def S(): return input()


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


def print_matrix(mat):
    for i in range(len(mat)):
        print(*mat[i])


YNL = {False: 'No', True: 'Yes'}
YNU = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()

nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']



show_flg = False


def main():
    N = I()
    F = []
    P = []

    for i in range(N):
        F.append(LI())

    for i in range(N):
        P.append(LI())

    M = 10
    ans = - (10 ** 19)

    for i in range(2 ** M):
        f = []
        for j in range(M):
            if ((i >> j) & 1):
                f.append(1)
            else:
                f.append(0)

        if not any(f):
            continue

        profit = 0
        for j in range(N):
            c = 0
            for k in range(10):
                if f[k] == 1 and F[j][k] == 1:
                    c += 1
            
            profit += P[j][c]
        ans = max(ans, profit)
        

    print(ans)

if __name__ == '__main__':
    main()

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

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

ans=-10**10
for joisino in c:
    SUM=0
    count=[0]*N
    for i in range(10):
        if joisino[i]==1:
            for g in range(N):
                if F[g][i]==1:
                    count[g]+=1
    for m in range(N):
        SUM+=P[m][count[m]]
    ans=max(ans,SUM)
print(ans)

Solution (Python):



def main():
  n = int(input())
  fs = []
  ps = []
  for _ in range(n):
    f = sum([v * (2**i) for i, v in enumerate(map(int, input().split()))])
    fs.append(f)
    
  for _ in range(n):
    p = list(map(int, input().split()))
    ps.append(p)
    
  max = -10**10    
  for x in range(1, 2**10):
    score = 0
    for i, f in enumerate(fs):
      c = bin(x & f).count('1')
      score += ps[i][c]
    if score > max:
      max = score
  print(max)

if __name__=='__main__':
  main()

Solution (Python):
N = int(input())
Flists = [list(map(int, input().split())) for _ in range(N)]
Plists = [list(map(int, input().split())) for _ in range(N)]
ans = -10**9
for i in range(1, 2**10):
    open = []
    for j in range(10):
        if ((i >> j) & 1):
            open.append(1)
        else:
            open.append(0)
    money = 0
    for num in range(N):
        Flist = Flists[num]
        same = sum([int(open[_] and Flist[_]) for _ in range(10)])
        money += Plists[num][same]
    ans = max(ans, money)
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)]

outcome_list = []
for i in range(1, 1 << 10):
    outcome = 0
    for f, p in zip(F, P):
        n_store = "{:010b}".format(i & f).count("1")
        outcome += p[n_store]
    outcome_list.append(outcome)
print(max(outcome_list))

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

outcome_list = []
for i in range(1, 1 << 10):
    outcome = 0
    for j, x in enumerate(f):
        both = "{:010b}".format(i & int(x, 2))
        n_store = sum(map(int, list(both)))
        outcome += p[j][n_store]
    outcome_list.append(outcome)
print(max(outcome_list))

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, 1024):  
    fund = 0
    for i in range(n):  
        cou = 0  
        for x in range(10):  
            if (item >> x) % 2 == 1 and arr[i][x] == 1:  
                cou += 1
        fund += arm[i][cou]
    ans = max(ans, fund)  

print(ans)

Solution (Python):
N = int(input())
F = [list(map(int, input().split())) for i in range(N)]
P = [list(map(int, input().split())) for j in range(N)]  
m = -9999999999  
for i in range(1, 2**10):
    s = 0
    for j in range(N):
        count = 0
        for k in range(10):
            if ((i >> k)&1) == 1 and F[j][k] == 1:
                count += 1
        s += P[j][count]
    m = max(m, s)  
print(m)

Solution (Python):
n = int(input())
f = [[0]*10 for _ in range(n)]
p = [[0]*11 for _ in range(n)]
wa = [0]*10
ans = -1000000000000000000000000

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

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

for i in range(2**10):
    if i == 0:
        continue
    pk = 0
    ls = [0,0,0,0,0,0,0,0,0,0]
    for j in range(10):
        if (i >> j) & 1:
            ls[j] = 1
        
    for k in range(n):
        o = 0
        for l in range(10):
            if f[k][l] == 1 and ls[l] == 1:
                o += 1
                
        pk += p[k][o]
        
    ans = max(ans,pk)
    
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):
    tmp=list(map(int,list(format(i, '010b'))))
    p_tmp=[0 for _ in range(n)]
    for i in range(n):
        cnt=0
        for j in range(10):
            if tmp[j]==1 and f[i][j]==tmp[j]:
                cnt+=1
        p_tmp[i]=cnt
    P=0
    for k in range(n):
        P+=p[k][p_tmp[k]]
    ans=max(ans,P)
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 = -10000000000
for i in range(1, 2**10):
    tmp = 0
    for j in range(N):
        cnt = 0
        for k in range(10):
            if((i>>k)%2 == 1 and F[j][k] == 1):
                cnt += 1
        tmp += P[j][cnt]
    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 = -10000000000
for mask in range(1, 2**10):
    tmp = 0
    for j in range(N):
        cnt = 0
        for k in range(10):
            if((mask>>k)%2 == 1 and F[j][k] == 1):
                cnt += 1
        tmp += P[j][cnt]
    ans = max(ans, tmp)

print(ans)