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):
from sys import stdin

input = stdin.readline

MAX_TIME = 10

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


def main():
    ans = -11000000001

    
    
    for i in range(1, 2 ** MAX_TIME):
        tmp = 0

        
        for j in range(N):
            
            cnt = sum([F[j][k] for k in range(MAX_TIME) if i >> k & 1])
            tmp += P[j][cnt]

        ans = max(ans, tmp)

    print(ans)
    return


main()

Solution (Python):
MAX_TIME = 10

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


def main():
    ans = -11000000001

    
    
    for i in range(1, 2 ** MAX_TIME):
        tmp = 0

        
        for j in range(N):
            
            cnt = sum([F[j][k] for k in range(MAX_TIME) if i >> k & 1])
            tmp += P[j][cnt]

        ans = max(ans, tmp)

    print(ans)
    return


main()

Solution (Python):

import copy
import numpy as np
import random

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



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

F = np.array(F)
P = np.array(P)


def cal_val(shop_num,open_time):
    same_time = int(np.dot(F[shop_num],open_time.T))
    
    return P[shop_num,same_time]











values = []
ans = -10**10
for i in range(1,2**10):
    open_time = np.zeros([10])
    for j in range(10):
        if i%2==1:
            open_time[j] = 1
        i = i//2
    value = 0
    for shop_num in range(n):
        value += cal_val(shop_num,open_time)
    values.append(value)
    ans = max(ans,value)


print(ans)

Solution (Python):


import itertools
import collections
import bisect


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

    
    

    
    INF = int(1e15)
    ans = -INF
    pattern = 1024  
    for i in range(1, pattern):
        score = 0
        
        for s in range(N):
            matched = 0
            f = F[s]
            p = P[s]
            
            
            for j in range(10):
                if (i >> j) & 1:  
                    matched += 1 if f[j] else 0

            
            score += p[matched]
        
        ans = max(ans, score)

    print(ans)


if __name__ == '__main__':
    main()

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


ans = -1 << 40
for mask in range(1, 1 << 10):
    t = 0
    for i in range(N):
        c = 0
        for j in range(10):
            if (mask >> j) & F[i][j]:
                c += 1
        t += P[i][c]
    ans = max(ans, t)

print(ans)

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


for i in range(1,1024):
    openTime = list(map(int, list("{:0>10}".format(bin(i)[2:]))))
    thisProfit = 0
    for n in range(N):
        shopOpneTime = F[n]
        shopProfit = P[n]
        counter = 0
        for j in range(10):
            if((shopOpneTime[j])and(openTime[j])):
                 counter += 1
        thisProfit += shopProfit[counter]
    maxProfit = max(thisProfit, maxProfit)

print(maxProfit)

Solution (Python):
N = int(input())
F = [list(map(int, input().split())) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]
ans = -float("inf")
for i in range(1, 2 ** 10):
    b, s = i, 0
    cnt = [0 for _ in range(N)]
    while b > 0:
        if b & 1:
            for j in range(N):
                cnt[j] += F[j][s]
        s += 1
        b >>= 1
    sub_ans = 0
    for j in range(N):
        sub_ans += P[j][cnt[j]]
    ans = max(ans, sub_ans)
print(ans)

Solution (Python):
import numpy as np

N = int(input())
F = [list(map(int, input().strip().split())) for i in range(N)]
P = [list(map(int, input().strip().split())) for i in range(N)]
maxProfit = -1000000000



for i in range(1,1024):
    openTime = list(map(int, list("{:0>10}".format(bin(i)[2:]))))
    thisProfit = 0
    for n in range(N):
        shopOpneTime = F[n]
        shopProfit = P[n]
        counter = 0
        for j in range(10):
            if((shopOpneTime[j])and(openTime[j])):
                 counter += 1
        thisProfit += shopProfit[counter]
    maxProfit = max(thisProfit, maxProfit)

print(maxProfit)

Solution (Python):
import numpy as np

N = int(input())
F = [list(map(int, input().strip().split())) for i in range(N)]
P = [list(map(int, input().strip().split())) for i in range(N)]
maxProfit = -1000000000



for i in range(1,1024):
    openTime = list(map(int, list("{:0>10}".format(bin(i)[2:]))))
    thisProfit = 0
    for n in range(N):
        shopOpneTime = F[n]
        shopProfit = P[n]
        counter = 0
        for j in range(10):
            if((shopOpneTime[j])and(openTime[j])):
                 counter += 1
        thisProfit += shopProfit[counter]
    maxProfit = max(thisProfit, maxProfit)

print(maxProfit)

Solution (Python):

from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import itertools
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return list(sys.stdin.readline())
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
mod = 1000000007


def C():
    N = I()
    F = LIR(N)
    P = LIR(N)
    ans = -1*float("INF")
    kaiten = list((itertools.product([0,1], repeat=10)))
    del kaiten[0]
    for patern in kaiten:
        i = list(patern)
        anskaiten = [0 for i in range(N)]
        for youbi, n in enumerate(i):
            if n == 1:
                for nn,f in enumerate(F):
                    if f[youbi] == 1:
                        anskaiten[nn] += 1
        ansb = 0
        
        for k, p in enumerate(P):
            ansb += p[anskaiten[k]]
        ans = max(ans, ansb)
    print(ans)
        
if __name__ == '__main__':
    C()

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007


def A():
    return


def B():
    return


def C():
    n = I()
    f = LIR(n)
    po = [1]*11
    for i in range(n):
        k = 0
        p = 1
        for j in range(10):
            k += p*f[i][j]
            p *= 2
            po[j+1] = p
        f[i] = k
    p = LIR(n)
    ans = -float("inf")
    for i in range(1,1024):
        k = 0
        for j in range(n):
            c = i&f[j]
            s = 0
            for l in po:
                if c&l:s += 1
            k += p[j][s]
        ans = max(ans,k)
    print(ans)

def D():
    n,C = LI()
    T = [[0 for i in range(200002)] for j in range(C)]
    for i in range(n):
        s,t,c = LI()
        c -= 1
        T[c][2*s] += 1
        T[c][2*t+1] -= 1
    for c in range(C):
        for i in range(200000):
            T[c][i+1] += T[c][i]
    ans = 0
    for i in range(200000):
        k = 0
        for c in range(C):
            if T[c][i]:k += 1
        ans = max(ans, k)
    print(ans)

def E():
    return


def F():
    return


def G():
    return


def H():
    return


if __name__ == "__main__":
    C()

Solution (Python):
def bit_index(n: int) -> list:
    '''n の立っているビットのインデックスを返します。
    '''
    res = []
    idx = 0
    while n > 0:
        if n & 1:
            res.append(idx)
        n >>= 1
        idx += 1
    return res


def shopping_street(N: int, F: list, P: list) -> int:
    max_profits = -float('inf')
    
    
    
    
    for i in range(1, 1 << 10):
        open_times = bit_index(i)
        profits = 0
        
        for n in range(N):
            shop_count = sum(F[n][t] for t in open_times)
            profits += P[n][shop_count]
        max_profits = max(max_profits, profits)
    return max_profits


if __name__ == "__main__":
    N = int(input())
    F = [[int(s) for s in input().split()] for _ in range(N)]
    P = [[int(s) for s in input().split()] for _ in range(N)]
    ans = shopping_street(N, F, P)
    print(ans)

Solution (Python):
import sys
from itertools import product

def main():
    input = sys.stdin.readline
    N = int(input())
    F = []
    for _ in range(N):
        A = list(map(int, input().split()))
        F.append(A)

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

    ans = -10**9
    l = [0, 1]
    shop = list(product(l, repeat=10))
    for s in shop:
        if sum(s) == 0:
            continue

        cur = 0
        for i in range(N):
            f = F[i]
            n = sum([f[j] * s[j] for j in range(10)])
            cur += P[i][n]

        ans = max(ans, cur)

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
L1 = []
L2 = []
ans = -10**10
for _ in range(N):
    l = list(map(int,input().split()))
    L1.append(l)
for _ in range(N):
    l = list(map(int,input().split()))
    L2.append(l)

for j in range(1,1024):
    b = format(j,'b').zfill(10)
    price = 0
    for k in range(N):
        cnt = 0
        for i in range(10):
            if L1[k][i] == int(b[i]) == 1:
                cnt += 1
        price += L2[k][cnt]
    ans = max(ans,price)
print(ans)

Solution (Python):
import itertools
c=itertools.product([0,1], repeat=10)
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**10
def C(ci):
    cnt=[0]*n
    for x in range(n):
        for y in range(10):
            if ci[y]==1 and f[x][y]==1:
                cnt[x]+=1
    res=0
    for z in range(n):
        res+=p[z][cnt[z]]
    return res
for ci in c:
    if all(i ==0 for i in ci):
        continue
    ans=max(ans, C(ci))
print(ans)

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

l = ['0','1']
def n_ary1(l,d): 
    if d == 1:
        return(l)
    ll = n_ary1(l,d-1)
    lll = []
    for i in l:
        for j in ll:
            lll.append(i+j)
            
    return(lll)

def l_and(l1,l2):
    s = 0
    for i in range(len(l1)):
        s += int(l1[i])&int(l2[i])
    return(s)

JJ = n_ary1(l,10)[1:]
ans = -float('inf')
for J in JJ:
    C = [l_and(F[i],J) for i in range(N)]
    p = sum([P[i][C[i]] for i in range(N)])
    ans = max(ans,p)
print(ans)

Solution (Python):
from itertools import product
N = int(input())
F = [list(map(int, input().split())) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]
x = - 10 ** 10
for a in product((0, 1), repeat=10):
    if not any(a):
        continue
    num = 0
    for f, p in zip(F, P):
        c = sum(map(lambda z: z[0] * z[1], zip(a, f)))
        num += p[c]
    x = max(x, num)
print(x)

Solution (Python):
import sys
sys.setrecursionlimit(10000)

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

def dfs(s):
    if len(s) == 10:
        value = -INF
        if "1" in s:
            value = 0
            c = [0 for i in range(N)]
            for i in range(5):
                for j in range(2):
                    for k in range(N):
                        if int(s[2*i+j]) * F[k][2*i+j]:
                            c[k] += 1
            for i in range(N):
                value += P[i][c[i]]
        return value
    else:
        return max(dfs(s+"0"), dfs(s+"1"))

print(dfs(""))

Solution (Python):

def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
n=I()
F=[int(input().replace(" ",""), 2) for _ in range(n)]
P=[IL() for i in range(n)]
ans=-pow(10,10)
for i in range(1,pow(2,10)):
    t=0
    for f,p in zip(F,P):
        t+=p[bin(f&i).count("1")]
    ans=max(ans,t)
print(ans)

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

maxv = -2<<100
for i in range(1, 1<<10):
    maxv = max(maxv, sum(p[bin(f&i).count('1')] for f, p in zip(F, P)))
print(maxv)

Solution (Python):
import itertools


def main():
    N = int(input())
    F = [tuple(map(int, input().split())) for _ in range(N)]
    P = [tuple(map(int, input().split())) for _ in range(N)]
    ans = -float("inf")
    for ptn in itertools.product((0, 1), repeat=10):
        if ptn == (0, 0, 0, 0, 0, 0, 0, 0, 0, 0):
            continue
        tmp = 0
        for i in range(N):
            common = sum([ptn[x] * F[i][x] for x in range(10)])
            tmp += P[i][common]
        ans = max(tmp, ans)
    print(ans)


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 = -(1e9+7)
for i in range(1, 2**10):
  b = 0
  for f, p in zip(F, P):
    b += p[bin(f&i).count("1")]
  ans = max(ans, b)
print(ans)

Solution (Python):
def calc(pat, F, P):
    ans = 0
    both = [0 for i in range(N)]
    for i in range(10):
        if pat[i] == 1:
            for j in range(N):
                if F[j][i] == 1:
                    both[j] += 1
    for i in range(N):
        ans += P[i][both[i]]
    return ans

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

zenbu = 2**10
res = []
for i in range(1, zenbu):
    pat = []
    bit = i
    for j in range(10):
        pat.append(bit % 2)
        bit //= 2
    res.append(calc(pat, F, P))

print(str(max(res)))

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

a = [list(map(int,input().split())) for i in range(n)]
b = [list(map(int,input().split())) for i in range(n)]
c = [0 for i in range(n)]
su = 0
co = -1*1<<40
for i in range(1,1<<10):
    ii = i
    for j in range(n):
        for k in range(10):
            if (a[j][k]<<k) & i != 0:
                c[j] += 1
    for j in range(n):
        su += b[j][c[j]]

    co = max(co,su)
    su = 0
    c = [0 for i in range(n)]

print(co)

Solution (Python):
import itertools
import numpy as np
N = int(input())
F = np.array([list(map(int, input().split())) for _ in range(N)])
P = [list(map(int, input().split())) for _ in range(N)]
benefit = -float("inf")

for i in itertools.product((0, 1), repeat=10):
    if sum(i) != 0:
        C = np.array(list(i)) + F
        pre_benefit = 0
        for j in range(N):
            count = len(np.where(C[j]==2)[0])
            pre_benefit += P[j][count]
        if benefit < pre_benefit:
            benefit = pre_benefit
print(benefit)

Solution (Python):
import itertools

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

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


ans = -float("inf")

for comb in itertools.product((0,1), repeat=10):
    rieki = 0
    for i in range(N):
        tmp_list = [a + b for a, b in zip(F[i], list(comb))]
        rieki += P[i][tmp_list.count(2)]

    if rieki > ans and sum(comb) != 0:
        ans = rieki

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

maxscore = -10**9
def bittolist(x):
    ret = []
    for _ in range(10):
        ret.append(x%2)
        x //= 2
    return ret
for i in range(1, 1024):
    open = bittolist(i)
    score = 0
    for store in range(n):
        count = 0
        for time in range(10):
            if f[store][time] == 1 and open[time] == 1:
                count += 1
        score += p[store][count]
    maxscore = max(maxscore, score)
print(maxscore)

Solution (Python):
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18

N=ri()
F=[rl() for _ in range(N)]
P=[rl() for _ in range(N)]
ans = -INF

import itertools
for d in itertools.product(range(2),repeat=10):
    if sum(d) == 0: continue
    res = 0
    for i in range(N):
        res += P[i][sum(map(lambda x,y:x&y, F[i], d))]
    ans = max(ans,res)

print(ans)

Solution (Python):
from itertools import product


def BothAreOpen(arrange1, arrange2):
    counter = 0
    for element in zip(arrange1, arrange2):
        if element == (1, 1):
            counter += 1
    return counter


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

ans = -1000000000000000000000000

for MyShop in product([0, 1], repeat=10):
    if MyShop == tuple([0] * 10):
        continue

    chofuku = []
    for OtherStore in OpeningHours:
        chofuku.append(BothAreOpen(MyShop, OtherStore))

    x = sum([Profits[i][chofuku[i]] for i in range(N)])
    if x > ans:
        ans = x

print(ans)

Solution (Python):

N=int(input())
F=list(int(input().replace(" ",""),2) for i in range(N))
P=list(list(map(int,input().split())) for i in range(N))
ans=-(1<<40)
for bit in range(1,1<<10):
    tmp = 0
    for i in range(N):
        tmp+=P[i][bin(bit&F[i]).count('1')]
    ans = max(ans,tmp)
print(ans)

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

Solution (Python):
from itertools import combinations

import numpy as np

n = int(input())
f = []
p = []

for i in range(n):
    f.append(np.array([int(i) for i in input().split()]))

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



max_score = -1e10

for my_shop_count in range(1, 11, 1): 
    for comb in combinations(np.arange(10), my_shop_count):
        score = 0
        for shop_index in range(n):
            order = 0
            for j in range(my_shop_count):
                order += f[shop_index][comb[j]]
            score += p[shop_index][order]

        if(score > max_score):
            max_score = score

print(max_score)

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

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

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 = -10 ** 11
for i in range(1, 2**10) :
    ans1 = 0
    t = format(i, "010b")
    for j in range(n) :
        kaburi = 0
        for k in range(10) :
            
            if int(t[k]) * F[j][k] == 1 :
                kaburi += 1
        ans1 += P[j][kaburi]
    
    
    
    ans = max(ans, ans1)

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 = -float('inf')
for i in range(1, 2 ** 10):
    A = []
    while i > 0:
        A.append(i % 2)
        i //= 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())
F=[]
P=[]
for n in range(N):
	F.append(list(map(int,input().split())))
for n in range(N):
	P.append(list(map(int,input().split())))
def DP(a,i):
	if i!=10:
		ans=max(DP(a+[1],i+1),DP(a+[0],i+1))
	elif any(a):
		ans=0
		for n in range(N):
			c=0
			for i in range(10):
				if F[n][i] and a[i]:
					c+=1
			ans+=P[n][c]
	else:
		ans=-float('inf')
	return ans
print(DP([],0))

Solution (Python):
import itertools

N = int(input())

Flist = []
for i in range(N):
    f = [int(x) for x in input().split()]
    Flist.append(f)

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

cases = []
for i in range(1,11):
    cases.extend(list(itertools.combinations([0,1,2,3,4,5,6,7,8,9], i)))

result = -10**9
for case in cases:
    counter = [0]*N
    cache = 0
    for x in case:
        for i,f in enumerate(Flist):
            if f[x] == 1:
                counter[i] += 1
    for i,count in enumerate(counter):
        cache += Plist[i][count]
    if cache > result:
        result = cache

print(result)

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

def score(_bin, F, P):
    score = 0
    for j, f in enumerate(F):
        hit_counter = 0
        for i in range(10):
            if _bin>>i & 1 and f[i] == 1:
                hit_counter += 1
        score += P[j][hit_counter]
    return score

max_score = -1<<30
for i in range(1,1<<10):
    max_score = max(max_score, score(i, F, P))

print(max_score)

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

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


best_value = -float("inf")
for flg in range(1, 2**10):
    bit = [(flg >> v) & 1 for v in range(10)]
    c = [0 for x in range(n)]
    for i in range(n):
        for v1, v2 in zip(bit, stores[i]):
            if v1 == v2 == 1:
                c[i] += 1
    benefit = 0
    for i, c_value in enumerate(c):
        benefit += p[i][c_value]
    best_value = max(best_value, benefit)
print(best_value)

Solution (Python):
N=int(input())
F=[[0]*10 for _ in range(N)]
P=[[0]*11 for _ in range(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()))
i=1
ans=int(-10e15)
cnt=0
while i<=int('1111111111',2):
    tmp_ans=0
    bin_str=format(i,'10b')
    for j in range(N):
        cnt=0
        for k in range(10):
            if bin_str[k]=='1' and F[j][k]==1:
                cnt+=1
        tmp_ans+=P[j][cnt]
    if tmp_ans>ans:
        ans=tmp_ans
    i+=1
print(ans)

Solution (Python):
I=input;n=int(I());f=[int(I()[::2],2)for _ in[0]*n];p=[I().split()for _ in[0]*n];print(max(sum(int(q[bin(i&g).count('1')])for g,q in zip(f,p))for i in range(1,1024)))

Solution (Python):
I=input;n=int(I());f=[int(I()[::2],2)for _ in[0]*n];p=[I().split()for _ in[0]*n];print(max(sum(int(q[bin(i&g).count('1')])for g,q in zip(f,p))for i in range(1,1024)))

Solution (Python):
I=input;n=int(I());f=[int(I()[::2],2)for _ in[0]*n];p=[list(map(int,I().split()))for _ in[0]*n];print(max(sum(q[bin(i&g).count('1')]for g,q in zip(f,p))for i in range(1,1024)))

Solution (Python):
import itertools

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

ans =int(-10e15)
for k in range(1,11):
  for j in itertools.combinations(range(10),k):
    tmp = 0
    for f,p in zip(F, P):
      num = sum([f[cnt] for cnt in j])
      tmp += p[num]
    ans = max(ans,tmp)
    
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())))
  
ma = -10e10

for i in range(1, 1024):
  t = i
  x = []
  for j in range(10):
    x.append(t % 2)
    t //= 2
  wa = 0
  for j in range(N):
    cnt = 0
    for k in range(10):
      if x[k] == 1 and F[j][k] == 1:
        cnt += 1
    wa += P[j][cnt]
    
  if ma < wa:
    ma = wa
print(ma)

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)]
d=[]
for i in range(n):
    c=""
    for j in range(10):
        c+=f[i][j]
    else:
        d.append(int(c,2))
ans=float("-inf")
for i in range(1,1024):
    k=0
    for j in range(n):
        k+=p[j][bin(d[j]&i).count("1")] 
    else:
        ans=max(k,ans)
print(ans)

Solution (Python):
from sys import stderr, setrecursionlimit
setrecursionlimit(2147483647)
def getint():
    return int(input())
def getints():
    return [int(i) for i in input().split()]
def getintlines(n=1):
    res = []
    for _ in range(n):
        res.append(getint())
    return res
def getintslines(n=1):
    res = []
    for _ in range(n):
        res.append(getints())
    return res
def debug(*args, **kwargs):
    print(*args, file=stderr, **kwargs)

n = getint()
f = getintslines(n)
p = getintslines(n)



profit = -10**10

for sale in range(1,1025):
    shops = [0]*n
    pattern = format(sale, '010b')
    for i, time in enumerate(pattern):
        if time == '1':
            for j in range(n):
                shops[j] += f[j][i]
    tmp = 0
    for i, s in enumerate(shops):
        tmp += p[i][s]
    profit = max(tmp, profit)
    
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 = -(10**9+7)
for i in range(1, 2**10):
  tmp = 0
  for f, p in zip(F, P):
    tmp += p[bin(f&i).count('1')]
  ans = max(ans, tmp)
print(ans)

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

Solution (Python):
n = int(input())
f, p = [], []
scores = []
for i in range(n):
    f.append(int(int("".join(list(input().split())), 2)))
for i in range(n):
    p.append(list(map(int,input().split())))
for i in range(1,1024):
    score = 0
    for j in range(n):
        double = bin(i & f[j]).count("1")
        score += p[j][double]
    scores.append(score)
print(max(scores))

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

Solution (Python):
import itertools
N = int(input())
F = [list(map(int,input().split())) for i in range(N)]
P = [list(map(int,input().split())) for i in range(N)]
b = [0,1]
ans = -float('inf')
for e in itertools.product(b,repeat=10):
    e = list(e)
    if e == [0]*10:
        continue
    res = 0
    for i in range(N):
        cnt = 0
        for j in range(10):
            if e[j] == 1 and F[i][j] == 1:
                cnt += 1
        res += P[i][cnt]
    if res > ans:
        ans = res
print(ans)

Solution (Python):
N=int(input())
F=[int(input().replace(' ',''),2) for i in range(N)]
P=[list(map(int,input().split())) for i in range(N)]
print(max(sum([p[bin(f&i).count('1')] for f,p in zip(F,P)]) 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 = -(10**9+7)
for i in range(1, 2**10):
  tmp = 0
  for f, p in zip(F, P):
    tmp += p[bin(f&i).count('1')]
  ans = max(ans, tmp)
print(ans)

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 = - 10**10

for i in range(1,1<<10):
    ans = max(ans, sum(P[n][bin(i&F[n]).count('1')] for n in range(N)))
print(ans)