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
import itertools












def toBit(n): 
    return bin(eval('0b' + str(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 == '0b0':
            continue
        profit = 0
        for i in range(n):
            checked = schedule[i]
            number_of_periods = bin(eval(checked) & eval(open_pattern)).count('1')
            profit += profit_table[i][number_of_periods]
        maximum_profit = max(maximum_profit, profit)

    print(maximum_profit)

if __name__ == "__main__":
    
    main()

Solution (Python):

n=int(input())
lists=[]
shoplist=[]
for i in range(n):
    lists.append(list(map(int,input().split())))
for j in range(n):
    shoplist.append(list(map(int,input().split())))
maxi=-10**10
for _ in range(1,2**10):
    string=format(_,"0%ib"%10)
    empty=[0 for i in range(n)]
    for i in range(n):
        some=lists[i]
        counter=0
        for k in range(10):
            if some[k]==1 and int(string[k])==1:
                counter+=1
        empty[i]=counter
    how=0
    for i in range(n):
        how+=shoplist[i][empty[i]]
    maxi=max(maxi,how)
print(maxi)

Solution (Python):
def examC(inf):
    N = I()
    F = [LI() for _ in range(N)]
    P = [LI() for _ in range(N)]
    loop = 2**10
    ans = -inf
    for i in range(1,loop):
        cur = [0]*N
        for j in range(10):
            if (i>>j)&1==1:
                for k in range(N):
                    if F[k][j]==1:
                        cur[k]+=1
        ansC =0
        for j in range(N):
            ansC += P[j][cur[j]]
        ans = max(ans,ansC)
    print(ans)


import sys,copy,bisect,itertools
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC(inf)

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

ma = -(1<<100)
for k in range(1, 1024):
    s = 0
    for i in range(N):
        s += P[i][bin(F[i] & k).count("1")]
    ma = max(ma, s)
print(ma)

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


li = list(product([0, 1], repeat=10))

ans = - 10 ** 19
for i in li[1:]:
  cnt = 0
  for f, p in zip(F, P):
    opendays = sum([a * b for a, b in zip(i, f)])
    cnt += p[opendays]
  ans = max(ans, cnt)
print(ans)

Solution (Python):
n=int(input())
F=[int(input().replace(' ',''),2) for i in range(n)]
P=[list(map(int,input().split())) for i in range(n)]
ans=-10**9
for i in range(1,1<<10):
    r=0
    for j in range(n):
        r+=P[j][str(bin(i&F[j])).count('1')]
    ans=max(ans,r)
print(ans)

Solution (Python):
n=int(input())
s=[list(map(int,input().split())) for i in range(n)]
ss=[list(map(int,input().split())) for i in range(n)]
ans=-10**11
for i in range(1,1024):
  status=str("{:b}".format(i)).zfill(10)
  opening=[]
  check=0
  for j in range(10):
    if int(status[j])==1:
      opening.append(j)
  for l in range(n):
    cnt=0
    for k in opening:
      cnt+=s[l][k]
    check+=ss[l][cnt]
  if check>ans:
    ans=check
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
import numpy as np
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)]
fra1 = [0] * 10
fra1[0] = 1
fra2 = [0] * 10
f1 = np.array(f)

def profit(op): 
    a = 0
    for i in range(n):
        a += p[i][int(op[i])]
    return a

def re(time,fra,op):
    if fra[time-1] == 1:
        op1 = op + f1[:,time-1]
    else:
        op1 = op
    
    if time == 10:
        if sum(fra) == 0:
            return -(10 ** 10)
        else:
            ans = profit(op1)
            return ans
    else:
        fra[time] = 1
        ans1 = re(time+1,fra,op1)

        fra[time] = 0
        ans2 = re(time+1,fra,op1)

        return max(ans1,ans2)

ope = np.zeros(n)



a1 = re(1,fra1,ope)
a2 = re(1,fra2,ope)

print(max(a1,a2))

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 7)

N = int(input())
flist = [list(map(int, input().split())) for _ in range(N)]
plist = [list(map(int, input().split())) for _ in range(N)]
alist = [0] * 10
def dfs(i, v, ans):
    if v == 10:
        tmp = 0
        if alist.count(1) == 0:
            return ans
        for j in range(N):
            cnt = 0
            for k in range(10):
                if alist[k] == 1 and flist[j][k] == 1:
                   cnt += 1
            tmp += plist[j][cnt]

        ans = max(ans, tmp)
        return ans

    alist[i] = 1
    ans = dfs(i + 1, v + 1, ans)
    alist[i] = 0
    ans = dfs(i + 1, v + 1, ans)
    return ans

print(dfs(0, 0, -10 ** 9 - 1))

Solution (Python):
n=int(input())
bit=[[1,1,1,1,1,1,1,1,1,1]]
for i in range(1,1023):
  num=i
  l1=[]
  while num!=0:
    l1.append(num%2)
    num=num//2
  while len(l1)<len(bit[-1]):
    l1.append(0)
  bit.append(l1)
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())))
max=-10**10
for i in range(1023):
  count=[0 for i in range(n)]
  b=bit[i]
  ben=0
  for j in range(10):
    if b[j]==0:
      pass
    else:
      for k in range(n):
        if f[k][j]==1:
          count[k]+=1
  for j in range(n):
    ben+=p[j][count[j]]
  if max<ben:
    max=ben
print(max)

Solution (Python):
N = int(input())
F = []
P = []
def Base_2_to_10(S):
	L = len(S)-1
	out = 0
	for i in reversed(range(L+1)):
		if S[i] == "1":
			out += 2 ** (L-i)
	return out

def Base_10_to_n(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out

for _ in range(N):
	s = "".join(list(map(str, input().split())))
	F.append(Base_2_to_10(s))

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

ans = float("inf") * (-1)

for i in range(1,2**10):
	tmp = 0
	for j in range(N):
		cmn = Base_10_to_n(i&F[j],2).count("1")
		tmp += P[j][cmn]
	ans = max(ans, tmp)

print(ans)

Solution (Python):
import sys
import itertools


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    f = [list(map(int, readline().split())) for _ in range(n)]
    p = [list(map(int, readline().split())) for _ in range(n)]
    mt = - (10 ** 10)
    for it in itertools.product([True, False], repeat=10):
        if sum(it) != 0:
            ls = [0] * n
            for i, iv in enumerate(it):
                for j in range(n):
                    ls[j] += 1 if f[j][i] == 1 and iv else 0
            t = 0
            for i in range(n):
                t += p[i][ls[i]]
            mt = max(mt, t)
    print(mt)


if __name__ == '__main__':
    solve()

Solution (Python):
import sys
import itertools


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    f = [list(map(int, readline().split())) for _ in range(n)]
    p = [list(map(int, readline().split())) for _ in range(n)]
    mt = - (10 ** 10)
    for it in itertools.product([True, False], repeat=10):
        if sum(it) != 0:
            ls = [0] * n
            for i, iv in enumerate(it):
                for j in range(n):
                    ls[j] += 1 if f[j][i] == 1 and iv else 0
            t = 0
            for i in range(n):
                t += p[i][ls[i]]
            mt = max(mt, t)
    print(mt)


if __name__ == '__main__':
    solve()

Solution (Python):
N = int(input())
Fs = [[int(f) for f in input().split(' ')] for _ in range(N)]
Ps = [[int(f) for f in input().split(' ')] for _ in range(N)]



def get_price(plan):
    price = 0
    for i, F in enumerate(Fs):
        n = sum([1 for f, p in zip(F, plan)
                 if f == 1 and p == 1])
        price += Ps[i][n]
    return price

prices = []

def dfs(i, array):
    if i == 10:
        if sum(array) > 0:
            price = get_price(array)
            prices.append(price)

    else:
        array[i] = 0
        dfs(i+1, array)

        array[i] = 1
        dfs(i+1, array)


dfs(0, [0 for _ in range(10)])
print(max(prices))

Solution (Python):
import numpy as np
N = int(input())
Fa = [list(map(int,input().split())) for i in range(N)]
P = [list(map(int,input().split())) for i in range(N)]
F = np.array(Fa)
ans = - 10**10
for i in range(1,2**10):
    tmp = 0
    joi = np.array(list(map(int,format(i,"010b"))))
    for j in range(N):
        tmp += P[j][np.dot(joi,F[j])]
    ans = max(tmp, ans)
print(ans)

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

N = int(input().strip())

openhour = [0] * 10
samehour = [0] * N

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

def f(i, openhour, samehour):
    if i == 10:
        if sum(openhour) == 0:
            return - 10 ** 9 - 7
        global N, F, P
        ret = sum([P[n][samehour[n]] for n in range(N)])
        return ret
    oh1 = openhour[:]
    oh2 = openhour[:]
    oh1[i] = 0
    oh2[i] = 1
    sh2 = samehour[:]
    for n in range(N):
        if F[n][i] == 1:
            sh2[n] += 1

    return max(f(i+1, oh1[:], samehour[:]),f(i+1, oh2[:], sh2[:]))

print(f(0, openhour[:], samehour[:]))

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

def rekkyo(l):
    if len(l)==10:
        if max(l) == 0: return -1*(10**9)
        ret = 0
        for i in range(n):
            tp = 0
            for j in range(10):
                if l[j] & f[i][j] == 1:
                    tp += 1
            ret += p[i][tp]
        return ret
    else:
        ret1 = rekkyo(l+[0])
        ret2 = rekkyo(l+[1])
        return max(ret1,ret2)

print(rekkyo([]))

Solution (Python):
N=int(input())
F=[[0]*10 for j in range(N)]

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

P=[]

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

L=[]
l=[0]*10

temp=""
c=0
while c>=0:
    if c==10:
        L.append(temp)
        temp=temp[:-1]
        c -= 1
    if l[c]==0:
        temp+="0"
        l[c]+=1
        c+=1
    elif l[c]==1:
        temp+="1"
        l[c]+=1
        c+=1
    elif l[c]==2:
        temp=temp[:-1]
        l[c]=0
        c-=1

CL=[]
mx=-1000000000000
for d in L[1:]:
    temp=0
    for i in range(N):
        C=[0]*N
        for j in range(10):
            if F[i][j]*int(d[j])==1:
                C[i]+=1
        temp+=P[i][C[i]]
        CL.append(C[i])

    mx=max(mx,temp)
CL=set(CL)
print(mx)

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

Solution (Python):
n = int(input())
f = [0] * n
m = - 10 ** 10
for i in range(n):
  f[i] = list(map(int,input().split()))
p = [0] * n
for i in range(n):
  p[i] = list(map(int,input().split()))
for i in range(1,2**10):
  cur = bin(i)[2:]
  cur = '0'*(10-len(cur)) + cur
  ri = 0
  for j in range(n):
    c = 0
    for k in range(10):
      if f[j][k] == int(cur[k]) == 1:
        c += 1
    ri += p[j][c]
  m = max(m,ri)
print(m)

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

ans = -10**18
for i in range(2**10+1, 2**11):
    num = 0
    b = bin(i)
    for j in range(N):
        cnt = 0
        for k in range(10):
            if F[j][k] == 1 and b[k+3] == "1":
                cnt += 1
        num += P[j][cnt]
    ans = max(ans, num)
    
print(ans)

Solution (Python):

import sys

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

D=[]    
for f in F: 
    n=0
    for i,x in enumerate(f):
        if x==1:
            n+=2**(9-i)
    D.append(n)


def count_one(n):
    cnt=0
    for i in range(10):
        cnt+=n>>i&1
    return cnt

ans=float("-inf")
for i in range(1,2**10):
    t=0 
    for j,d in enumerate(D):
        c=count_one(d&i)    
        t+=P[j][c]
    ans=max(ans,t)

print ans

Solution (Python):
import sys
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)]
dp = [0] * (pow(2, 10))
for i in range(pow(2, 10)):
  for j in range(N):
    c = 0
    for k in range(10):
      if f[j][k]:
        if i & (1 << k):
          c += 1
    dp[i] += p[j][c]
res = -float("inf")
for i in range(1, pow(2, 10)):
  res = max(res, dp[i])
print(res)

Solution (Python):
import itertools
n = int(input())
list_f = []
for i in range(n):
  temp = list(map(int, input().split()))
  list_f.append(temp)
list_p = []
for i in range(n):
  temp = list(map(int, input().split()))
  list_p.append(temp)
  
cand = list(itertools.product([0, 1], repeat=10))
cand = cand[1:]
max_p = -float("inf")
for c in cand:
  temp = 0
  for idx, one_f in enumerate(list_f):
    count_same = sum([1 for i, j in enumerate(c) if j == 1 and one_f[i] == 1])
    temp += list_p[idx][count_same]
  if temp > max_p:
    max_p = temp
print(max_p)

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

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

ans = 10**9
ans *= -1
for i in range(1,1024):
  tmp = format(i,'b').zfill(10)
  litmp = [0]*n
  for j in range(10):
    if tmp[j] == "1":
      for k in range(n):
        litmp[k] += lishop[k][j]

  tmp2 = 0
  for j in range(n):
    tmp2 += liben[j][litmp[j]]
  ans = max(tmp2,ans)
print(ans)

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

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

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

Solution (Python):
from operator import mul
n = int(input())
cof = [1 << x for x in range(10)]
fs = [sum(map(mul, map(int, input().split()), cof)) for _ in range(n)]

ps = [list(map(int, input().split())) for _ in range(n)]
ans = float('-inf')
for g in range(1, 1024):
    sum=0
    for f, p in zip(fs, ps):
        tmp2=bin(f & g).count('1')
        
        sum+=p[tmp2]
    ans = max(ans, sum)
print(ans)

Solution (Python):
from operator import mul
 
n = int(input())
cof = [1 << x for x in range(10)]

fs = [sum(map(mul, map(int, input().split()), cof)) for _ in range(n)]
ps = [list(map(int, input().split())) for _ in range(n)]
ans = float('-inf')
for g in range(1, 1024):
    sum=0
    for f, p in zip(fs, ps):
        tmp2=bin(f & g).count('1')
        sum+=p[tmp2]
  
    
    
    ans = max(ans, sum)

print(ans)

Solution (Python):
from operator import mul
 
n = int(input())
cof = [1 << x for x in range(10)]

fs = [sum(map(mul, map(int, input().split()), cof)) for _ in range(n)]
ps = [list(map(int, input().split())) for _ in range(n)]
ans = float('-inf')
for g in range(1, 1024):
    sum=0
    for f, p in zip(fs, ps):
        sum+=p[bin(f & g).count('1')]
  
    
    
    ans = max(ans, sum)

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):
from operator import mul
 
n = int(input())
cof = [1 << x for x in range(10)]
fs = [sum(map(mul, map(int, input().split()), cof)) for _ in range(n)]
ps = [list(map(int, input().split())) for _ in range(n)]
ans = float('-inf')
for g in range(1, 1024):
    ans = max(ans, sum(p[bin(f & g).count('1')] for f, p in zip(fs, ps)))
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)]
times = list(itertools.product([0, 1], repeat=10))
times.remove((0, 0, 0, 0, 0, 0, 0, 0, 0, 0))
profit = float('-inf')
for exhibit in times:
    c = []
    for shop in f:
        c.append([exhibit[i] + shop[i] for i in range(10)].count(2))
    profit = max(profit, sum([p[i][c[i]] for i in range(n)]))
print(profit)

Solution (Python):

import itertools

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)]
    bit_list = list(itertools.product([0, 1], repeat=10))
    bit_list.pop(0)
    answer = -10**9-1
    for b in bit_list:
        profit = 0
        for i in range(N):
            a = 0 
            for j in range(10):
                if b[j]==1 and F[i][j]==1:
                    a+=1
            profit+=P[i][a]

        answer = max(answer,profit)

    print(answer)
    return 

if __name__ == '__main__':
    main()

Solution (Python):

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


def main():
    import math
    import collections
    import itertools

    n = int(input())
    fs = [int(input().replace(' ', ''), 2) for _ in range(n)]
    
    ps = [list(map(int, input().split())) for _ in range(n)]
    
    ans = -float("INF")
    for i in range(1, 2 ** 10):
        num_simal_stores = [bin(i & f).count('1') for f in fs]
    
        ans_tmp = 0
        for i in range(n):
            ans_tmp += ps[i][num_simal_stores[i]]

        ans = max(ans, ans_tmp)
    
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
from collections import defaultdict
from bisect import bisect_left, bisect_right
N = int(input())
dic = defaultdict(list)
for i in range(N):
  F = [int(c) for c in input().split()]
  for j in range(10):
    if F[j]==1:
      dic[j] += [i]

p = {}
for i in range(N):
  P = [int(c) for c in input().split()]
  p[i] = P[:]

ans = []
for i in range(1,2**10):
  log = []
  x = i
  m = 0
  for j in range(10):
    if x%2==1:
      log += dic[j]
    x = x>>1
  
  log.sort()
  for i in range(N):
    l = bisect_left(log, i)
    r = bisect_right(log, i)
    m += p[i][r-l]

  if ans==[]:
    ans = m
  elif ans<m:
    ans = m

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

l=[0]*(2**10-1)
for i in range(1,2**10):
  op=list(map(int,list(bin(i)[2:].zfill(10))))
  for n in range(N):
    c=0
    for o in range(10):
      if op[o]==1 and F[n][o]==1:
        c+=1
    l[i-1]+=P[n][c]
    
print(max(l))

Solution (Python):
import sys
n = int(input())
f_ls = []
p_ls = []
INF= 1e10
for j in range(n):
    f = [int(i) for i in sys.stdin.readline().split()]
    f_ls.append(f)
for j in range(n):
    p = [int(i) for i in sys.stdin.readline().split()]
    p_ls.append(p)

best = -INF
for i in range(1,1<<10):
    score = 0
    for shop in range(n):
        cnt = 0
        p = p_ls[shop]
        for ind, (j,k) in enumerate(zip(bin(i)[2:].zfill(10), f_ls[shop])):
            if j == "1" and k == 1:
                cnt += 1
        score += p[cnt]
    if best < score:
        best = score
print(best)

Solution (Python):
n = int(input())
f = []
p = []

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

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

ans = -10**9
for i in range(1,2**10): 
    opn = [0 for i in range(10)]
    scr = 0

    for j in range(10):
        memo = (i>>j)
    
    

        if memo&1:
            opn[j] = 1
    
    for k in range(n):
        cnt = 0
        for l in range(10):
            if opn[l] and f[k][l]:
                cnt += 1
        scr += p[k][cnt]

    ans = max(scr,ans)

print(ans)

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

for loop in range(1,1024):
  rieki = 0
  f = str(format(loop,"b")).rjust(10,"0") 
  for i in range(N): 
    Fnum = 0
    for j in range(10): 
      Fnum = Fnum + F[i][j] * int(f[j])
    
    rieki = rieki + P[i][Fnum] 
  Pre.append(rieki) 
print(max(Pre))

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 = -(1<<30)
for b in range(1, (1<<10)):
    tmp = 0
    for i in range(N):
        cnt = 0
        for j in range(10):
            if (b>>j&1) and F[i][j]:
                cnt += 1
        tmp += P[i][cnt]
    ans = max(ans, tmp)

print(ans)

Solution (Python):
N = int(input())
F = [[[0 for k in range(2)] for j in range(5)] for i in range(N)]

for i in range(N):
    l = [int(_) for _ in input().split()]
    for j in range(10):
        if j % 2 == 0:
            F[i][j//2][0] = l[j]
        else:
            F[i][(j-1)//2][1] = l[j]

P = [0] * N

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

res = -10000000000

for u in range(1<<10):
        if u != 0:
            tmp = 0
            for i in range(N):
                cnt = 0
                for j in range(5):
                    for k in range(2):
                        if F[i][j][k] & ((u>>(2*j+k))&1):
                            cnt += 1
                tmp += P[i][cnt]
            res = max(res,tmp)

print(res)

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

    ans = max(ans, tmp)

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())))
op=[[0],[1]]
for i in range(9):
    tmp=[]
    for j in op:
        tmp.append(j+[0])
        tmp.append(j+[1])
    op=tmp
ans=-10000000000000
for i in tmp:
    if sum(i)==0:
        continue
    t=0
    for k in range(n):
        c=0
        for j in range(10):
            c+=f[k][j]*i[j]
        t+=p[k][c]
    ans=max(t,ans)
print(ans)

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

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

Solution (Python):
import sys

























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**10
    for i in range(1,1<<10):
        tmp=0
        for f,p in zip(F,P):
            tmp+=p[bin(f&i).count("1")]
        ans=max(ans,tmp)
    print(ans)



if __name__ == '__main__':
    main()

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

ans = -1e10
for i in range(1, 2**10):
    s = 0
    for j in range(n):
        tmp = int(F[j], 2)
        tmp = i & tmp
        c = bin(tmp).count("1")
        s += P[j][c]
    if s > ans:
        ans = s
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_list = []
for i in range(1, 2**10):
    pattern = [0]*10
    for j in range(10):
        if ((i>>j) & 1):
            pattern[j] = 1
    profit = 0
    for k in range(N):
        n_time_both_open = 0
        for l in range(10):
            if pattern[l] & F[k][l] == 1:
                n_time_both_open += 1 
        profit += P[k][n_time_both_open]
    ans_list.append(profit)
    
print(max(ans_list))

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

B = [list(bin(i)[2:].zfill(10)) for i in range(1, 1024)]

ans = - float("inf")
for i in range(1023):
    
    score = 0
    for j in range(N):
        
        open_store = 0
        for k in range(10):
            if B[i][k]=="1" and F[j][k]==1:
                open_store += 1
        score += P[j][open_store]
    if score > ans:
        ans = score
print(ans)

Solution (Python):
n=int(input())
def two(x):
	k=bin(x)
	return "0"*(12-len(k))+k[2:]
ans=-10**15
f=[]
p=[]
for _ in range(n):
	x=list(map(int,input().split()))
	f.append(x)
for _ in range(n):
	x=list(map(int,input().split()))
	p.append(x)
for i in range(1,2**10):
	pro=0
	for j in range(n):
		cnt=0
		for k in range(10):
			if two(i)[k]=="1" and f[j][k]==1:
				cnt+=1
		pro+=p[j][cnt]
	ans=max(ans,pro)
print(ans)

Solution (Python):
N = int(input())
F = [0] * N
for i in range(N):
    F[i] = [int(x) for x in input().split()]
P = [0] * N
for k in range(N):
    P[k] = [int(y) for y in input().split()]
kaburi = [0]*N  
ans = -10**9  

eigyou = [0]*10  
for j in range(1, 2**10):
    rieki = 0
    for p in range(10):
        if j % 2 == 1:
            eigyou[p] = 1
        else:
            eigyou[p] = 0
        j = j//2
    for q in range(N):
        kaburi[q] = 0
        for m in range(10):
            if F[q][m] == eigyou[m] == 1:
                kaburi[q] += 1
        rieki += P[q][kaburi[q]]
    if rieki > ans:
        ans = rieki
print(ans)

Solution (Python):
def solve():
    n = int(input())
    F = [input().replace(' ','') for _ in range(n)]
    P = [[int(p) for p in input().split()] for _ in range(n)]
    l = []
    for i in range(1,2**10):
        o = bin(i).replace('0b','').zfill(10)
        profit = 0
        for f,p in zip(F,P):
            count = 0
            for a,b in zip(o,f):
                if a == b == '1':
                    count += 1
            profit += p[count]
        l.append(profit)
    return max(l)

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

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
def inputs():return [int(x) for x in input().split()]
f = [inputs() for _ in range(N)]
p = [inputs() for _ in range(N)]
cnt =[0]*(N)
ans = -10**9
for bit in range(1,1<<10):
    ans1 = 0
    cnt =[0]*(N)
    for j in range(10):
        for i in range(N):
            if bit&1<<j and f[i][j]==1:
                cnt[i] +=1
    ans1 += sum([p[i][cnt[i]] for i in range(N)])
    ans = max(ans1,ans)
print(ans)

Solution (Python):
import itertools
N = int(input())
F = [list(map(int,input().split())) for _ in range(N)]
F.insert(0,[0])
P = [list(map(int,input().split())) for _ in range(N)]
P.insert(0,[0])
cmax = -10**10
for x in itertools.product((0,1),repeat=10):
    if sum(x)>0:
        cnt = 0
        for i in range(1,N+1):
            c = 0
            for j in range(10):
                if x[j]==1 and F[i][j]==1:
                    c += 1
            cnt += P[i][c]
        cmax = max(cmax,cnt)
print(cmax)

Solution (Python):
import numpy as np
n = int(input())
shops = []
for _ in range(n):
    shops.append(list(map(int, input().split())))
scores = []
for _ in range(n):
    scores.append(list(map(int, input().split())))

cans = []
def dfs(ind, array):
    if ind == 10:
        cans.append(array)
    else:
        dfs(ind+1, array + [0])
        dfs(ind+1, array + [1])
dfs(0, [])
cans.remove([0 for _ in range(10)])

totalscorelist = []
for one in cans:
    indexlist = []
    for other in shops:
        one = np.array(one)
        other = np.array(other)
        k = np.dot(one, other)
        indexlist.append(k)
    totalscore = 0
    for scorebord, index in zip(scores, indexlist):
        totalscore += scorebord[index]
    totalscorelist.append(totalscore)
print(max(totalscorelist))