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

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
F = [LIST() for _ in range(N)]
P = [LIST() for _ in range(N)]

ans = -INF
for i in range(1, 1<<10):
	i = "{:b}".format(i).zfill(10)
	tmp = 0
	for j in range(N):
		cnt = 0
		for k in range(10):
			if int(i[k]) and F[j][k]:
				cnt += 1
		tmp += P[j][cnt]
	ans = max(ans, tmp)
print(ans)

Solution (Python):
n=int(input())
f=[0]*n
for i in range(n):
  x=list(map(int,input().split()))
  for j in range(len(x)):
    if x[j]==1:
      f[i]+=1<<j
  
p=[[0 for j in range(10)] for i in range(n)]

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

ans=10**9*(-1)-1
for i in range(1,2**10):
  pro=0
  for j in range(len(f)):
    open=0
    for k in range(10):
      if (i>>k)&1==1 and (f[j]>>k)&1==1:
        open+=1
    pro+=p[j][open]
  if ans<pro:
    ans=pro
print(ans)

Solution (Python):

import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1


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


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, F, P):

    F = [reduce(lambda x, y: x * 2 + y, f) for f in F]

    ans = -1e+100
    for i in range(1, 2**10):
        tmp = 0
        for p, f in zip(P, F):
            v = f & i
            c = bin(v).count('1')
            tmp += p[c]
        ans = max(ans, tmp)
        if tmp == 0:
            for p, f in zip(P, F):
                v = f & i
                c = bin(v).count('1')
    return ans


def main():
    N = read_int()
    F = [read_int_n() for _ in range(N)]
    P = [read_int_n() for _ in range(N)]
    print(slv(N, F, P))


if __name__ == '__main__':
    main()

Solution (Python):
N=int(input())
F=[list(map(int,input().split())) for i in range(2*N)]
F,P=F[:N],F[N:]
from itertools import product
r=-10**9
for i in range(1,1024):
  x=[(i>>(9-j))%2 for j in range(10)]
  r=max(r,sum([P[j][sum([F[j][i]*x[i] for i in range(10)])] for j in range(N)]))
print(r)

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

for v in itertools.product([0,1], repeat=10):
  if sum(v)==0: 
    continue 
  a=0
  for i in range(n):
    temp=0
    for j in range(10):
      if f[i][j]==v[j]==1:
        temp+=1
    a+=p[i][temp]
  ans=max(ans,a)
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)]
pls=[]
for i in range(1,2**10):
  bin=format(i,"b").zfill(10)
  pf=0
  for x in range(n):
    cnt=0
    for j in range(10):
      if int(bin[j])==f[x][j]==1:
        cnt+=1
    pf+=p[x][cnt]
  pls.append(pf)
print(max(pls))

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

bit=list(itertools.product([0,1], repeat=10))
bit.pop(0)
ans=-10**10

for i in range(1023):
    a=0
    for j in range(N):
        t=sum([F[j][k]*bit[i][k] for k in range(10)])
        a+=P[j][t]
    ans=max(a,ans)

print(ans)

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

anss = []
for i in range(1, 2**10):
  l = [0]*n
  for j in range(10):
    if  (i >> j) & 1:
      for k in range(n):
        l[k] += fs[k][j]
  ans = 0
  for m in range(n):
    ans += ps[m][l[m]]
  anss.append(ans)
  
anss.sort(reverse=True)
print(anss[0])

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

anss = []
for i in range(1, 2**10):
  l = [0]*n
  for j in range(10):
    if  (i >> j) & 1:
      for k in range(n):
        l[k] += fs[k][j]
  ans = 0
  for m in range(n):
    ans += ps[m][l[m]]
  anss.append(ans)
  
anss.sort(reverse=True)
print(anss[0])

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

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

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

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



allcase = np.array(list(product([0, 1], repeat=10)), dtype=bool)



ans = -(10 ** 9)

for a in allcase:
    if sum(a) == 0:
        
        continue
    profit = 0
    for shop in range(n):
        
        idx = np.count_nonzero(np.logical_and(f[shop], a))

        profit += p[shop][idx]
    ans = max(ans, profit)

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 ** 10
for f in list(itertools.product([0, 1], repeat=10))[1:]:
    p = sum([P[i][sum([F[i][j] * f[j] for j in range(10)])] for i in range(N)])
    ans = max(ans, p)

print(ans)

Solution (Python):
n = int(input())
shop = [list(map(int, input().split())) for _ in range(n)]
p = [list(map(int, input().split())) for _ in range(n)]
candidate = []
for i in range(1, 2 ** 10):
    is_open = [False] * 10
    cnt = [0] * n
    for j in range(10):
        if (i >> j) & 1:
            is_open[j] = True
    for k in range(n):
        for l in range(10):
            if is_open[l] and shop[k][l] == 1:
                cnt[k] += 1
    now_profit = 0
    for k in range(n):
        now_profit += p[k][cnt[k]]
    candidate.append(now_profit)
candidate.sort(reverse=True)
print(candidate[0])

Solution (Python):


N=int(input())

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

ans=-10**18
for i in range(1,2**10):
    l=list(map(int,bin(i)[2:]))
    l=[0]*(10-len(l))+l
    shop=[0]*N
    for time,flag in enumerate(l):
        for i in range(N):
            if F[i][time]==1 and flag:
                shop[i]+=1
    temp=0
    for i in range(N):
        temp+=P[i][shop[i]]
    ans=max(ans,temp)
        
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**10
for k in range(1,1<<10):
    op=[k>>j&1 for j in range(10)]
    res=0
    for i in range(N):
        c=sum([F[i][j]&op[j] for j in range(10)])
        res+=P[i][c]
    ans=max(ans,res)

print(ans)

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

ans = (10**10) * (-1)


for i in range(1<<10):
    if i == 0:
        continue
    
    Cov = [0] * n
    can = 0
    for j in range(10):
        
        
        
        if (i>>j)&1 == 1:
            for k in range(n):
                if F[k][j] == 1:
                    Cov[k] = Cov[k] + 1
        
    for l in range(n):
        can += P[l][Cov[l]]
    
    if can >= ans:
        ans = can

print(ans)

Solution (Python):

if __name__ == '__main__':
    N=int(input())
    F=[]
    P=[]
    m=-10**10
    for i in range(N):
        temp=input().split()
        F.append(temp)
    for i in range(N):
        temp = list(map(int, input().split()))
        P.append(temp)

    for i in range(1,2**10):
        binary=i
        profit=0
        for j in range(N):
            f_binary=int(''.join(F[j]),2)
            number=binary&f_binary
            count=0
            while number>0:
                number&=number-1
                count+=1
            profit+=P[j][count]
        m=max(m,profit)
    print(m)

Solution (Python):
n = int(input())
flst = []
for _ in range(n):
  flst.append(int(''.join(input().split()), 2))
plst = []
for _ in range(n):
  plst.append([int(i) for i in input().split()])
m = - 1 << 30
for i in range(1, 1 << 10):
  r = 0
  for j in range(n):
    s = i & flst[j]
    c = 0
    while s:
        s &= s - 1
        c += 1
    r += plst[j][c]
  m = max(m, r)
print(m)

Solution (Python):
n = int(input())
flst = []
for _ in range(n):
  flst.append([int(i) for i in input().split()])
plst = []
for _ in range(n):
  plst.append([int(i) for i in input().split()])
m = - 1 << 30
for i in range(1, 1 << 10):
  r = 0
  for j in range(n):
    c = 0
    for k in range(10):
      if (i >> k & 1) & flst[j][k]:
        c += 1
    r += plst[j][c]
  m = max(m, r)
print(m)

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

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

ans = -(10**10)
for i in range(2**10):
    one_or_zero = [0] * 10
    for j in range(10):
        if ((i >> j) & 1):
            one_or_zero[10 - 1 - j] = 1
    if 1 not in one_or_zero:
        pass
    else:
        tmp_ans = 0
        for m in range(N):
            count = 0
            for k in range(10):
                if F[m][k] == 1 and one_or_zero[k] == 1:
                    count += 1
            tmp_ans += P[m][count]
        if tmp_ans > ans:
            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)]

profit = (-1) * 10**10
for bit in range(1, 2**10):
    duplicate_list = [0] * n
    for i in range(10):
        if bit & (1 << i):
            for num, f_ in enumerate(f):
                duplicate_list[num] += f_[i]
    tmp_profit = sum([p[num][cnt] for num, cnt in enumerate(duplicate_list)])
    profit = max(profit, tmp_profit)

print(profit)

Solution (Python):
N=int(input())
F=[[int(s) for s in input().split()] for i in range(N)]
P=[[int(s) for s in input().split()] for i in range(N)]
def bi(num):
  val_ls=[0 for _ in range(10)]
  for bi_i in range(10):
    if (2**bi_i)&num>0:
      val_ls[bi_i]=1
  return val_ls
def ri(bi_ls):
  val_ri=0
  for ri_i in range(N):
    val=0
    for j in range(10):
      if bi_ls[j]==F[ri_i][j] and bi_ls[j]==1:
        val+=1
    val_ri+=P[ri_i][val]
  return val_ri
print(max([ri(bi(i)) for i in range(1,1024)]))

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

ans = -float('inf')
for i in range(1,2**10):
  sum = 0
  for idx, j in enumerate(F):
    bin_num = int("".join(j), 2)
    num = bin(i & bin_num)[2:].count('1')
    sum += P[idx][num]
  if (sum > ans):
    ans = sum
print(ans)

Solution (Python):


N = int(input())
F = []
for n in range(N):
    f = [i for i in input().split()]
    
    str_f = ''.join(f)
    int_f = int(str_f, 2)
    F.append(int_f)

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


max_benefit = -100000000000000
for i in range(1, 1024):
    benefit = 0
    for n in range(N):
        
        and_number = F[n] & i
        count = bin(and_number).count('1')
        benefit += P[n][count]
    if benefit > max_benefit:
        max_benefit = benefit

print(max_benefit)

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

ans = -float("inf")
for i in range(1 , 1024):
    sum_val = 0
    mapping = []
    for k in range(N):
        cnt = 0
        for j in range(10):
            if i >> j & 1 and open[k][j] == 1:
                cnt += 1
        mapping.append(cnt)
    for k in range(N):
        sum_val += sales[k][mapping[k]]
    if sum_val > ans:
        ans = sum_val
print(ans)

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

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

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

ans = (10**7) * N * (-1)
for i in range(1,2**10):
  bin_i_list = [int(x) for x in '{:0=10b}'.format(i)]
  count_list = []
  for n in range(N):
    count = 0
    for l in range(10):
      if F[n][l] == 1 and bin_i_list[l] == 1:
        count += 1
    count_list.append(count)

  tmp_ans = 0
  for n in range(N):
    tmp_ans += P[n][count_list[n]]

  ans = max(tmp_ans,ans)

print(ans)

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

answer = -float('inf')
for x in itertools.product([int(0),int(1)],repeat=10):
  if x != (0, 0, 0, 0, 0, 0, 0, 0, 0, 0):
    value=0
    for i in range(N):
      count=0
      for j in range(10):
        if x[j]==1 and F[i][j]=='1':
          count +=1
      value += int(P[i][count])
    answer=max(answer,value)
print(answer)

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)]
l=[0]*1024
for i in range(1024):
    I=format(i,'b').zfill(10)
    for k in range(n):
        c=0
        for j in range(10):
            if I[j]=='1' and f[k][j]==1:
                c+=1
        l[i]+=p[k][c]    
print(max(l[1:]))

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

l=[0]*1024

for i in range(1024):
    I=format(i,'b').zfill(10)
    for k in range(n):
        c=0
        for j in range(10):
            if I[j]=='1' and f[k][j]==1:
                c+=1
        l[i]+=p[k][c]  

print(max(l[1:]))

Solution (Python):
import random as rng
import itertools as it
import collections as col
import heapq as hq
import sys
import copy as cp
sys.setrecursionlimit(10**9)


def dump_impl(*objects):
    print(*objects, file=sys.stderr)


def dump_dummy(*objects):
    pass


dump = dump_impl if "DEBUG" in sys.argv else dump_dummy

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 = None
for x in it.product([0, 1], repeat=10):
    if not any(x):
        continue
    sumP = 0
    for i in range(N):
        c = sum(map(lambda fijkxjk: (1 if all(fijkxjk) else 0), zip(F[i], x)))
        dump(i, c, list(x), P[i][c])
        sumP += P[i][c]
    ans = max([ans, sumP]) if ans else sumP
dump(N, F, P)
print(ans)

Solution (Python):
import random as rng
import itertools as it
import collections as col
import heapq as hq
import sys
import copy as cp
sys.setrecursionlimit(10**9)


def dump_impl(*objects):
    print(*objects, file=sys.stderr)


def dump_dummy(*objects):
    pass


dump = dump_impl if "DEBUG" in sys.argv else dump_dummy

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 = None
for x in it.product([0, 1], repeat=10):
    if not any(x):
        continue
    sumP = 0
    for i in range(N):
        c = sum(map(lambda fijkxjk: (1 if all(fijkxjk) else 0), zip(F[i], x)))
        dump(i, c, list(x), P[i][c])
        sumP += P[i][c]
    ans = max([ans, sumP]) if ans else sumP
dump(N, F, P)
print(ans)

Solution (Python):

si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
n=ni()
f=[nl() for _ in range(n)]
p=[nl() for _ in range(n)]
o = []
ans = -10**10
for i in range(2**10):
    op = [0]*10
    for j in range(10):
        if ((i>>j)&1):
            op[10-1-j]=1
    if not any(op):
        continue
    else:
        o.append(op)

for oo in o:
    value = 0
    for i,ff in enumerate(f):
        t=0
        for j in range(10):
            if oo[j]==1 and ff[j]==1:
                t+=1
        value += p[i][t]
    ans = max(ans,value)

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) ]
ans = -float("inf")
for i in range(1, 2**10):
  t = 0
  for j in range(n):
    c = bin(F[j] & i).count("1")
    t += P[j][c]
  ans = max(ans, t)
print(ans)

Solution (Python):
def main():
    N = int(input())
    F = [[int(i) for i in input().split()] for j in range(N)]
    P = [[int(i) for i in input().split()] for j in range(N)]
    ans = [0] * (1 << 10)
    for i in range(N):
        for bit in range(1 << 10):
            c = 0
            for j in range(10):
                if bit & (1 << j):
                    if F[i][j] == 1:
                        c += 1
            ans[bit] += P[i][c]
    ans[0] = -(1 << 60)
    print(max(ans))


if __name__ == '__main__':
    main()

Solution (Python):











import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log 
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    F=LLIN(N)
    P=LLIN(N)
    ans = -inf
    max_bit = 1<<10
    for bit in range(1,max_bit):
        res = 0
        for i,f in enumerate(F):
            cnt = 0
            for j in range(10):
                if (1<<j)&bit and f[j]:
                    cnt += 1
            res += P[i][cnt]
        ans = max(res,ans)
    print(ans)
if __name__ == '__main__':
    main()

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

ans = 0
for j in range(n):
    ans += p[j][f[j][0] & 1]
for i in range(2, 1024):
  bene = 0
  for j in range(n):
    count = 0
    for k in range(10):
      count += f[j][k] & (i >> k)
    bene += p[j][count]
  ans = max(ans, bene)
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)]
a=2**10
s = [bin(i)[2:] for i in range(a)]
for i in range(a):
    s[i]='0'*(10-len(s[i]))+s[i]
    s[i]=s[i][::-1]
cnt=[0]*n
ans=[0]*a
ans[0]=-10**9
for i in range(1,a):
    for j in range(n):
        for k in range(10):
            if int(s[i][k])==1 and 1==f[j][k]:
                cnt[j]+=1
        ans[i]+=p[j][cnt[j]]
    
    cnt=[0]*n
print(max(ans))

Solution (Python):
n = int(input())
other = [[s for s in input().split(" ")] for _ in range(n)]
profit = [[int(s) for s in input().split(" ")] for _ in range(n)]
for i in range(1, 1024):
  b = bin(i)[2:].zfill(10)
  l = [b[j] for j in range(10)]
  ans = 0
  for j in range(n):
    cnt = 0
    for me, othe in zip(l, other[j]):
      if me == "1" and othe == "1":
        cnt += 1
    ans += profit[j][cnt]
  if i == 1:
    final_ans = ans
  else:
    if ans > final_ans:
      final_ans = ans
      
print(final_ans)

Solution (Python):
N = int(input())
F = []
for _ in range(N):
    F.append(sum([int(f)<<i for i, f in enumerate(input().split())]))

P = [list(map(int, input().split())) for _ in range(N)]
B = []
for d in range(1,1024):
    b = 0
    for f, p in zip(F,P):
        c = 0
        ovlp = d&f
        while ovlp:
            if ovlp&1: c+=1
            ovlp>>=1
        b+=p[c]
    B.append(b)

print(max(B))

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 = []
stk = []

stk.append([0] * N)

for i in range(10):
    len_stk = len(stk)
    for j in range(len_stk):
        total = 0
        arr = []
        for k in range(N):
            open_cnt = stk[j][k] + f[k][i]
            arr.append(open_cnt)
            total += p[k][open_cnt]
        ans.append(total)
        stk.append(arr)

print(max(ans))

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

ans = -float('inf')

for i in range(1, 1024):
    B = bin(i)[2:][::-1]
    count = [0]*N
    s = 0
    for i, b in enumerate(B):
        if b == '1':
            for j, f in enumerate(F):
                if f[i] == 1:
                    count[j] += 1
    for p, c in zip(P, count):
        s += p[c]
    ans = max(ans, s)
print(ans)

Solution (Python):

from collections import deque
import bisect
import math
import heapq
import itertools



inf = float("inf")
mod = 10**9 + 7




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

ans = -inf
for i in range(1024):
    if i == 0:
        continue
    b = bin(i)
    b = b.lstrip("0b")
    while len(b) < 10:
        b = "0"+b
    
    kari = 0
    for j in range(N):
        f = F[j]
        p = P[j]
        C = 0
        for k in range(10):
            if b[k] == "1" and f[k] == 1:
                C+=1
        kari += p[C]
    ans = max(ans,kari)
    
print(ans)

Solution (Python):
from collections import Counter,defaultdict,deque
import sys
import bisect
import math
import itertools
import string
import queue
import copy


from itertools import permutations, combinations
from heapq import heappop, heappush
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
 
def inp(): 
    return int(input())
def inpm(): 
    return map(int,input().split())
def inpl(): 
    return list(map(int, input().split()))
def inpls(): 
    return list(input().split())
def inplm(n): 
    return list(int(input()) for _ in range(n))
def inpll(n): 
    return [list(map(int, input().split())) for _ in range(n)]

def main():
    n=inp()
    f=[]
    for _ in range(n):
        f.append(inpl())
    p=[]
    for _ in range(n):
        p.append(inpl())
    ans=-10**10
    for i in range(1,11):
        for j in combinations(range(10),i):
            do = [0 for _ in range(10)]
            for k in j:
                do[k]=1
            benefit = 0
            for l in range(n):
                s=0
                for u in range(10):
                    s+=f[l][u]*do[u]
                benefit += p[l][s]
            ans=max(ans,benefit)
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    inf=float("inf")
    n = int(input())
    period_shop_to_open = [[0] * n for _ in range(10)]
    for shop in range(n):
        aa = list(map(int, input().split()))
        for period, opened in enumerate(aa):
            period_shop_to_open[period][shop] = opened
    shop_times_to_profit = [list(map(int, input().split())) for _ in range(n)]

    ans = -inf
    for j_open in range(1,1 << 10):
        shop_to_open_times = [0] * n
        for shop in range(n):
            for period in range(10):
                if (j_open >> period) & 1 and period_shop_to_open[period][shop]:
                    shop_to_open_times[shop] += 1
        profit = 0
        for shop in range(n):
            profit += shop_times_to_profit[shop][shop_to_open_times[shop]]
        ans = max(ans, profit)
    print(ans)

main()

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

ans = float('-inf')
for bit in range(1,1024):
    sum_p = 0
    for shop in range(N):
        time = bin(F[shop] & bit).count('1')
        sum_p += P[shop][time]

    ans = max(sum_p, ans)
print(ans)

Solution (Python):
n = int(input())
other = [[s for s in input().split(" ")] for _ in range(n)]
profit = [[int(s) for s in input().split(" ")] for _ in range(n)]
for i in range(1, 1024):
  b = bin(i)[2:].zfill(10)
  l = [b[j] for j in range(10)]
  ans = 0
  for j in range(n):
    cnt = 0
    for me, othe in zip(l, other[j]):
      if me == "1" and othe == "1":
        cnt += 1
    ans += profit[j][cnt]
  if i == 1:
    final_ans = ans
  else:
    if ans > final_ans:
      final_ans = ans
      
print(final_ans)

Solution (Python):
from sys import stdin

n = int(stdin.readline().rstrip())
f = [list(map(int,stdin.readline().rstrip().split())) for _ in range(n)]
p = [list(map(int,stdin.readline().rstrip().split())) for _ in range(n+1)]

def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)

ma = -1*(10**10)
for i in range(1,1024):
    s = Base_10_to_n(i,2).zfill(10)
    total = 0
    for j in range(n):
        point = 0
        for k in range(10):
            if int(s[k]) == 1 and f[j][k] == 1:
                point += 1
        total += p[j][point]
    ma = max(ma,total)   
print(ma)

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

ans=-10**18
for i in range(1,2**10):
  cnt=0
  for j in range(N):
    cnt+=P[j][bin(F[j] & i).count('1')]
  ans=max(ans,cnt)
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**18
for i in range(1,2**10):
  tmp=0
  for j in range(N):
    cnt=0
    for k in range(10):
      if i&(1<<k) and F[j][k]:
        cnt+=1
    tmp+=P[j][cnt]
  ans=max(ans,tmp)
print(ans)

Solution (Python):
from itertools import product
N=int(input())
F = [list(map(int, input().split())) for i in range(N)]
P = [list(map(int, input().split())) for i in range(N)]
store_str=list(product('01', repeat=10))
store=[[int(i) for i in j] for j in store_str]
store.pop(0)
all_sum=[]
for s in store:
    value_list=[]
    for i,j in zip(F,P): 
        l=len([1 for a,b in zip(s,i) if a==1 and b==1])
        value_list.append(j[l])
    value_sum=sum(value_list)
    all_sum.append(value_sum)
print(max(all_sum))

Solution (Python):
import sys
import itertools












def toBit(n): 
    return eval('0b' + n)

def main():

    n = int(sys.stdin.readline().rstrip())

    schedule = [toBit(''.join(str(x) for x in sys.stdin.readline().split())) for _ in range(n)]
    profit_table = [[int(x) for x in sys.stdin.readline().split()] for _ in range(n)]

    maximum_profit = -10**10
    for open_pattern in itertools.product('01', repeat=10):
        open_pattern = toBit(''.join(open_pattern))
        if open_pattern == 0:
            continue
        profit = 0
        for i in range(n):
            checked = schedule[i]
            number_of_periods = bin(checked & open_pattern).count('1')
            profit += profit_table[i][number_of_periods]
        maximum_profit = max(maximum_profit, profit)

    print(maximum_profit)

if __name__ == "__main__":
    
    main()