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 _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]

ans = - 10**10

for i in range(1,1<<10):
    score = 0
    for n in range(N):
        f = "".join(map(str,F[n])) 
        b = "{:010b}".format(i)
        c = [int(f[i]) & int(b[i]) for i in range(10)]
        cnt = len(list(filter( lambda x: x, c)))
        score += P[n][cnt]
    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)]
from itertools import product
gain=[]
for p in product([0,1,2,3],repeat=5):
    C=[0 for i in range(N)]
    for i in range(5):
        for j in range(N):
            am=F[j][2*i]
            pm=F[j][2*i+1]
            if p[i]==1:
                C[j]+=am
            elif p[i]==2:
                C[j]+=pm
            elif p[i]==3:
                C[j]+=am+pm
    g=0
    for j in range(N):
        g+=P[j][C[j]]
    
    flag=False
    for i in range(5):
        if p[i]!=0:
            flag=True
    if flag:
        gain.append(g)

print(max(gain))

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 k in range(1, 2**10):
    *bi, = map(int, bin(k).zfill(10).replace('b', '0')[::-1])
    ans = max(ans, sum([p[i][[bi[j] & f[i][j] for j in range(10)].count(1)]
              for i in range(n)]))
print(ans)

Solution (Python):
def solve(N, Fs, Ps):
    profit = - 10 ** 10
    for k in range(1, 1025):
        b = "{:010b}".format(k)
        p = 0
        for P, F in zip(Ps, Fs):
           p += P[sum(F[i] * int(b[i]) for i in range(10))]
        profit = max(profit, p)
    return profit

if __name__ == "__main__":
    N = int(input())
    Fs = [tuple(map(int, input().split(" "))) for _ in range(N)]
    Ps = [tuple(map(int, input().split(" "))) for _ in range(N)]
    print(solve(N, Fs, Ps))

Solution (Python):

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

P = []
for _ in range(N):
    P.append(list(map(int, input().split())))
    
ans = - float('inf')
for n in range(1, 1<<10):
    cur = 0
    for mise in range(N):
        mise_open = F[mise]
        both_open_cnt = bin(mise_open&n).count("1")
        cur += P[mise][both_open_cnt]
    ans = max(cur, ans)
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 = -999999999999999999
for i in range(1 << 10):
    A = [0] * N

    cnt = 0
    for j in range(10):
        if (i >> j) & 1:
            cnt += 1
            for k in range(N):
                if F[k][j] == 1:
                    A[k] += 1
    if cnt == 0:
        continue
    tmp = 0
    for t in range(N):
        tmp += P[t][A[t]]

    if tmp > ans:
        ans = tmp
print(ans)

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

from itertools import product
ans = -float('inf')
for jo in product(range(2), repeat=10):
    if sum(jo) == 0:
        continue
    prof = 0
    for p, f in zip(ps, fs):
        sim = sum(i * j for i, j in zip(jo, f))
        prof += p[sim]
    if prof > ans:
        ans = prof

print(ans)

Solution (Python):
def binaryarray_to_int(a):
    res = 0
    for x in a:
        res = (res << 1) + x
    return res

def count_bits(x):
    res = 0
    while x > 0:
        res += (x & 1)
        x = x >> 1
    return res


def solve():
    N = int(input())

    F = [
        binaryarray_to_int(
            [int(x) for x in input().split()]
        )
        for _ in range(N)
    ]

    P = [
        [int(x) for x in input().split()]
        for _ in range(N)
    ]

    
    ans = -float("inf")
    for mask in range(1, 1024):
        p = 0
        for i in range(N):
            bit = mask & F[i]
            c = count_bits(bit)
            p += P[i][c]
        ans = max(ans, p)

    return ans


print(solve())

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

ans = -float("inf")
for bit in range(1 << 10) :
    expl = []
    for k in range(10) :
        if bit & (1 << k) :
            expl.append(k)
    if len(expl) :
        benefit = 0
        for i in range(N) :
            cnt = 0
            for j in range(len(expl)) :
                if F[i][expl[j]] :
                    cnt += 1
            benefit += P[i][cnt]
        if ans < benefit :
            ans = benefit
print(ans)

Solution (Python):


from itertools import product

def main():
    n = int(input())
    f = []
    p = []
    for ob in (f, p):
        for i in range(n):
            ro = list(map(int, input().split()))
            ob.append(ro)
    res = -99999999999
    for open_at in product((0, 1), repeat=10):
        if 1 not in open_at:
            continue
        res = max(res, get_rieki(f, p, open_at, n))
    print(res)

def get_rieki(f, p, open_at, n):
    res = 0
    for i in range(n):
        cnt = sum(f[i][t] * open_at[t] for t in range(10))
        res += p[i][cnt]
    return res

main()

Solution (Python):


from itertools import product

def main():
    n = int(input())
    f = []
    p = []
    for ob in (f, p):
        for i in range(n):
            ro = list(map(int, input().split()))
            ob.append(ro)
    res = -99999999999
    for open_at in product((0, 1), repeat=10):
        if 1 not in open_at:
            continue
        res = max(res, get_rieki(f, p, open_at, n))
    print(res)

def get_rieki(f, p, open_at, n):
    res = 0
    for i in range(n):
        cnt = 0
        for t in range(10):
            if f[i][t] == 1 and open_at[t] == 1:
                cnt += 1
        res += p[i][cnt]
    return res

main()

Solution (Python):
import itertools
N = int(input())
F, P = [], []
for _ in range(N):
    F.append(list(map(int, input().split())))
for _ in range(N):
    P.append(list(map(int, input().split())))
combinations = list(itertools.product((0, 1), repeat=10))[1:]
c = [0] * N
max_profit = -1000000001
for comb in combinations:
    profit = 0
    for i in range(N):
        c[i] = sum([F[i][jk] * comb[jk] for jk in range(10)])
        profit += P[i][c[i]]
    max_profit = max(max_profit, profit)
print(max_profit)

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

maxt = None
for i in range(1, 2**10):
  total = 0
  for _f, _p in zip(f, p):
    c = 0
    for bi, fi in zip(reversed(bin(i)[2:]), _f):
      if fi==1 and int(bi)==1:
        c += 1
    total += _p[c]
  maxt = max(total, maxt) if maxt is not None else total
print(maxt)

Solution (Python):
n = int(input())
F = [[int(i) for i in input().split()] for i in range(n)]
P = [[int(i) for i in input().split()] for i in range(n)]

ans = - 10 ** 10
for i in range(1, 2 ** 10):
    x = i
    A = []
    while x:
        A.append(x % 2)
        x //= 2
    while len(A) < 10:
        A.append(0)
        
    tmp = 0
    for j in range(n):
        cnt = 0
        for k in range(10):
            if F[j][k] == 1 and A[k] == 1:
                cnt += 1
        tmp += P[j][cnt]
    ans = max(ans, tmp)
    
print(ans)

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

open = []
earn = []

for _ in range(N):
    open.append(list(map(int, input().split())))

for _ in range(N):
    earn.append(list(map(int, input().split())))


ans = -float('inf')
for i in range(1, 1 << 10):
    tmp = 0
    same = [0]*N
    for j in range(N):
        for k in range(10):
            if open[j][k] == 1 and (i & (1 << k)):
                same[j] += 1

    for j in range(N):
        tmp += earn[j][same[j]]
    ans = max(ans, tmp)

print(ans)

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

open = []
earn = []

for _ in range(N):
    open.append(list(map(int, input().split())))

for _ in range(N):
    earn.append(list(map(int, input().split())))


ans = -float('inf')
for i in range(1, 1 << 10):
    tmp = 0
    same = [0]*N
    for j in range(N):
        for k in range(10):
            if open[j][k] == 1 and (i & (1 << k)):
                same[j] += 1

    for j in range(N):
        tmp += earn[j][same[j]]
    ans = max(ans, tmp)

print(ans)

Solution (Python):
n = int(input())
F = [[int(i) for i in input().split()] for i in range(n)]
P = [[int(i) for i in input().split()] for i in range(n)]

ans = -10 ** 10
for i in range(1, 2 ** 10):
    tmp = i
    A = []
    while tmp:
        A.append(tmp % 2)
        tmp //= 2
    while len(A) != 10:
        A.append(0)

    temp = 0
    for s in range(n):
        count = 0
        for t in range(10):
            if F[s][t] == 1 and A[t] == 1:
                count += 1
        temp += P[s][count]
    ans = max(ans, temp)
        
print(ans)

Solution (Python):
def calc_p(F, P, O):
    return P[sum(1 for f, o in zip(F, O) if f == 1 and o == 1)]

def calc_sum(Fs, Ps, O):
    return sum(calc_p(F, P, O) for F, P in zip(Fs, Ps))

def main(Fs, Ps):
    print(max(calc_sum(Fs, Ps, list(map(int, list('{0:010d}'.format(int(format(i, 'b'))))))) for i in range(1, 1024)))

if __name__ == '__main__':
    N = int(input())
    Fs = [list(map(int, input().split(' '))) for _ in range(N)]
    Ps = [list(map(int, input().split(' '))) for _ in range(N)]
    main(Fs, Ps)

Solution (Python):


import sys

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

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


n = II()
F = [LI() for _ in range(n)]
P = [LI() for _ in range(n)]

ans = -INF
for bit in range(1, 1024):
    profit = 0
    for shop in range(n):
        cnt = 0
        for shift in range(10):
            if not bit >> shift & 1:
                continue

            if F[shop][shift]:
                cnt += 1

        profit += P[shop][cnt]

    ans = max(ans, profit)

print(ans)

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

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

def bfs(list_hoge=[[]],depth=0):
    queue = []
    for e in list_hoge:
        for b in [0,1]:
            copy = e[:]
            copy.append(b)
            queue.append(copy)
    if depth == 10:
        return list_hoge[1:]
    list_hoge = queue[:]
    return bfs(list_hoge,depth+1)

ans = -float("inf")
for e in bfs():
    common = []
    for i in range(N):
        c = 0
        for j in range(10):   
            if e[j] == 1 and info[i][j] == 1:
                c += 1
        common.append(c)
    benefit = 0
    for i in range(N):
        c_i = common[i]
        benefit += p[i][c_i]
    if benefit > ans:
        ans = benefit
print(ans)

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

ans = -10**10
for i in range(1, 2**10):
    tmp = i
    b = []
    while tmp:
        b.append(tmp % 2)
        tmp //= 2
    while len(b) != 10:
        b.append(0)

    tmp = 0
    for j in range(N):
        cnt = 0
        for k in range(10):
            if b[k] == 1 and F[j][k] == 1:
                cnt += 1
        tmp += P[j][cnt]
    ans = max(ans, tmp)

print(ans)

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

Ans = -9999999999
for i in range(1 << 10):
    xx = bin(i)[2::].zfill(10)
    if xx == "0000000000":
        continue
    
    ans = 0
    for i in range(N):
        cnt = 0
        for j in range(10):
            if xx[j]=="1" and F[i][j]=="1":
                cnt += 1
        ans += P[i][cnt]

    Ans = max(Ans,ans)

print(Ans)

Solution (Python):


II = lambda: int(input())
MI = lambda: map(int, input().split())


def main():
    N = II()
    F = [tuple(MI()) for _ in range(N)]
    P = [tuple(MI()) for _ in range(N)]
    TS = 10

    ans = -float("inf")
    s = set()
    for tt in range(1, 2**TS):
        ts_open = [min(1, tt & (1 << i)) for i in range(TS)]
        s.add(tuple(ts_open))
        a = 0
        for i in range(N):
            o = 0
            for j in range(TS):
                if ts_open[j] and F[i][j] == 1: o += 1
            a += P[i][o]
        ans = max(ans, a)
    return ans


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

Solution (Python):
import itertools

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

answers = []
for bit in range(1, 2 ** 10):
    t = [min(1, bit & (1 << i)) for i in range(10)]
    answer = 0
    for i in range(n):
        c = sum(1 for j in range(10) if f[i][j] == 1 and t[j] == 1)
        answer += p[i][c]
    answers.append(answer)

print(max(answers))

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)]
max_profit = -10**9

for c in product(range(2),repeat=10):
    profit = 0

    if c == (0,0,0,0,0,0,0,0,0,0):
        continue

    for i in range(n): 
        common_business_day = 0
        for j in range(10):
            if c[j] == F[i][j] == 1:
                common_business_day += 1
        profit += P[i][common_business_day]
    
    max_profit = max(profit,max_profit)

print(max_profit)

Solution (Python):
N = int(input())
d1 = [int(input().replace(' ',''),2) for i in range(N)]
d2 = [list(map(int,input().split())) for l in range(N)]
ans = []


for i in range(1 << 10):
    if i != 0:
        sum = 0
        for j in range(N):
            temp = 0
            a = int(d1[j])
            b = a & i
            for k in range(10):
                if ((b >> k) & 1) == 1:
                    temp += 1
            else:
                sum += d2[j][temp]
        ans.append(sum)

print(max(ans))

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

a = list(range(10))
cnt = 0
total = 0
total_p = []
for i in range(1,11):
    c = list(itertools.combinations(a,i))
    
    for tap in c:
        for j in range(n):
            for num in tap:
                if f[j][num] == 1:
                    cnt += 1
                    
            total += p[j][cnt]
            cnt = 0
        
        total_p.append(total)
        total = 0

print(max(total_p))

Solution (Python):
n = int(input())
f = []
for i in range(n):
    f.append(list(int(i) for i in input().split()))

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

res = -10**9
for b in range(1,2**10):
    bit = bin(b)[2:]
    bit = '0'*(10-len(bit))+bit
    tmp = 0
    for i in range(n):
        count = 0
        for j in range(10):
            if int(bit[j])==f[i][j]==1:
                count += 1
        tmp += p[i][count]
    res = max(res,tmp)
print(res)

Solution (Python):

def getIntList(): return [int(x) for x in input().split()]
def zeros(n): return [0 for i in range(n)]

N = int(input())
F = []
for i in range(N):
    F.append(getIntList())

P = []
for i in range(N):
    P.append(getIntList())


maxProf = -10**9
for n in range(1,2**10):
    a = zeros(10)
    m = n
    for i in range(10):
        a[i] = m % 2
        m //= 2
    prof = 0
    for i in range(N):
        c = 0
        for j in range(10):
            c += a[j]*F[i][j]
        prof += P[i][c]
    if prof>maxProf: maxProf = prof
print(maxProf)

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

is_open=[]
def count_score(is_open,N,F,P):
    is_open_copy=list(is_open)
    if len(is_open_copy)==10:
        flag = True
        for t in is_open_copy:
            if t:
                flag=False
                break
        if flag:
            return -10**27
        count_N = [0 for i in range(N)]
        for i in range(N):
            for j in range(10):
                if is_open[j] and F[i][j]==1:
                    count_N[i]+=1
        score = 0
        for i in range(N):
            score+=P[i][count_N[i]]
        return score
    return max(count_score(is_open_copy+[True],N,F,P),count_score(is_open_copy+[False],N,F,P))

print(count_score(is_open,N,F,P))

Solution (Python):
ls = []
def onoff(n):
    global ls
    if len(n) == 10:
        ls.append(n)
    else:
        onoff(n + '0')
        onoff(n + '1')
onoff('0')
onoff('1')
del ls[0]
n = int(input())
f = [list(map(str,input().split())) for x in range(n)]
p = [list(map(int,input().split())) for x in range(n)]
ans = -99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
for i in range(1023):
    check = 0
    for j in range(n):
        count = 0
        for k in range(10):
            if ls[i][k] == f[j][k] and ls[i][k] == '1':
                count += 1
        check += p[j][count]
    ans = max(ans,check)
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 = []

for i in range(2**10):
    tmp = 0
    for j in range(N):
        num = 0
        for index, k in enumerate(F[j]):
            if k == 1:

                if i & 2**index:
                    num += 1
        tmp += P[j][num]
    ans.append(tmp)
ans = ans[1:]
print(max(ans))

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

open_Shop=[]
for i in range(N):
    open_shop=list(map(int,input().split()))
    open_Shop.append(open_shop)
    
profit_List=[]
for i in range(N):
    profit_list=list(map(int,input().split()))
    profit_List.append(profit_list)
    

max_profit=(-1000000000)

sub_Array=[]
for i in range(1,1024):
    Num=i
    for j in range(10):
        sub_Array.append(Num//(2**(9-j)))
        Num%=2**(9-j)
    score=0
    profit=0
    for k in range(N):
        for l in range(10):
            score+=(open_Shop[k][l]*sub_Array[l])
        profit+=profit_List[k][score] 
        score=0
    if max_profit<profit:
        max_profit=profit
    sub_Array=[]
    

print(max_profit)

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

for bit in range(1, 1 << 10):
    a = [0 for _ in range(n)]
    for j in range(10):
        for i in range(n):
            if bit%2==1 and F[i][j]:
                a[i] += 1
        bit //= 2
    tmp = 0
    for i in range(n):
        tmp += P[i][a[i]]
    res = max(res, tmp)
print(res)

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

F = [[int(j) for j in input().split()] for i in range(N)]
P = [[int(j) for j in input().split()] for i in range(N)]

ans = -999999999999999
for i in range(1,1<<10):
    res = 0
    for j in range(N):
        cnt = 0
        for k in range(10):
            if ((i>>k)&1 == 1) and (F[j][k] == 1):
                cnt+=1
        res += P[j][cnt]
    ans = max(ans,res)
print(ans)

Solution (Python):
def openlist(i):
    S = format(i, "b")
    ret = [0] * 10
    for j, i in enumerate(reversed(range(len(S)))):
        ret[-1*(j+1)] = int(S[i])
    return ret


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

ans = -1 * 10 ** 9
for i in range(1, 2**10):
    S = openlist(i)
    
    opstore = [sum([S[x]==1 and F[k][x]==1 for x in range(10)]) for k in range(n)]
    tmp_ans = sum([P[k][opstore[k]] for k in range(n)])
    ans = max(ans, tmp_ans)
print(ans)

Solution (Python):
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
f = [int("".join(ls()), 2) for _ in range(n)]      
p = [list(li()) for _ in range(n)]

def dfs(cur:int, depth:int):
    if depth == 10:
        if cur == 0:
            return -float("inf")
        else:
            profit = 0
            for i,fi in enumerate(f):
                both = 0
                
                for mask in range(10):
                    if cur&(1<<mask) and fi&(1<<mask):
                        both += 1
                
                profit += p[i][both]
                
            return profit
    
    else:
        return max(dfs(cur+(1<<depth), depth+1),
                   dfs(cur, depth+1))
        
print(dfs(0,0))

Solution (Python):
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
f = [int("".join(ls()), 2) for _ in range(n)]      
p = [list(li()) for _ in range(n)]

def dfs(cur:int, depth:int):
    if depth == 10:
        if cur == 0:
            return -float("inf")
        else:
            return sum([p[i][bin(cur&fi).count("1")] for i, fi in enumerate(f)])
    
    else:
        return max(dfs(cur+(1<<depth), depth+1),
                   dfs(cur, depth+1))
        
print(dfs(0,0))

Solution (Python):
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
f = [int("".join(ls()), 2) for _ in range(n)]      
p = [list(li()) for _ in range(n)]


ans = -float("inf")
for bit in range(1, 1<<10):
    profit = 0
    
    for i,fi in enumerate(f):
        both = 0
        
        for mask in range(10):
            if bit&(1<<mask) and fi&(1<<mask):
                both += 1
        
        profit += p[i][both]
    
    ans = max(ans, profit)
    
print(ans)

Solution (Python):
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
f = [int("".join(ls()), 2) for _ in range(n)]      
p = [list(li()) for _ in range(n)]


ans = -float("inf")
for bit in range(1, 1<<10):
    profit = 0
    
    for i,fi in enumerate(f):
        both = bin(bit&fi).count("1")
        profit += p[i][both]
    
    ans = max(ans, profit)
    
print(ans)

Solution (Python):
N = input()
F = [map(int, raw_input().split()) for _ in range(N)]
P = [map(int, raw_input().split()) for _ in range(N)]
res = -float('inf')
for i in range(1, 2 ** 10):
  mask = '0' * (10 - len(bin(i)) + 2) + bin(i)[2:]
  cand = 0
  for j in range(N):
    c = 0
    for k in range(10):
      c += F[j][k] & int(mask[k])
    cand += P[j][c]
  res = max(res, cand)
print res

Solution (Python):

N = int(input())
farr = []
parr = []
for i in range(N):
    farr.append(list(map(int,input().split())))
for i in range(N):
    parr.append(list(map(int,input().split())))
paym = -10**10
count = 0
for i in range(1,1<<10):
    pay = 0
    for j in range(N):
        tmp = i
        for k in range(10):
            if farr[j][k] == 1 and (tmp//2**k)%2 == 1:
                count += 1
            if tmp == 0:
                break
        pay += parr[j][count]
        count = 0
        
    if pay > paym:
        paym = pay

print(paym)

Solution (Python):
def abc080_c():
    import numpy as np
    import itertools

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

    for i in range(1, 11):
        for seq in itertools.combinations([i for i in range(10)], i):
            tmp = 0
            for j in range(n):
                tmp += p[j][sum(f[j][np.array(seq)])]
            benefits = np.append(benefits, tmp)

    print(max(benefits))


abc080_c()

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

Solution (Python):
def main():
    n = int(input())
    fs = [list(map(int, input().split())) for _ in range(n)]
    ps = [list(map(int, input().split())) for _ in range(n)]

    res = -(1 << 30)
    for b in range(1, 1 << 10):
        p = 0
        for i in range(n):
            c = 0
            for j in range(10):
                if (b >> j) & 1 and fs[i][j]:
                    c += 1
            p += ps[i][c]
        if res < p:
            res = p

    print(res)


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
f_list = []
p_list = []
ans_list = []
for i in range(n):
    f = list(map(int, input().split()))
    f_list.append(f)
for i in range(n):
    p = list(map(int, input().split()))
    p_list.append(p)
for i in range(1, 1<<10):
    ans = 0
    for j in range(n):
        count = 0
        for k in range(10):           
            if (i>>k & 1) == 1 and f_list[j][k] == 1:
                count += 1
        ans += p_list[j][count]
    ans_list.append(ans)
print(max(ans_list))

Solution (Python):
N = int(input())
F = []
P = []
for _ in range(N):
    F.append([int(f) for f in input().split()])
for _ in range(N):
    P.append([int(p) for p in input().split()])
res = []
for bit in range(1, 1 << 10):
    open_times = []
    for i in range(10):
        if((bit >> i) & 1) == 1:
            open_times.append(i)

    profit = 0
    for i in range(N):
        num_open = 0
        for open_time in open_times:
            if F[i][open_time]:
                num_open += 1
        profit += P[i][num_open]
    res.append(profit)

print(max(res))

Solution (Python):
N = int(input())
F = []
P = []
for _ in range(N):
    F.append([int(f) for f in input().split()])
for _ in range(N):
    P.append([int(p) for p in input().split()])
res = []
for bit in range(1, 1 << 10):
    open_times = []
    for i in range(10):
        if((bit >> i) & 1) == 1 and P:
            open_times.append(i)

    profit = 0
    for i in range(N):
        num_open = 0
        for open_time in open_times:
            if F[i][open_time]:
                num_open += 1
        profit += P[i][num_open]
    res.append(profit)

print(max(res))

Solution (Python):
N=int(input())
F=[int(input().replace(' ', ''), 2) for i in range(N)]
P=[[int(j) for j in input().split()] for j in range(N)]
a=-10**10
for i in range(1,1024):
    a=max(a, sum([P[j][bin(i&F[j]).count('1')] for j in range(N)]))
print(a)

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

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

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

max_num = -(10**9)
for i in range(1, 1<<10):
    point = 0
    for j in range(N):
        point += P[j][bin(i&F[j]).count("1")]
    
    
    
    max_num = max(max_num, point)

print(max_num)

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())))
count = {}
ans = []
for bits in range(1 << 10):
    count = {}
    for i in range(10):
        if (bits >> i & 1) == 1:
            for j in range(n):
                if j not in count: 
                    count[j] = f[j][i]
                else:
                    count[j] += f[j][i]
    if count != {}:
        flag = 0
        for k in range(n):
            if count[k] != 0:
                flag = 1
        if flag:
            check = 0
            for l in range(n):
                check += p[l][count[l]]
            ans.append(check)
print(max(ans))