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

Solution (Python):



import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
op=[LI() for i in range(n)]
pro=[LI() for i in range(n)]
vals=[]
for j in range(1,2**10):
    ans=0
    common=[0 for i in range(n)]
    for k in range(n):
        for i in range(10):
            x=(j>>i) %2
            common[k]+=x*op[k][i]
        ans+=pro[k][common[k]]
    vals.append(ans)
print(max(vals))

Solution (Python):



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

    ans = -10**10

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

numf=[]
ansp=0
ans=-float('inf')

for i in range(1,2**10):
  l=str(bin(i)).lstrip("0b")
  ll=list(l.zfill(10))
  ilist=[int(xl) for xl in ll]
  j=0
  ansp=0
  for jlist in f:
    suml=[ilist[k]*jlist[k] for k in range(10)]
    c=sum(suml)
    ansp+=p[j][c]
    j+=1

  ans=max(ans,ansp)

print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]




N = ii()
F = li2(N)
P = li2(N)

B = 2**10

ans = -float('inf')
for i in range(1, B):
    pro = 0
    for j in range(N):
        cnt = 0
        for k in range(11):
            if (i & 1 << k) and F[j][k] == 1:
                cnt += 1
        pro += P[j][cnt]
    ans = max(ans, pro)

print(ans)

Solution (Python):

N = int(input())
Shop_info =[list(map(int, input().split())) for _ in range(N)]
Earn = [list(map(int, input().split())) for _ in range(N)]
ans = - float('inf')
for i in range(1,2**10):
    Open = [0] * N
    ansi = 0
    for j in range(10):
        if (i >> j) & 1 == 1:
            for k in range(N):
                if Shop_info[k][j]:
                    Open[k] += 1
    for x, o in enumerate(Open):
        ansi += Earn[x][o]
    ans = max(ans, ansi)
print(ans)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


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


def is_nth_bit_set(x, n):
    if x & (1 << n):
        return 1
    else:
        return 0


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 = -INF
    total = 2 ** 10
    for pattern in range(1, total):
        joisino = [is_nth_bit_set(pattern, i) for i in range(10)]
        benefit = 0
        for f, p in zip(F, P):
            cnt = 0
            for i, j in zip(joisino, f):
                if i and j:
                    cnt += 1

            benefit += p[cnt]

        if ans < benefit:
            ans = benefit

    print(ans)


if __name__ == "__main__":
    main()

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

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

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

ans = -1e10
for bits in range(1<<10):
    if bits == 0: continue

    cnt = [0 for i in range(N)]
    for i in range(10):
        if not (bits>>i & 1): continue 

        for shop in range(N):
            if F[shop][i]: cnt[shop] += 1
    
    benefit = 0
    for shop in range(N):
        benefit += P[shop][cnt[shop]]
    
    ans = max(ans, benefit)

print(ans)

Solution (Python):
import sys
import os
import math
import bisect
import collections
import itertools
import heapq
import re
import queue



ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)


MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

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

    ret = -MAX
    for b in range(1, 1 << 10):
        tmp = 0
        for n in range(N):
            o = 0
            for t in range(10):
                if b >> t & 1 and F[n][t] == 1:
                    o += 1
            tmp += P[n][o]
        ret = max(ret, tmp)
    print(ret)


if __name__ == '__main__':
    main()

Solution (Python):
from itertools import product

N=int(input())
F=[ [[0 for _ in range(2)] for _ in range(5)] for _ in range(N)]
P= [[0] for _ in range(N)]
total= [[0 for _ in range(5)] for _ in range(2)]

for i in range(N):
  tmp=list( map(int,input().split()) )
  for j in range(5):
    for k in range(2):
      F[i][j][k]=tmp[2*j+k]
for i in range(N):
  P[i]=list(map(int,input().split()))
  
maxi=float("-inf")
combi=product([1,0],repeat=10)

for kumi in combi:
  mini=float("-inf")
  if sum(kumi)==0:
    pass
  else:      
    tmp=0
    for i in range(N):
      summ=0
      for k,open in enumerate(kumi):
        m,n = k//2, k%2
        summ += open * F[i][m][n]
      tmp += P[i][summ]
  maxi=max(maxi,tmp)
      
print(maxi)

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)]
x=[]
for i in range(1,2**10):
    j_open=format(i,'b').zfill(10)
    pro_sum=0
    for j in range(n):
        one_sum=0
        for k in range(10):
            if f[j][k]==1 and j_open[k]=='1':one_sum+=1
        pro_sum+=p[j][one_sum]
    x.append(pro_sum)
print(max(x))

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import copy
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

N = getN()
F = []
for i in range(N):
    
    f = list(map(str, input().split()))
    
    falta = ''.join(f)
    
    F.append(int(falta, 2))
P = []
for i in range(N):
    p = getList()
    P.append(p)


ans = -10 ** 24


for bit in range(1, 1 << 10):
    sum = 0
    
    for i in range(N):
        open = F[i] & bit
        
        index = str(bin(open)).count('1')
        sum += P[i][index]
    ans = max(ans, sum)
print(ans)

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import copy
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

N = getN()
F = []
for i in range(N):
    
    f = list(map(str, input().split()))
    
    falta = ''.join(f)
    
    F.append(int(falta, 2))
P = []
for i in range(N):
    p = getList()
    P.append(p)
ans = -10 ** 24


for bit in range(1, 1 << 10):
    sum = 0
    
    for i in range(N):
        open = F[i] & bit
        
        index = str(bin(open)).count('1')
        sum += P[i][index]
    ans = max(ans, sum)
print(ans)

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)]
ans = -(10**10)
for l in itertools.product(range(2), repeat=10):
  if sum(l) == 0:
    continue
  s = 0
  for i in range(n):
    c = 0
    for j in range(10):
      c += l[j] * f[i][j]
    s += p[i][c]
  ans = max(ans, s)
print(ans)

Solution (Python):
n = int(input())
lis = []
for i in range(2 ** 10):
    openls = []
    for j in range(10):
        if ((i >> j) & 1) == 1:
            openls.append(j)
    lis.append(openls)

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

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

ret = - 10 ** 1000

for item in lis:
    if sum(item) == 0:
        continue
    tmp = 0
    for i in range(n):
        same = 0
        for val in item:
            if f[i][val] == 1:
                same += 1
        tmp += p[i][same]
    ret = max(ret, tmp)

print(ret)

Solution (Python):
n = int(input())
opn = [list(map(str,input().split())) for i in range(n)]
pnt = [list(map(int,input().split())) for i in range(n)]
ma = -10**100

for i in range(1,1024):
    stt = str(format(i,'010b'))
    p = 0
    for i,sh in enumerate(opn):
        ci = 0
        for j, st in enumerate(sh):
            if stt[j] == "1" and st == "1":
                ci += 1
        p += pnt[i][ci]
    if ma < p:
        ma = p

print(ma)

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") * -1

for i in range(1, 2 ** 10):
    idx = []
    times = []
    for j in range(10):
        if i >> j & 1 == 1:
            idx.append(j)
    for f in F:
        total = 0
        for i in idx:
            if f[i]:
                total += 1
        times.append(total)
    bft = 0
    for p, t in zip(P, times):
        bft += p[t]
    ans = max(bft, ans)

print(ans)

Solution (Python):
import numpy as np
n = int(input())
timezones = np.array([[int(i) for i in input().split()] for _ in range(n)])
points = np.array([[int(i) for i in input().split()] for _ in range(n)])
max_scores = - float('inf')
for i in range(1, 2 ** 10):
    indices = []
    for j in range(10):
        if i & (1 << j):
            indices.append(j)
    nums = timezones[:, indices].sum(axis=1)
    scores = points[range(n), nums].sum()
    max_scores = max(max_scores, scores)
print(max_scores)

Solution (Python):
N = int(input())
F = tuple(tuple(map(int, input().split())) for _ in range(N))
P = tuple(tuple(map(int, input().split())) for _ in range(N))
ans = -float("inf")
for n in range(1, 1024):
    indices = [0] * N
    for i in range(N):
        for j in range(10):
            if (n >> (9 - j)) & 1:
                indices[i] += F[i][j]
    ans = max(ans, sum(profit[idx] for profit, idx in zip(P, indices)))
print(ans)

Solution (Python):
from functools import reduce

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

pattern = []
for i in range(2 ** 10):
    temp = [0] * 10
    for j in range(10):
        if (i >> j) & 1:
            temp[j] = 1
    pattern.append(temp)
pattern.remove([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])

ans = -10 ** 10
for i in range(len(pattern)):
    my_store = pattern[i]
    profit = 0
    for j in range(n):
        same_open = [x & y for (x, y) in zip(pattern[i], f[j])]
        profit += p[j][sum(same_open)]
    ans = max(ans, profit)

print(ans)

Solution (Python):
from collections import deque

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

ans = -10**10
q = deque()
q.append([])
while q:
  x = q.pop()
  if len(x) == 10:
    tmp = 0
    i = 0
    while i < N:
      tmp += P[i][sum([x[j]*FF[i][j] for j in range(10)])]
      i += 1
    ans = max(ans, -10**10 if sum(x) < 1 else tmp)
  else:
    q.append(x+[0])
    q.append(x+[1])
print(ans)

Solution (Python):
N=int(input())
F1=[]
F2=[]
for i in range(N):
    F=list(map(int,input().split()))
    F1.append(F[::2])
    F2.append(F[1::2])
P=[list(map(int,input().split())) for _ in range(N)]

ans=-float("inf")
for i in range(1,2**10):
    F_am=[0]*5
    F_pm=[0]*5
    for j in range(5):
        F_am[j]=i%2
        i//=2
        F_pm[j]=i%2
        i//=2
    c=[0]*N
    for j in range(N):
        for k in range(5):
            if F_am[k]==1 and F1[j][k]==1:
                c[j]+=1
            if F_pm[k]==1 and F2[j][k]==1:
                c[j]+=1
    val=0
    for j in range(N):
        val+=P[j][c[j]]
    ans=max(ans,val)
print(ans)

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

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


def calc(isOpen):
    global ans
    isAllClose = True
    for i in range(10):
        if isOpen[i]:
            isAllClose = False

    if isAllClose:
        return

    rieki = 0
    for i in range(N):
        count = 0
        for j in range(10):
            if Fs[i][j] and isOpen[j]:
                count += 1

        rieki += Ps[i][count]

    ans = max(ans, rieki)


def search(isOpen):
    if len(isOpen) == 10:
        calc(isOpen)
    else:
        search(isOpen + [True])
        search(isOpen + [False])


ans = -float('inf')
search([])

print(ans)

Solution (Python):

import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

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

if __name__ == '__main__':
    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)]
from itertools import product as pr
x=-10**9
for ch in list(pr([0,1],repeat=10)):
  if 1 not in ch:
    continue
  s=0
  for j in range(n):
    c=0
    t=f[j]
    for k in range(10):
      if ch[k] and t[k]:
        c+=1
    s+=p[j][c]
  x=max(x,s)
print(x)

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

ans=-float("inf")

def j(a):
    tmp=0
    for i in range(n):
        cnt=0
        for j in range(10):
            if F[i][j]==1 and a[j]==1:
                cnt+=1
        tmp+=P[i][cnt]
    return tmp

for pa in itertools.product([0,1],repeat=10):
    pa=list(pa)
    if not pa.count(1)==0:
        ans=max(ans,j(pa))

print(ans)

Solution (Python):

import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def solve():
    N = Scanner.int()
    F = Scanner.int_list_list(N)
    P = Scanner.int_list_list(N)
    ans = -INF
    for i in range(1, 1 << 10):
        o = [False for _ in range(10)]
        for j in range(10):
            if i >> j & 1:
                o[j] = True
        t = [0 for _ in range(N)]
        for j in range(10):
            if not o[j]:
                continue
            for k in range(N):
                t[k] += F[k][j]
        tmp = 0
        for j in range(N):
            tmp += P[j][t[j]]
        ans = max(ans, tmp)
    print(ans)


def main():
    
    solve()


if __name__ == "__main__":
    main()

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

S = []
for _ in range(N):
    s = int(''.join(input().split()), 2)
    S.append(s)

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

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

print(ans)

Solution (Python):
from itertools import product

bit = [0, 1]

lst = list(product(bit, repeat=10))

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

res = -1 << 30
for v in lst:
	if v.count(0) == 10: continue
	fund = 0
	for i in range(n):
		cnt = 0
		for x in range(10):
			if F[i][x] == 1 and v[x] == 1:
				cnt += 1
		fund += P[i][cnt]
	res = max(res, fund)

print(res)

Solution (Python):
n = int(input())
F = [[] * 10 for _ in range(n)]
P = [[] * 10 for _ 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()))


res = -1<<30
for item in range(1, 1 << 10):
	fund = 0
	for i in range(n):
		cnt = 0
		for x in range(10):
			if item >> x & 1 and F[i][x] == 1:
				cnt += 1
		fund += P[i][cnt]
	res = max(res, fund)

print(res)

Solution (Python):
import sys

N = int(sys.stdin.readline().rstrip())

F = [[] for _ in range(N)]
for i in range(N):
    F[i] = list(map(int, sys.stdin.readline().rstrip().split()))

P = []
for i in range(N):
    P.append(list(map(int, sys.stdin.readline().rstrip().split())))

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

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=-pow(10,9)

for i in range(1,2**10):
  s=[]
  for j in range(10):
    if ((i>>j) & 1):
      s.append(j)
  ansi=0
  for j in range(n):
    ansi+=p[j][sum([f[j][si] for si in s])]
  ans=max(ans,ansi)
print(ans)

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

ans = -10**9

for i in range(2**10):
    tmp = 0
    cnts = [0]*n
    if i==0:continue
    for j in range(10):
        if i>>j &1:
            for shop in range(n):
                if opens[shop][j] ==1:
                    cnts[shop]+=1
    for shop in range(n):
        tmp+=P[shop][cnts[shop]]

    ans = max(tmp,ans)
print(ans)

Solution (Python):
from sys import stdin
def main():
    
    readline=stdin.readline
    N=int(readline())
    F=[]
    for i in range(N):
        f=int("".join(readline().strip().split(" ")),2)
        F.append(f)
    P=[]
    for i in range(N):
        p=list(map(int,readline().split()))
        P.append(p)
    
    max_res=float("-inf")
    for output in range(1,1<<10):
        res=0
        for j in range(N):
            c=bin(output&F[j]).count("1")
            res+=P[j][c]
        max_res=max(res,max_res)

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

Solution (Python):
n = int(input())
f = [[int(i) for i in input().split()] for _ in range(n)]
p = [[int(i) for i in input().split()] for _ in range(n)]
ans = -float("inf")
for x in range(1,1<<10):
    res = 0
    for i in range(n):
        cnt = 0
        for j in range(10):
            if x>>j&1 and f[i][j]: cnt += 1
        res += p[i][cnt]
    ans = max(ans,res)
print(ans)

Solution (Python):
from sys import stdin
def main():
    
    readline=stdin.readline
    N=int(readline())
    F=[]
    for i in range(N):
        f=list(map(int,readline().split()))
        F.append(f)
    P=[]
    for i in range(N):
        p=list(map(int,readline().split()))
        P.append(p)
    
    max_res=-float("inf")
    for i in range(1<<10):
        if i==0:
            continue
        else:
            output=[]
            for j in range(10):
                if(i>>j)&1:
                    output.append(j)

            oc=[0]*10  
            for j in output:
                oc[j]=1
            
            res=0
            for j in range(N):
                c=0
                for k in range(10):
                    if oc[k]==1 and F[j][k]==1:
                        c+=1
                res+=P[j][c]
            max_res=max(res,max_res)

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

Solution (Python):
def main():
    from itertools import product
    import heapq

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

    l = [[0, 0], [1, 0], [0, 1], [1, 1]]
    r = range(4)
    ans = []
    heapq.heapify(ans)
    for c in product(r, r, r, r, r):
        v = [l[i] for i in c]
        s = sum(v, [])
        if sum(s) == 0:
            continue
        t = sum(y[sum([i * j for i, j in zip(s, x)])] for x, y in zip(f, p))
        heapq.heappush(ans, -t)

    print(-1 * heapq.heappop(ans))


if __name__ == '__main__':
    main()

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

    l = [[0, 0], [1, 0], [0, 1], [1, 1]]
    r = range(4)
    ans = - 10 ** 9
    for c in product(r, r, r, r, r):
        v = [l[i] for i in c]
        s = sum(v, [])
        if sum(s) == 0:
            continue
        t = 0
        for x, y in zip(f, p):
            m = sum([i * j for i, j in zip(s, x)])
            t += y[m]

        ans = max(ans, t)

    print(ans)


if __name__ == '__main__':
    main()

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):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np

def abc080_c_np():
    N = int(readline())  
    
    F = np.zeros((N, 10), dtype=np.int8)
    for i in range(N): F[i] = readline().split()
    
    P = np.zeros((N, 11), dtype=np.int32)
    for i in range(N): P[i] = readline().split()
    ans = -10**12  

    
    from itertools import product
    for mask in product(range(2), repeat=10):
        if mask.count(1) == 0: continue
        profit = 0
        mask_np = np.array(mask, np.int8)
        for i in range(N):
            
            overlap = np.logical_and(F[i,:], mask_np).sum()
            profit += P[i, overlap]
        ans = max(profit, ans)
    print(ans)

abc080_c_np()

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np

def abc080_c_np():
    N = int(readline())  
    
    F = np.zeros((N, 10), dtype=np.int8)
    for i in range(N): F[i] = readline().split()
    
    P = np.zeros((N, 11), dtype=np.int32)
    for i in range(N): P[i] = readline().split()
    ans = -10**12  

    
    from itertools import product
    for mask in product(range(2), repeat=10):
        if mask.count(1) == 0: continue
        profit = 0
        mask_np = np.array(mask, np.int8)
        for i in range(N):
            
            overlap = np.multiply(F[i,:], mask_np).sum()
            profit += P[i, overlap]
        ans = max(profit, ans)
    print(ans)

abc080_c_np()

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np

def abc080_c():
    N = int(readline())  
    
    F = np.zeros((N, 10), dtype=np.int8)
    for i in range(N): F[i] = readline().split()
    
    P = np.zeros((N, 11), dtype=np.int32)
    for i in range(N): P[i] = readline().split()
    ans = -10**12  

    
    from itertools import product
    for mask in product(range(2), repeat=10):
        if mask.count(1) == 0: continue
        profit = 0
        for i in range(N):
            
            overlap = np.multiply(F[i,:], mask).sum()
            profit += P[i, overlap]
        ans = max(profit, ans)
    print(ans)

abc080_c()

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def abc080_c():
    N = int(readline())  
    
    F = [list(map(int, readline().split())) for _ in range(N)]
    
    P = [list(map(int, readline().split())) for _ in range(N)]
    ans = -10**12  

    
    from itertools import product
    from operator import mul
    for mask in product(range(2), repeat=10):
        if mask.count(1) == 0: continue
        profit = 0
        for i in range(N):
            
            
            overlap = sum(map(mul, F[i], mask))
            profit += P[i][overlap]
        ans = max(profit, ans)
    print(ans)

abc080_c()

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np

def abc080_c():
    N = int(readline())  
    
    F = np.array([list(map(int, readline().split())) for _ in range(N)], dtype=np.int32)
    
    P = np.array([list(map(int, readline().split())) for _ in range(N)], dtype=np.int32)
    ans = -10**12  

    
    from itertools import product
    for mask in product(range(2), repeat=10):
        if mask.count(1) == 0: continue
        profit = 0
        for i in range(N):
            
            overlap = np.multiply(F[i,:], mask).sum()
            profit += P[i, overlap]
        ans = max(profit, ans)
    print(ans)

abc080_c()

Solution (Python):

import numpy as np
n = int(input())
f = [list(map(int, input().split())) for _ in [0]*n]
p = [list(map(int, input().split())) for _ in [0]*n]

m = -float("INF")
from itertools import*
for j in product([0, 1], repeat=10):
    if sum(j) == 0:
        continue
    t = 0
    for i, k in enumerate(f):
        t += p[i][sum(np.array(j) & np.array(k))]
    m = max(t, m)
print(m)