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

def main():
    line = sys.stdin.readline()
    n = int(line.rstrip())
    f = [None for i in range(n)]
    p = [None for i in range(n)]
    for i in range(n):
        line = sys.stdin.readline()
        f[i] = getFn([int(x) for x in line.rstrip().split(' ')])
        
    for i in range(n):
        line = sys.stdin.readline()
        p[i] = [int(x) for x in line.rstrip().split(' ')]
    vMax = None
    for t in range(1, 1024):
        s = 0
        for i in range(n):
            common = countBit(f[i] & t)
            s += p[i][common]
        if vMax is None or vMax < s:
            vMax = s
    print(vMax)

def getFn(f):
    s = 0
    for b in f:
        s = (s << 1) | b
    return s

def countBit(c):
    s = 0
    while c > 0:
        if c & 1 == 1:
            s += 1
        c >>= 1
    return s

if __name__ == '__main__':
    main()

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 numpy as np
from itertools import combinations as comb
N = int(input())
F = np.array([list(map(int, input().split())) for i in range(N)])
P = np.array([list(map(int, input().split())) for i in range(N)])
max_score = -10**7 * N - 1
d_arrN = list(range(N))
d_arr10 = list(range(10))
for i in range(10):
	for o_c in comb(d_arr10, i + 1):
		c_i = F[:, o_c].sum(axis=1)
		score = P[d_arrN, c_i].sum()
		max_score = max(max_score, score)
print(max_score)

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):
  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 = input()
F = []
P = []
for _ in xrange(N):
    F.append(map(int, raw_input().split()))
for _ in xrange(N):
    P.append(map(int, raw_input().split()))

calendar = [[]]
for _ in xrange(10):
    newCalendar = []
    for y in calendar:
        newCalendar.append(y + [0])
        newCalendar.append(y + [1])
    calendar = newCalendar
calendar.pop(0)

profits = []
for timeTable in calendar:
    currentProfit = 0
    for shopProfit, shopCalendar in zip(P, F):
        currentProfit += shopProfit[len([1 for (i, j) in zip(timeTable, shopCalendar) if i and j])]
    profits.append(currentProfit)
print max(profits)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
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 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()
def pf(s): return print(s, flush=True)


def main():
    n = I()
    f = [LI() for _ in range(n)]
    p = [LI() for _ in range(n)]
    ii = [2**_ for _ in range(10)]
    r = -inf
    for k in range(1,2**10):
        a = [0] * n
        for i in range(10):
            if k&ii[i]:
                for j in range(n):
                    if f[j][i] == 1:
                        a[j] += 1
        tr = 0
        for i in range(n):
            tr += p[i][a[i]]
        if r < tr:
            r = tr

    return r



print(main())

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

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):
N = int(raw_input())
F = []
for n in range(N):
    F.append([int(val) for val in raw_input().split(" ")])
P = []
for n in range(N):
    P.append([int(val) for val in raw_input().split(" ")])

max_val = None
for i_X in xrange(1, 2**10):
    c_i = [0]*N
    for i_pos in range(10):
        X_ijk = (i_X/(2**i_pos))%2
        for i_n in xrange(N):
            c_i[i_n] += F[i_n][i_pos] * X_ijk
    score = sum([P[i_n][c_i[i_n]] for i_n in xrange(N)])
    if (type(max_val) == type(None)) or (score > max_val):
        max_val = score

print max_val

Solution (Python):

inp = input()
N = int(inp)

eigyo = []

b = []
Ci = []
for i in range(N):
    N_ = list(map(int, input().split()))
    eigyo.append(N_)
    Ci.append(sum(N_))

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


ans = -(1<<30)
a = list(map(lambda x: x*0, list(range(10))))
count = 0

def func():
    
    global count
    count += 1
    
    cc = 0
    if count!=1:
        for i in range(N):
            count_c = 0
            for j,element in enumerate(eigyo[i]):
                if element==a[j] and a[j]==1:
                    count_c += 1
            cc += P[i][count_c]
        global ans
        ans = max(ans, cc)
            
    

def dfs(pos):
    if pos==10:
        func()
        return
    a[pos] = 0
    dfs(pos+1)
    a[pos] = 1
    dfs(pos+1)


dfs(0)
print(ans)

Solution (Python):
import itertools

n = int(input())

f, p, profits = [], [], []

for _ in range(n):
    tmp = [int(x) for x in input().split()]
    f.append(tmp)

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

a = [0,1]

for x_ in itertools.product(a, repeat=10):
    x = list(x_)
    if sum(x) == 0:
        pass
    else:
        profit = 0
        for i, y in enumerate(f):
            count = 0
            for j,k in zip(x,y):
                if j == 1 and k == 1:
                    count += 1
            profit += p[i][count]
        profits.append(profit)

print(max(profits))

Solution (Python):
n = int(input())
f = []
for i in range(n):
    f.append(list(map(int, input().split(" "))))
flag = True
p = []
for i in range(n):
    p.append(list(map(int, input().split(" "))))

storeopen = [0,0,0,0,0,0,0,0,0,1]


maxmoney = None

while flag:
    money = 0
    for store in range(n):
        count = 0
        for i in range(10):
            if f[store][i] == 1 and storeopen[i] == 1:
                count += 1
        money += p[store][count]
    if maxmoney is None:
        maxmoney = money
    else:
        maxmoney = max(maxmoney, money)

    if sum(storeopen) == 10:
        flag = False
    else:
        storeopen[9] += 1
        for i in range(10):
            if storeopen[9-i] == 2:
                storeopen[9-i] = 0
                storeopen[8-i] += 1
print(maxmoney)

Solution (Python):

N=int(input())

F=[]
P=[]

table = [2**i for i in range(10)]

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

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


maxx=-1000000000001


for i in range(1,1024):
    total=0
    for j in range(N):
        n=0
        for k in range(10):
            n +=(1 if i&table[k] !=0 else 0)*F[j][k]
        total += P[j][n]
    if total >maxx:
        maxx= total
print(maxx)

Solution (Python):

N=int(input())

F=[]
P=[]

table = [2**i for i in range(10)]


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

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


maxx=-1000000000001

for i in range(1,1024):
    total=0
    for j in range(N):
        n=0
        for k in range(10):
            n +=(1 if i&table[k] !=0 else 0)*F[j][k]
        total += P[j][n]
    if total >maxx:
        maxx= total
print(maxx)

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

def main():
    N = int(input())
    F_all = [[int(i) for i in input().split()] for _ in range(N)]
    P_all = [[int(i) for i in input().split()] for _ in range(N)]
    ans = float('-inf')
    for i in range(1, 11):
        
        for iOPs in itertools.combinations(range(10), i):
            gain = 0
            for f, p in zip(F_all, P_all):
                c = sum(f[k] for k in iOPs)
                gain += p[c]
            ans = max(ans, gain)
    return ans


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

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

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

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

ans = -float('inf')
for i in range(1, 1 << 10):
  profit = 0
  for j in range(N):
    a = i
    count = 0
    for k in range(10):
      count += a & shops[j][k]
      a >>= 1
    profit += profits[j][count]
  ans = max(ans, profit)

print(ans)

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



def solve(K):
    ans = 0
    n = 0
    while n < N:
        num = 0
        for i in range(10):
            if int(K[i]) == F[n][i] and K[i] == '1':
                num = num + 1
        ans += P[n][num]
        n += 1
    return ans
Ans = solve('%010d' % 1)
for m in range(1,1024):
    K = []
    L = int(format(m, 'b'))
    L = '%010d' % L
    k = solve(L)
    Ans = max(Ans, k)
print(Ans)

Solution (Python):
def c_shopping_street(N, F, P):
    ans = -float('inf')
    for b in range(1, 1024):  
        cc = 0  
        for i in range(N):
            c = 0  
            for j in range(10):
                if ((b >> j) % 2 == 1) and F[i][j] == 1:
                    c += 1
            cc += P[i][c]
        ans = max(ans, cc)  
    return ans

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

Solution (Python):
import itertools

N = int(input())
Fs = [tuple(map(int, input().split())) for i in range(N)]
Ps = [tuple(map(int, input().split())) for i in range(N)]

ans = -float('inf')
for numOP in range(1, 11):
    for iOPs in itertools.combinations(range(10), numOP):

        profit = 0
        for F, P in zip(Fs, Ps):
            c = sum([F[i] for i in iOPs])
            profit += P[c]
        ans = max(ans, profit)

print(ans)

Solution (Python):
import sys
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
INF = float("inf")
sys.setrecursionlimit(10**7)


dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]


def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W


def main():
    N = int(input())
    F = [[0] * 10 for _ in range(N)]
    for i in range(N):
        s = input().split()
        for j in range(10):
            F[i][j] = int(s[j])
    P = [[0] * 11 for _ in range(N)]
    for i in range(N):
        s = input().split()
        for j in range(11):
            P[i][j] = int(s[j])

    ans = -INF
    
    for b in range(1, 2 ** 10):
        o = [0] * 10
        for i in range(10):
            if b & 1 << i:
                o[i] = 1

        total = 0
        for i in range(N):
            c = 0
            for j in range(10):
                if o[j] == 1 and F[i][j] == 1:
                    c += 1
            total += P[i][c]
        ans = max(ans, total)
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
N = int(raw_input())
lisday = []
lisp= []
last = []
for num in xrange(N):
  lisday.append( map(int,raw_input().split()) )
for num in xrange(N):
  lisp.append( map(int,raw_input().split()) ) 
for n in xrange(1,1024):
	n2 = format(n,"010b")
	lissum =[]
	for numb in xrange(N):
		check = map(int,list(str(n2)))
		count = 0
		for select in xrange(10):
			if check[select] == 1 and lisday[numb][select] == 1:
				count += 1
		lissum.append(lisp[numb][count])
	last.append(sum(lissum))
print max(last)

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)]
print(max(sum(p[bin(f & g).count('1')] for f, p in zip(fs, ps)) for g in range(1, 1024)))

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

joisino = [False] * 10


def dfs(i):
    if i == 10:
        if joisino.count(True) == 0:
            return -float('inf')
        score = 0
        for j in range(N):
            G = [(joisino[k] and (F[j][k] == 1)) for k in range(10)]
            count = G.count(True)
            score += P[j][count]
        return score
    else:
        ans1 = dfs(i + 1)
        joisino[i] = True
        ans2 = dfs(i + 1)
        joisino[i] = False
        return max(ans1, ans2)


ans = max(-float('inf'), dfs(0))
print(ans)

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

def count(x):
    cunt = 0
    for i in range(len(openlist)):
        if f[x][9-i] == openlist[len(openlist)-i-1]==1:
            cunt +=1
        
    return cunt
max1 = -10000000000000
for i in range(1,1024):
    sum = 0
    open = format(i,'b')
    openlist = [int(j) for j in open]
    
    for k in range(n):
        sum += p[k][count(k)]
    max1 = max(max1,sum)
print(max1)

Solution (Python):

N = int(input())

F = []
P = []

table = [2**i for i in range(10)]

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

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

maxx = -1000000001

for i in range(1, 1024):
    total = 0
    for j in range(N):
        n = 0
        for t in range(10):
            n += (1 if i&table[t] != 0 else 0)*F[j][t]
        total += P[j][n]
    if total > maxx:
        maxx = total

print(maxx)

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):
n = int(input())
f = [int(''.join(input().split()), 2) for _ in range(n)]
p = [list(map(int, input().split())) for _ in range(n)]
print(max(
    sum(p[i][sum(map(int, bin(b & f[i])[2:]))] for i in range(n))
    for b in range(1, 2**10)))

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 = -(1 << 62)
for ss in range(1, 1 << 10):
    b = [0] * n
    s = ss
    for i in range(5):
        c0 = 1 if s & 1 else 0
        c1 = 1 if s & 2 else 0
        for j in range(n):
            b[j] += F[j][i * 2] * c0 + F[j][i * 2 + 1] * c1
        s >>= 2
    ts = 0
    for i in range(n):
        ts += P[i][b[i]]
    res = max(res, ts)
print(res)

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

res = -2100000000
for onechan in range(1, 2 ** 10):
  count = [0 for x in range(n)]
  b = 0
  d = onechan
  for k in range(10):
    if d % 2 == 1:
      for i in range(n):
        if f[i][k] == 1:
          count[i] += 1
    d //= 2

  for i in range(n):
    b += p[i][count[i]]
  res = max(b, res)

print(res)

Solution (Python):

import copy

shop_num = int(input().rstrip())


shop_data = {}
for i in range(shop_num):
	shop_data[i] = input().rstrip().split(' ')


shop_benefit = {}
for i in range(shop_num):
	shop_benefit[i] = input().rstrip().split(' ')

patterns = [0, 1, 2, 3];

targets = []
for pattern1 in patterns:
	list1 = []
	if pattern1 == 1:
		list1.append(0)
	elif pattern1 == 2:
		list1.append(1)
	elif pattern1 == 3:
		list1.append(0)
		list1.append(1)

	for pattern2 in patterns:
		list2 = copy.deepcopy(list1)
		if pattern2 == 1:
			list2.append(2)
		elif pattern2 == 2:
			list2.append(3)
		elif pattern2 == 3:
			list2.append(2)
			list2.append(3)
		for pattern3 in patterns:
			list3 = copy.deepcopy(list2)
			if pattern3 == 1:
				list3.append(4)
			elif pattern3 == 2:
				list3.append(5)
			elif pattern3 == 3:
				list3.append(4)
				list3.append(5)
			for pattern4 in patterns:
				list4 = copy.deepcopy(list3)
				if pattern4 == 1:
					list4.append(6)
				elif pattern4 == 2:
					list4.append(7)
				elif pattern4 == 3:
					list4.append(6)
					list4.append(7)
				for pattern5 in patterns:
					list5 = copy.deepcopy(list4)
					if pattern5 == 1:
						list5.append(8)
					elif pattern5 == 2:
						list5.append(9)
					elif pattern5 == 3:
						list5.append(8)
						list5.append(9)

					targets.append(copy.deepcopy(list5))

ben_list = []
for target in targets:
	if (len(target) <= 0):
		continue;
	ben = 0
	for key in shop_data:
		count = 0
		for time in range(10):
			data = int(shop_data[key][time])
			if time in target:
				if data == 1:
					count += 1

		ben += int(shop_benefit[key][count])

	ben_list.append(ben)

print(max(ben_list))

Solution (Python):


import sys

def overlap(source, target):
    n = 0
    for s, t in zip(source, target):
        if s == 1 and s == t:
            n += 1
    return n

def main(argv):
    line = sys.stdin.readline()
    while line:
        n = int(line.rstrip("\n"))
        f = []
        for i in xrange(n):
            f.append(map(lambda x: int(x), 
              sys.stdin.readline().rstrip("\n").split(" ")))
        p = []
        for i in xrange(n):
            p.append(map(lambda x: int(x), 
              sys.stdin.readline().rstrip("\n").split(" ")))

        max_profit = -10**7 * n - 1
        for index in xrange(1, 2**10):
            b = map(lambda x: int(x), bin(index)[2:].zfill(10))

            profit = 0
            for i in xrange(n):
                c = overlap(b, f[i])
                profit += p[i][c]

            if profit > max_profit:
                max_profit = profit

        print max_profit

        line = sys.stdin.readline()

if __name__ == "__main__":
    main(sys.argv)

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

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

s = [0] * (2 ** 10)
for i in range(N):
    for j in range(2 ** 10):
        s[j] += P[i][c[i][j]]

print(max(s[1:]))

Solution (Python):
import numpy as np
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())))

pattern = []
tmp = []
for i in range(n):
    tmp.append(f[i][0])
pattern.append(tmp)

for i in range(1, 10):
    tmp = []
    tmp_loop = pattern[:]
    for j in range( n):
        tmp.append(f[j][i])
    for pat in tmp_loop:
        pattern.append(list(np.array(pat)+np.array(tmp)))
    pattern.append(tmp)

ans = -100000000000
for pat in pattern:
    a = 0
    for i in range(n):
        a += p[i][pat[i]]
    ans = max(ans, a)
print(ans)

Solution (Python):

import itertools
def to_bool(i):
    if i == '1':
        return True
    return False


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

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

result = None
for eigyou in itertools.product((True,False), repeat=10):
    if sum(1 for a in eigyou if a) == 0:
        continue
    goukei = None
    for i in range(n):
        if goukei is None:
            goukei = p[i][sum(1 for a,b in zip(eigyou,f[i]) if a and b)]
        else:
            goukei += p[i][sum(1 for a,b in zip(eigyou,f[i]) if a and b)]
    if result is None:
        result = goukei
    if result < goukei:
        result = goukei
    
print(result)

Solution (Python):
import itertools
N=input()
F=[]
for i in range(N):
	F.append(map(int,raw_input().split()))


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



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

l.remove((0, 0, 0, 0, 0, 0, 0, 0, 0, 0))

b=[[] for i in range(2**10-1)]


for ind_i,i in enumerate(l):
	for j in F:
		
		
		b[ind_i].append(sum([min(t) for t in zip(i, j)]))


b_sum=0
ans=float("-inf")
for ind_i,i in enumerate(b):
	b_sum=0
	for ind_j,j in enumerate(i):
		
		b_sum+=P[ind_j][j]
	
	ans=max(ans,b_sum)

print ans

Solution (Python):
n = input()
f = [raw_input().split() for _ in xrange(n)]
p = [map(int, raw_input().split()) for _ in xrange(n)]
a = -9999999999L
for _ in xrange(1, 1024):
    cnt, b = 0, '0' * (12 - len(bin(_))) + bin(_)[2:]
    for i, n in enumerate(f):
        ci = 0
        for x in xrange(10):
            if b[x] == n[x] and b[x] == '1':
                ci += 1
        cnt += (p[i][ci])
    a = max(cnt, a)
print a

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



def solve(K):
    ans = 0
    n = 0
    while n < N:
        num = 0
        for i in range(10):
            if int(K[i]) == F[n][i] and K[i] == '1':
                num = num + 1
        ans += P[n][num]
        n += 1
    return ans
Ans = solve('%010d' % 1)
for m in range(1,1024):
    K = []
    L = int(format(m, 'b'))
    L = '%010d' % L
    k = solve(L)
    Ans = max(Ans, k)
print(Ans)

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())))
def solve(lst):
    if sum(lst) == 0:
        return -float("inf")
    res = 0
    for i in range(n):
        num = 0
        for j in range(10):
            if lst[j] == 1 and f[i][j] == 1:
                num += 1
        res += p[i][num]
    return res
l = []
for _a in range(2):
        for _b in range(2):
            for _c in range(2):
                for _d in range(2):
                    for _e in range(2):
                        for _f in range(2):
                            for _g in range(2):
                                for _h in range(2):
                                    for _i in range(2):
                                        for _j in range(2):
                                            res = solve([_a, _b, _c, _d, _e, _f, _g, _h, _i, _j])
                                            l.append(res)
print(max(l))

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)]
all = [list(format(i,'b').zfill(10)) for i in range(1,1025)]
ans = -100000000000000000000000

for i in range(1024):
    cnt = []
    gokei = 0
    for j in range(N):

        z = 0
        for a,b in zip(all[i],F[j]):
            if int(a)+b==2:
                z += 1
        cnt.append(z)
    for m in range(N):
        gokei += P[m][cnt[m]]

    ans = max(ans, gokei)

print(ans)

Solution (Python):
import numpy as np
n = int(input())
f = np.zeros((n, 10))
p = np.zeros((n, 11))
for i in range(n):
    f[i] = np.array(list(map(int, input().split())))

for i in range(n):
    p[i] = np.array(list(map(int, input().split())))

l = 10
f_n = 2**l-1
ans = (-10**7)*10*n
for i in range(2**l-1):
    ff = np.array(list(map(int,list(format(f_n,'b').zfill(l)))))
    c = np.sum(ff*f, dtype=np.int64, axis=1)
    c = np.eye(11)[c]
    tmp = np.sum(c*p)
    if ans < tmp:
        ans = tmp
    f_n -= 1
    
print (int(ans))

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

ans=-10**9
f=[[0 for i in range(10)] for j in range(n)]
p=[[0 for i in range(11)] for j in range(n)]

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


for i1 in range(2):
  for i2 in range(2):
    for i3 in range(2):
      for i4 in range(2):
        for i5 in range(2):
          for i6 in range(2):
            for i7 in range(2):
              for i8 in range(2):
                for i9 in range(2):
                  for i10 in range(2):
                    sumi=i1+i2+i3+i4+i5+i6+i7+i8+i9+i10
                    count=[0 for i in range(n)]
                    for ii in range(n):
                        if i1==f[ii][0] and i1==1:
                          count[ii]=count[ii]+1
                        if i2==f[ii][1] and i2==1:
                          count[ii]=count[ii]+1
                        if i3==f[ii][2] and i3==1:
                          count[ii]=count[ii]+1
                        if i4==f[ii][3] and i4==1:
                          count[ii]=count[ii]+1   
                        if i5==f[ii][4] and i5==1:
                          count[ii]=count[ii]+1
                        if i6==f[ii][5] and i6==1:
                          count[ii]=count[ii]+1
                        if i7==f[ii][6] and i7==1:
                          count[ii]=count[ii]+1
                        if i8==f[ii][7] and i8==1:
                          count[ii]=count[ii]+1
                        if i9==f[ii][8] and i9==1:
                          count[ii]=count[ii]+1   
                        if i10==f[ii][9] and i10==1:
                          count[ii]=count[ii]+1                          
                    
                    if sumi>0:
                      ans_0=0
                      
                      for i in range(n):
                         ans_0=ans_0+p[i][count[i]]
                      ans=max(ans,ans_0)
                          
                                                                            
print(ans)

Solution (Python):
from itertools import product

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

max_res = 0

for i,j in enumerate(product("01",repeat=10)):
    if i != 0:
        res = [0 for _ in range(N)]
        for k, flag in enumerate(j):
            if flag == "1":
                for l,f in enumerate(F):
                    if f[k] == "1":
                        res[l] += 1
        buf = 0
        for m in range(N):
            buf += int(P[m][res[m]])
        if i==1:
            max_res = buf
        else:
            max_res = max(buf,max_res)

print(max_res)

Solution (Python):
import copy

N=int(input())
F=[ [ [ 0 for i in range(3)] for j in range(6)] for k in range(N+1)]

for i in range(1,N+1):
     line = [int(k) for k in input().split()]
     for j in range(1,6):
         for k in range(1,3):
             F[i][j][k]=line[2*(j-1)+(k-1)]

P=[[0 for i in range(11)] for j in range(N+1)]
for i in range(1,N+1):
    line = [int(j) for j in input().split()]
    for k in range(11):
        P[i][k]=line[k]




stack=[]
stack.append([True])
stack.append([False])
rieki_max=float("inf")

while(1):
    if len(stack)==0:
        break
    kumiawase=stack.pop()
    if len(kumiawase)==10:
        
        if kumiawase.count(True)==0:
            continue
        kaburi=[0 for i in range(N+1)]
        for i in range(1,6):
            for j in range(1,3):
                if kumiawase[(i-1)*2+j-1]==False:
                    continue
                for k in range(1,N+1):
                    if F[k][i][j]==1:
                        kaburi[k]+=1
        rieki=0
        
        for i in range(0,N+1):
            rieki+=P[i][kaburi[i]]
        
        if rieki_max < rieki or rieki_max==float("inf"):
            rieki_max = rieki
    else:
        tmp_a = copy.deepcopy(kumiawase)
        tmp_a.append(True)
        stack.append(tmp_a)
        tmp_b = copy.deepcopy(kumiawase)
        tmp_b.append(False)
        stack.append(tmp_b)
print(rieki_max)

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

benefits = -1000000000

for t in range(1,1024):
  bits = list(bin(t))
  a = [0 for _ in range(n)]
  jk = 0
  while jk < 10:
    b = bits.pop()
    if b == "b":
      break
    elif b == "0":
      jk += 1
      continue
    else:
      for i in range(n):
        if f[i][jk]:
          a[i] += 1
      jk += 1
  
  s = 0
  for i in range(n):
    s += p[i][a[i]]
  else:
    benefits = max(s,benefits)
else:
  print(benefits)