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):
def solve():
  n = int(input())
  f = []
  ans = -1000000000
  for i in range(n):
    tmp = list(int(i) for i in input().split())
    f.append(tmp)
  p = []
  for i in range(n):
    tmp = list(int(i) for i in input().split())
    p.append(tmp)
  for bit in range(1,2**10):
    benefit = 0
    ope = 0
    query = [0]*n
    for j in range(10):
      if (bit>>j)&1 == 1:
        for i in range(n):
          if f[i][j]:
            query[i] += 1

    for i in range(n):
      benefit += p[i][query[i]]
    ans = max(ans,benefit)
  print(ans)
        
        
      
solve()

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_v = -(10 ** 10)
for i in range(1,2**10):

    S_cnt = [0] * N 
    for j in range(10):
        if i % 2 == 1:
            for k in range(N):
                if F[k][j] == 1:
                    S_cnt[k] += 1
        i //= 2

    tmp_v = 0
    for j in range(N):
        tmp_v += P[j][S_cnt[j]]
    max_v = max(max_v, tmp_v)

print(max_v)

Solution (Python):
import sys
from functools import reduce
import copy
import math
from pprint import pprint
import collections


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(inputs):
    N = len(inputs) // 2
    stores_hour = list(map(string_to_int, inputs[:N]))
    benefit_table = list(map(string_to_int, inputs[N:]))

    pattern_num = 2 ** 10

    max_benefit = None
    for i in range(1, pattern_num):
        bits = bin(i)[2:]
        less_digit = 10 - len(bits)
        zero_padding = ['0' for i in range(less_digit)]
        pattern = zero_padding + list(bits)

        benefit = 0
        for i, store in enumerate(stores_hour):
            match_count = 0
            for j, t in enumerate(store):
                if int(pattern[j]) == 1 and t == 1:
                    match_count += 1
            benefit += benefit_table[i][match_count]
        if max_benefit is None or max_benefit < benefit:
            max_benefit = benefit
    return max_benefit


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    N = int(input())
    ret = solve(inputs(N * 2))
    print(ret)

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 = []
for i in range(1,2**10):
    a = [0]*n
    for j in range(10):
        if i >> j & 1:
            for k in range(n):
                a[k] += f[k][j]
    ans.append(sum([p[i][a[i]] for i in range(n)]))
print(max(ans))

Solution (Python):
N = 0
FList = []
PList = []

def open_shop_num( n ):
    open_shop = [0] * N
    for i in range(10):
        if n % 2 == 1:
            for shop in range(N):
                if FList[shop][i] == 1:
                    open_shop[shop] += 1
        n = n//2
    return open_shop

def calc_profit( open_shop ):
    sum1 = 0
    for i in range(N):
        sum1 += PList[i][open_shop[i]]
    return sum1

N = int(input())
for _ in range(N):
    FList.append(list(map(int,input().split())))
for _ in range(N):
    PList.append(list(map(int,input().split())))

ans = -(10**10)
for pat in range(1,2**10):
    open_shop = open_shop_num( pat )
    ans = max(ans, calc_profit(open_shop))
print(ans)

Solution (Python):
from itertools import product

n = int(input())
f_all = []
for i in range(n):
    fi = list(map(int, input().split()))
    f_all.append(fi)
p_all = []
for i in range(n):
    pi = list(map(int, input().split()))
    p_all.append(pi)

res = -99999999999
for pro in product([0, 1], repeat=10):
    if sum(pro) == 0:
        continue
    total = 0
    for i in range(n):
        count = 0
        for j in range(10):
            if pro[j] == 1 and f_all[i][j] == 1:
                count += 1
        total += p_all[i][count]
    res = max(res, total)
print(res)

Solution (Python):
n = int(input())
a = [list(map(int,input().split())) for _ in range(n)]
b = [list(map(int,input().split())) for _ in range(n)]
ans = []
for i in range(1,2**10):
    dp = [0]*n
    for j in range(10):
        if i >> j & 1:
            for k in range(n):
                dp[k] += a[k][j]
    ans.append(sum([b[x][y] for x,y in enumerate(dp)]))
print(max(ans))

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

max_Profit = -10**12
for i in range(1,2**10):
  C = [0]*n
  for j in range(10):
    for k in range(n):
        if F[k][j] == ((i >> j) & 1) == 1:
          C[k] += 1
  profit = 0
  for l in range(n):
    profit += P[l][C[l]]
  max_Profit = max(max_Profit,profit)
  
print(max_Profit)

Solution (Python):
max_time = 10
n = int(input())
f = [sum(v << max_time - k - 1 for k, v in
         enumerate(map(int, input().split())))
     for i in range(n)]
p = [[int(j) for j in input().split()] for i in range(n)]
pattern = [sum(i >> j & 1 for j in range(max_time))
           for i in range(2 ** max_time)]
print(max(sum(
    p[j][pattern[f[j] & i]] for j in range(n))
          for i in range(1, 2 ** max_time)))

Solution (Python):


def main(N,F,P):
    inf = float("INF")
    ans = -inf
    
    for i in range(1,1<<10):
        count = [0]*N
        tmp = 0
        for j in range(10):
            if((i>>j)&1):
                for k in range(N):
                    if F[k][j]==1:
                        count[k] += 1
            else:
                continue
            
        for l in range(N):
            tmp += P[l][count[l]]
        ans = max(ans,tmp)
    print(ans)

if __name__ == '__main__':
    N = int(input())
    F,P = [],[]
    for i in range(N):
        F.append([int(j) for j in input().split()])
    for i in range(N):
        P.append([int(j) for j in input().split()])
    main(N,F,P)

Solution (Python):
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 = -10 ** 10

for i in range(1, 2 ** 10):
  T = [0] * 10
  for j in range(10):
    if ((i >> j) & 1):
      T[j] = 1
      
  pro = 0
  for i in range(N):
    c = 0
    for j in range(10):
      if F[i][j] == 1 and T[j] == 1:
        c += 1
    pro += P[i][c]
  ans = max(pro, ans)

print(ans)

Solution (Python):
n = int(input())
f = []
for _ in range(n):
    s = 0
    l = list(map(int, input().split()))
    for i in range(10):
        s += l[i]<<i
    f.append(s)
p = [list(map(int, input().split())) for _ in range(n)]
b = []
for i in range(1,1024):
    w = 0
    for j in range(n):
        idx = format(i & f[j], 'b').count('1')
        w += p[j][idx]
    b.append(w)
print(max(b))

Solution (Python):
N=int(input())
M=[[0 for i in range(2**10)] for j in range(N)]
K=[0]*(2**10)
F=[list(map(int,input().split())) for _ in range(N)]
P=[list(map(int,input().split())) for _ in range(N)]

for i in range(2**10):
  for j in range(10):
    for k in range(N):
      if (i>>9-j)&1 and F[k][j]:
        
        M[k][i]+=1

for i in range(2**10):
  for k in range(N):
    K[i]+=P[k][M[k][i]]
print(max(K[1:]))

Solution (Python):

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


max_profit = - 10 ** 9
for bit in range(1 << 10):
    if bit == 0: 
        continue

    profit = 0
    c=[0] * n
    for i in range(10):
        if bit >> i & 1:
            
            for j in range(n):
                c[j] += f[j][i]
    
    for i in range(n):
        profit += p[i][c[i]]
    max_profit = max(max_profit, profit)

print(max_profit)

Solution (Python):
from collections import defaultdict

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


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

for i in range(N):
	P = getlist()
	PL.append(P)


ans = -float("inf")
for i in range(1, 1 << 10):
	D = defaultdict(int)
	for j in range(10):
		if ((i >> j) & 1) == 1:
			for k in range(N):
				D[k] += 1 & FL[k][j]
	val = 0
	for j in range(N):
		val += PL[j][D[j]]
	ans = max(ans, val)
print(ans)

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

input = sys.stdin.readline

N = int(input())

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

f = np.array(F)
p = np.array(P)

def cal(f, p, v):
    total = 0
    max_total = -10**10
    c = np.dot(f, v.T)
    for ci in c.T:
        total = sum([p[i,cii] for i, cii in enumerate(ci)])
        max_total = max(total, max_total)
    return max_total

v = np.array(list(product([0,1],repeat=10)))
v[0] = np.array([0,0,0,0,0,0,0,0,0,1])

print(cal(f, p, v))

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

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

    ans = -10**7*N
    for i in range(1, 1<<10):
        tmp = 0
        for j,f in enumerate(F):
            c = bin(i&f).count("1")
            tmp += P[j][c]
        ans = max(ans, tmp)
    print(ans)

if __name__ == '__main__':
    main()

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

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

    ans = -10**7*N
    for i in range(1, 1<<10):
        tmp = 0
        for s,f in enumerate(F):
            c = 0
            for j in range(10):
                if (i>>j)&1&f[j]:
                    c += 1
            tmp += P[s][c]
        ans = max(ans, tmp)
    print(ans)

if __name__ == '__main__':
    main()

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

def main():
    N = int(input())
    F = []
    for _ in range(N):
        
        F.append(int(input().replace(" ", "", -1), 2))
    P = []
    for i in range(N):
        P.append(list(map(int, input().split())))

    ans = -10**7*N
    for i in range(1, 1<<10):
        tmp = 0
        for j,f in enumerate(F):
            
            c = bin(i&f).count("1")
            tmp += P[j][c]
        ans = max(ans, tmp)
    print(ans)

if __name__ == '__main__':
    main()

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


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

P = [[int(j) for j in input().split()] for j in range(N)]

ans = -float('inf')


for i in range(1, 2**10):
    
    temp = 0 
    for j in range(N):
        
        temp += P[j][bin(i&F[j]).count('1')]
    ans = max(ans, temp)

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

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

Solution (Python):
import numpy as np
n = int(input())

f = []
for i in range(n):
    f.append(int(input().replace(' ', ''), 2))

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

max_val = -10 ** 9
for i in range(1, 2 ** 10):
    benefit = 0
    for j in range(n):
        match = str(bin(i & f[j])).count('1')
        benefit += p[j, match]
    if benefit > max_val:
        max_val = benefit
print(int(max_val))

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 = [format(i, 'b').zfill(10) for i in range(1, 2 ** 10)]
ans = []

for i in l:
    c = [0] * N
    for j in range(10):
        if i[j] == '1':
            for k in range(N):
                if F[k][j] == 1:
                    c[k] += 1
                else:
                    continue
        else:
            continue
    temp = 0
    for j in range(N):
        temp += P[j][c[j]]
    ans.append(temp)

print(max(ans))

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

ans = -float('inf')

for i in range(1, 2**10):
    temp = 0
    for j in range(N):
        temp += P[j][bin(i&F[j]).count('1')]
    ans = max(ans, temp)

print(ans)

Solution (Python):
n=int(input())
f=[0 for i in range(n)]
for i in range(n):
    fi=int("".join(list(input().split())),2)
    f[i] = fi
p=[[] for i in range(n)]
for i in range(n):
    pi=list(map(int,input().split()))
    p[i] = pi
ans=-9999999999999
for i in range(1,1024):
    bene=0
    for j in range(n):
        c = str(bin(i & f[j])).count("1")
        bene+=p[j][c]
    if(ans < bene):
        ans = bene
print(ans)

Solution (Python):
N=int(input())
F=[int(input().replace(' ',''),2) for i in range(N)]
P=[list(map(int,input().split())) for i in range(N)]
print(max(sum([p[bin(f&i).count('1')] for f,p in zip(F,P)]) for i in range(1,2**10)))

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

import numpy as np

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

Cands = [[]]
for i in range(10):
  temp = []
  for cand in Cands:
    temp.append(cand + [0])
    temp.append(cand + [1])
    Cands = temp
Cands = Cands[1:]

max_p = -10000000000
for cand in Cands:
  sum_p = 0
  for i in range(n):
    day_num = np.dot(cand, F[i])
    sum_p += P[i][day_num]
  max_p = max(sum_p, max_p)
print(max_p)

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=sys.stdin.readline
def resolve():
    n=int(input())
    run=[int(input().replace(' ',''),2) for _ in range(n)]
    profit=[tuple(map(int,input().split())) for _ in range(n)]
    print(max(sum(profit[j][bin(run[j]&i).count('1')] for j in range(n)) for i in range(1,1<<10)))
resolve()

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=sys.stdin.readline
def resolve():
    n=int(input())
    run=[0]*n
    for i in range(n):
        A=tuple(map(int,input().split()))
        a=0
        for d in range(10):
            a+=A[d]<<d
        run[i]=a
    profit=[tuple(map(int,input().split())) for _ in range(n)]
    ans=-INF
    for i in range(1,1<<10):
        score=0
        for j in range(n):
            score+=profit[j][bin(run[j]&i).count('1')]
        ans=max(ans,score)
    print(ans)
resolve()

Solution (Python):
import itertools
import numpy as np

N = int(input())
F = [0] * N
for i in range(N):
    F[i] = np.array([int(x) for x in input().split()])

P = [0] * N
for i in range(N):
    P[i] = np.array([int(x) for x in input().split()])

max_bene = -1e10
for p in itertools.product([0, 1], repeat=10):
    if sum(p) == 0:
        continue
    p = np.array(p)
    bene = 0
    for i in range(N):
        c = np.dot(F[i], p)
        bene += P[i][c]

    if bene > max_bene:
        max_bene = bene

print(max_bene)

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

ans = -1e10
for i in range(1,2**10):
    temp = 0
    for j in range(N):
        temp += P[j][bin(i&F[j]).count("1")]
    if temp > ans:
        ans = temp
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)]
res = -float('inf')
for i in range(1, 2**10):
    s = list(map(int, list(bin(i)[2:].rjust(10, '0'))))
    val = 0
    for f, p in zip(fs, ps):
        count = 0
        for a, b in zip(s, f):
            if a == 1 and b == 1:
                count += 1
        val += p[count]
    res = max(res, val)
print(res)

Solution (Python):
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=float('-inf')
for i in range(1,2**10):
    check_sum=0
    for j in range(n):
        check=0
        for l in range(10):
            if i>>l &f[j][l]:
                check+=1
        check_sum+=p[j][check]
    ans=max(ans,check_sum)
print(ans)

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

ans = -1000000000

for i in range(1,1024):
    F0 = [0]*10
    i_temp = i
    for j in range(10):
        F0[j] = i_temp%2
        i_temp = int(i_temp/2)
    
    c = [0]*N
    for j in range(10):
        if F0[j] == 1:
            for k in range(N):
                c[k] += F[k][j]
    
    ans_temp = 0
    for j in range(N):
        ans_temp += P[j][c[j]]
    ans = max(ans, ans_temp)

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

max_x=-10**10
for i in range(2**10):
    if i == 0 : continue
    joi=[1 if ((i & 2**j)!=0) else 0 for j in range(10) ]
    x=0
    for j in range(N):
        x+=P[j][sum([1 for k in range(10) if (F[j][k]==1) and (joi[k]==1)])]
    if max_x<=x:
        max_x=x
print(max_x)

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



ans = -(10**10)
for i in range(1,1<<10):
  A = [0 for _ in range(10)]
  for j in range(10):
    A[j] = (i & (1<<j)) >>j
  
  profit = 0
  for j in range(N):
    c = 0
    for f,a in zip(F[j],A):
      c += f*a
    profit += P[j][c]
  ans = max(ans,profit)
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)]

x = list(product(range(2), repeat = 10))
x.remove(tuple([0]*10))

ans = float('-inf')
for i in range(len(x)):
  p = 0
  for j in range(N):
    c = 0
    for k in range(10):
      if x[i][k] == 1 and F[j][k]== 1:
        c += 1
    p += P[j][c]
  if ans < p:
    ans = p
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)]

import itertools
zero = [0,1]
ans = -float("inf")
for i in itertools.product(zero,repeat = 10):
    if i != (0,)*10:
        tmp = 0
        for j in range(N):
            c = 0
            for k in range(10):
                c += i[k]*F[j][k]
            tmp += P[j][c]
        if ans < tmp:
            ans = tmp
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
n = int(input())
f = []
for i in range(n):
    tmp = 0
    for j in map(int, input().split()):
        tmp <<= 1
        tmp |= j
    f.append(tmp)
pay = [list(map(int, input().split())) for _ in range(n)]
ans = -float('INF')
for i in range(1,1<<10):
    tmp = 0
    for j in range(n):
        tmp += pay[j][str(bin(f[j] & i)).count('1')]
    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 = -float("inf")
for i in range(1, 2 ** 10):
    i_bin = "{:010b}".format(i)
    sm = 0
    for shop_i in range(n):
        cnt = 0
        for j, dig in enumerate(i_bin):
            if f[shop_i][j] * int(dig):
                cnt += 1
        sm += p[shop_i][cnt]
    ans = max(ans, sm)
        
print(ans)

Solution (Python):
from itertools import product
import numpy as np
N = int(input())
F = np.array([list(map(int, input().split())) for _ in range(N)])
P = np.array([list(map(int, input().split())) for _ in range(N)])
M = np.array([0]*1023)
for i, f in enumerate(product([0, 1], repeat=10)) :
    if not any(f) : continue
    f = np.array(f)
    a = np.sum(F*f, axis=1)
    M[i-1] = sum([l[i] for l, i in zip(P, a)])
print(np.max(M))

Solution (Python):
N=int(input())
F=[int(input().replace(' ',''),2) for i in range(N)]
P=[list(map(int,input().split())) for i in range(N)]
print(max(sum([p[bin(f&i).count('1')] for f,p in zip(F,P)]) for i in range(1,2**10)))

Solution (Python):
N=int(input())
F=[int(input().replace(' ',''),2) for i in range(N)]
P=[list(map(int,input().split())) for i in range(N)]
print(max(sum([p[bin(f&i).count('1')] for f,p in zip(F,P)]) for i in range(1,2**10)))

Solution (Python):
"""
知識問題
- 全列挙
  - 条件数は数え上げ可能
    - 最大で2^10 = 1024
- ビット演算を利用して、個数をカウントする
  - 2進数:1010 => 10進数:10であることを利用して、1の個数をカウント。この場合、期待値は2
    - 10進数の値を配列のindex = 10
    - 2進数にした時の1の個数を、その配列のindexの値 = 2
  - 何桁かは事前に分かっている必要がある
  - カウント方法は下記:
    - 桁数: 10
    - 条件のindex = 500
    - 条件のindexをバイナリにした時の1の個数は、桁数毎に1とのandの合計: sum(500 >> j & 1 for j in range(10))
- 店舗iが、何回同じ時間帯に開店したかは、bit演算andを利用
  - index & F[i]
- 同じ時間帯
"""

n = int(input())
f = []
for _ in range(n):
    f.append(int("0b{}".format(input().replace(' ', '')), 2))

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

pattern = [sum(i >> j & 1 for j in range(10)) for i in range(2 ** 10)]

candidates = []
for j in range(1, 2 ** 10):
    total = 0
    for i in range(n):
        total += p[i][pattern[f[i] & j]]
    candidates.append(total)
print(max(candidates))

Solution (Python):
ans = -10 ** 9
A = [0] * 10


def func():
    if sum(A) == 0:
        return
    score = 0
    for i in range(N):
        days = sum([a * f for a, f in zip(A, F[i])])
        score += P[i][days]
    global ans
    ans = max(ans, score)


def dfs(pos):
    if pos == 10:
        func()
        return
    A[pos] = 0
    dfs(pos + 1)
    A[pos] = 1
    dfs(pos + 1)


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

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

print(ans)

Solution (Python):
from itertools import product

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

M = -float('inf')
for open in product([0, 1], repeat=10) :
    if sum(open) == 0 :
        continue
        
    ret = 0
    for i in range(N) :
        ret += P[i][sum([F[i][j] & open[j] for j in range(10)])]
    M = max(M, ret)
print(M)

Solution (Python):

import sys


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

    ans = -10000000000000000
    for i in range(1,1<<10):
        pf = 0
        for j in range(N):
            c = 0
            for k in range(10):
                if(i & (1<<k)):
                    if(F[j][k]):
                        c += 1
            pf += P[j][c]

        ans = max(ans, pf)
        

    print(ans)

    pass

if __name__ == '__main__':
    main()

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

ans = -INF
for i in range(1,2**10):
    cnt = [0]*N
    res = 0
    bs = format(i,"b")
    bs = bs.zfill(10)
    for j in range(N):
        fs = "".join(F[j])
        for k in range(10):
                cnt[j] += int(fs[k])*int(bs[k])
    for l in range(N):
        res += P[l][cnt[l]]
    if res > ans:
        ans = res
print(ans)

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

ans = -INF
for i in range(1,2**10):
    cnt = [0]*N
    res = 0
    bs = format(i,"b")
    bs = bs.zfill(10)
    for j in range(N):
        fs = "".join(F[j])
        for k in range(10):
            if fs[k] == "1" and bs[k] == "1":
                cnt[j] += 1
    for l in range(N):
        res += P[l][cnt[l]]
    if res > ans:
        ans = res
print(ans)

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

def main():
    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 = -int(1e10)
    for i in range(1, 2**10):
        count = np.zeros((N), dtype=int)
        
        for j in range(10):
            if i&1:
                count += f[:,j]
            i >>= 1
        ans = max(ans, sum([p[i,count[i]] for i in range(N)]))
    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 = -float('inf')
r = (0,0,0,0,0,0,0,0,0,0)
for w in itertools.product(range(2), repeat=10):
    if w == r:
        continue
    result = 0
    for i in range(N):
        f = F[i]
        count = 0
        for j in range(10):
            if f[j] == 1 and w[j] == 1:
                count += 1
        result += P[i][count]
    ans = max(ans, result)
print(ans)

Solution (Python):
from itertools import combinations, product

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

idx_list = [i for i in range(0,10)]
ans = -1 * float('inf')
for i in range(1,11):
  for combination in combinations(idx_list,i):
    jos = [0 for _ in range(10)]
    for idx in combination:jos[idx] = 1
    
    prof_sum = 0
    for j in range(N):
      num_open = sum([a*b for a,b in zip(jos,F[j][:])])
      prof_sum += P[j][num_open]
    if ans < prof_sum: ans = prof_sum
print(ans)

Solution (Python):
n=int(input())
F=[int(input().replace(" ",""),2) for _ in range(n)]
P=[list(map(int,input().split())) for _ in range(n)]
ans=[]
for i in range(1,1024):
  p=0
  for j in range(n):
    p+=P[j][bin(i&F[j]).count("1")]
  ans.append(p)
print(max(ans))

Solution (Python):
def resolve():
    n = int(input())
    f = list(int("".join(input().split()), 2) for _ in range(n))
    p = list(list(map(int, input().split())) for _ in range(n))
    INF = 10 ** 18
    ans = -INF
    for i in range(1, 2 ** 10):
        profit = 0
        for j, fi in enumerate(f):
            same = bin(i & fi)[2:].count("1")
            profit += p[j][same]
        ans = max(ans, profit)
    print(ans)


if __name__ == "__main__":
    resolve()

Solution (Python):
from collections import Counter,defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

n = inp()
f = [inpl() for _ in range(n)]
p = [inpl() for _ in range(n)]
ans = -10**9

for flag in itertools.product([0,1], repeat=10):
    tmp = 0
    if not any(flag):
        continue
    for _ in range(n):
        cnt = 0
        for i,j in enumerate(flag):
            if j and f[_][i]:
                cnt += 1
        tmp += p[_][cnt]
    ans = max(ans, tmp)
print(ans)

Solution (Python):

import sys
import math
from collections import defaultdict


sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]


mod = 10**9 + 7


def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))



from itertools import product

N = I()
F = [[[0]*2 for _ in range(5)] for _ in range(N)]
P = []
for i in range(N):
    temp = III()
    for j in range(5):
        for k in range(2):
            F[i][j][k] = temp[j*2+k]
for _ in range(N):
    P.append(III())

ans = -float('inf')
A = list(product([True, False],repeat=10))
for a in A:
    if a == (False,)*10:
        continue
    val = 0
    for i in range(N):
        count = 0
        for j in range(5):
            for k in range(2):
                if a[2*j+k]==True and F[i][j][k]==1:
                    count += 1
        val += P[i][count]
    if val > ans:
        ans = val

print(ans)

Solution (Python):
import sys
import  math
from statistics import *
from collections import *
from operator import itemgetter
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n = ni()
fff = []
ppp = []
for i in range(n):
    fff.append(na())
for i in range(n):
    ppp.append(na())
ans = -9999999999999999999999
for b in range(1, 1<<10):
    s = 0
    for i in range(n):
        c = 0
        for j in range(10):
            if (b >> j & 1) and (fff[i][j] == 1):
                c += 1
        s += ppp[i][c]
    if ans < s:
        ans = s
print(ans)