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



"""abc080_c"""


import sys


def numFromBitList(l):
    """Get number from bit list."""
    n = 0
    for i, v in enumerate(l):
        n += v * 2 ** i
    return n

def main():
    """Main function."""
    n = int(input())

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

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

    max_ = -sys.maxsize
    for i in range(1, 1024):
        profit = 0
        for idx, f in enumerate(fs):
            profit += ps[idx][bin(i & f)[2:].count('1')]
        max_ = max(max_, profit)

    print(max_)


if __name__ == '__main__':
    sys.exit(main())

Solution (Python):
N = int(input())
a = []
b = []
total_profit = []
for i in range(N):
    a.append(list(map(int, input().split())))
for j in range(N):
    b.append(list(map(int, input().split())))

for k in range(2, 2 ** 10):
    d = bin(k)
    e = "0" * (12 - len(d)) + d[2:]
    profit = 0
    for l in range(N):
        common_open = 0
        for m in range(10):
            if a[l][m] == 1 and int(e[m]) == 1:
                common_open = common_open + 1
        profit = profit + b[l][common_open]
    total_profit.append(profit)

print(max(total_profit))

Solution (Python):
N = int(raw_input())
F = []
for i in range(N):
    li = map(int,raw_input().split())
    F.append(li)
P = []
for i in range(N):
    li = map(int,raw_input().split())
    P.append(li)
bigest = None
for i in range(1024):
    kasa = []
    for x in range(N):
        kasa.append(0)
    i = i + 1 
    bi = str(bin(i)).split("b")[1]
    bi = (10-len(bi))*"0" + bi
    for i2 in range(10):
        if bi[i2]  == "1":
            for i3 in range(N):
                if F[i3][i2] == 1:
                    kasa[i3] += 1
    me = 0 
    for i2 in range(N):
        me += P[i2][kasa[i2]]
    if bigest < me or bigest == None:
        bigest = me
print bigest

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)

Solution (Python):



import numpy as np

n = raw_input()
n = int(n)
f = np.zeros([n,10],int)
for i in range(n):
    line = raw_input()
    line = line.split()
    line = map(int,line)
    f[i] = line
p = np.zeros([n,11],int)
for i in range(n):
    line = raw_input()
    line = line.split()
    line = map(int,line)
    p[i] = line

for i in range(2**10):
    kaburi = np.zeros([n],int)
    num = i
    for j in range(10):
        shutten = num % 2
        num = num / 2
        if shutten == 1:
            for k in range(n):
                if f[k,j] == 1:
                    kaburi[k] += 1
    rieki = 0
    for k in range(n):
        rieki += p[k][kaburi[k]]
    if i <= 1:
        saidai = rieki
    else:
        saidai = max(rieki,saidai)

print saidai

Solution (Python):
import sys
import numpy as np
import itertools as it

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 LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

n = I()
F, P = [], []
for _ in range(n):
    F.append(LI())

for _ in range(n):
    P.append(LI())

F = np.array(F)

b = (0, 1)
b10 = (b,)*10
iter_ = it.product(*b10)

Fdotx = [F.dot(x) for x in iter_][1:]

print(max([sum([P[i][val] for i, val in enumerate(row)]) for row in Fdotx]))

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

max_ = -1000000000

for i in range(1, 2 ** 10):
    pattern = [int((i >> _i) % 2 == 1) for _i in range(10)]
    
    score = 0
    for n in range(N):
        same_num = 0
        for j in range(10):
            if pattern[j] == 0:
                continue
            if F[n][j] == 1:
                same_num += 1
        score += P[n][same_num]
    if score > max_:
        max_ = score
print(max_)

Solution (Python):
import itertools

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

    

    max1 = -float('inf')
    max2 = -float('inf')

    for target in list(itertools.product(range(2), repeat=10)):
        sum_every_shop = 0
        for i in range(N):
            sum_same_time = 0
            for j in range(10):
                if target[j] == 1 and F[i][j] == 1:
                    sum_same_time += 1

            sum_every_shop += P[i][sum_same_time]

        if max2 < sum_every_shop:
            max2 = sum_every_shop

        if max1 < max2:
            max1, max2 = max2, max1
            result_target = target

    if result_target == (0, 0, 0, 0, 0, 0, 0, 0, 0, 0):
        print(max2)
    else:
        print(max1)

Solution (Python):
import sys
import math

N = int(input())
F = []
for i in range(N):
    F.append(list(map(int, input().split(' '))))
P = []
for i in range(N):
    P.append(list(map(int, input().split(' '))))
maxprofit = None 
for i in range(1, 1024):
    binstr = bin(i) 
    original = list(map(int, binstr[2:]))
    original = [0]*(10-len(original)) + original
    profit = 0
    for j in range(N):
        s = [a+b for (a, b) in zip(original, F[j])]
        dup = len([a for a in s if a == 2])
        profit += P[j][dup]
    if not maxprofit or maxprofit < profit:
        maxprofit = profit
print(maxprofit)

Solution (Python):
n=int(input())
num=[]
for _ in range(n):
    s=input()
    s=s.replace(" ","")
    
    num.append(int(s,2))
    
p=[]
for _ in range(n):
    l=[int(x) for x in input().split()]
    p.append(l)
ans=-10**20
for i in range(1,1024):
    tot=0
    ind=0
    for ele in num:
        var=ele&i 
        tot+=p[ind][bin(var).count('1')]
        ind+=1 
    ans=max(ans,tot)
print(ans)

Solution (Python):
import sys

line = sys.stdin.readline()
N = int(line.strip())

F = {}
for i in range(N):
    line = sys.stdin.readline().strip()
    xs = [int(x) for x in line.split()]
    for j in range(10):
        F[i, j] = xs[j]

f = [sum((1 << j) for j in range(10) if F[i,j]) for i in range(N)]

pt = [sum(((i >> j) & 1) for j in range(10)) for i in range(2**10)]

P = {}
for i in range(N):
    line = sys.stdin.readline().strip()
    xs = [int(x) for x in line.split()]
    for j in range(11):
        P[i, j] = xs[j]


rr = -100000000000000000000

for i in range(1, 2**10):
    r = sum([P[j, pt[f[j] & i]] for j in range(N)])
    if rr < r:
        rr = r

print(rr)

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

result = -float("inf")
    
for i in range(2 ** 10):
    if i != 0:
        op = list(bin(i)[2:].zfill(10))
        profit = 0
        for n in range(N):
            num = 0
            for j in range(10):
                if str(F[n][j]) == op[j] == "1":
                    num += 1
            profit += P[n][num]
        if i == 2 or result < profit:
            result = profit
print(result)

Solution (Python):

from itertools import product
def inpl(): return map(int, input().split())

N = int(input())
F = [tuple(inpl()) for _ in range(N)]
P = [tuple(inpl()) for _ in range(N)]

result = -1 * 10**12
for T in product([0, 1], repeat=10):
    if sum(T) == 0:
        continue
    tmp = 0
    for i in range(N):
        c = sum([f*t for f, t in zip(F[i], T)])
        tmp += P[i][c]
    result = max(result, tmp)
print(result)

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=[[0 for i in range(10)]for i in range(N)]
for i in range(N):
    st=input().split()
    indexnum=0
    for j in range(10):
            tmp=True
            if int(st[indexnum]):
                tmp=True
            else:
                tmp=False
            F[i][j]=tmp
            indexnum+=1
P=[[0 for i in range(11)] for i in range(N)]
for i in range(N):
    st=input().split()
    for j in range(10):
        P[i][j]=int(st[j])
xmax=-1e+10
for t in range(1,1024):
    a=[0 for i in range(10)]
    s=t
    for i in range(10):
       a[i]=(s%2)
       s=(s-a[i])//2
    x=0
    for i in range(N):
        c=0
        for j in range(10):
            if F[i][j] and a[j]==1:
                c+=1
        x+=P[i][c]
    if xmax<x:
        xmax=x
print(xmax)

Solution (Python):

import numpy as np
import itertools
n = int(input())
f = np.zeros((n,10),dtype='int32')
p = np.zeros((n,11),dtype='int32')
for i in range(n):
    f[i] = list(map(int,input().split()))
for i in range(n):
    p[i] = list(map(int,input().split()))
    

op = [0,1]
ans = -10**9
pro = list(itertools.product(op, repeat=10))
for i in pro:
    if(sum(i)==0):continue
    tmp = 0
    for j in range(n):
        tmp += p[j][np.dot(np.array(i),f[j])]
    ans = max(ans,tmp)
print(ans)

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

f=[]
for _ in range(N):
  f.append(map(int,raw_input().split(' ')))

p=[]
for _ in range(N):
  p.append(map(int,raw_input().split(' ')))

s=float('-inf')
for t in range(1,1024):
  l=map(int,list(bin(t)[2:].zfill(10)))
  tmp=0
  for i in range(N):
    c=0
    for t in range(10):
      if l[t]==0:
        continue
      if f[i][t]:
        c+=1

    tmp+=p[i][c]

  if tmp>s:
    s=tmp
    
print s

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

reward_list=[]
for i in range(1023):
    k=i+1
    t=[]
    c=[0 for j in range(N)]
    while(1):
        t.append(k%2)
        k=k//2
        if(k==0):
            length=len(t)
            if(length<10):
                for i in range(10-length):
                    t.append(0)
            break
    reward=0
    for j in range(N):
        for f in range(10):
            c[j]+=F[j][f]*t[f]
        reward+=P[j][c[j]]
    reward_list.append(reward)
print(max(reward_list))

Solution (Python):



def solve():
    n = int(input())
    fl = [[int(i) for i in input().split()] for _ in range(n)]
    pl = [[int(i) for i in input().split()] for _ in range(n)]
    ans = -1 * 100 * (10 ** 7)
    for cnt in range(1, 2 ** 10 + 1):
        cnt_list = [0]*n
        for i in range(n):
            t = cnt
            digit = 0
            while t > 0:
                if t & 1 != 0 and fl[i][digit - 1] == 1:
                  cnt_list[i] += 1
                t >>= 1
                digit += 1
        tsum = 0
        for i in range(n):
            tsum += pl[i][cnt_list[i]]
        ans = max(tsum, ans)
    print(ans)


if __name__=="__main__":
    solve()

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

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


def help(a):
    if sum(a) == 0:
        return -float("inf")
    res = 0
    for i in range(n):
        num = 0
        for j in range(10):
            if a[j] == 1 and f[i][j] == 1:
                num += 1
        res += p[i][num]
    return res
lst = []
for a1 in range(2):
        for a2 in range(2):
            for a3 in range(2):
                for a4 in range(2):
                    for a5 in range(2):
                        for a6 in range(2):
                            for a7 in range(2):
                                for a8 in range(2):
                                    for a9 in range(2):
                                        for a10 in range(2):
                                            res = help([a1, a2, a3, a4, a5, a6, a7, a8, a9, a10])
                                            lst.append(res)
print(max(lst))

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

F = []
for _ in range(N):
    f = []
    for i in input().split():
        f.append(1 if i == '1' else 0)
    F.append(f)

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

ans = -1000000000
for i in range(1, 1024):
    val = 0
    S = []
    for j in range(10):
        S.append(1 if i & 2 ** j else 0)
    for k in range(N):
        n = 0
        for l in range(10):
            n += S[l] * F[k][l]
        val += P[k][n]
    if val > ans:
        ans = val

print(ans)

Solution (Python):
import itertools

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

best = -100000000000
for i in range(1, 11):
    for x in itertools.combinations(range(0, 10), i):
        sum = 0
        for j in range(n):
            fs = 0
            for k in x:
                if f[j][k] == 1: fs += 1
            sum += p[j][fs]
        if sum > best:
            best = sum
print best

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 = -1e10
for i in range(1, 2**10):
    d = [0 for _ in range(n)]
    pi = 0
    for j in range(10):
        if (1 << j) & i:
            for k in range(n):
                d[k] += f[k][j]
    ans = max(ans, sum(map(lambda k: p[k][d[k]], range(n))))

print(ans)

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

ans = -float('inf')
for i in range(1,2**10):
    tmp = 0
    for n in range(N):
        c = 0
        for b in range(10):
            if ((i >> b)&1) & isopen[n][b]:
                c += 1
        tmp += gain[n][c]
    ans = max(ans, tmp)
print(ans)

Solution (Python):
import sys
import itertools

def get_ben(time_list, shop_open_list, ben_list):
    count_list = []
    for shop_list in shop_open_list:
        count_list.append(len(list(filter(lambda i: (shop_list[i] == 1) and (time_list[i] == 1), list(range(10))))))
    res = 0
    for i, count in enumerate(count_list):
        res += ben_list[i][count]
    return res

n = int(sys.stdin.readline().strip())

shop_open_list = []
ben_list =[]

for _ in range(n):
    shop_open_list.append(list(map(int, sys.stdin.readline().strip().split(" "))))

for _ in range(n):
    ben_list.append(list(map(int, sys.stdin.readline().strip().split(" "))))

B = (0,1)
cand = []
for l in itertools.product(B, repeat = 10):
    if sum(l) == 0:
        continue
    cand.append(get_ben(l, shop_open_list, ben_list))

print(str(max(cand)))

Solution (Python):
if __name__ == '__main__':

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

    from itertools import product

    ans = -10 ** 10
    for decision in product([0, 1], repeat=10):
        if not any(decision):
            continue
        tans = 0
        for fv, pv in zip(fs, ps):
            c = 0
            for f, d in zip(fv, decision):
                c += f * d
            tans += pv[c]
        ans = max(ans, tans)
    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)]
ans = -10**100
for b in range(1,2**10):
  a = 0
  for i in range(N):
    c = 0
    for j in range(10):
      c += int(b>>j&1 and F[i][j])
    a += P[i][c]
  ans = max(ans, a)
print ans

Solution (Python):
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n = ni()
fs = []
for i in range(n):
    x = na()
    ptn = 0
    for j in range(10):
        ptn |= x[j]<<j
    fs.append(ptn)
ps = []
for i in range(n):
    ps.append(na())

def bct(x):
    ret = 0
    while x > 0:
        ret += x&1
        x >>=1
    return ret

ans = -9999999999999999
for i in range(1, 1024):
    s = 0
    for j in range(n):
        s += ps[j][bct(fs[j]&i)]
    ans = max(ans, s)
print(ans)