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
readline = sys.stdin.readline

N = int(readline())
F = [None] * N
for i in range(N):
  F[i] = int(readline().rstrip().replace(" ",""),2)
    
P = [None] * N
for i in range(N):
  P[i] = list(map(int,readline().split()))
  
ans = -(10 ** 10)
for i in range(1, 2 ** 10):
  
  
  point = 0
  for j in range(N):
    
    debug = False
    c = bin(i & F[j])[2:].count("1")
    point += P[j][c]
  if ans < point:
    ans = point
  
print(ans)

Solution (Python):
N,*f = map(int, open(0).read().split())
F = [f[i*10:i*10+10] for i in range(N)]
P = [f[N*10+i*11:N*10+i*11+11] for i in range(N)]
ans = -1 * pow(10,10)
opened = [0] * 10
for i in range(1,2**10):
    temp = 0
    for j in range(10):
        if i >> j & 1:
            opened[j] = 1
        else:
            opened[j] = 0
    for j in range(N):
        c = sum(opened[k]*F[j][k] for k in range(10))
        temp += P[j][c]
    ans = max(ans,temp)
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 ** 30)
for p in product(range(2), repeat=10):
    if sum(p) == 0: continue
    tmp = 0
    for i in range(N):
        
        cnt = 0
        for j in range(10):
            if p[j] and F[i][j]:
                cnt += 1
        tmp += P[i][cnt]
    ans = max(ans, tmp)
print(ans)

Solution (Python):
from itertools import product
from operator import mul
def main():
    n = int(input())
    f = [tuple(map(int, input().split())) for _ in range(n)]
    p = [tuple(map(int, input().split())) for _ in range(n)]

    patterns = tuple(product([0,1], repeat=10))
    results = []
    for pate in patterns:
        if sum(pate) == 0:
            continue
        r = 0
        for i1, fe in enumerate(f):
            r += p[i1][sum(tuple(map(mul, pate, fe)))]
        results.append(r)
    print(max(results))
if __name__ == '__main__':
    main()

Solution (Python):
import sys
input = sys.stdin.readline
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())))

cand = []
for i in range(1, 2 ** 10):
  cnt = [0] * n
  for j in range(10):
    if i & (1 << j):
      for k in range(n):
        if f[k][j]:
          cnt[k] += 1
  v = 0
  for k in range(n):
    v += p[k][cnt[k]]
  cand.append(v)
    
print(max(cand))

Solution (Python):
import sys
input = sys.stdin.readline
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())))

cand = []
for i in range(1, 2 ** 10):
  cnt = [0] * n
  for j in range(10):
    if i & (1 << j):
      for k in range(n):
        if f[k][j]:
          cnt[k] += 1
  v = 0
  for k in range(n):
    v += p[k][cnt[k]]
  cand.append(v)
    
print(max(cand))

Solution (Python):
N = int(input())
F = []
P = []
for i in range(N):
    F += [list(map(int, input().split()))]
for i in range(N):
    P += [list(map(int, input().split()))]
ans = float('-inf')

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

Solution (Python):
N = int(input())
F = []
P = []
for i in range(N):
    F += [list(map(int, input().split()))]
for i in range(N):
    P += [list(map(int, input().split()))]
ans = float('-inf')

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

Solution (Python):
def main():
    n = int(input())
    F = [list(map(int, input().split())) for _ in range(n)]
    P = [list(map(int, input().split())) for _ in range(n)]
    ans = -float('inf')
    for i in range(1, 1 << 10):
        A = [0] * 10
        for j in range(10):
            if i >> j & 1:
                A[j] = 1
        C = [0] * n
        for k in range(n):
            c = 0
            for a, f in zip(A, F[k]):
                if a == f == 1:
                    c += 1
            C[k] = c
        ans = max(ans, sum([P[i][c] for i, c in enumerate(C)]))
    print(ans)


if __name__ == '__main__':
    main()

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

lis=[]
for i in list(itertools.product([0,1],repeat=10))[1:]:
    lisi=0
    for j in range(n):
        sj=0
        for k in range(10):
            sj+=i[k]*f[j][k]
        lisi+=p[j][sj]
    lis.append(lisi)

print(max(lis))

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

lis=[]
for i in list(itertools.product([0,1],repeat=10))[1:]:
    lisi=0
    for j in range(n):
        sj=0
        for k in range(10):
            sj+=i[k]*f[j][k]
        lisi+=p[j][sj]
    lis.append(lisi)

print(max(lis))

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

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

ans = -float("inf")
for i in range(1, 2**10):
    isOpen = []
    for j in range(10):
        if i & (1<<j):
            isOpen.append(1)
        else:
            isOpen.append(0)
    res = 0
    for j in range(n):
        cnt = 0
        for k in range(10):
            if isOpen[k] and f[j][k]:
                cnt += 1
        res += p[j][cnt]
    ans = max(ans, res)

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

print(ans)

Solution (Python):
X = open(0).readlines()
n = int(X[0])
F = []
for x in X[1:n+1]:
    F.append(list(map(int, x.split())))
P = []
for x in X[n+1:]:
    P.append(list(map(int, x.split())))

ans = -10**10
for i in range(1, 2**10):
    A = [(i >> j) & 1 for j in range(10)]
    s = 0
    for j in range(n):
        c = sum(p and a for p, a in zip(F[j], A))
        s += P[j][c]
    if ans < s:
        ans = s
print(ans)

Solution (Python):
n = int(input())
c = [list(map(int, input().split())) for i in range(n)]
p = [list(map(int, input().split())) for i in range(n)]
ans2 = -10**10
for i in range(1, 2**10):
  ans = 0
  count = [0]*n
  for j in range(10):
     if ((i >> j) & 1):
        for k in range(n):
          if c[k][j] == 1:
            count[k] += 1
  for l in range(n):
    ans += p[l][count[l]]
  if ans> ans2:
    ans2 =ans
print(ans2)

Solution (Python):
import math

n=int(input())
f=list()
p=list()
ans=-10**10
for i in range(n):
    f.append(list(map(int,input().split())))
for i in range(n):
    p.append(list(map(int,input().split())))
for i in range(1,1<<10):
    shop=list()
    cnt=[0]*n
    tmp=0
    for j in range(10):
        if i>>j&1:
            shop.append(j)
    for s in range(n):
        for k in shop:
            if(f[s][k]==1):
                cnt[s]+=1
        tmp+=p[s][cnt[s]]
    ans=max(ans,tmp)
print(ans)

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

ans = -float('inf')
for bit in range(1, 2 ** 10):
    
    score = 0
    for i in range(len(f)):
        
        cnt = 0
        for j in range(10):
            
            if f[i][j] & (bit >> j):
                cnt += 1
        score += p[i][cnt]
    ans = max(score, ans)
print(ans)

Solution (Python):
MAX_TIME = 10
n = int(input().rstrip())

P = [sum(int(i) << MAX_TIME-k-1 for k, i in enumerate(input().rstrip().split())) for j in range(n)]
S = [list(map(int, input().rstrip().split())) for i in range(n)]

    
pattern = [sum(i >> j & 1 for j in range(MAX_TIME)) for i in range(2 ** MAX_TIME)]
result = -float('inf')


for i in range(1, 2**MAX_TIME):
    temp = 0
    for l, j in zip(P, S):
        temp += j[pattern[l & i]]
    result = max(result, temp)
print(result)

Solution (Python):
import itertools
mylist = [0, 1]
n = int(input().rstrip())

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

maxnum = - float('inf')
for i in itertools.product(mylist, repeat = 10):
    if sum(i) == 0:
        continue
    sell = 0
    for j, k in zip(mise, mine):
        temp = 0
        for l in range(10):
            if j[l] == i[l] and j[l] == 1:
                temp += 1
        sell += k[temp]
    maxnum = max(maxnum, sell)
print(maxnum)

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

print(ans)

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

ans = -float("INF")
for bit in range(1 << 10):
    day = []
    for i in range(10):
        if (bit >> i) & 1:
            day.append(i)
    if day == [] or bit == 0:
        continue
    tmp = 0
    for i in range(N):
        c = 0
        for k in day:
            if F[i][k] == 1:
                c += 1
        tmp += P[i][c]
    ans = max(ans, tmp)

print(ans)

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

ans = -10000000000
for bit in range(1, 1<<10):
  now = 0
  for i in range(N):
    c = 0
    for j in range(10):
      if (1&bit>>j) & F[i][j]:
        c += 1
    now += P[i][c]
  ans = max(ans, now)
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,2**10):
    now = 0
    for j in range(n):
        cou = 0
        for k in range(10):
            if (i >> k & f[j][k]) == 1:
                cou += 1
        now += p[j][cou]
    ans = max(ans,now)
print(ans)

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

import itertools

xl = list(itertools.product(range(2), repeat=10))

res = -1*(10**10)

for i in range(1,1024):
    temp =0
    for j in range(n):
        op = 0
        
        for k in range(10):
            op += xl[i][k]*fl[j][k] 
        temp += pl[j][op]
    
    res = max(res,temp)
    
print(res)

Solution (Python):
n = int(input())
f = []
for i in range(n):
    fi = list(map(int,input().split()))
    f.append(fi)
p = []
for i in range(n):
    t = list(map(int,input().split()))
    p.append(t)
ma = -1 * 10 ** 12
for bit in range(1024):
    count = 0
    countc = 0
    for i in range(n):
        countb = 0
        for j in range(10):
            if bit >> j & 1 and f[i][j] == 1:
                countb+=1
                countc+=1
        count+= p[i][countb]
    if countc == 0:
        continue
    ma = max(ma,count)
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 = -10**9
for i in range(1, pow(2, 10)):
    res = 0
    for j in range(n):
        cnt = 0
        for k in range(10):
            if (i >> k)&1 and f[j][k]:
                cnt += 1
        res += p[j][cnt]
    ans = max(ans, res)
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,2**10):
    now = 0
    for j in range(n):
        cou = 0
        for k in range(10):
            if (i >> k & f[j][k]) == 1:
                cou += 1
        now += p[j][cou]
    ans = max(ans,now)
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()))
    bi = ''.join(f)
    F.append(int(bi, 2))
P = []
for i in range(N):
    p = getList()
    P.append(p)


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

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7


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

ans = -INF
for i in range(1, 1<<10):
	i = list("{:b}".format(i).zfill(10))
	profit = 0
	for j in range(N):
		cnt = sum([int(i[k])*F[j][k] for k in range(10)])
		profit += P[j][cnt]
	ans = max(ans, profit)

print(ans)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7


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

ans = -INF
for i in range(1, 1<<10):
	i = list("{:b}".format(i).zfill(10))
	profit = 0
	for j in range(N):
		cnt = 0
		for k in range(10):
			if i[k] == "1" and F[j][k] == 1:
				cnt += 1
		profit += P[j][cnt]
	ans = max(ans, profit)

print(ans)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7


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

ans = -INF
for x in product([0, 1], repeat=10):
	x = list(x)
	if 1 in x:
		profit = 0
		for i in range(N):
			common = sum([x[j]*F[i][j] for j in range(10)])
			profit += P[i][common]
		ans = max(ans, profit)

print(ans)

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

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

print(ans)

Solution (Python):
N = int(input())
list_FF = []

for i in range(N):
  list_F = list(map(int, input().split()))
  list_FF.append(list_F)

list_PP = []

for i in range(N):
  list_P = list(map(int, input().split()))
  list_PP.append(list_P)  
  
count = 1
quota = 0

for i in range(N):
  quota+= list_PP[i][list_FF[i].count(1)]

maxquota = quota
    
while count < 2** 10:
  l = list(bin(count))
  lc_tdc = l[2:]
  l_tdc = []
  while lc_tdc:
    l_tdc.append(int(lc_tdc.pop(0)))
  
  while len(l_tdc) < 10:
    l_tdc.insert(0, 0)

  quota = 0
  
  for i in range(N):
    corresp = 0
    for j in range(10):
      corresp+= l_tdc[j]* list_FF[i][j]
    quota+= list_PP[i][corresp]
  maxquota = max(quota, maxquota)
      
  count+= 1

print(maxquota)

Solution (Python):
def count_c(li1, li2):
    c = 0
    for i in range(10):
        if li1[i] == 1 and li1[i] == li2[i]:
            c += 1
    return c


n = int(input())
open_time_list = [list(map(int, input().split())) for _ in range(n)]
profit_list = [list(map(int, input().split())) for _ in range(n)]
ans = -10000000000000000000000000000000000

for i in range(1, 2 ** 10):
    f_list_joisino = list(map(int, list(format(i, 'b').zfill(10))))
    temp_profit = 0
    for profit_index, f_list in enumerate(open_time_list):
        temp_profit += profit_list[profit_index][count_c(
            f_list, f_list_joisino)]
    if ans < temp_profit:
        ans = temp_profit

print(ans)

Solution (Python):
import numpy as np
n = 10
bit_base = 2
def Base_10_to_n(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out
  
def main():
  N = int(input())
  F = []
  for i in range(N):
    F.append(list(map(int, input().split())))
  F = np.array(F)
  P = []
  for i in range(N):
    P.append(list(map(int, input().split())))
  ans = -1*10**9
  for i in range(bit_base**n):
    if i == 0: continue
    s = Base_10_to_n(i, bit_base)
    s = s.zfill(n)
    for num, j in enumerate(s):
      ans_temp = 0
      s = list(s)
      s = np.array([int(i) for i in s])
      C = np.sum(F*s, axis = 1)
      for k,c in enumerate(C):
        ans_temp += (P[k][c])
      ans = max(ans, ans_temp)
  print(ans)
if __name__ == "__main__":
  main()

Solution (Python):



from itertools import accumulate
n = int(input())
lis = []
for i in range(n):
    A=[int(i) for i in input().split()]
    lis.append(A)
ans = [0]*10
lis2 = []
for i in range(n):
    p = [int(i) for i in input().split()]
    lis2.append(p)


ans = -10000000000
for i in range(1,1<<10):
    kaburi = [0]*n
    tmp = 0
    for j in range(11):
        if(i & 1<<j):
            for k in range(n):
                if lis[k][j]:
                    kaburi[k]+=1
    for j in range(n):
        tmp += lis2[j][kaburi[j]]

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

Solution (Python):


import sys






















from itertools import product, permutations  







def main():
    mod = 1000000007                
    inf = float('inf')              
    
    sys.setrecursionlimit(10**6)    
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())

    def count_both_opened(pattern, seq):
        cnt = 0
        for i in range(len(pattern)):
            if pattern[i] == 1 and seq[i] == 1:
                cnt += 1
        return cnt
    
    
    n = ii()
    opened = [lmi() for _ in range(n)]
    profit = [lmi() for _ in range(n)]

    max_profit = -inf
    for pattern in product([1, 0], repeat=10):
        money = 0
        if any(pattern):
            for i in range(n):
                cnt = count_both_opened(pattern, opened[i])
                money += profit[i][cnt]
            
            max_profit = max(max_profit, money)

    print(max_profit)

if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
F = list()
P = list()
ans = - 10**10
for i in range(N):
  F.append(list(map(int, input().split())))
for i in range(N):
  P.append(list(map(int, input().split())))
for i in range(1, 1<<10):
  shop = list()
  cnt = [0]*N
  tmp = 0
  for j in range(10):
    if i>>j & 1:
      shop.append(j)
  for s in range(N):
    for p in shop:
      if(F[s][p] == 1):
        cnt[s] += 1
    tmp += P[s][cnt[s]]
  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, 2**10):
  c = [0] * N
  for j in range(10):
    if i>>j & 1:
      for k in range(N):
        c[k] += F[k][j]
  profit = sum([P[k][c[k]] for k in range(N)])
  ans = max(ans, profit)

print(ans)

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

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

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

INF = 1e100
ans = -1 * INF
for i in range(2**10):
    ch = [0] * 10
    cnt = 0
    for j in range(10):
        if (i >> j) & 1:
            ch[j] = 1
            cnt += 1
    if not cnt:
        continue
    total = 0
    for k in range(n):
        ct = 0
        for l in range(10):
            if opens[k][l] and ch[l]:
                ct += 1
        total += score[k][ct]
    ans = max(ans, total)

print(ans)

Solution (Python):






import sys
input = sys.stdin.readline

import math

import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache






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






def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]


def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()


def DD(arg): return defaultdict(arg)



def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


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 make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd (a, b)


def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count


def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))


def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count





N = I()
F = ILL(N)
P = ILL(N)

for i in range(N):
  F[i] = base_n_to_10(sum(F[i][j]*10**j for j in range(10)),2)
  
ans = -INF
for b in range(1,1<<10):
  rieki = 0
  for i in range(N):
    match = count_bit(F[i] & b)
    rieki += P[i][match]
  ans = max(ans,rieki)
  
print(ans)

Solution (Python):
N=int(input())
F=[int(input().replace(" ",""),2) for i in range(N)]
P=[list(map(int,input().split())) for j in range(N)]
print(max(sum([p[bin(i&f).count("1")] for f,p in zip(F,P)]) for i in range(1,2**10)))

Solution (Python):
from itertools import product


def main():
    N = int(input())
    F = [list(map(int, input().split(' '))) for _ in range(N)]
    P = [list(map(int, input().split(' '))) for _ in range(N)]
    ans = - 10**10
    for pattern in product([0, 1], repeat=10):
        if sum(pattern) == 0:
            continue
        profit = 0
        for n in range(N):
            c = sum([1 if p == f == 1 else 0 for p, f in zip(pattern, F[n])])
            profit += P[n][c]
        ans = max([ans, profit])
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
F = []
P = []

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

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

ans = -10 ** 18


for i in range(1, 2**10):
    kaburi_list = []
    tmp = 0
    for tenpo in range(N):
        kaburi = 0
        for j in range(10):
            if i >> j & F[tenpo][-(j+1)] == 1:
                kaburi += 1
        kaburi_list.append(kaburi)
        tmp += P[tenpo][kaburi]
    ans = max(ans, tmp)

print(ans)

Solution (Python):
N = int(input())
F = []
P = []

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

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

ans = -10 ** 9

for i in range(1, 2**10):
    kaburi_list = []
    tmp = 0
    for tenpo in range(N):
        kaburi = 0
        for j in range(10):
            if i >> j & F[tenpo][-(j+1)] == 1:
                kaburi += 1
        kaburi_list.append(kaburi)
        tmp += P[tenpo][kaburi]
    ans = max(ans, tmp)

print(ans)

Solution (Python):
def solve(n, f_list, p_list):

    ans = [0] * 1024
    
    for i in range(1, 1024):
        for f, p in zip(f_list, p_list):
            c = bin(f & i).count("1")
            ans[i] += p[c]
    
    return max(ans[1:])

if __name__ == "__main__":
    n = int(input())
    f_list = [int("".join(input().split()),2) for i in range(n)]
    p_list = [[int(j) for j in input().split()] for i in range(n)]
    print(solve(n, f_list, p_list))

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