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())
open=[]
for i in range(n):
    a=list(map(int,input().split()))
    open.append(a)
point=[]
for i in range(n):
    p=list(map(int,input().split()))
    point.append(p)

ans=-float("inf")
for i in range(1,2**10):
    tmp=0
    joi_open=[0]*10
    for j in range(10):
        if (i>>j)&1:
            joi_open[j]=1
    for j in range(n):
        cnt=0
        for k in range(10):
            if open[j][k]==joi_open[k]==1:
                cnt+=1
        tmp+=point[j][cnt]
    ans=max(ans,tmp)
print(ans)

Solution (Python):
def solve():
    import numpy as np
    n = int(input())
    oc = [list(map(int, input().split())) for _ in range(n)]
    prof = [list(map(int, input().split())) for _ in range(n)]

    oc = np.array(oc)
    prof = np.array(prof)

    inf = 10 ** 10
    ans = - inf

    for a in range(1, 1 << 10):
        res = np.zeros(n, dtype=np.int64)
        for b in range(10):
            if a >> b & 1:
                res += oc[:, b]
        tmp = 0
        for i, x in enumerate(res):
            tmp += prof[i, x]
        ans = max(ans, tmp)
    print(ans)


solve()

Solution (Python):
def solve():
    n = int(input())
    oc = [list(map(int, input().split())) for _ in range(n)]
    prof = [list(map(int, input().split())) for _ in range(n)]

    inf = 10 ** 16
    ans = - inf

    for a in range(1, 1 << 10):
        res = 0
        for i in range(n):
            cnt = 0
            for x in range(10):
                if a >> x & 1 and oc[i][x] == 1:
                    cnt += 1
            res += prof[i][cnt]
        ans = max(ans, res)
    print(ans)


solve()

Solution (Python):
def solve():
    import numpy as np
    n = int(input())
    oc = [[] for _ in range(n)]
    prof = [[] for _ in range(n)]

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

    oc = np.array(oc)
    prof = np.array(prof)

    ans = -9999999999

    for a in range(1, 1 << 10):
        res = np.zeros(n, dtype=np.int64)
        for b in range(10):
            if a >> b & 1:
                res += oc[:, b]
        
        tmp = 0
        for i, x in enumerate(res):
            tmp += prof[i, x]
        
        ans = max(ans, tmp)
    print(ans)


solve()

Solution (Python):
def solve():
    n = int(input())
    oc = [list(map(int, input().split())) for _ in range(n)]
    prof = [list(map(int, input().split())) for _ in range(n)]

    ans = -9999999999

    for a in range(1, 1 << 10):
        res = 0
        for i in range(n):
            cnt = 0
            for x in range(10):
                if (a >> x) % 2 == 1 and oc[i][x] == 1:
                    cnt += 1
            res += prof[i][cnt]
        ans = max(ans, res)
    print(ans)


solve()

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

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

print(ans)

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

F = np.empty((N,10))
P = np.empty((N,11))
for i in range(N):
  Flist = np.array(list(map(int, input().split())), dtype = int)
  F[i] = Flist
for i in range(N):
  Plist = np.array(list(map(int, input().split())), dtype = int)
  P[i] = Plist
BenefitMax = 0

for i in range(1,1024):
  A = np.zeros(10)
  iForBin = i
  for j in range(10):
    if iForBin %2 == 1:
      A[j] = 1
    iForBin = iForBin // 2
  ADotF = np.tensordot(A,F,((0),(1)))
  Benefit = 0
  for j in range(N):
    Benefit += P[j,int(ADotF[j])]
  if i == 1:
    BenefitMax = Benefit
  else:
    if BenefitMax < Benefit:
      BenefitMax = Benefit

print(int(BenefitMax))

Solution (Python):
from itertools import product
N=int(input())

F=[]
P=[]

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

ans=-10**10
for p in product(range(2),repeat=10):
    if len(set(p))==1 and p[0]==0:
        continue
    p_ = 0
    for idx,f in enumerate(F):
        c=0
        for i in range(10):
            c += f[i]*p[i]
        p_ += P[idx][c]
        
    if ans < p_:
        ans=p_
        
print(ans)

Solution (Python):
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)])
 
ans = - (10 ** 11)
 
for n in range(1, 1024):
    bits = np.array(list(map(int, list('{:010b}'.format(n)))))
    dup = np.sum(F * bits, axis=1)
    ans = max(ans, np.sum(P[range(N), dup]))

print(ans)

Solution (Python):
n = int(input())
data1 = [list(map(int,input().split())) for _ in range(n)]
data2 = [list(map(int,input().split())) for _ in range(n)]
ans = []
trans = -1
for i in range(2**10):
    S = [0]*n
    l = 0
    for j in range(10):
        for k in range(n):
            S[k] += data1[k][j]*((i>>j)&1)
    for j in range(n):
        l += data2[j][S[j]]
    ans.append(l)
    if not i:
        trans = l
ans.sort()
print(ans[-1] if ans[-1] != trans else ans[-2])

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

Solution (Python):
n=int(input())
m=10
f=[list(map(int,input().split())) for _ in range(n)]
p=[list(map(int,input().split())) for _ in range(n)]
ans=-10**18
for i in range(1,2**m):
  s=0
  for j in range(n):
    cnt=0
    for k in range(m):
      if (i>>k)&1 and f[j][k]:
        cnt+=1
    s+=p[j][cnt]
  ans=max(s,ans)
print(ans)

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


inf = float("inf")
ans = -inf
for i in range(1, 2**10):
    op = []
    for j in range(10):
        if (i >> j) & 1:
            op.append(1)
        else:
            op.append(0)

    res = 0
    for k in range(N):
        temp = 0
        for l in range(10):
            if op[l] == 1 and F[k][l] == 1:
                temp += 1
        res += P[k][temp]
    ans = max(ans, res)

print(ans)

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

ans = -9999999999
for item in range(1,2**10):
  fund = 0
  for i in range(N):
    cou = 0
    for x in range(10):
      if (item >> x) % 2 == 1 and arr[i][x] == 1:
        cou += 1
    fund += arm[i][cou]
  ans = max(ans, fund)

print(ans)

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

res = -float('inf')
for i in range(1, 2 ** 10):
    profit = 0
    for j in range(n):
        cnt = 0
        for k in range(10):
            if (i >> (9 - k)) & 1 and f[j][k]:
                cnt += 1
        profit += p[j][cnt]
    res = max(res, profit)

print(res)

Solution (Python):
import sys
import itertools

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')

INF = 10**9 + 7


def main():
    N = in_n()
    F = [in_nl() for _ in range(N)]
    P = [in_nl() for _ in range(N)]

    comb = list(itertools.product(range(2), repeat=10))[1:]

    ans = -INF
    for com in comb:
        r = 0
        for i in range(N):
            count = 0
            for j in range(10):
                if F[i][j] == com[j] == 1:
                    count += 1
            r += P[i][count]
        ans = max(ans, r)

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
f=[list(map(int,input().split())) for i in range(n)]
p=[list(map(int,input().split())) for i in range(n)]
ans=-(10**10)
for i in range(1,1024):
    bit=bin(i)[2:].zfill(10)
    a=0
    for j in range(n):
        b=0
        for k in range(10):
            if int(bit[k]) and f[j][k]:
                b+=1
        a+=p[j][b]
    ans=max(ans,a)
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)]

result = -float('inf')
for i in product([True, False], repeat=10):
    if i.count(False) == 10:
        continue
    t = 0
    for j in range(N):
        t += P[j][sum(1 & F[j][k] for k in range(10) if i[k])]
    result = max(result, t)
print(result)

Solution (Python):
n = int(input())
F = [tuple(int(x) for x in input().split()) for _ in range(n)]
P = [tuple(int(x) for x in input().split()) for _ in range(n)]
ans = -10**18
for bit in range(1, 1<<10):
    A = [0] * n  
    for i in range(10):
        if bit & (1<<i):  
            for j in range(n):
                if F[j][i] == 1:
                    A[j] += 1
    profit = 0
    for j in range(n):
        profit += P[j][A[j]]
    ans = max(ans, profit)
print(ans)

Solution (Python):
n = int(input())
F = []
ans = -float('inf')
for i in range(n):
    a = "".join(input().split())
    a = int(a, 2)
    F.append(a)
p = [list(map(int,input().split())) for i in range(n)]
for i in range(1,2**10):
    tmp = 0
    for j in range(n):
        cnt = bin(i&F[j]).count("1")
        tmp +=p[j][cnt]
    else:
        ans = max(ans,tmp)
print(ans)

Solution (Python):





import math
import fractions
import sys
import bisect
import heapq  
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr



def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod



def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a


inf = 10 ** 18
mod = 10 ** 9 + 7

n = ir()
f = [lr() for i in range(n)]
p = [lr() for i in range(n)]
ans = -inf
for i in range(1,2**10):
    pre = 0
    num = [0 for k in range(n)]
    for j in range(10):
        if (i >> j) & 1:
            for k in range(n):
                num[k] += f[k][j]
    for j in range(n):
        pre += p[j][num[j]]
    ans = max(ans, pre)
print(ans)

Solution (Python):
def solve():
    N = int(input())
    F = []
    for _ in range(N):
        f = list(map(int,input().split()))
        F.append(f)
    
    P = []
    for _ in range(N):
        p = list(map(int,input().split()))
        P.append(p)
    
    ans = -float('inf')
    for i in range(1, 1 << 10):
        me = [0] * 10
        for j in range(10):
            if (i >> j) & 1:
                me[j] = 1

        c = []
        for j in range(N):
            cnt = 0
            for k in range(10):
                if F[j][k] == 1 and me[k] == 1:
                    cnt += 1
            
            c.append(cnt)
        
        now = 0
        for j in range(N):
            now += P[j][c[j]]
        
        ans = max(ans, now)
    
    print(ans)
    
if __name__ == '__main__':
    solve()

Solution (Python):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
fs = [None]*n
for i in range(n):
    l = list(map(int, input().split()))
    fs[i] = set([i for i in range(10) if l[i]])
p = [None]*n
for i in range(n):
    p[i] = list(map(int, input().split()))
ans = -float("inf")
for b in range(1<<10):
    if b==0:
        continue
    score = 0
    s = set()
    for i in range(10):
        if b>>i&1:
            s.add(i)
    for i in range(n):
        score += p[i][len(s&fs[i])]
    ans = max(ans, score)
print(ans)

Solution (Python):
n = int(input())
f = []
ans = -10**9

for i in range(n):
    a = input().split()
    f.append(a)

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

for i in range(1, 2**10):
    ref = 0
    i = str(bin(i))[2:].zfill(10)
    for j in range(n):
        cnt = 0
        for k in range(10):
            if i[k] == f[j][k] == "1":
                cnt += 1
        ref += p[j][cnt]
    else:
        ans = max(ans, ref)

print(ans)

Solution (Python):
N = int(input())
F = []
for i in range(N):
    A = list(map(int, input().split()))
    F.append(A[::-1])
 
P = []
for i in range(N):
    A = list(map(int, input().split()))
    P.append(A)
 
result = float("inf")*(-1)
for i in range(1, 2**10):
    ans = 0
    for l in range(N):
        c = 0
        for j in range(10):
            if ((i>>j) & 1):
                if F[l][j] == 1:
                    c += 1
        ans += P[l][c]
    result = max(ans, result)
print(result)

Solution (Python):
from itertools import product
def main():
    N = int(input())
    F = []
    for _ in range(N):
        f = list(map(int, input().split()))
        F.append(f)
    P = []
    for _ in range(N):
        p = list(map(int, input().split()))
        P.append(p)
    m = -10**21
    for i in product(range(2), repeat=10):
        if sum(i) == 0:
            continue
        r = 0
        for j in range(N):
            r += P[j][sum(ii&jj for ii, jj in zip(i, F[j]))]
        m = max(r, m)
    return m
print(main())

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(2**10):
    bag = []
    for j in range(10):
        if (i>>j)&1:
            bag += [j]

    tmp = 0
    is_cnt = False
    for n in range(N):
        f = F[n]
        cnt = 0
        for b in bag:
            if f[b] == 1:
                cnt += 1
        tmp += P[n][cnt]
        if cnt:
            is_cnt = True
    
    if is_cnt:
        ans = max(ans, tmp)

print(ans)

Solution (Python):
import itertools
N=int(input())
F=[list(map(int,input().split())) for _ in range(N)]
P=[list(map(int,input().split())) for _ in range(N)]
ans=-10**9
for i in list(itertools.product(range(2),repeat=10)):
  if sum(i)==0:
    continue
  bns=0
  for j in range(N):
    b=0
    for k in range(10):
      if i[k]*F[j][k]==1:
        b+=1
    bns+=P[j][b]
  ans=max(ans,bns)
print(ans)

Solution (Python):
n = int(input())
f = []
ans = -10**9

for i in range(n):
    a = "".join(input().split())
    a = int(a, 2)
    f.append(a)

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

for i in range(1, 2**10):
    ref = 0
    for j in range(n):
        cnt = bin(i&f[j]).count("1")
        ref += p[j][cnt]
    else:
        ans = max(ans, ref)

print(ans)

Solution (Python):
n = int(input())
f = []
ans = -10**9

for i in range(n):
    a = "".join(input().split())
    a = int(a, 2)
    f.append(a)

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

for i in range(1, 2**10):
    ref = 0
    for j in range(n):
        cnt = bin(i & f[j]).count("1")
        ref += p[j][cnt]
    else:
        ans = max(ans, ref)

print(ans)

Solution (Python):
n = int(input())
l = []
m = []
ans = -10**9

for i in range(n):
    f = "".join(input().split())
    f = int(f, 2)
    l.append(f)

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

for i in range(1, 2**10):
    ref = 0
    for j in range(n):
        cnt = bin(i & l[j]).count("1")
        ref += m[j][cnt]
    else:
        ans = max(ans, ref)

print(ans)

Solution (Python):
import itertools
N = int(input())
F =[ list(input().split()) for i in range(N)]
P =[ list(input().split()) for i in range(N)]
set01 = list(itertools.product('01',repeat = 10))
counter = []
ans = -10**9
for s01 in set01:
    if s01 != ("0","0","0","0","0","0","0","0","0","0"):
        prof = 0
        for i in range(N):
            counter = 0
            for j in range(10):
                if s01[j] =="1" and F[i][j] == "1":
                    counter += 1
            prof += int(P[i][counter])
        ans = max(ans,prof)
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 = -(1<<30)

for b in range(1,1<<10):
  cc = 0
  for i in range(N):
    c = 0
    for j in range(10):
      if (b>>j&1) & F[i][j]:
        c+=1
    cc += P[i][c]
  if res<cc:
    res = cc
    
print(res)

Solution (Python):
n = int(input())
f = [list(map(int, input().split())) for _ in range(n)]
p = [list(map(int, input().split())) for _ in range(n)]
ans = -float("inf")
for i in range(1,2**10):
    res = 0
    for j in range(n):
        tnp = 0
        for k in range(10):
            if ((i>>k)&1):
                if (f[j][k]==1):
                    tnp += 1
        res += p[j][tnp]
    ans = max(ans,res)
print(ans)

Solution (Python):
def count_set_bits(n):
    count = 0
    while n:
        count += n & 1
        n >>= 1
    return count


N = int(input())
F = [int("".join(input().split()), 2) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]
ans = -float("inf")
for i in range(1, 1 << 10):
    tmp = 0
    for j in range(N):
        tmp += P[j][count_set_bits(i & F[j])]
    ans = max(ans, tmp)
print(ans)

Solution (Python):
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(map(int,input().split()))
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

N = i()
F = [l() for _ in range(N)]
P = [l() for _ in range(N)]
ans = INF*-1
for bit in range(1,1<<10):
    nans = 0
    B = [(bit>>i)&1 for i in range(10)]
    for i in range(N):
        cnt = 0
        for j in range(10):
            if B[j] == 1 and F[i][j] == 1:
                cnt += 1
        nans += P[i][cnt]
    ans = max(ans,nans)
print(ans)

Solution (Python):
N = int(input())
F = [0] * N
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()))



ans = - 10 ** 10

for i in range(1, 2 ** 10):
  open_n = [0] * N
  profit = 0
  for j in range(10):
    if ((i >> j) & 1):
      for k in range(N):
        if F[k][j] == 1:
          open_n[k] += 1
  for l in range(N):
    profit += P[l][open_n[l]]
  if ans < profit:
    ans = profit
          
print(ans)

Solution (Python):
def main():
    N = int(input())
    F = [list(map(int, input().split())) for _ in range(N)]
    P = [list(map(int, input().split())) for _ in range(N)]
    ans = -(10**15)
    for i in range(2**10):
        tmp = []
        for j in range(10):
            if ((i >> j) & 1):
                tmp.append(j)
        if not tmp:
            continue
        score = 0
        for k in range(N):
            cnt = 0
            for l in range(10):
                if F[k][l] == 1 and l in tmp:
                    cnt += 1
            score += P[k][cnt]

        ans = max(ans, score)

    print(ans)
if __name__ == "__main__":
    main()

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

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

result = float("inf")*(-1)
for i in range(1, 2**10):
    ans = 0
    for l in range(N):
        c = 0
        for j in range(10):
            if ((i>>j) & 1):
                if F[l][j] == 1:
                    c += 1
        ans += P[l][c]
    result = max(ans, result)
print(result)

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

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

ans=-10**12
for i in range(1, 1<<10):
    tmp=0
    for j in range(n):
        consist=f[j]&i
        cnt=0
        for k in range(10):
            if (consist>>k)%2:
                cnt+=1
        tmp+=p[j][cnt]
    ans=max(ans,tmp)
print(ans)

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

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

ans=-10**12
for i in range(1, 1<<10):
    tmp=0
    for j in range(n):
        consist=list(bin(f[j]&i)[2:])
        cnt=0
        for k in consist:
            if k=='1':
                cnt+=1
        tmp+=p[j][cnt]
    ans=max(ans,tmp)
print(ans)

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

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

result = float("inf")*(-1)
for i in range(1, 2**10):
    ans = 0
    for l in range(N):
        c = 0
        for j in range(10):
            if ((i>>j) & 1):
                if F[l][j] == 1:
                    c += 1
        ans += P[l][c]
    result = max(ans, result)
print(result)

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):
    score = 0
    jonson = [0 for _ in range(10)]

    
    for j in range(10):
        if ((i >> j)&1):
            jonson[j] = 1
    
    for k in range(N):
        cnt = 0
        for l in range(10):
            if F[k][l] == jonson[l] == 1:
                cnt += 1
        score += P[k][cnt]

    ans = max(score, ans)

print(ans)

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

ci = 0
c = []
P_max = -1000000000
for i in range(2):
    for j in range(2):
        for k in range(2):
            for l in range(2):
                for m in range(2):
                    for n in range(2):
                        for o in range(2):
                            for p in range(2):
                                for q in range(2):
                                    for r in range(2):
                                        if i==0 and j==0 and k==0 and l==0 and m==0 and n==0 and o==0 and p==0 and q==0:
                                            r = 1
                                        P_sample = 0
                                        for s in range(N):
                                            ci = F[s][0]*i + F[s][1]*j + F[s][2]*k + F[s][3]*l + F[s][4]*m + F[s][5]*n + F[s][6]*o + F[s][7]*p + F[s][8]*q + F[s][9]*r
                                            P_sample += P[s][ci]
                                        P_max = max(P_max, P_sample)

print(P_max)

Solution (Python):
n = int(input())
op = []
for _ in range(n):
    l = list(map(int, input().split()))
    op.append(l)
score = []
for _ in range(n):
    l = list(map(int, input().split()))
    score.append(l)
final = -999999999999999999999999


for pat in range(1,2**10):
    openNum = [0] * n
    for i in range(10):
        if ((pat >> i) & 1) == 1:
            for j in range(n):
                if op[j][i] == 1:
                    openNum[j] += 1
    res = 0
    for i in range(n):
        res += score[i][openNum[i]]
    final = max(final, res)
print(final)

Solution (Python):
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)])

ans = - (10 ** 11)

for n in range(1, 1024):
    bits = np.array(list(map(int, list('{:010b}'.format(n)))))
    dup = np.sum(F * bits, axis=1)
    ans = max(ans, np.sum(P[range(N), dup]))

print(ans)

Solution (Python):
def popcnt(n):
    c = (n & 0x5555555555555555) + ((n >> 1) & 0x5555555555555555)
    c = (c & 0x3333333333333333) + ((c >> 2) & 0x3333333333333333)
    c = (c & 0x0f0f0f0f0f0f0f0f) + ((c >> 4) & 0x0f0f0f0f0f0f0f0f)
    c = (c & 0x00ff00ff00ff00ff) + ((c >> 8) & 0x00ff00ff00ff00ff)
    c = (c & 0x0000ffff0000ffff) + ((c >> 16) & 0x0000ffff0000ffff)
    c = (c & 0x00000000ffffffff) + ((c >> 32) & 0x00000000ffffffff)
    return c


n = int(input())
f = [sum([(1 << (9 - x)) * y for x, y in enumerate(list(map(int, input().split())))]) for _ in range(n)]
p = [list(map(int, input().split())) for _ in range(n)]

ans = -1 << 60
for i in range(1, 1024):
    tmp = 0
    for x, y in zip(f, p):
        tmp += y[popcnt(i & x)]
    ans = max(ans, tmp)

print(ans)

Solution (Python):
n = int(input())
F = [[*map(int, input().split())] for _ in range(n)]
P = [[*map(int, input().split())] for _ in range(n)]
ans = -10000000*100
for i in range(1, 1<<10): 
    s = 0
    for j in range(n): 
        cj = 0
        for k in range(10):
            if i>>k & 1 and F[j][k]: cj += 1
        s += P[j][cj]
    ans = max(ans ,s)
print(ans)

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

def c(i, open_pattern):
    ret = 0
    for j in range(10):
        if open_pattern>>j & 1: 
            if F[i][j]: ret += 1 
    return ret

ans = -10000000*100
for i in range(1, 1<<10): 
    s = 0
    for j in range(n): 
        cj = c(j, i)
        s += P[j][cj]
    ans = max(ans ,s)
print(ans)

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

def c(i, open_patern):
    ret = 0
    for j in range(10):
        if open_patern>>j & 1: 
            if F[i][j]: ret += 1 
    return ret

ans = -10000000*100
for i in range(1, 1<<10): 
    s = 0
    for j in range(n): 
        cj = c(j, i)
        s += P[j][cj]
    ans = max(ans ,s)
print(ans)

Solution (Python):
n = int(input())
F = []











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



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



def c(i, open_my_shop):
    ret = 0
    for j in range(10):
        if open_my_shop>>j & 1: 
            if F[i][j]: 
                ret += 1
    return ret

ans = -10*10000000*10









for i in range(1, 1<<10): 
    s = 0
    for j in range(n): 
        cj = c(j, i)
        s += P[j][cj]
    ans = max(ans ,s)

print(ans)

Solution (Python):
n=int(input())
f=[0]*n
p=[0]*n
INF=10**9
for i in range(n):
    f[i]=list(map(int,input().split()))
for i in range(n):
    p[i]=list(map(int,input().split()))
ans=-INF
for i in range(1,1<<10):
    cnt=0
    l=[0]*n
    for j in range(10):
        if (i>>j)%2==1:
            for h in range(n):
                if f[h][j]==1:
                    l[h]+=1
    x=0
    for i in range(n):
        x+=p[i][l[i]]
    ans=max(x,ans)
print(ans)

Solution (Python):
def solve(bit):
    ret = 0
    for i in range(n):
        cnt = 0
        for j in range(10):
            if L[i][j] == bit[j] == 1:
                cnt += 1
        ret += p[i][cnt]
    return ret

n = int(input())
L = [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 << 10):
    bit = [0] * 10
    for j in range(10):
        if i >> j & 1:
            bit[j] = 1
    if 1 in bit:
        ans = max(ans, solve(bit))
print(ans)

Solution (Python):
n = int(input())
f_list = [int("".join(input().split()), 2) for _ in range(n)]
p_list = [[int(x) for x in input().split()] for _ in range(n)]
ans = -(10 ** 10)
for i in range(1, 2 ** 10):
    temp = 0
    for j in range(n):
        temp += p_list[j][bin(i & f_list[j]).count("1")]
    if temp > ans:
        ans = temp
print(ans)

Solution (Python):
n=int(input())
F=[]
for i in range(n):
  F.append(list(map(int,input().split())))
P=[]
for i in range(n):
  P.append(list(map(int,input().split())))
maxp=-10**11
for i in range(1,2**10):
  prof=0
  s='{0:b}'.format(i)
  S=[]
  for i in range(len(s)):
    S.append(s[i])
  S.reverse()
  for i in range(10-len(s)):
    S.append('0')
  S.reverse()
  for j in range(n):
    count=0
    for k in range(10):
      count+=int(S[k])*F[j][k]
    prof+=P[j][count]
  maxp=max(maxp,prof)
print(maxp)