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

ans = 0
for ff, i in enumerate(itertools.product([0, 1], repeat=10)):
    if sum(i) == 0:
        continue
    point = 0
    for idx, f in enumerate(F):
        count = 0
        for a, b in zip(i, f):
            count += a * b
        point += P[idx][count]

    if ff == 1:
        ans = point
    else:
        
        
        ans = max(ans, point)

print(ans)

Solution (Python):
def bitCount(bits):
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555)
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333)
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f)
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff)
    return (bits & 0x0000ffff) + (bits >> 16 & 0x0000ffff)


N = int(input())
F = [0] * N
for i in range(N):
    F[i] = int("".join(input().split()), 2)

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

maxx = -9999999999999999
for bina in range(1, 2**10):
    total = 0
    for i in range(N):
        zyu = bina & F[i]
        total += P[i][bitCount(zyu)]
    maxx = max(total, maxx)

print(maxx)

Solution (Python):
N = int(input())
f = []
for i in range(N):
    F = map(str, input().split())
    f.append("0B" + ''.join(F))
P = [list(map(int, input().split())) for i in range(N)]

ans = -float("inf")
for bit in range(1, 2 ** 10):
    profit = 0  
    for i in range(N):    
        c = bin( bit & int(f[i], 0) )
        index = c.count('1')
        profit += P[i][index]
    ans= max(ans, profit)

print(ans)

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

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

answer = -float("inf")
for i in range(1, 2**10):
    temporary = 0
    for j in range(n):
        c = bin(i & F[j]).count("1")
        temporary += P[j][c]
    answer = max(answer, temporary)

print(answer)

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

ans = []


K = 2 
M = 10 
for i in range(K**M):
    TF=[0]*M

    for j in range(M):
        TF[M-j-1] = i % K
        i //= K
    
    benefit = 0
    if sum(TF) != 0:
        for j in range(N):
            c = 0
            for k in range(10):
                if TF[k] == 1 and F[j][k] == 1:
                    c += 1
            benefit += P[j][c]
        ans.append(benefit)

print(max(ans))

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

ans = []


K = 2 
M = 10 
for i in range(K**M):
    TF=[0]*M

    for j in range(M):
        TF[M-j-1] = i % K
        i //= K
    
    benefit = 0
    if sum(TF) != 0:
        for j in range(N):
            c = 0
            for k in range(10):
                if TF[k] == 1 and F[j][k] == 1:
                    c += 1
            benefit += P[j][c]
        ans.append(benefit)

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

maxprofit = -(10 ** 10)
for i in range(1, 2 ** 10):
    conflicts = [0] * N
    for t in range(10):
        opening = bool(i & (1 << t))
        for j in range(N):
            if F[j][t] and opening:
                conflicts[j] += 1
    profit = 0
    for j in range(N):
        profit += P[j][conflicts[j]]
    if maxprofit < profit:
        maxprofit = profit
        maxstate = i

print(maxprofit)

Solution (Python):
import sys
input = sys.stdin.readline
n = int(input())
chk = []
for _ in range(n):
  f = input().split()
  chk.append(int(''.join(f),2))

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

import collections
ans = -float('inf')
for i in range(1,2**10):
  que = 0
  for j,cj in enumerate(chk):
    d = format(i & cj,'b')
    c = collections.Counter(d)
    que += p[j][c['1']]
  ans = max(ans,que)
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
n = int(input())
chk = []
for _ in range(n):
  f = input().split()
  chk.append(int(''.join(f),2))
chk = tuple(chk)

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

import collections
ans = -float('inf')
for i in range(1,2**10):
  que = 0
  for j,cj in enumerate(chk):
    d = format(i & cj,'b')
    c = collections.Counter(d)
    que += p[j][c['1']]
  ans = max(ans,que)
print(ans)

Solution (Python):
import itertools
n=int(input())
f=[tuple(map(int,input().split())) for _ in range(n)]
p=[tuple(map(int,input().split())) for _ in range(n)]
ll=list(itertools.product(range(2),repeat=10))[1:]
ans=-10**10
for l in ll:
    t=0
    for i in range(n):
        c=0
        for j in range(10):
            if l[j]==1:
                if f[i][j]==l[j]:
                    c+=1
        t+=p[i][c]
    ans=max(ans,t)
print(ans)

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

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

max_score = -float('inf')
for pattern_i in range(1, 2**10):
  op_num = [0]*data
  for pos_i in range(10):
    if pattern_i & 1<<pos_i:
      for n_i in range(data):
        op_num[n_i] += F[n_i][pos_i]
  max_score = max(max_score, sum([p_i[op_num_i] for p_i, op_num_i in zip(P, op_num)]))

print(max_score)

Solution (Python):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


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

    ans = -INF

    from itertools import product, chain

    for bit in range(1, 1 << 10):
        c = [0] * n
        for time in range(10):
            if bit >> time & 1:
                for shopnum, shopopen in enumerate(f):
                    if shopopen[time]:
                        c[shopnum] += 1

        prof = 0

        for shopnum in range(n):
            prof += p[shopnum][c[shopnum]]

        ans = max(ans, prof)

    print(ans)


if __name__ == '__main__':
    main()

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

def return_C(i, List):
    j = ''.join(List)
    j = int(j, 2)
    AND = i & j
    return bin(AND).count('1')

ans = - 10 ** 10
for i in range(1, 2 ** 10):
    temp = 0
    for j in range(N):
        c = return_C(i, F[j])
        temp += P[j][c]
    ans = max(ans, temp)

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

bit = 1<<10
ans = -10**10
for i in range(1,bit):
    tmp = 0
    for j in range(n):
        cj = 0
        for k in range(10):
            cj+= f[j][k] & (i>>k)
        tmp += p[j][cj]
    ans = max(ans,tmp)
print(ans)

Solution (Python):
n=int(input())
f=['' for _ in range(n)]
p=[[] for _ in range(n)]
for i in range(n):
  f[i]=int(''.join(input().split()),2)
for i in range(n):
  p[i]=list(map(int,input().split()))
ans=-10**9
for i in range(1,1024):
  tmp=0
  for j in range(n):
    k=str(format(i&f[j],'010b')).count('1')
    tmp+=p[j][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
sys.setrecursionlimit(10 ** 7)

import itertools

n = int(readline())
f = [list(map(int, readline().split())) for _ in range(n)]
p = [list(map(int, readline().split())) for _ in range(n)]
bit = list(itertools.product([0, 1], repeat=10))
ans = -float('inf')
bit.pop(0)
for i in range(2 ** 10 - 1):
    memo = 0
    flag = False
    for j in range(n):
        cnt = 0
        for k in range(10):
            if bit[i][k] == f[j][k] == 1:
                cnt += 1
        if cnt != 0:
            flag = True
        memo += p[j][cnt]
    if flag:
        ans = max(ans, memo)
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 ** 20
for i in range(1, 2 ** 10):
    cnt = [0] * n
    calc = 0
    for j in range(10):
        if i >> j & 1:
            for k in range(n):
                if f[k][j] == 1:
                    cnt[k] += 1
                
    for k in range(n):
        calc += p[k][cnt[k]] 
    
    ans = max(ans, calc)

print(ans)

Solution (Python):
def resolve():
    N = int(input())
    F = [int(input().replace(" ", ""), 2) for i in range(N)]
    P = [list(map(int, input().split(" "))) for i in range(N)]
    maxtotal = -1*float("inf")
    maxpattern = ""
    for bits in range(1, (1<<10)):
        total = 0
        for i in range(N):
            c = bin(bits & F[i]).count("1")
            total += P[i][c]
        if maxtotal < total:
            maxpattern = bits
            maxtotal = total
    print(maxtotal)




if '__main__' == __name__:
    resolve()

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 ** 30
for i in range(1, 2 ** 10):
    cnt = [0] * n
    calc = 0
    
    for j in range(10):
        if i >> j & 1:
            for k in range(n):
                if f[k][j] == 1:
                    cnt[k] += 1
    
                
    for k in range(n):
        calc += p[k][cnt[k]] 
    
    ans = max(ans, calc)

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

ans=-10**50
for z in product((0, 1), repeat=10):
    profit_count=0  
    for i in range(n):
        work_count=0  
        for j in range(10):  
            if f[i][j]==1 and z[j]==1:  
                work_count+=1
        profit_count+=p[i][work_count]
    if ans<profit_count:  
        if 1 in z:   
            ans=profit_count
print(ans)

Solution (Python):
from itertools import product
A = {}
B = {}
N = int(input())

for n in range(1, N + 1):
    A[n] = input().split()

for n in range(1, N + 1):
    B[n] = [int(m) for m in input().split()]


ans = -10**10

for C in product(('1', '0'), repeat=10):
    if C != tuple('0' * 10):
        D = {v: 0 for v in range(1, N + 1)}
        E = 0
        for u in range(0, 10):
            for v in range(1, N + 1):
                if C[u] == A[v][u] == '1':
                    D[v] += 1

        for v in D:
            E += B[v][D[v]]

        if E > ans:
            ans = E

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 = -(10 ** 18)
for op in range(1, 2 ** 10):
  overlaps = [0] * n
  for k,v in enumerate(f):
    overlap = 0
    for j in range(10):
      if ((op >> j) & 1) and v[j]:
        overlap += 1
    overlaps[k] = overlap
  tmp = 0
  for k,v in enumerate(overlaps):
    tmp += p[k][v]
  ans = max(ans, tmp)
print(ans)

Solution (Python):
n=int(input())
sche=[0 for i in range(n)]

for h in range(n):
    sche[h]={i for i,v in enumerate(input().split()) if v=="1" }
profit=[list(map(int,input().split())) for i in range(n)]
ans=-float("INF")
for i in range(1,1024):
    op={j for j in range(10) if (i>>j)%2}
    pre=0
    for g in range(n):
        pre+=profit[g][len(op&sche[g])]
    ans=max(pre,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)]
ans = -1e100
for i in range(1,2**10):
    A = [0]*10
    profit = 0
    j = 0
    while i > 0:
        A[j] += i&1
        j += 1
        i = i >> 1
    for j in range(n):
        dup = 0
        for a,f in zip(A,F[j]):
            dup += a&f
        profit += P[j][dup]
    ans = max(ans,profit)
print(ans)

Solution (Python):
n = int(input())
shop = [] 
profit = [] 
for i in range(n):
    shop.append(list(map(int,input().split())))
for i in range(n):
    profit.append(list(map(int,input().split())))
cond = [bin(i)[2:].zfill(10) for i in range(1,2**10)]
ans = -int(1e15)
for i in range(len(cond)):
    pro_cnt = 0
    tar = cond[i]
    for j in range(n):
        tar_shop = shop[j]
        cnt = 0
        for k in range(10):
            if int(tar[k]) & tar_shop[k] == 1:
                cnt += 1
        pro_cnt += profit[j][cnt]
    ans = max(ans, pro_cnt)
print(ans)

Solution (Python):
import sys
import numpy as np

I = np.array(sys.stdin.read().split(), dtype=np.int64)
n = I[0]
f = I[1:10*n+1].reshape(n, 10)
p = I[10*n+1:].reshape(n, 11)

def main():
    combs = np.arange(1, 1 << 10)[:, None] >> np.arange(10) & 1
    res = (combs[:, None] & f).sum(axis=2)
    res = p[np.arange(n), res[:, None]].sum(axis=2)
    print(res.max())

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)]
print(max(sum(p[j][sum(i>>k&1 and f[j][k] for k in range(10))] for j in range(n)) for i in range(1,2**10)))

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

Solution (Python):










"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""

""" n! mod m 階乗
mod = 1e9 + 7
N = 10000000
fac = [0] * N
def ini():
  fac[0] = 1 % mod
  for i in range(1,N):
    fac[i] = fac[i-1] * i % mod"""

"""mod = 1e9+7
N = 10000000
pw = [0] * N
def ini(c):
  pw[0] = 1 % mod
  for i in range(1,N):
    pw[i] = pw[i-1] * c % mod"""

"""
def YEILD():
  yield 'one'
  yield 'two'
  yield 'three'
generator = YEILD()
print(next(generator))
print(next(generator))
print(next(generator))
"""
"""def gcd_(a,b):
  if b == 0:
    return a
  return gcd_(a,a % b) 
"""def extgcd(a,b,x,y):
  d = a
  if b!=0:
    d = extgcd(b,a%b,y,x)
    y -= (a//b) * x
    print(x,y)
  else:
    x = 1
    y = 0
  return d"""

"""def gcd(a,b):
  if b == 0:
    return a
  return gcd(b, a % b)
def lcm(a,b):
  g = gcd(a,b)
  return (a * b) // g"""

"""import bisect 
print(A,bisect.bisect_left(A,4))
print(C,n - bisect.bisect_right(C,4))
print(sum(bisect.bisect_left(A,b) * (n-bisect.bisect_right(C,b)) for b in B))"""

def readInts():
  return list(map(int,input().split()))
mod = 10**9 + 7

def main():
  n = int(input())
  F = [readInts() for _ in range(n)]
  P = [readInts() for _ in range(n)]
  
  max_score = -float('inf')
  
  for i in range(1, 2**10):
    op_num = [0] * n
    for j in range(10):
      if i & 1 << j:
        for n_i in range(n):
          op_num[n_i] += F[n_i][j]
    max_score = max(max_score, sum([p_i[op_num_i] for p_i, op_num_i in zip(P,op_num)]))
  print(max_score)
if __name__ == '__main__':
  main()

Solution (Python):
from sys import stdin
import itertools

N = int(stdin.readline().rstrip())
F = []

for i in range(N):
    f = [int(x) for x in stdin.readline().rstrip().split()]
    F.append(f)
    
P = []
for i in range(N):
    p = [int(x) for x in stdin.readline().rstrip().split()]
    P.append(p)

ans = -10**9
for i in itertools.product([0,1],repeat=10):
    if sum(i) == 0:
        continue
    score = 0
    for ind,f in enumerate(F):
        num = sum([j*k for j,k in zip(i,f)])
        score += P[ind][num]
    ans = max(ans,score)
    
print(ans)

Solution (Python):
import itertools

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

it = itertools.product((0, 1), repeat=10)
next(it)

ans = -float('inf')
for t in it:
    p_sum = 0
    for i in range(N):
        c = sum(F[i][x] * t[x] for x in range(10))
        p_sum += P[i][c]
    ans = max(ans, p_sum)

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**18
for i in range(1,2**10):
  idx=set()
  for j in range(10):
    if (i>>j)&1:
      idx.add(j)
  s=0
  for j in range(n):
    cnt=0
    for k in range(10):
      if k in idx:
        if f[j][k]:
          cnt+=1
    s+=p[j][cnt]
  ans=max(ans,s)
print(ans)

Solution (Python):
n = int(input())
F = [[int(x) for x in input().split()] for i in range(n)]
P = [[int(x) for x in input().split()] for i in range(n)]
res = -10**12
for bit in range(1, 2 ** 10):
    cc = 0
    for i in range(n):
        cc += P[i][sum([(F[i][j]==1 and (1 & (bit >> j))==True) for j in range(10)])]
    res = max(res, cc)
print(res)

Solution (Python):
n = int(input())
list_F = [ list(map(int,input().split(" "))) for i in range(n)]
list_P = [ list(map(int,input().split(" "))) for i in range(n)]
ans = (-1)*pow(10, 9)
a = 0
for i in range(1, 2**10):
    value = 0
    for k in range(n):
        l = list_F[k]
        cnt = 0
        for j in range(10):
            if ((i >> j) & 1):
                if l[j] == 1:
                    cnt += 1
        value += list_P[k][cnt]
    ans = max(ans, value)

print(ans)

Solution (Python):
N = int(input())
 
F = []
 
for _ in range(N):
    f = list(input().strip().split())
    F.append(int("".join(f), 2))

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

ans = -10**10-7

for i in range(1,2**10):
    candi = 0
    for j in range(N):
        tmp = i & F[j]
        p = format(tmp, 'b').count("1")
        candi += P[j][p]
    ans = max(ans,candi) 
    
print(ans)

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

F = []

for _ in range(N):
    f = list(input().strip().split())
    F.append(int("".join(f), 2))


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

ans = -float('inf')

for i in range(1, 2**10):
    candi = 0
    for n in range(N):
        tmp = i & F[n]
        p = format(tmp, 'b').count("1")
        candi += P[n][p]
    if candi == 0:
        foo = 1
    ans = max(ans, candi)

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

ans = -(int(1e9) + 7)

for i in range(2 ** 10):
    d = [False] * 10
    for j in range(10):
        if i >> j & 1:
            d[j] = True
    if not True in d:
        continue

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

Solution (Python):
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True 
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n = inn()
f = []
p = []
for i in range(n):
    f.append(inl())
for i in range(n):
    p.append(inl())
mx = -BIG
for t in range(1,2**10):
    s = [(t>>i)%2 for i in range(10)]
    sm = 0
    for i in range(n):
        x = sum([s[j]*f[i][j] for j in range(10)])
        sm += p[i][x]
    mx = max(mx,sm)
print(mx)

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**18

for i in range(1, 2**10):
    A = [0]*10
    
    for j in range(10):
        if (i>>j)&1:
            A[j] = 1
        
    ans_cand = 0
    
    for j in range(N):
        c = 0
        
        for k in range(10):
            if F[j][k]==1 and A[k]==1:
                c += 1
        
        ans_cand += P[j][c]
    
    ans = max(ans, ans_cand)

print(ans)

Solution (Python):
n = int(input())
fll = []
pll = []

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

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

ans = -float("inf")
from itertools import product
for bits in product([0, 1], repeat=10):
    if sum(bits) == 0:
        continue
    tmp = 0
    for fl, pl in zip(fll, pll):
        count = 0
        for f, bit in zip(fl, bits):
            if f and bit:
                count += 1
        tmp += pl[count]
    ans = max(ans, tmp)

print(ans)

Solution (Python):





from copy import deepcopy


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

    
    n_overlaps_list = []

    def rec(time_i, counts, flag):
        
        
        
        if time_i == 10:
            if not flag:
                
                n_overlaps_list.append(counts)
            return None

        counts_1 = deepcopy(counts)
        counts_2 = deepcopy(counts)

        for i in range(len(counts)):
            if F[i][time_i] == 1:
                counts_2[i] += 1

        rec(time_i+1, counts_1, flag and True)  
        rec(time_i+1, counts_2, False)  

    rec(0, [0] * N, True)
    

    ans = -(10**10)
    tmp = None
    for n_overlaps in n_overlaps_list:
        candidate = 0
        for i in range(N):
            candidate += P[i][n_overlaps[i]]
        if candidate > ans:
            ans = candidate
            tmp = n_overlaps
    
    
    return ans


print(main())

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

F = []
for _ in range(N):
    tmp = list(map(int, input().split()))
    v = 0
    for i in range(5 * 2):
        v += tmp[i] << i
    F.append(v)

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

ans = -1 * (10**12)
for bit in range(1, 1 << (5 * 2)):
    v = 0
    for i in range(len(F)):
        f = F[i]
        product = bit & f
        cnt = 0
        for j in range(5 * 2):
            if product & (1 << j):
                cnt += 1
        v += P[i][cnt]
    ans = max(ans, v)
print(ans)

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

F = []
for _ in range(N):
    tmp = list(map(int, input().split()))
    v = 0
    for i in range(5 * 2):
        v += tmp[i] << i
    F.append(v)

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

ans = -1 * (10**12)
for bit in range(1, 1 << (5 * 2)):
    v = 0
    for i in range(len(F)):
        f = F[i]
        product = bit & f
        cnt = 0
        for j in range(5 * 2):
            if product & (1 << j):
                cnt += 1
        v += P[i][cnt]
    ans = max(ans, v)
print(ans)

Solution (Python):
n = int(input())
f = [0]*n
for i in range(n):
  f[i] = [int(x) for x in input().split()]

p = [0]*n
for i in range(n):
  p[i] = [int(x) for x in input().split()]

ans = -10**9-7

for i in range(2**10):
  o = [0]*10
  for j in range(10):
    if (i >> j) & 1:
      o[j] = 1
  if not any(o):
    continue
  sub = 0
  for k in range(n):
    key = 0
    for j in range(10):
      if o[j] and f[k][j]:
        key += 1
    sub += p[k][key]
  if sub > ans:
    ans = sub

print(ans)

Solution (Python):
n = int(input())
f = [0]*n
for i in range(n):
  f[i] = [int(x) for x in input().split()]

p = [0]*n
for i in range(n):
  p[i] = [int(x) for x in input().split()]

ans = -10**9-7

for i in range(2**10):
  o = [0]*10
  for j in range(10):
    if (i >> j) & 1:
      o[j] = 1
  if not any(o):
    continue
  sub = 0
  for k in range(n):
    key = 0
    for j in range(10):
      if o[j] and f[k][j]:
        key += 1
    sub += p[k][key]
  if sub > ans:
    ans = sub

print(ans)

Solution (Python):

from itertools import product


try:
    from typing import List
except ImportError:
    pass


def solve(N: int, F: "List[List[int]]", P: "List[List[int]]"):
    print(max(
        sum(
            Pi[sum(ptnj * Fij for ptnj, Fij in zip(ptn, Fi))]
            for Fi, Pi in zip(F, P)
        )
        for ptn in product((0, 1), repeat=10)
        if sum(ptn) != 0
    ))


def main():
    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)
    ]
    solve(N, F, P)


if __name__ == '__main__':
    main()

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

cnts = [0] * 10
for F in Fs:
    for i,f in enumerate(F):
        cnts[i] += f

ans = -10**10
for i in range(1,2**10):
    bs = list(bin(i)[2:].zfill(10))
    cnt_all = 0
    for fs,ps in zip(Fs, Ps):
        cnt = 0
        for i in range(10):
            if int(bs[i]) * int(fs[i]) == 1:
                cnt += 1
        cnt_all += ps[cnt]
    ans = max(cnt_all,ans)
    
print(ans)

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




profit_list=[]
for i in range(1, 2 ** 10):
    profit=0
    for k in range(N):
        kaburi = i & F[k]
        
        kaburi_count=0
        for j in range(10):
            if ((kaburi >> j) & 1):
                kaburi_count+=1
        profit+=P[k][kaburi_count]
    profit_list.append(profit)

print(max(profit_list))

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

def readlines(n):
    for _ in range(n):
        yield list(map(int,input().split()))

def bene(me, f, p):
    a = len([0 for m in me if f[m] == 1])
    return p[a]

def main():
    n = int(input())
    F = list(readlines(n))
    P = list(readlines(n))

    for i in range(1, 11):
        for comb in combinations(range(10), i):
            yield sum(bene(comb, f, p) for f, p in zip(F,P))

    
print(max(main()))

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

def readlines(n):
    for _ in range(n):
        yield list(map(int,input().split()))

def bene(me, f, p):
    a = sum(1 if f[m] == 1 else 0 for m in me)
    return p[a]

def main():
    n = int(input())
    F = list(readlines(n))
    P = list(readlines(n))

    for i in range(1, 11):
        for comb in combinations(range(10), i):
            yield sum(bene(comb, f, p) for f, p in zip(F,P))

    
print(max(main()))

Solution (Python):
N=int(input())
F=[int('0b'+''.join(list(input().split(' '))),0) 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):
    tmp = 0
    for j,k in zip(P,F):
        tmp += j[str(bin(i&k)).count('1')]
    ans = max(tmp,ans)
print(ans)

Solution (Python):
n = int(input())
F = []
for i in range(n):
  f = list(map(int,input().split()))
  shop = []
  for j in range(5):
    shop.append([f[2*j],f[2*j+1]])
  F.append(shop)
P = [list(map(int,input().split())) for _ in range(n)]

import numpy as np
ans = -float('inf')
for i in range(1,2**10):
  index =format(i,'b').zfill(10)
  open_j = [int(j) for j in index]
  open_j = np.array(open_j).reshape(5,2)
  score = 0
  for j in range(n):
    count = 0
    for k in range(5):
      for l in range(2):
        if F[j][k][l] and open_j[k][l]:
          count += 1
    score += P[j][count]
  ans = max(ans,score)
print(ans)

Solution (Python):
n = int(input())
opened = [int('0b' + input().replace(' ', ''), 2) for i in range(n)]
prise = [list(map(int, input().split())) for i in range(n)]

ans = -float('INF')
for i in range(1,int('10000000000', 2)):
    cnt = [0 for i in range(n)]
    for j in range(10):
        if 1<<j & i == 0:
            continue
        for k in range(n):
            if 1<<j & opened[k]:
                cnt[k] += 1
    tmp = sum([prise[k][cnt[k]] for k in range(n)])
    if tmp > ans:
        
        ans = tmp
print(ans)

Solution (Python):
n=int(input())
S=[int(input().replace(' ',''),2) for _ in range(n)]
C=[list(map(int,input().split())) for _ in range(n)]
A=[]
for i in range(1,2**10):
    ans=0
    for j in range(n):
        cnt=bin(S[j]&i).count('1')
        ans+=C[j][cnt]
    A.append(ans)
print(max(A))

Solution (Python):
n=int(input())
S=[list(map(str,input().split())) for _ in range(n)]
C=[list(map(int,input().split())) for _ in range(n)]
A=[]
for i in range(1,2**10):
    ans=0
    X=format(i,'b').zfill(10)
    for j in range(n):
        cnt=0
        for k in range(10):
            if S[j][k]=='1' and X[k]=='1':
                cnt+=1
        ans+=C[j][cnt]
    A.append(ans)
print(max(A))

Solution (Python):
n=int(input())
S=[list(map(str,input().split())) for _ in range(n)]
C=[list(map(int,input().split())) for _ in range(n)]
A=[]
for i in range(1,2**10):
    ans=0
    X=format(i,'b').zfill(10)
    for j in range(n):
        cnt=0
        for k in range(10):
            if S[j][k]=='1' and X[k]=='1':
                cnt+=1
        ans+=C[j][cnt]
    A.append(ans)
print(max(A))