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

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

ans = -1000000000
for i in range(1, 1<<10):
	psum = 0
	for j in range(n):
		cnt = 0
		for k in range(10):
			if ((i>>k) & 1)==1 and f[j][k]==1:
				cnt += 1
		psum += p[j][cnt]
	ans = max(ans, psum)
print(ans)

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

l=[]
for k in range(1,1024):
  l.append(format(k,'010b'))

L=[]
for m in range(1023):
  C=0
  for q in range(n):
    c=0
    for r in range(10):
      if f[q][r]*int(l[m][r])==1:
        c+=1
    C+=p[q][c]
  L.append(C)
print(max(L))

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)]
ans = -float('inf')
for v in product([0, 1], repeat=10):
    if v.count(1) == 0:
        continue
    tmp = 0
    for i in range(n):
        c = 0
        for j in range(10):
            if v[j] == 1 and f[i][j] == 1:
                c += 1
        tmp += p[i][c]
    ans = max(ans, tmp)
print(ans)

Solution (Python):
import math

N = int(input())

F = [None] * N
P = [None] * N

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

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

def rieki(shopIdx, joisinoBit):
    binStr = "".join(F[shopIdx])
    shopBit = int(binStr,2)

    common = shopBit & joisinoBit
    r = 0
    c = common
    while(c != 0):
        if c%2 == 1:
            r += 1
        c //= 2
    return P[shopIdx][r]


ma = -10**10
for bit in range(1,2 ** 10):
    r = 0
    for shopIdx in range(N):
        r += rieki(shopIdx, bit)
    ma = max(ma, r)

print(ma)

Solution (Python):
N = int(input())
F = []
P = []
for i in range(N):
    temp = [int(i) for i in input().split()]
    tt = 0b0
    for j in range(len(temp)):
        tt += 2 ** j * temp[j]
    F.append(tt)
    
for i in range(N):
    temp = [int(i) for i in input().split()]
    P.append(temp)

def bene(bit):
    res = 0
    for i in range(N):
        a = bit & F[i]
        cc = 0
        for j in str(bin(a)):
            if j == "1":
                cc += 1
        res += P[i][cc]
    return res

benes = [bene(i) for i in range(1,1024)]
benes.sort()
print(benes[-1])

Solution (Python):
def inpl(): return [int(i) for i in input().split()]
import numpy as np
N = int(input())
F = np.zeros((N, 10), dtype = int)
P = np.zeros((N, 11), dtype = int)
ans = -10**11
for i in range(N):
    F[i] = np.array(inpl())
for i in range(N):
    P[i] = np.array(inpl())
for ctr in range(1,1024):
    tmpans = 0
    ctr = list(map(int, bin(ctr)[2:]))
    ctr = np.array([0]*(10-len(ctr)) + ctr)
    for j in range(N):
        tmpans += P[j][np.dot(ctr,F[j])]
    ans = max(ans, tmpans)
print(ans)

Solution (Python):

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

res = None
for i in range(1,2**10):
    joisino = [str(i>>n&1) for n in range(10)]
    prof = 0
    for j in range(n):
        c = 0
        for k in range(10):
            if joisino[k]=="1" and f[j][k]=="1":
                c += 1
        prof += p[j][c]
    if res is None:
        res = prof
    else:
        res = max(res, prof)
print(res)

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

cnt=[0]*n
ans=tmp=0
for i in range(1,1<<10):
    tmp=0
    cnt=[0]*n
    for j in range(10):
        if (i&(1<<j)):
            for k in range(n):
                if (f[k][j]): cnt[k]+=1
    for l in range(n):
       tmp+=p[l][cnt[l]]
    if i==1: ans=tmp
    else: ans=max(ans,tmp)

print(ans)

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

ans = - 10 ** 10
for i in range(1, 2 ** 10):
    ans = max(ans, sum([P[j][bin(i&F[j]).count('1')] for j in range(N)]))
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)]

res = -float('inf')
for i in range(1,1<<10):
    a = [0]*n
    for j in range(10):
        for m in range(n):
            if i&1 and f[m][j]:
                a[m] += 1
        i >>= 1
    w = 0
    for j in range(n):
        w += p[j][a[j]]
    res = max(res,w)
print(res)

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

ans = -10**18
for b in range(1,2**10):
    tmp = 0
    for i in range(N):
        c = 0
        for k in range(10):
            if b&(1<<k) and F[i][k]:
                c += 1
        tmp += P[i][c]
    ans = max(ans,tmp)
print(ans)

Solution (Python):
n = int(input())
f = [[0 for j in range(10)] for i in range(n)]
p = [[0 for i in range(11)] for j in range(n)]
for i in range(n):
    f[i] = [int(i) for i in input().split()]
for i in range(n):
    p[i] = [int(i) for i in input().split()]

totalProfit = 0
N = [i for i in range(10)]  
for i in range(1, 1 << len(N)):
    output = []
    for j in range(len(N)):
        if ((i >> j) & 1) == 1:
            output.append(j)  
    profit = 0
    for j in range(n):
        sameOpen = 0
        for k in output:
            if f[j][k] == 1:  
                sameOpen += 1
        profit += p[j][sameOpen]
        
    
    if i == 1:
        totalProfit = profit
    else:
        totalProfit = max(totalProfit, profit)
print(totalProfit)

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

maxp = -100000000000
def culc(nowt, open):
    global n
    global f
    global p
    global maxp
    if 10 <= nowt:
        tmp_max = 0
        for i in range(n):
            count = 0
            for j in range(10):
                if f[i][j] == 1 and open[j] == 1:
                    count += 1
            tmp_max += p[i][count]
        maxp = max(maxp, tmp_max)
    else:
        culc(nowt + 1, open + [0])
        culc(nowt + 1, open + [1])
for i in range(1, 11):
    culc(i, [0] * (i - 1) + [1])
print(maxp)

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)]
combos = sorted(list(itertools.product([0, 1], repeat=10)))
ans = -float('inf')

for combo in combos[1:]:
  total = 0

  for i in range(len(F)):
    count = 0      
    for a, b in zip(combo, F[i]):
      if a == 1 and b == 1:
        count += 1
    total += P[i][count]
  
  ans = max(ans, total)

print(ans)

Solution (Python):
N = int(input())
isopen = [list(map(int,input().split())) for i in range(N)]
gain = [list(map(int,input().split())) for i in range(N)]
 
ans = -float('inf')
for i in range(1,2**10):
    tmp = 0
    for n in range(N):
        c = 0
        for b in range(10):
            if (i >> b) & isopen[n][b]:
                c += 1
        tmp += gain[n][c]
    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)]
result = -(10 ** 7) * 100

for i in range(1, 1024):
    array = []
    num = i
    for _ in range(10):
        array.append(num%2)
        num //= 2

    point = 0
    for j in range(N):
        counter = 0
        for k in range(10):
            if array[k] == 1 and F[j][k] == 1:
                counter += 1

        point += P[j][counter]

    result = max(result, point)

print(result)

Solution (Python):
N=int(input())
Time_Table=[[int(i) for i in input().split()] for i in range(N)]
Price=[[int(i) for i in input().split()] for i in range(N)]
S=-10000000000000
for i in range(1,1024):
  List_kari=[]
  List=[0]*10
  List_kari=list(str(bin(i))) 
  S_kari=0
  del List_kari[0:2]
  for j in range(len(List_kari)):
    List[9-j]=int(List_kari[len(List_kari)-j-1])
  for k in range(N):
    m=0
    for n in range(10):
      if Time_Table[k][n]==1 and List[n]==1:
        m+=1
    S_kari+=Price[k][m]    
  if S<S_kari:
    S=S_kari
print(S)

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())))
    
    
def calc_profit(open_list):
    if not (True in open_list):
        return -10**27
    count = [0 for i in range(N)]
    for i in range(10):
        if open_list[i]:
            for j in range(N):
                if F[j][i]==1:
                    count[j]+=1
    profit=0
    for i in range(N):
        profit+=P[i][count[i]]
    return profit

def get_max(l):
    if len(l)==10:
        return calc_profit(l)
    else:
        return max(get_max(l+[True]),get_max(l+[False]))

print(get_max([]))

Solution (Python):
n = int(input())
f = []
for i in range(n):
    f.append([int(m) for m in input().split()])
p = []
for i in range(n):
    p.append([int(m) for m in input().split()])

fcount = 0
pcount= 0
pli = []
for i0 in range(2):
    for i1 in range(2):
        for i2 in range(2):
            for i3 in range(2):
                for i4 in range(2):
                    for i5 in range(2):
                        for i6 in range(2):
                            for i7 in range(2):
                                for i8 in range(2):
                                    for i9 in range(2):
                                        ili = [i0,i1,i2,i3,i4,i5,i6,i7,i8,i9]
                                        if ili != [0,0,0,0,0,0,0,0,0,0]:
                                            for j in range(n):
                                                for k in range(10):
                                                    if ili[k] == f[j][k] and ili[k] == 1:
                                                        fcount += 1
                                                pcount += p[j][fcount]
                                                fcount = 0
                                            pli.append(pcount)
                                            pcount = 0
print(max(pli))

Solution (Python):
n = int(input())
f = []
for _ in [0]*n:
  f += [list(map(int,input().split()))]
p = []
for _ in [0]*n:
  p += [list(map(int,input().split()))]
m = -10000001*n
for x in range(1,1024):
  k = 0
  s = format(x,'010b')
  for t in range(n):
    k += p[t][sum([int(s[i])*f[t][i] for i in range(10)])]
  m = max(m,k)
print(m)

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

def bc10(num):
    num_tmp = num
    ret = 0
    for i in range(10):
        if num_tmp % 2: ret += 1
        num_tmp = num_tmp >> 1
    return ret


F_mask = [0] * N
for i, F_row in enumerate(F): F_mask[i] += sum([(2 ** j) * item for j, item in enumerate(F_row)])

ans = - (10 ** 7) * N
for case in range(1, 2 ** 10):
    
    joisino = 0
    case_tmp = case
    for i in range(10):
        joisino += (case_tmp % 2) << i
        case_tmp = case_tmp >> 1
    
    profit = 0
    for i, enemy in enumerate(F_mask): profit += P[i][bc10(joisino & enemy)]
    
    
    if ans < profit: ans = profit

print(ans)

Solution (Python):
N = int(input())
F=[]
P=[]
k=[0]*10
for i in range(N):
    F.append(list(map(int, input().strip().split())))
for i in range(N):
    P.append(list(map(int, input().strip().split())))


ans=-10**10
for i in range(1,2**11-1):
    tmp=0
    s='{0:010b}'.format(i)
    for k in range(N):
        c=0
        for j in range(10):
            if (int(s[j])+F[k][j])==2:
                c+=1
        tmp+=P[k][c]
    ans=max(ans,tmp)
    
print(ans)

Solution (Python):
import sys
def 解():
    input = sys.stdin.readline
    iN = int(input())
    
    
    
    
    aF = list(map(lambda x:int(input().rstrip().replace(' ',''),2),range(iN)))
    
    
    aP = list(map(lambda x:[int(_) for _ in input().split()],range(iN)))
    iD = 2**10
    
    
        
    
        
        
    
    
    
    print(max(sum( map(lambda x:aP[x][bin(aF[x] & i).count("1")],range(iN)))for i in range(1,iD)))
    
解()

Solution (Python):
import sys
def 解():
    input = sys.stdin.readline
    iN = int(input())
    aF = [0]*iN
    aP = [0]*iN
    
    
    aF = list(map(lambda x:int(input().rstrip().replace(' ',''),2),range(iN)))
    
    
    aP = list(map(lambda x:[int(_) for _ in input().split()],range(iN)))
    iD = 2**10
    iMax = -1*(10**10)
    for i in range(1,iD):
        
        iM = sum(map(lambda x:aP[x][bin(aF[x] & i).count("1")],range(iN)))
        
        
        if iMax < iM:
            iMax = iM
    print(iMax)
解()

Solution (Python):
import sys
def 解():
    input = sys.stdin.readline
    iN = int(input())
    aF = [0]*iN
    aP = [0]*iN
    for i in range(iN):
        aF[i] = int(input().rstrip().replace(' ',''),2)
    for i in range(iN):
        aP[i] = [int(_) for  _ in input().split()]
    iD = 2**10
    iMax = -1*(10**10)
    for i in range(1,iD):
        iM = 0
        for j in range(iN):
            iM += aP[j][bin(aF[j] & i).count("1")]
        if iMax < iM:
            iMax = iM
    print(iMax)
解()

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)]
total = -10**10
for i in range(1, 1024):
    x = list(map(int, list(format(i, '010b'))))
    tmp = 0
    for j in range(n):
        a = 0
        for k in range(10):
            a += x[k] * f[j][k]
        tmp += p[j][a]
    total = max(tmp, total)
print(total)

Solution (Python):

"""
Created on Sun Nov  4 17:22:42 2018
ABC080
@author: maezawa
"""
import itertools as itr

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


profit = -10**10
for oph in itr.product([0,1], repeat=10):
    if oph == (0,0,0,0,0,0,0,0,0,0):
        continue
    c = [0]*n
    for i in range(n):
        c[i] = sum([f[i][j]*oph[j] for j in range(10)])
    pcurrent = sum([p[i][c[i]] for i in range(n)])
    if pcurrent > profit:
        profit = pcurrent
        

print(profit)

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):
    A = list(format(i, "b").zfill(10))
    Index = []
    for j in range(10):
        if A[j] == "1":
            Index.append(j)
    Benefit = 0
    for j in range(N):
        count = 0
        for a in Index:
            if F[j][a] == 1:
                count += 1
        Benefit += P[j][count]
    Ans = max(Ans, Benefit)
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)]

cross = [0]*n
profit = 0
max = 0
for i in range(n):
    if f[i][0] == 1:
        cross[i] = cross[i] + 1

for i in range(n):
    for j in range(10):
        if cross[i] == j:
            profit = profit + p[i][j]

max = profit
cross = [0]*n
profit = 0

for day in range(1, 2047):
    S = format(day, 'b').zfill(10)
    
    for j in range(10):
        if S[j] == str(1):
            for i in range(n):
                if f[i][j] == 1:
                   cross[i] = cross[i] + 1

    for i in range(n):
        for j in range(10):
           if cross[i] == j:
               profit = profit + p[i][j]

    if profit >= max:
        max = profit
    
    cross = [0]*n
    profit = 0

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_num = -10000001 * 1000
sum = 0

for i in range(1024):
    if i == 0:
        continue
    b = bin(i)
    for n in range(N):
        f = F[n]
        s = ""
        for _n in range(10):
            s += str(f[_n])
        s = "0b" + s
        and_num = int(b, 0) & int(s, 0)
        match_nums = list(format(and_num, 'b'))
        match_num = 0
        for _n in match_nums:
            if int(_n) == 1:
                match_num += 1
        sum += P[n][match_num]
    if sum > max_num:
        max_num = sum
    sum = 0
print(max_num)

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

e_list = []

for i in range(1,1024):
    temp = i
    temp_l = []
    for j in range(10):
        temp_l.append(temp % 2)
        temp = temp // 2

    temp_l.reverse()
    e_list.append(temp_l)

ans = []

for wk in e_list:
    plice = 0
    for fi,pi in zip(F,P):
        c_num = 0
        for f,e in zip(fi,wk):
            if e == 1 and e == f:
                c_num += 1

        plice += pi[c_num]
    ans.append(plice)

print(max(ans))

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

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

num = -float("inf")
for i in range(1, 1 << 10):
    tmp = 0
    for k in range(N):
        rec = 0
        for j in range(10):
            if i & 1 << j and F[k][j]:
                rec += 1
        tmp += P[k][rec]
    num = max(num, tmp)

print(num)

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

ans = -float('inf')
for k in range(1,1<<10):
    tmp = 0
    for fs,ps in zip(F,P):
        cnt = 0
        for b in range(10):
            if (k>>b)&1 and fs[b]:
                cnt += 1
        tmp += ps[cnt]
    ans = max(ans, tmp)
print(ans)

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

res = []
for i in range(1, 2**10 + 1):
    index = list("0000000000")
    binary = list(bin(i)[2:])
    index[-len(binary):] = binary
    index = list(map(int, index))
    kaburi = [sum([i * f for i, f in zip(index, F[n])]) for n in range(N)]
    res.append(sum([P[n][k] for n, k in zip(range(N), kaburi)]))

print(max(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 = -float('inf')
for k in range(1,1<<10):
    tmp = 0
    for fs,ps in zip(F,P):
        cnt = 0
        for b in range(10):
            if (k>>b)&1 and fs[b]:
                cnt += 1
        tmp += ps[cnt]
    ans = max(ans, tmp)
print(ans)

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

sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

def dfs(depth:int, inbis:str, f:list, p:list):
    if depth != 10:
        return max(dfs(depth+1, inbis+"1",f,p),
                   dfs(depth+1, inbis+"0",f,p))
        
    else:
        if inbis.count("1") == 0:
            return -10**10
        else:
            biz = [int(i) for i in inbis]
            ans = 0
            for i in range(len(f)):
                common = [biz[j]*f[i][j] for j in range(10)]
                ans += p[i][sum(common)]
                
            return ans

n = ni()
f = []
p = []
for _ in range(n):
    f.append(list(li()))
for _ in range(n):
    p.append(list(li()))
    
print(dfs(0,"",f,p))

Solution (Python):

import numpy as np
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=-1*pow(10,10)
ans_tmp=0
Self=[0]*10
c=0

for i in range(pow(2,10)):
    ans_tmp=0
    if i !=0:
        i_tmp = i
        for j in range(10):
            Self[j]=i_tmp//pow(2,9-j)
            i_tmp-=Self[j]*pow(2,9-j)
        for k in range(N):
            c=np.dot(F[k],Self)
            ans_tmp+=P[k][c]
        if ans<ans_tmp:
            ans=ans_tmp
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)]
P_list = []


for i in range(1, 2 ** 10):
    a = list(bin(i))[2::]
    while len(a) < 10:
        a = ["0"] + a
    P_list.append(a)
finalans = -1000000000000000
for i in P_list:
    ans = 0
    cnt = [0 for i in range(N)]
    for j in range(10):
        if i[j] == "1":
            for k in range(N):
                if F[k][j] == 1:
                    cnt[k] += 1
    for j in range(N):
        ans += P[j][cnt[j]]
    
    finalans = max(finalans, ans)

print(finalans)

Solution (Python):
from itertools import product
al=list(product([0,1],repeat=10))
n=int(input())
a=[list(map(int, input().split())) for i in range(n)]
p=[list(map(int, input().split())) for i in range(n)]
ans=-100000000000
for i in al:
    if sum(i)==0:continue
    q=0
    for j in range(n):
        count=0
        for k in range(10):
            if a[j][k]==1 and i[k]==1:
                count+=1
        q+=p[j][count]
    ans=max(ans,q)
print(ans)

Solution (Python):
import numpy as np
N = int(input())
opengrid = []
for i in range(N):
    array = list(map(int, input().strip().split(' ')))
    opengrid.append(array)
benefit = []
for i in range(N):
    array = list(map(int, input().strip().split(' ')))
    benefit.append(array)
i = 1
st = []
while i <= 1023:
  x = bin(i)[2:]
  y = '0'*(10-len(x))+x
  z = []
  for chara in y:
    z.append(int(chara))
  st.append(z)
  i += 1
maxx = -99999999999
for pat in st:
  j = 0
  ans = 0
  while j < N:
    v1 = np.array(pat)
    v2 = np.array(opengrid[j])
    x = np.dot(v1,v2)
    ans += benefit[j][x]
    j += 1
  maxx = max(maxx,ans)
print(maxx)

Solution (Python):
from itertools import product
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 = -float('inf')

def culc(F, P, l):
    ret = 0
    for i in range(N):
        c = sum([j == k == 1 for j, k in zip(F[i], l)])
        ret += P[i][c]
    return ret

for l in product([0,1],repeat=10):
    if sum(l) == 0:
        continue
    ans = max(ans, culc(F, P, l))
print(ans)

Solution (Python):
f = lambda: list(map(int,input().split()))

n = int(input())
F = [f() for _ in range(n)]
P = [f() for _ in range(n)]

from itertools import product
mul = product((0, 1), repeat=10)

ans = -float('inf')
for m in mul:
    if any(m):
        ben = 0
        for shop in range(n):
            op = sum(m[j] & F[shop][j] for j in range(10))
            ben += P[shop][op]
        ans = max(ans,ben)
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**10
for bit in range(1, 1<<10):
    score = 0
    for i in range(n):
        time = 0
        for t in range(10):
            if bit&(1<<t) and f[i][t] == 1:
                time += 1
        score += p[i][time]
    ans = max(ans, score)

print(ans)

Solution (Python):


def zehnpaard():
    from itertools import product

    n = int(input())
    fs = [[int(x) for x in input().split()] for _ in range(n)]
    ps = [[int(x) for x in input().split()] for _ in range(n)]

    xs = product((0, 1), repeat=10)
    next(xs)
    print(max(sum(p[sum(a==b==1 for a, b in zip(f, x))] for f, p in zip(fs, ps)) for x in xs))

def solver():
    import itertools
    N = int(input())

    
    Fs = [list(map(int, input().split())) for n in range(N)]
    Ps = [list(map(int, input().split())) for n in range(N)]

    
    Xs = itertools.product([0,1], repeat=10)
    next(Xs) 

    ans = (-10**7)*N
    for x in Xs:
        profit = 0
        for n in range(N):
            c = 0
            for a, b in zip(x, Fs[n]):
                if a==b==1:
                    c += 1
            profit += Ps[n][c]
        ans = max(ans, profit)
    print(ans)


if __name__ == "__main__":
    solver()

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

ans = -10000000000
for store in range(1, 1024):
    p_sum = 0
    for i, v in enumerate(f):
        c = v & store
        p_sum += p[i][bin(c).count('1')]
    ans = max(ans, p_sum)

print(ans)

Solution (Python):


INF = float('inf')


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


N = int(input())

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

ans = -INF
for i in range(1, 1 << 10):

    score = 0
    for shop in range(N):

        both_open = 0
        for period in range(10):
            if i >> period & F[shop][period] == 1:
                both_open += 1

        score += P[shop][both_open]

    ans = max(ans, score)

print(ans)

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

ret = -float('inf')
for i in range(1, 1024):
    k = 0
    for a in range(N):
        count = 0
        for j in range(10):
            if F[a][j] == 1 and i & (1 << j) > 0:
                count += 1
        k += D[a][count]

    ret = max(ret, k)

print(ret)

Solution (Python):
from itertools import product

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



best_score = float("-inf")

for i in product((0, 1), repeat=10):
    if sum(i) == 0:
        continue

    score = 0
    for k in range(n):
        num = sum([p * q for p, q in zip(i, F[k])])
        score += P[k][num]

    best_score = max(best_score, score)

print(best_score)

Solution (Python):
import math
N = int(input())
F = [[] * 10 for i in range(N)]
for i in range(N):
    F[i] = list(map(int, input().split()))
P = [[] * 11 for i in range(N)]
for i in range(N):
    P[i] = list(map(int, input().split()))
L = [0] * 10
Sum_max = -float("inf")
for i in range(1, 1024):
    for j in range(10):
        L[j] = i % 2
        i = int(i / 2)
    Sum = 0
    for j in range(N):
        count = 0
        for k in range(10):
            if L[k] == 1 and F[j][k] == 1:
                count += 1
        Sum += P[j][count]
    Sum_max = max(Sum_max, Sum)
print(Sum_max)

Solution (Python):
N=int(input())
F=[]
for i in range(N):
    tmp=list(input().split())
    F.append(int(''.join(tmp)))
P=[list(map(int, input().split())) for _ in range(N)]
ans=-float("inf")
for i in range(1,1<<10):
    s=[]
    for j in range(N):
        tmp=str(bin(i & int(str(F[j]), 2)))
        s.append(P[j][sum(list(map(int, list(tmp[2:]))))])
    if ans<sum(s):
        ans=sum(s)
print(ans)

Solution (Python):


from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


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 = -INF
    for p in product([0, 1, 2, 3], repeat=5):
        if sum(p) == 0:
            continue
        t = 0
        for n in range(N):
            num = 0
            for y in range(0, 10, 2):
                if p[y // 2] == 1:
                    num += F[n][y]
                if p[y // 2] == 2:
                    num += F[n][y + 1]
                if p[y // 2] == 3:
                    num += F[n][y] + F[n][y + 1]

            t += P[n][num]
        ans = max(ans, t)
    
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
from itertools import product

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 = -1e9-1
for i in product((0,1),repeat=10):
  gain = 0
  if i == (0,0,0,0,0,0,0,0,0,0):
    continue
  for j in range(N):
    cnt = 0
    for k in range(10):
      cnt += i[k]*F[j][k]
    gain += P[j][cnt]
  ans = max(ans,gain)

print(ans)

Solution (Python):
import sys

input = sys.stdin.readline

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

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