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

ans=-10**18
for i in range(1<<10):
  if i==0:continue
  tp=0
  for j in range(n):
    tcnt=0
    for k in range(10):
      if i&(1<<k):tcnt+=f[j][k]
    tp+=p[j][tcnt]
  ans=max(ans,tp)
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 = []
stk = [[0] * n]

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

print(max(ans))

Solution (Python):
import sys
input = sys.stdin.readline
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 i in range(1,2**10):
    bin = format(i,'b').zfill(10)
    c = [0]*n
    for j in range(n):
        for k in range(10):
            if bin[k] == '1' and f[j][k] == 1:
                c[j] += 1
    r = 0
    for i in range(n):
        r += p[i][c[i]]
    ans = max(ans, r)
print(ans)

Solution (Python):
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt, ceil
from functools import lru_cache, reduce
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())



def warshall_floyd(d, n):
    
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d



def dijkstra_heap(s, edge, n):
    
    d = [10**20] * n
    used = [True] * n 
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d


def factorization(n):
    arr = []
    temp = n
    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 lcm(x, y):
    return (x * y) // gcd(x, y)


def lcm_list(numbers):
    return reduce(lcm, numbers, 1)


def gcd_list(numbers):
    return reduce(gcd, numbers)


def is_prime(n):
    if n <= 1:
        return False
    p = 2
    while True:
        if p ** 2 > n:
            break
        if n % p == 0:
            return False
        p += 1
    return True



def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P


def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret



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

ans = -INF
for i in range(1 << 10):
    if i == 0:
        continue
    bit = bin(i)[2:].zfill(10)
    
    profit = 0

    for j in range(n):
        cnt = 0 
        for k in range(10):
            if bit[k] == "1" and f[j][k] == 1:
                cnt += 1
        profit += p[j][cnt]
    ans = max(ans, profit)
print(ans)

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

ans = -float("inf")
for i in range(1,1 << 10):
    l = [0]*n
    for j in range(10):
        
        if ((i >> j) & 1) == 1:
            
            for k in range(n):
                if f[k][j] == 1:
                    l[k]+= 1
    
    ansi = 0
    for m in range(n):
        ansi += p[m][l[m]]
    ans = max(ans,ansi)
print(ans)

Solution (Python):
import sys










INF = sys.maxsize


ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))





def main():
    n = ni()
    d1 = []
    d2 = []
    for i in range(n):
        t = sys.stdin.readline().split()
        tmp = "".join(t)
        d1.append(int(tmp))
    for i in range(n):
        d2.append(na())

    ans = -10**9
    for i in range(1, 2 ** 10):
        cost = 0
        for j in range(n):
            b = i & int(str(d1[j]),2)
            b = list(format(b, "b"))
            b = [int(n) for n in b]
            b = sum(b)
            cost += d2[j][b]

        ans = max(ans, cost)

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import sys










INF = sys.maxsize


ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))





def main():
    n = ni()
    d1 = []
    d2 = []
    for i in range(n):
        t = sys.stdin.readline().split()
        tmp = "".join(t)
        d1.append(int(tmp))
    for i in range(n):
        d2.append(na())

    ans = -10**9
    for i in range(1, 2 ** 10):
        cost = 0
        for j in range(n):
            b = i & int(str(d1[j]),2)
            b = list(format(b, "b"))
            b = [int(n) for n in b]
            b = sum(b)
            cost += d2[j][b]

        ans = max(ans, cost)

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    from itertools import combinations

    N = int(input())
    F = []
    for _ in range(N):
        t = 0
        for j, b in enumerate(map(int, input().split())):
            if b:
                t |= (1 << j)
        F.append(t)
    
    P = [list(map(int, input().split())) for _ in range(N)]
    

    ans = -10 ** 9 - 1
    for open_ in range(1, 10 + 1):
        for comb in combinations(range(10), r=open_):
            t = 0
            for j in comb:
                t |= (1 << j)

            p = 0
            for i, f in enumerate(F):
                x = bin(t & f).count('1')
                p += P[i][x]

            ans = max(ans, p)

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):

import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = -inf ;ans = 0 ;count = 0 ;pro = 1

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

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

ans = -10**9
for i in range(1, 2**10):
    profit = 0
    for ff, pp in zip(f, p):
        cnt = 0
        for j in range(10):
            cnt += ((i>>j)&1)&ff[j]
        profit += pp[cnt]
    ans = max(ans, profit)
print(ans)

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

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

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

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

ans=-np.inf

for b in range(1,2**10):
    now=0
    L=np.zeros(N)
    for i in range(10):
        if b>>i&1==1:
            L+=F[:,i]
    for i in range(N):
        now+=P[i,int(L[i])]
    ans=max(ans, now)

print(ans)

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


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


def readint():
    return int(input())


def readnums():
    return map(int, input().split())


def readstrs():
    return input().split()


def main():
    N = readint()
    F = [''.join(readstrs()) for _ in range(N)]
    P = [list(readnums()) for _ in range(N)]
    ans = -(10 ** 9)
    for i in range(1, 1024):
        val = 0
        for j, f in enumerate(F):
            c = bin(i & int(f, 2))[2:]
            v = sum(map(int, c))
            val += P[j][v]

        ans = max(ans, val)

    print(ans)


if __name__ == "__main__":
    main()

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

F = []
for _ in range(N):
    mask = 0
    for f in map(int, input().split()):
        mask <<= 1
        mask |= f
    F.append(mask)

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

def calc(state):
    ret = 0
    for f, ps in zip(F, P):
        f &= state
        cnt = 0
        while f > 0:
            cnt += f % 2
            f //= 2
        ret += ps[cnt]
    return ret

ans = -10**18
for state in range(1, 1 << 10):
    ans = max(ans, calc(state))
print(ans)

Solution (Python):
def main():
    n = int(input())
    f = [list(map(int,input().split())) for i in range(n)]
    p = [list(map(int,input().split())) for i in range(n)]
    bit = 1<<10
    res = -10**10
    for i in range(1,bit):
        chk = [0]*n
        cnt = 0
        for j in range(10):
            if (i>>j)&1:
                for k in range(n):
                    if f[k][j] == 1:
                        chk[k] += 1
        for l in range(n):
            cnt += p[l][chk[l]]
        res = max(res,cnt)
    print(res)

if __name__ == '__main__':
    main()

Solution (Python):
from itertools import product
N=int(input())
F = [[[0 for _ in range(3)] for _ in range(6)] for _ in range(N+1)]
for i in range(1,N+1):
    A = list(map(int,input().split()))
    F[i][1][1] = A[0]
    F[i][1][2] = A[1]
    F[i][2][1] = A[2]
    F[i][2][2] = A[3]
    F[i][3][1] = A[4]
    F[i][3][2] = A[5]
    F[i][4][1] = A[6]
    F[i][4][2] = A[7]
    F[i][5][1] = A[8]
    F[i][5][2] = A[9]
P = [[0 for _ in range(11)] for _ in range(N+1)]
for i in range(1,N+1):
    P[i] = list(map(int,input().split()))
pmax = -10**10
for x in product((0,1),repeat=10):
    if sum(x)>0:
        G = [[0 for _ in range(3)] for _ in range(6)]
        G[1][1] = x[0]
        G[1][2] = x[1]
        G[2][1] = x[2]
        G[2][2] = x[3]
        G[3][1] = x[4]
        G[3][2] = x[5]
        G[4][1] = x[6]
        G[4][2] = x[7]
        G[5][1] = x[8]
        G[5][2] = x[9]
        p = 0
        for i in range(1,N+1):
            cnt = 0
            for j in range(1,6):
                for k in range(1,3):
                    if F[i][j][k]==1 and G[j][k]==1:
                        cnt += 1
            p += P[i][cnt]
        pmax = max(pmax,p)
print(pmax)

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 1, 0, -1, 1, -1, -1, 1]
dy = [1, 0, -1, 0, 1, -1, 1, -1]
debugmode = True

n = INT()
f = [LIST() for _ in range(n)]
p = [LIST() for _ in range(n)]

def func(i, arr):
    if i == 10:
        if sum(arr) == 0:
            return -inf
        pp = 0
        for i in range(n):
            cnt = 0
            for j in range(10):
                if arr[j] == 1 and f[i][j] == 1:
                    cnt += 1
            pp += p[i][cnt]
        return pp
    tmp = deepcopy(arr)
    tmp[i] = 1
    return max(func(i + 1, arr), func(i + 1, tmp))

print(func(0, [0 for _ in range(10)]))

Solution (Python):
import sys
from itertools import product

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    F = [list(map(int, input().split())) for _ in range(n)]
    P = [list(map(int, input().split())) for _ in range(n)]

    res = -f_inf
    for pattern in product([0, 1], repeat=10):
        if sum(pattern) == 0:
            continue

        score = 0
        for f, p in zip(F, P):
            cnt = 0
            for i in range(10):
                if pattern[i] == f[i] == 1:
                    cnt += 1
            score += p[cnt]

        res = max(res, score)

    print(res)


if __name__ == '__main__':
    resolve()

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)]
    answer = -float("inf")
    for i in range(1, pow(2, 10)):
        now = 0
        cnt = [0 for _ in range(n)]
        for j in range(10):
            if (i >> j) & 1:
                for k in range(n):
                    if f[k][j]:
                        cnt[k] += 1
        for j in range(n):
            now += p[j][cnt[j]]
        answer = max(answer, now)
    print(answer)


if __name__ == '__main__':
    main()

Solution (Python):
from itertools import product
n = int(input())
F = [tuple(map(int, input().split()))for _ in range(n)]
P = [tuple(map(int, input().split()))for _ in range(n)]
INF = 10**18
ans = -INF
for schedule in product([0, 1], repeat=10):
    if 1 not in schedule:
        continue
    p_sum = 0
    for i, f in enumerate(F):
        cnt = 0
        for x, y in zip(schedule, f):
            if x == y == 1:
                cnt += 1
        p_sum += P[i][cnt]
    if ans < p_sum:
        ans = p_sum
print(ans)

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

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

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

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

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

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

all_cand = []
for i in range(2**10):
  p_m_list = [False for i in range(10)]
  for j in range(10):
    if ((i >>j) & 1):
      p_m_list[j] = True
  all_cand.append(p_m_list)
all_cand.pop(0)
result_list = []

for cand in all_cand:
  result = 0
  for j in range(n):
    c = 0
    for i in range(10):
      if cand[i] == True and f_list[j][i] == 1:
        c += 1
    result += p_list[j][c]
  result_list.append(result)
  
print(max(result_list))

Solution (Python):
import itertools

n = int(input())
F = [None for i in range(n)]
P = [None for i in range(n)]
for i in range(n):
    F[i] = list(map(int, input().split()))
for i in range(n):
    P[i] = list(map(int, input().split()))
comb = list(itertools.product([0,1],repeat=10))
comb.pop(0)




ans = -float("INF")
for i in comb:
    koho = 0
    for j in range(n):
        count = 0
        for k in range(10):
            if i[k]==1 and F[j][k]==1:
                count+=1
        koho += P[j][count]
    ans = max(ans,koho)

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

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    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)]
    profit = -10**10
    
    
    n = 10
    
    for i in range(1, 2 ** n):
        bag = [0] * N
        cnt = 0

        """        
        10進数表記　2進数表記
        0           000
        1           001
        2           010
        3           011
        4           100
        5           101
        6           110
        7           111
        """

        for j in range(n):  
            if ((i >> j) & 1):  
                for k in range(N):
                    if F[k][j] == 1:
                        bag[k] += 1
        for l in range(N):
            cnt += P[l][bag[l]]
        profit = max(profit, cnt)
    print(profit)


resolve()

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)]
ma=-10000000000000
for i in range(1,2**10):
    check=[0]*n
    for j in range(10):
        if (i>>j) & 1:
            for k in range(n):
                check[k]+=f[k][j]
    ma_sub=0
    for i in range(n):
        ma_sub+=p[i][check[i]]
    ma=max(ma,ma_sub)
print(ma)

Solution (Python):
import numpy as np
N = int(input())
F = [[int(x) for x in input().split()] for _ in range(N)]
P = [[int(x) for x in input().split()] for _ in range(N)]

import itertools
answer = -(10 ** 18)
for a in itertools.product([0,1], repeat = 10):
  if sum(a) == 0:
    continue
  profit = 0
  for shop in range(N):
    profit += P[shop][sum(a[i]*F[shop][i] for i in range(10))]
  if answer < profit:
    answer = profit

print(answer)

Solution (Python):
n=int(input())
f=[]
P=[]
for i in range(n):
    a=list(map(int,input().split()))
    f.append(a)
for i in range(n):
    a=list(map(int, input().split()))
    P.append(a)
from itertools import product
ans=-(10**10)
for p in product([0, 1], repeat = 10):
    if sum(p)!=0:
        ret = 0
        for i in range(n):
            cnt = 0
            for j in range(10):
                if p[j] == f[i][j] and p[j] == 1:
                    cnt += 1
            ret += P[i][cnt]
        ans = max(ans, ret)
print(ans)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from itertools import product

n = int(readline())
f = [list(map(int, readline().split())) for _ in range(n)]
p = [list(map(int, readline().split())) for _ in range(n)]
ans = -float('inf')
for bit in list(product([0, 1], repeat=10))[1:]:
    v = 0
    for ff, pp in zip(f, p):
        cnt = 0
        for i, check in enumerate(ff):
            if bit[i] == check == 1:
                cnt += 1
        v += pp[cnt]
    if ans < v:
        ans = v
print(ans)

Solution (Python):
import sys
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=-1*sys.maxsize
for i in range(1, 2**10):
  temp=0
  for shop in range(n):
    cnt=0
    for j in range(10):
      if (i>>j & 1 and f[shop][j] == 1):
        cnt+=1
    temp+=p[shop][cnt]
  ans=max(ans,temp)
print(ans)

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

def main():
    N = int(readline())
    F = []
    for _ in range(N):
        inp = list(map(int, readline().rstrip().split()))
        F.append(set([i for i, e in enumerate(inp) if e]))

    P = [list(map(int, readline().rstrip().split())) for _ in range(N)]
    ans = -10**10
    for i in range(1, 2**10):
        b = bin(i)[2:].zfill(10)
        t = set([j for j, e in enumerate(b) if e == '1'])
        pro = 0
        for f, p in zip(F, P):
            d = f & t
            pro += p[len(d)]
        ans = max(ans, pro)
    
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
input = sys.stdin.readline
n = int(input())
f = [int("".join(input().split()),base=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):
  profit = 0
  for j in range(n):
    cnt = bin(i&f[j]).count("1")
    profit += p[j][cnt]
  ans = max(ans,profit)
print(ans)

Solution (Python):
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

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

ans = - (1 << 30)
for i in range(1 << 10):
    profit = 0
    ok = False
    for j in range(N):
        cnt = bin(i & F[j]).count("1")
        if cnt > 0:
            ok = True
        profit += P[j][cnt]

    if ok:
        ans = max(ans, profit)

print(ans)

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

ans = -1 * float('inf')
for i in range(1, 2**10):
    tmp = 0
    for j in range(N):
        product = i & int(F[j], base=2)
        c = bin(product).count('1')
        tmp += P[j][c]
    ans = max(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)]

s = [list(map(int,bin(x)[2:].zfill(10))) for x in range(1,2**10)]
c = 0
ans = 0
max = -1000000000
for k in range(2**10-1):
    for i in range(n):
        for j in range(10):
            c += f[i][j]*s[k][j]
        ans += p[i][c]
        c=0
    if ans > max:
        max = ans
    ans = 0
print(max)

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


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

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


ans=-np.inf
for b in range(1,2**10):
    C=np.zeros(N)
    for i in range(10):
        if b>>i&1==1:
            now=F[:,i]
            C+=now
    subnow=0
    
    for j,c in enumerate(C):
        subnow+=P[j][int(c)]
    ans=max(ans, subnow)

print(ans)

Solution (Python):
import sys

readline = sys.stdin.readline
N = int(input())
shop = [int(readline().replace(' ', ''), 2) for _ in range(N)]
profits = [list(map(int, readline().split())) for _ in range(N)]
ans = -10**20
for bit in range(1, 1<<10+1):
    profit = 0
    cnt = 0
    for s, p in zip(shop, profits):
        num = bin(bit&s).count('1')
        if num:
            cnt += 1
        profit += p[num]
    if cnt and ans < profit:
        ans = profit
print(ans)

Solution (Python):
n = int(input())
shop_open = [0] * n
profit_ls = [0] * n
for i in range(n):
    shop_open[i] = list(map(int, input().split()))
for i in range(n):
    profit_ls[i] = list(map(int, input().split()))

num_patterns = 2 ** 10
max_profit = -float('inf')
for pattern_10 in range(1,num_patterns):
    pattern_ls = [0] * 10
    for d in range(10):
        if ((pattern_10 >> d) & 1):
            pattern_ls[d] = 1
    profit = 0
    for shop_ind in range(n):
        the_shop_open = shop_open[shop_ind]
        both_open_times = 0
        for time in range(10):
            if the_shop_open[time] == 1 and pattern_ls[time] == 1:
                both_open_times += 1
        profit += profit_ls[shop_ind][both_open_times]
    max_profit = max(max_profit, profit)
print(max_profit)

Solution (Python):
from itertools import product

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

ret = -10 ** 18
for p in product([0, 1], repeat=10):
    if sum(p) == 0:
        continue
    t = 0
    for i in range(N):
        cnt = 0
        for j in range(10):
            if p[j]:
                cnt += f_lst[i][j]
        t += p_lst[i][cnt]
    ret = max(ret, t)
print(ret)

Solution (Python):
import sys
import math  
import bisect  
import queue  


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


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)

    ans = -1000000000
    for am in range(2 ** 5):
        for pm in range(2 ** 5):
            opens = [0 for _ in range(10)]
            for i in range(5):
                if ((am >> i) & 1):
                    opens[2 * i] = 1
                if ((pm >> i) & 1):
                    opens[2 * i + 1] = 1
            if sum(opens) == 0:
                continue
            res = 0
            for i, fs in enumerate(F):
                cnt = 0
                for f, o in zip(fs, opens):
                    if f == 1 and o == 1:
                        cnt += 1
                res += P[i][cnt]
            ans = max(ans, res)

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
from itertools import product

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

ret = -10 ** 18
for p in product([0, 1], repeat=10):
    if sum(p) == 0:
        continue
    t = 0
    for i in range(N):
        cnt = 0
        for j in range(10):
            if p[j]:
                cnt += f_lst[i][j]
        t += p_lst[i][cnt]
    ret = max(ret, t)
print(ret)

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

fmat=[]
for i in range(N):
  array=list(map(int,input().split()))
  fmat.append(array)
  
pmat=[]
for i in range(N):
  array=list(map(int,input().split()))
  pmat.append(array)



max_answer=-10**9
for bit in itertools.product(range(2),repeat=10):
  if sum(bit)==0:
    continue
    
  answer=0  
  for i in range(N):
    both_num=0
    for j in range(10):
      if bit[j]==1 and fmat[i][j]==1:
        both_num+=1
    
    answer+=pmat[i][both_num]
    
  max_answer=max(max_answer,answer)
  
print(max_answer)

Solution (Python):
n=int(input())
f=[]
P=[]
for i in range(n):
    a=list(map(int,input().split()))
    f.append(a)
for i in range(n):
    a=list(map(int, input().split()))
    P.append(a)
from itertools import product
ans=-(10**10)
for p in product([0, 1], repeat = 10):
    if sum(p)!=0:
        ret = 0
        for i in range(n):
            cnt = 0
            for j in range(10):
                if p[j] == f[i][j] and p[j] == 1:
                    cnt += 1
            ret += P[i][cnt]
        ans = max(ans, ret)
print(ans)

Solution (Python):
import itertools

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

    f[i]=fij
p=[[]]*n
for i in range(n):
    pij=list(map(int,input().split()))
    p[i]=pij
    
pmax=-10**11
for a in itertools.product([0,1], repeat=10):
    if sum(a)==0:
        continue
    psum=0
    for ni in range(n):
        k=0
        for i in range(10):
            if f[ni][i]==1 and a[i]==1:
                k+=1
        psum=psum+p[ni][k] 
    pmax=max(pmax,psum)   

print(pmax)