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 = [0]*N
P = [0]*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()))


def calc(lst):
    res = 0
    for n in range(N):
        cnt = 0
        for i in range(10):
            if lst[i] + F[n][i] == 2:
                cnt += 1
        res += P[n][cnt]
    return res

def func(acc):
    if len(acc) == 10:
        if 1 in acc:
            return calc(acc)
        else:
            return -2e9
    else:
        return max(func(acc + [0]), func(acc + [1]))

print(func([]))

Solution (Python):
from itertools import product
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 p in product([0, 1], repeat = 10):
    if sum(p) == 0:
        continue
    res = 0
    for i in range(N):
        cnt = 0
        for j in range(10):
            if p[j]:
                cnt += F[i][j]
        res += P[i][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 = (-1)*float('inf')

for i in range(1,1024):
    tmp = 0
    for j in range(N):
        count = 0
        for k in range(10):
            if ((i>>k)&1)&F[j][k]:
                count+=1
        tmp+=P[j][count]
    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=[]
for k in range(2**10,2**11):
    a=[]
    t = [0 for x in range(n)]
    s = bin(k)[3:]
    for i in range(10):
        if s[i]=='1':
            for j in range(n):
                if f[j][i]==1:
                    t[j]+=1
    if max(t)!=0:
        a = [p[i][t[i]] for i in range(n)]
        ans.append(sum(a))
print(max(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 b in range(1,2**10):
    tmp = 0
    for i in range(N):
        c = 0
        for k in range(10):
            if b&(1<<k) and F[i][k]:
                c += 1
        tmp += P[i][c]
    ans = max(ans,tmp)
print(ans)

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

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

Solution (Python):
N = int(input())
F = [list(map(int, input().split())) for k in range(N)]
P = [list(map(int, input().split())) for k in range(N)]
B = [format(k,'b').zfill(10) for k in range(1,1024)]
ans = -10**9

for d in B:
    t = 0
    E = [0 for k in range(N)]
    for l in range(N):
        for k in range(10):
            E[l] += int(d[k])*F[l][k]
    for k in range(N):
        t += P[k][E[k]]
    ans = max(t,ans)

print(ans)

Solution (Python):
def max_profit(num, time1, time2, pro, idx):
    if idx == 10:
        if time1 == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]:
            return -1000000000

        prof = 0
        for i in range(num):
            cnt = 0
            for j, k in zip(time1, time2[i]):
                if j == 1 and j == k:
                    cnt += 1
            prof += pro[i][cnt]

        return prof

    time3 = time1.copy()
    p1 = max_profit(num, time3, time2, pro, idx+1)
    time3[idx] = 1
    p2 = max_profit(num, time3, time2, pro, idx+1)

    return max(p1, p2)


n = int(input())
t = [list(map(int, input().split())) for i in range(n)]
p = [list(map(int, input().split())) for j in range(n)]
t1 = [0 for k in range(10)]
print(max_profit(n, t1, t, p, 0))

Solution (Python):
from itertools import compress

def main():
    N = int(input())
    F = tuple(tuple(map(int, input().split())) for _ in [0] * N)
    P = tuple(tuple(map(int, input().split())) for _ in [0] * N)

    profits = -float('inf')
    mask = 1
    while mask < (1 << 10):
        n = 0
        sel = list(map(int, format(mask, '010b')))
        for i, f in enumerate(F):
            j = sum(compress(f, sel))
            n += P[i][j]
        profits = max(profits, n)
        mask += 1

    print(profits)

main()

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

F,P,b,T = [],[],1,-9999999999

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

while b < 1 << 10:
    bs = "{0:10b}".format(b)
    bsi = 0
    S = [0]*N
    for c in bs:
        if c == "1":
            for i in range(N):
                S[i] += F[i][bsi]
        bsi += 1
    t = 0
    for i in range(N):
        t += P[i][S[i]]
    if T < t:
        T = t
    b += 1
print(T)

Solution (Python):
def ans():
    tmp = -9999999999999
    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)]

    def calculate(B):
        v = []
        for n in range(N):
            mcnt = 0
            for k in range(10):
                if B[k] == '1' and F[n][k] == 1:
                    mcnt += 1
            v.append(P[n][mcnt])
        return sum(v)

    for i in range(1, 1 << 10):
        bi = bin(i)
        bi = bi[2:]
        bi = '0' * (10 - len(bi)) + bi
        tmp = max(tmp, calculate(bi))
    return print(tmp)


ans()

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

l = []
ans = -10000000000000000000000000000
def f(now, i):
  if i >= 10:
    l.append(list(now))
    return
  
  f(now+"1", i+1)
  f(now+"0", i+1)
f("", 0)

for i in range(len(l)-1):
  temp = 0
  for j in range(len(shops)):
    count = 0
    for k in range(10):
      if shops[j][k] == "1" and l[i][k] == "1":
        count += 1
    temp += int(profits[j][count])
  if temp > ans:
    ans = temp

print(ans)

Solution (Python):
N=int(input())
H=['']*N
W=['']*N
x=[]
for i in range(N):
    H[i]=list(map(int,input().split()))
for j in range(N):
    W[j]=list(map(int,input().split()))
for k in range(1,1024):
    t=[]
    for ii in range(10):
        if k&(1<<ii):
            t+=[1]
        else:
            t+=[0]
    ans=0
    for jj in range(N):
        s=0
        for kk in range(10):
            s+=H[jj][kk]*t[kk]
        ans+=W[jj][s]
    x.append(ans)
print(max(x))

Solution (Python):

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

result = -float("inf")



for b in range(1, 1<<10):

    profit = 0
    
    for i in range(n):

        common_opening = 0
        
        for j in range(10):

            if 1&(b>>j) and f[i][j] == 1:

                common_opening += 1
        profit += p[i][common_opening]

    result = max(result, profit)

print(result)

Solution (Python):







def calc_benefit(my_schedule, others_schedule, benefit_table, answer):
    score = 0

    if sum(my_schedule) == 0:
        return benefit_total

    for index, other_schedule in enumerate(others_schedule):
        count = 0

        for mine, other in zip(my_schedule, other_schedule):
            if mine == other == 1:
                count += 1
        score += benefit_table[index][count]
    return max(score, benefit_total)



def dfs(my_schedule, others_schedule, benefit_table, benefit_total, pos):
    if pos == 10:
        return calc_benefit(my_schedule, others_schedule, benefit_table, benefit_total)

    my_schedule[pos] = 0
    foo = dfs(my_schedule, others_schedule, benefit_table, benefit_total, pos + 1)
    my_schedule[pos] = 1
    bar = dfs(my_schedule, others_schedule, benefit_table, benefit_total, pos + 1)
    return max(foo, bar)


if __name__ == '__main__':
    shop_count = int(input())
    others_schedule = [list(map(int, input().split())) for _ in range(shop_count)]
    benefit_table = [list(map(int, input().split())) for _ in range(shop_count)]

    benefit_total = -1000000000
    my_schedule = [None] * (10)

    
    benefit_total = dfs(my_schedule, others_schedule, benefit_table, benefit_total, 0)
    print(benefit_total)

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=2**10
both=[0]*n
ans=-1000000000
profit=0
num=0
for i in range(1023):
    count+=1
    bit=bin(count)
    for j in range(n):
        for k in range(10):
            if int(bit[k+3])&F[j][k]:
                num+=1
        profit+=P[j][num]   
        num=0           
    if profit>ans:
        ans=profit
    profit=0
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,1<<10):
    tot=0
    for k in range(n):
        bit=0
        for j in range(10):
            if i&(1<<j) and f[k][j]==1: bit+=1
        tot+=p[k][bit]
    ans=max(ans,tot)
print(ans)

Solution (Python):
from itertools import product

N = int(input())
F = []
P = []

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


def main():
    open_count = [0 for i in range(N)]
    cnt = 0
    max_profit = - float('inf')

    for sister_store in list(product((0,1), repeat=10))[1:]:
        profit = 0
        for store_num in range(N):
            profit += calc_profit(sister_store, store_num)
        if profit > max_profit:
            max_profit = profit
    print(max_profit)

def calc_profit(sister, store_num):
    co_open = 0
    
    for i in range(10):
        """
        print("{0:<10} {1:d}".format("sister :",sister[i]))
        print("{0:<10} {1:d}".format(" store :",F[store_num][i]))
        """
        co_open += sister[i] * F[store_num][i]

    return P[store_num][co_open]
main()

Solution (Python):
N=int(input())
bord=[[] for i in range(N)]
for i in range(N):
  bord[i]=[int(x) for x in input().split()]
sales=[[] for i in range(N)]
for i in range(N):
  sales[i]=[int(x) for x in input().split()]

ans=-100000000000
for i in range(1,2**10):
  res=0
  for j in range(N):
    cnt=0
    for k in range(10):
      if (i>>k)%2 and bord[j][k]==1:
        cnt+=1
    res+=sales[j][cnt]
  ans=max(res,ans)
print(ans)

Solution (Python):
import itertools
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)]
answer = -10**9
for i in itertools.product(range(2),repeat=10):
	if sum(i) != 0:
		num = 0
		for j in range(n):
			num2 = 0
			for k in range(10):
				num2 += i[k]*f[j][k]
			num += p[j][num2]
		if answer < num:
			answer = num
print(answer)

Solution (Python):
n = int(input())
f = [int(input()[::2], 2) for i in range(n)]
p = [list(map(int, input().split())) for l in range(n)]
ans = -float("inf")
for h in range(1, 1024):
    ans = max(ans, sum(p[g][sum(list(map(int, bin(f[g] & h)[2:])))] for g in range(n)))
print(ans)

Solution (Python):
import itertools
n = int(input())
f = []
p = []
res = -10**100
for i in range(n):
    f.append(list(map(int,input().split())))
for i in range(n):
    p.append(list(map(int,input().split())))
l = [0,1]
q = list(itertools.product(l,repeat=10))
del q[0]
for i in q:
    r = 0
    for j in range(n):
        c = 0
        for k in range(10):
            if i[k] and f[j][k]:
                c += 1
        r += p[j][c]
    res = r if res<r else res
print(res)

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

plist = []
for i in range(1,1024):
    plist.append(format(i,'010b'))

score = {}
for i in range(len(plist)):
    m = 0
    choice = plist[i]
    for j in range(N):
        count = 0
        for k in range(10):
            if choice[k] == F[j][k] == "1":
                count += 1
        m += P[j][count]
    score[i] = m

print(max(score.values()))

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

a     = []
count = 0
point = []
PP = []

for _ in range(2**10+1,2**10*2):
    a.append(list(map(int,list(bin(_)[3:]))))

for k in range(2**10-1):
    for i in range(n):
        for j in range(10):
            if f[i][j]&a[k][j] == 1:
                count += 1
        point.append(p[i][count])
        count = 0
    PP.append(sum(point))
    point = []
print (max(PP))

Solution (Python):
n=int(input())
f=[[[0for i in range(2)]for j in range(5)]for k in range(n)]
p=[[0for i in range(11)]for j in range(n)]
opn=[[0for i in range(2)]for j in range(5)]
maxi=-10**9
for i in range(n):
  l=list(map(int,input().split()))
  for j in range(5):
    f[i][j][0]=l[j*2]
    f[i][j][1]=l[j*2+1]
for i in range(n):
  p[i]=list(map(int,input().split()))
for i in range(1,2**10):
  s=bin(i)[2:].zfill(10)
  for j in range(10):opn[j//2][j%2]=int(s[j])
  ben=0
  for j in range(n):
    same=0
    for k in range(10):
      same+=opn[k//2][k%2]*f[j][k//2][k%2]
    ben+=p[j][same]
  maxi=max([maxi,ben])
print(maxi)

Solution (Python):
import numpy as np
l = 10
f = 2 ** l - 1
ans = -float("inf")
n = int(input())
def ch(n):
    if int(n) == 1:
        return 1
    else:
        return 2
j = np.array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0] for j in range(n)])
for i in range(n):
    j[i] = (np.array(list(map(ch, input().split()))))
costs = np.array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] for j in range(n)])
for i in range(n):
    costs[i] = (np.array(list(map(int, input().split()))))
for i in range(2**l - 1):
    ff = np.array(list(map(int, list(format(f, "b").zfill(l)))))
    tmp = 0
    for h in range(n):
        tmp += costs[h][np.sum(ff == j[h])]
    ans = max(ans, tmp)
    f -= 1
print(ans)

Solution (Python):


import sys

u"""
1023回全て check
"""

def ones(n):
    o = 0
    for i in xrange(0, 10):
        b = 1 << i
        if n & b:
            o += 1
    return o

n = int(raw_input().split()[0])


openL = []
for _ in xrange(0, n):
    fs = ''.join( [e for e in raw_input().split()] )
    openL.append( int(fs, base=2) )
    
profL = []
for _ in xrange(0, n):
    profL.append( [int(e) for e in raw_input().split()] )







maxP = -sys.maxint - 1
for i in xrange(1, 1024):
    p = 0
    for x in xrange(0, len(openL)):
        ox = openL[x]
        px = profL[x]
        p += px[ ones(ox & i) ]

    if p > maxP:
        maxP = p
    
sys.stdout.write('%d\n' % maxP)
sys.stdout.flush()

Solution (Python):

"""
https://beta.atcoder.jp/contests/abc080/tasks/abc080_c

"""
import sys
from sys import stdin
input = stdin.readline


def solve(N, F, P):
    max_profit = float('-inf')

    for i in range(1, 2**10):
        profit = 0
        opens = [int(x) for x in bin(i)[2:].zfill(10)]
        for shop in range(1, N+1):
            match = [1 for a, b in zip(opens, F[shop]) if a and b]
            m = sum(match)
            profit += P[shop][m]
        if profit > max_profit:
            max_profit = profit
    return max_profit


def main(args):
    
    
    
    
    
    
    
    
    

    N = int(input())
    F = [[]]
    P = [[]]
    for _ in range(N):
        F.append([int(x) for x in input().split()])
    for _ in range(N):
        P.append([int(x) for x in input().split()])
    ans = solve(N, F, P)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Solution (Python):
count = int(input().rstrip())
shops = [input().split() for i in range(count)]
gain = [input().split() for i in range(count)]

 
max = -1000000000
for k in range(1,1024):
    tmp = format(k,'b').zfill(10)
    tmp_sum = 0
    for N in range(count):
        shop_count = 0
        for l in range(10):
            if tmp[l] == shops[N][l] and tmp[l] =='1':
                shop_count +=1
        tmp_sum += int(gain[N][shop_count]) 
    if max < tmp_sum:
        max = tmp_sum
 
print(max)

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

cost = -10**10
for a in itertools.product((0, 1), repeat=10):
    if a==(0, 0, 0, 0, 0, 0, 0, 0, 0, 0):
        continue
    tmp_cost = 0
    for i in range(N):
        tmp_c = 0
        l = 0
        for j in range(5):
            for k in range(2):
                tmp_c += F[i][l]*a[l]
                l += 1
        tmp_cost += P[i][tmp_c]
    cost = max(cost, tmp_cost)

print(cost)

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

ans = -100000000000
for k in range(1, 2 ** 10):
    val = 0
    for i in range(N):
        c = bin(k & F[i]).count("1")
        val += P[i][c]
    ans = max(ans, val)
print(ans)

Solution (Python):


n=int(raw_input())
f=[map(int,raw_input().split()) for i in xrange(n)]
p=[map(int,raw_input().split()) for i in xrange(n)]
res=-float('inf')
for i in xrange(1,1024):
 temp=0
 for j in xrange(n):
  cnt=0
  for k in xrange(10):
   cnt+=int(i>>k&1 and f[j][k])
  temp+=p[j][cnt]
 res=max(temp,res)
print res

Solution (Python):

def profit(xs, n, F, P):
    return sum([P[i][sum(map(lambda x: x[0]*x[1], zip(xs, F[i])))] for i in range(n)])


def vector(k):
    return [1 if k & 1 << i else 0 for i in range(10)]


def foo(n, F, P):
    return max([profit(vector(pat), n, F, P) for pat in range(1, 1024)])


if __name__ == "__main__":
    n = int(input())
    F = {}
    P = {}
    for i in range(n):
        F[i] = list(map(int, input().split()))
    for i in range(n):
        P[i] = list(map(int, input().split()))
        
    print(foo(n, F, P))

Solution (Python):
N=int(input())
F=[]
P=[]
for i in range(N):
  F.append(list(map(int,input().split(' '))))
for i in range(N):
  P.append(list(map(int,input().split(' '))))
res=-1145141919810
for i in range(1023):
  i=bin(i+1 | 0b10000000000)
  i=str(i[3:])
  tmp=0
  for j in range(N):
    count=0
    for k in range(10):
      if int(i[k])==1 and F[j][k]==1:count+=1
    tmp+=P[j][count]
  if tmp>=res:res=tmp
print(res)

Solution (Python):
import math
import numpy as np
from operator import mul




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)]
c = list(range(N))
max_p = -100**7-1

for i in range(1,2**10):
    i_bin = format(i, 'b').zfill(10)
    i_list = [int(x) for x in list(str(i_bin))]
    profit = 0 
    for j in range(N):
        
        combine = map(mul, f[j], i_list)
        c[j] = sum(combine) 
        profit += p[j][c[j]]
    if profit > max_p:
        max_p = profit

print(max_p)

Solution (Python):
N = input()
F = [map(int, raw_input().split()) for i in range(N)]
P = [map(int, raw_input().split()) for i in range(N)]
M = 10
ans = -10**10
for mask in range(1, 2**M):
    m = [int((mask & (2**i)) > 0) for i in range(M)]
    ok = False
    sales = 0
    for i in range(N):
        cnt = 0
        for j in range(M):
            if m[j] + F[i][j] == 2:
                ok = True
                cnt += 1
        sales += P[i][cnt]
    if ok:
        ans = max(ans, sales)
print ans

Solution (Python):
import numpy as np

n = int(input())
f = np.zeros((n, 10), dtype=np.int64)
p = np.zeros((n, 11), dtype=np.int64)

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

r = -1e18
for b in range(1, 1<<10):
  s = 0
  for i in range(n):
    c = 0
    for j in range(10):
      if (b >> j) & 1 == 1 and f[i][j]:
        c += 1
    s += p[i][c]
  if r < s:
    r = s

print(r)

Solution (Python):


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

ans = float("-inf")

for i in range(1,1 << 10):
  res=0
  for n in range(N):
    count=0
    for j in range(10):
      if i & F[n][j] << j: count+=1
    res+=P[n][count]
  ans=max(res,ans)
print(ans)

Solution (Python):
n = int(input())
f = [int(input().replace(" ",""),2) for j in range(n)]
p = [[int(i) for i in input().split()] for i in range(n)]

out = float('-inf')


for i in range(1,1024):
    b = 0
    for j in range(n):
        b += p[j][bin(f[j] & i).count('1')]
    out = max(b, out)
print(out)

Solution (Python):
import itertools
seq=('0','1')
a=list(itertools.product(seq, repeat=10))
n=int(input())

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

flg=0

z  = 0
z1 = -10000000000000
for ai0 in a:
  ai=[int(i) for i in ai0]
  z0=0

  if max(ai) > 0:
    for j in range(n):
      z0 += c[j][sum([x * y for x, y in zip(f[j], ai)])]

    if z0 > 0:
      z  = max(z,z0)
      flg=1
    else:  
      z1 = max(z1,z0)
    
if flg==0:
  print(z1)
else:
  print(z)

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 = None
for i in range(1, 1<<10):
    Fk = [[F[j][k] * ((i >> k) & 1) for k in range(10)] for j in range(N)]
    Cs = [sum(Fk[i]) for i in range(N)]
    s = sum([P[i][Cs[i]] for i in range(N)])
    if ans is None or ans < s:
        ans = s
print(ans)

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

Solution (Python):
n = int(input())
     
f = [int(input().replace(" ", ""), 2) for _ in range(n)]
p = [list(map(int, input().split())) for _ in range(n)]
     
ans = float('-inf')
     
for i in range(1, 1024):
    price = 0
    for j in range(n):
        price += p[j][bin(i & f[j]).count('1')]
    ans = max(ans, price)
     
print(ans)

Solution (Python):
import itertools
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())))

a = [i for i in range(10)]
combi = []
for i in range(10):
    combi.extend(list(itertools.combinations(a,i+ 1)))


ans =  - float("inf")
for i in combi:
    
    cnt = [0]*n
    for j in i:
        for k in range(n):
            cnt[k] += f[k][j]
    profit = sum([p[k][cnt[k]] for k in range(n)])
    ans = max(ans, profit)
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)]

def ev(lst):
    ret = 0
    for i in range(N):
        cnt = sum([1 if F[i][j] * lst[j] == 1 else 0 for j in range(10)])
        ret += P[i][cnt]
    return ret

NEG_INF = -100000000000000000000

def dfs(acc):
    if len(acc) == 10:
        if acc.count(1) == 0:
            return NEG_INF
        return ev(acc)

    lazy = max(dfs(acc + [0]), dfs(acc + [1]))
    return lazy

ans = dfs([])
print(ans)

Solution (Python):

def sum_benefit(anded):
    summed= 0
    for shop in range(n_shop):
        summed += i_benefit[shop][anded[shop]]
    return summed

n_shop = int(input())
i_schedule = []
i_benefit = []


max_profit = 0


for i in range(n_shop):
    i_schedule.append(int(input().replace(" ",""),2))
    
for i in range(n_shop):
    i_benefit.append(list(map(int,input().split())))
    max_profit += min(i_benefit[i])
    




schedule = [i for  i in range(1,1024)]


for sch in schedule:
    anded = []
    for j in range(n_shop):
        anded.append(format(sch & i_schedule[j], "b").count("1"))     
        
    profit = sum_benefit(anded)
    
    if max_profit <= profit:
        max_profit = profit
    

print(max_profit)

Solution (Python):
from operator import mul
n = int(input())
cof = [1 << x for x in range(10)]

fs = [sum(map(mul, map(int, input().split()), cof)) for _ in range(n)]
ps = [list(map(int,input().split())) for _ in range(n)]
ans = float("-inf")
for g in range(1,1024):
    ans = max(ans, sum(p[bin(f&g).count("1")] for f, p in zip(fs, ps)))
    
print(ans)

Solution (Python):

def binarize(txt):
    xs = txt.split(' ')
    xs = [int(x) for x in xs]
    b = 0
    for i in range(10):
        b += xs[i] * (2 ** i)
    return b


def count1(b):
    b = b[2:]
    count = 0
    for i in range(len(b)):
        if b[i] == '1':
            count += 1
    return count


N = input()
N = int(N)

F = [0 for i in range(N)]

for i in range(N):
    txt = input()
    F[i] = binarize(txt)


P = [[] for i in range(N)]

for i in range(N):
    xs = input().split(' ')
    P[i] = [int(x) for x in xs]


m = - 10 ** 11

for i in range(1, 2**10):

    score = 0

    for j in range(N):
        b = bin(i & F[j])
        count = count1(b)
        score += P[j][count]

    if score > m:
        m = score

print(m)

Solution (Python):
from logging import getLogger, basicConfig, DEBUG
basicConfig(level=DEBUG)
LOG = getLogger(__name__)

N = int(input())

def get_count_logical_and(base_int, list):
    result = []
    for item in list:
        logical_and = format(base_int & item, 'b').zfill(10)
        count = logical_and.count("1")
        result.append(count)
        
        
        
        
    return result

def get_profits(pattern_array, lists):
    profits = 0
    for i in range(N):
        index = pattern_array[i]
        profit_list = lists[i]
        profits += profit_list[index]
        
    return profits

def main():
    business_list = [int(input().replace(' ', ''), 2) for _ in range(N)]
    profits = [list(map(int, input().split())) for _ in range(N)]
    result = -float('inf')
    for i in range(1, 2 ** 10):
        open_pattern = get_count_logical_and(i, business_list)
        result = max(result, get_profits(open_pattern, profits))
        
    print(result)

if __name__ == '__main__':
    main()

Solution (Python):
n = input()
s = list()
for i in xrange(1, 2**10):
    s.append(i)
time_table = list()
benefit = list()
for _ in xrange(n):
    time_table.append("".join(raw_input().split()))
for _ in xrange(n):
    benefit.append(list(map(int, raw_input().split())))

op = [[None for i in xrange(n)] for j in xrange(2**10-1)]
for i in xrange(n):
    for j in xrange(2**10-1):
        op[j][i] = sum(map(int, list(bin(s[j] & int(time_table[i],2))[2:])))

print max([sum([benefit[i][op[j][i]] for i in xrange(n)]) for j in xrange(2**10-1)])

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')
jkopen =  [[0 for j in range(5)] for k in range(2)]
for openday in range(1,1024):
    for j in range(5):
        for k in range(2):
            jkopen[k][j] = (openday & 2**(5*k+j))//2**(5*k+j)
    benefit = 0

    for shop in range(N):
        counter = 0
        for j in range(5):
            for k in range(2):
                counter += (jkopen[k][j] & F[shop][k+2*j])
        benefit += P[shop][counter]

    ans = int(max(ans,benefit))
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)]
t={i:0 for i in range(1,2**10)}
for i in range(1,2**10):
  d, b={j:0 for j in range(n)}, format(i, "010b")
  for j in range(n):
    for k in range(10):
      if (i>>k)%2&f[j][k]==1: d[j]+=1
    t[i]+=p[j][d[j]]
print(max(t.values()))

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

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


profit = float("-inf")

for i in range(1,1024):
	tmp = 0
	tmp2 = 0
	for j in range(N):
		tmp = (bin(i & F[j]).count('1'))
		tmp2 = tmp2 + P[j][tmp]
	profit = max(profit, tmp2)

print(profit)

Solution (Python):
n = int(input())
     
f = [int(input().replace(" ", ""), 2) for _ in range(n)]
p = [list(map(int, input().split())) for _ in range(n)]
     
ans = float('-inf')
     
for i in range(1, 1024):
    price = 0
    for j in range(n):
        price += p[j][bin(i & f[j]).count('1')]
    ans = max(ans, price)
     
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 = -1234567890
for mask in range(1,2**10):
    tmp = 0
    for i in range(n):
        cnt = 0
        for x in range(10):
            if (mask>>x) % 2 == 1 and f[i][x] == 1: cnt += 1
        tmp += p[i][cnt]
    ans = max(ans, tmp)
 
print(ans)