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 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] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007


def A():
    n,a,b = LI()
    print(min(n*a,b))
    return


def B():
    s = S()
    print(s.count("1"))
    return


def C():
    n = list(map(int, S()))
    k = 0
    s = sum(n)
    for i in range(len(n)):
        k *= 10
        k += n[i]
    if k%s == 0:
        print("Yes")
    else:
        print("No")
    return


def D():
    n = I()
    a = LI()
    ans = float("inf")
    for i in range(n):
        m = 0
        while a[i]%2 == 0:
            m += 1
            a[i] //= 2
        ans = min(m,ans)
    print(ans)
    return


def E():
    def dfs(n,k):
        if n == 10:
            l.append(k)
        else:
            dfs(n+1,k+[0])
            dfs(n+1,k+[1])
    n = I()
    f = LIR(n)
    p = LIR(n)
    l = []
    dfs(0,[])
    ans = -float("inf")
    for k in l[1:]:
        m = 0
        c = [0 for i in range(n)]
        for i in range(n):
            for j in range(10):
                c[i] += f[i][j]&k[j]
            m += p[i][c[i]]
        ans = max(m,ans)
    print(ans)
    return


def F():
    n,k = LI()
    a = LI()
    d = defaultdict(int)
    for i in a:
        d[i] += 1
    d = list(d.values())
    d.sort()
    ans = 0
    for i in range(len(d)-k):
        ans += d[i]
    print(ans)
    return


def G():
    n,c = LI()
    ch = LIR(n)
    T = [[0 for i in range(100002)] for j in range(c+1)]
    for s,t,cha in ch:
        T[cha-1][s] += 1
        T[cha-1][t+1] -= 1
    for i in range(c):
        for j in range(100000):
            T[i][j+1] += T[i][j]
            if T[i][j] >= 1:
                T[i][j] = 1
    ans = 0
    for i in range(100001):
        m = 0
        for j in range(c+1):
            m += T[j][i]
        ans = max(m,ans)
    print(ans)
    return


def H():
    n = I()
    a = LI()
    ma = a.index(max(a))
    mi = a.index(min(a))
    ans = []
    if abs(a[ma]) > abs(a[mi]):
        ans.append([ma+1,1])
        ans.append([ma+1,1])
        a[0] += 2*a[ma]
        for i in range(n-1):
            ans.append([i+1,i+2])
            ans.append([i+1,i+2])
            a[i+1] += 2*a[i]
    else:
        ans.append([mi+1,n])
        ans.append([mi+1,n])
        a[-1] += 2*a[mi]
        for i in range(n-1)[::-1]:
            ans.append([i+2,i+1])
            ans.append([i+2,i+1])
            a[i] += 2*a[i+1]
    print(len(ans))
    for i in ans:
        print(*i)
    return


def I_():
    n = I()
    print(1080/(n-1))
    return


def J():
    h,w,n = LI()
    p = LIR(n)
    if n%2 == 1:
        print(-1)
        quit()
    ans = []
    for i in range(1,h+1):
        c = 0
        m = i/w
        for x,y in p:
            if m*x < y:c += 1
            elif m*x == y:
                c = 0
                break
        if c == n//2:
            ans.append([w,i])

    for i in range(1,w):
        c = 0
        m = h/i
        for x,y in p:
            if m*x < y:c += 1
            elif m*x == y:
                c = 0
                break
        if c == n//2:
            ans.append([i,h])
    if len(ans) == 0:
        print(-1)
        quit()
    ans.sort()
    for x,y in ans:
        print("("+str(x)+","+str(y)+")")
    return




def L():
    return


def M():
    return



if __name__ == "__main__":
    E()

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

from itertools import combinations

mm = None
for i in range(1, 11):
  for ss in combinations(range(0, 10), i):
    m = 0
    for j in range(N):
      c = sum(f for k, f in enumerate(FF[j]) if k in ss)
      m += PP[j][c]
    if mm is None:
      mm = m
    else:
      mm = max(mm, m)
print(mm)

Solution (Python):
n=int(input());f,p=[],[];ans=""
for _ in range(n):f.append(list(map(int,input().split())))
for _ in range(n):p.append(list(map(int,input().split())))
for i in range(1,2**10):
  s=bin(i)[2:].zfill(10);a=0
  for j in range(n):
    m=0
    for h in range(10):
      if s[h]=="1":m+=f[j][h]
    a+=p[j][m]
  ans=(a if ans==""else max(ans,a))
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=-10**9
for i in range(1,2**10):
  a=0
  m=[i%2,i//2%2,i//4%2,i//8%2,i//16%2,i//32%2,i//64%2,i//128%2,i//256%2,i//512%2]
  mm=[0 for i in range(n)]
  for i in range(10):
    for j in range(n):
      if m[i]==1 and f[j][i]==1:
        mm[j]+=1
  for i in range(n):
    a+=p[i][mm[i]]
  ans=max(ans,a)
print(ans)

Solution (Python):
N = int(input())
fn = [list(map(int,input().split())) for _ in range(N)]
pn = [list(map(int,input().split())) for _ in range(N)]
bitf = []
for i in range(N):
    temp = 0
    for j in range(10):
        temp += ((2 ** j) * fn[i][j])
    bitf.append(temp)

def func(x , y):
    return bin(x & y).count('1')
ans = (-1) * 10 ** 10
for i in range(1,2**10):
    temp = 0
    for j in range(N):
        temp += pn[j][func(i,bitf[j])]
    ans = max(ans , temp)
print(ans)

Solution (Python):


















import math
import copy
from collections import defaultdict, Counter

from itertools import product

from itertools import permutations

from itertools import combinations
from bisect import bisect_left, bisect_right


def i_inpl(): return int(input())
def s_inpl(): return map(int,input().split())
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")

N = i_inpl()
F = []
for _ in range(N):
    Fi = l_inpl()
    F.append(Fi)

P = []
for _ in range(N):
    Pi = l_inpl()
    P.append(Pi)



ans = -1 * INF
for i in range(1, 2**10):
    tmp = 0
    for j in range(N):
        c = 0
        
        for k in range(10):
            if ((i>>k) & 1) & F[j][k]:
                c += 1
        tmp += P[j][c]
    ans = max(ans, tmp)

print(ans)

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

bits = []
for i in range(n):
  bit = int(input().replace(" ", ""), 2)
  bits.append(bit)
p = [[int(item) for item in input().split()] for _ in range(n)]

ans = - 10**9
for i in range(1,2**10):
  val = 0
  for j,mise in enumerate(p):
    val += mise[bin(i & bits[j]).count("1")]
  ans = max(ans, val)
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 = -(10**7) * 10 * 100

for i in range(1,2**10):  
  counter = [0]*N 
  tmp = 0 
  for j in range(10):    
    if (i>>j) & 1:
      for k in range(N):
        if F[k][j] ==1:
          counter[k] += 1
  for l in range(N):
    tmp += P[l][counter[l]]
      
  ans = max(tmp,ans)
print(ans)

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**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
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 pf(s): return print(s, flush=True)

N = I()
F = []
for i in range(N):
    F.append(LI())
P = []
for i in range(N):
    P.append(LI())

"""
各時間帯をon/offで2通り全探索すると、2**10になる。
"""
ans = -10**18
def dfs(l):
    global ans
    if len(l) == 10:
        if all(item == 0 for item in l):
            return
        
        point = 0
        for n in range(N):
            s = sum([f for fidx, f in enumerate(F[n]) if f == l[fidx] == 1])
            point += P[n][s]
        ans = max(ans, point)
        return
    dfs(l + [0])
    dfs(l + [1])

dfs([])
print(ans)

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

N=int(input())
count=[]
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:
        if "1" not in s:
            val=-INF
        if "1" in s:
            val=0
            c=[0 for i in range(N)]
            for i in range(N):
                
                count=0
                for j in range(10):
                    
                    if int(int(s[j])*F[i][j]):
                        c[i]+=1
                    

            for i in range(N):
                val+=P[i][c[i]]
        return val
    else:
        return max(dfs(s+"0"),dfs(s+"1"))
print(dfs(""))

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

bits = []
for i in range(n):
    bit = int(input().replace(" ", ""), 2)
    bits.append(bit)
p = [[int(item) for item in input().split()] for _ in range(n)]

ans = - 10**9
for i in range(1,2**10):
    val = 0 
    for j, mise in enumerate(p):
        val += mise[bin(i & bits[j]).count("1")]
    ans = max(ans, val)

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

B=[bin(i)[2:] for i in range(1024)]
for i in range(len(B)):
    while(len(B[i])<10):
        B[i]="0"+B[i]
c=0
ans=-10**9
for b in B[1:]:
    res=0
    for index,f in enumerate(F):
        
        for i,j in zip(f,b):
            if(str(i)==j and i==1):
                c+=1
        
        
        res+=P[index][c]
        c=0
    ans=max(ans,res)
print(ans)

Solution (Python):
import itertools

def main():
    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()]

    ans = -float("inf")
    for i0, i1, i2, i3, i4, i5, i6, i7, i8, i9 in itertools.product(range(2), range(2), range(2),range(2), range(2), range(2),range(2), range(2), range(2), range(2)):
        i_list = [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9]
        if sum(i_list) != 0:
            value = 0
            for j in range(n):
                value += p[j][sum([i_list[_]*f[j][_] for _ in range(10)])]
            ans = max(ans, value)

    print(ans)


main()

Solution (Python):
n = int(input())
f = [input().split(' ') for _ in range(n)]
p = [input().split(' ') for _ in range(n)]
res = -10 ** 7 * n
for num in range(1, 1024):
  tmp = 0
  for index in range(0, n):
    tmp += int(p[index][len([True for x in range(0, 10) if f[index][x]=='{:010b}'.format(num)[x]=='1'])])
  res = max(tmp, res)
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)]
ans = -float('inf')
for i in range(1, 2 ** 10):
    t = 0
    for j in range(N):
        c = 0
        for k in range(10):
            c += ((i >> k) & 1) & F[j][k]
        t += P[j][c]
    ans = max(ans, t)
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)]

ans = -float("inf")
for pattern in itertools.product(range(2), repeat=10):
  if sum(pattern)==0:
    continue

  tmp_ans = 0
  for mise_i in range(n):
    tmp_cnt = 0
    for i,ptn in enumerate(pattern):
      if ptn == 1 and f[mise_i][i] == 1:
        tmp_cnt += 1
    tmp_ans += p[mise_i][tmp_cnt]
  if tmp_ans > ans:
    ans = tmp_ans
print(ans)

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())))
inf=1<<60
ans=-inf
for t in range(1,2**10):
    a=0
    for i in range(N):
        c=0
        for j in range(10):
            if F[i][j]==1 and (t & (1<<j)) != 0:
                c+=1
        a+=P[i][c]
    ans=max(ans,a)
print(ans)

Solution (Python):
N=int(input())
Open=[list(map(int,input().split())) for i in range(N)]
Profit=[list(map(int,input().split())) for i in range(N)]
ans=-1*float('inf')
for x in range(1,2**10):
    check=bin(x)[2:]
    check='0'*(10-len(check))+check
    now=0
    for i in range(N):
        cnt=0
        for k in range(10):
            if int(check[k])*Open[i][k]==1:
                cnt+=1
        now+=Profit[i][cnt]
    ans=max(ans,now)
print(ans)

Solution (Python):
def base10to(n, b):
    if (int(n/b)):
        return base10to(int(n/b), b) + str(n % b)
    return str(n % b)


N = int(input())
f = []
for i in range(N):
    f.append(list(map(int, input().split())))
p = []
for i in range(N):
    p.append(list(map(int, input().split())))
ans = []
for i in range(1,1024):
    lis = list(base10to(i, 4).zfill(5))
    temp = 0
    for k in range(N):
        count = 0
        for j in range(len(lis)):
            if lis[j] == '0':
                count += f[k][2*j]*0 + f[k][2*j + 1]*0
            elif lis[j] == '1':
                count += f[k][2*j]*1 + f[k][2*j + 1]*0
            elif lis[j] == '2':
                count += f[k][2*j]*0 + f[k][2*j + 1]*1
            elif lis[j] == '3':
                count += f[k][2*j]*1 + f[k][2*j + 1]*1
        temp += p[k][count]
    ans.append(temp)
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 = -10 ** 10

def calc(b):
    p = 0
    for i in range(N):
        c = 0
        for j in range(10):
            c += F[i][j] * b[j]
        p += P[i][c]
    return p

def dfs(b):
    global ans
    if len(b) == 10:
        if max(b) == 0:
            return
        ans = max(ans, calc(b))
        return
    dfs(b + [0])
    dfs(b + [1])

dfs([0])
dfs([1])
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 = -10 ** 10
for b in range(1, 2 ** 10):
    bin_str = format(b, '010b')
    p = 0
    for i in range(N):
        c = 0
        for j in range(10):
            c += F[i][j] * int(bin_str[j])
        p += P[i][c]
    ans = max(ans, p)
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)] 

INF=10**9
ans=-INF

for i in range(1,2**10):
    tmpans=0
    for n in range(N):
        c=0
        for j in range(10):
            if (i>>j&1)&F[n][j]:
                c+=1
        tmpans+=P[n][c]

    ans=max(ans,tmpans)

print(ans)

Solution (Python):
def solve(string):
    n, *fp = map(int, string.split())
    f = "".join(map(str, fp[:10 * n]))
    p = fp[10 * n:]
    int_f = [int(f[10 * i:10 * (i + 1)], 2) for i in range(n)]
    return str(
        max(
            sum([p[11 * i + bin(o & _f).count("1")]
                 for i, _f in enumerate(int_f)])
            for o in range(1, 2**10)))


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(2 * n)])))

Solution (Python):
def solve(string):
    n, *fp = string.split()
    n = int(n)
    f = fp[:10 * n]
    p = list(map(int, fp[10 * n:]))
    int_f = [int("".join(f[10 * i:10 * (i + 1)]), 2) for i in range(n)]
    return str(
        max(
            sum([p[11 * i + bin(o & _f).count("1")]
                 for i, _f in enumerate(int_f)])
            for o in range(1, 2**10)))


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(2 * n)])))

Solution (Python):
def solve(string):
    n, *fp = string.split()
    n = int(n)
    f = fp[:10 * n]
    p = list(map(int, fp[10 * n:]))
    ans = -n * 10**7
    int_f = [int("".join(f[10 * i:10 * (i + 1)]), 2) for i in range(n)]
    for o in range(1, 2**10):
        tmp = [sum(map(int, "{:b}".format(o & _f))) for _f in int_f]
        ans = max(ans, sum([p[11 * i + t] for i, t in enumerate(tmp)]))
    return str(ans)


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(2 * n)])))

Solution (Python):
from itertools import product
import numpy as np


def solve(string):
    n, *fp = map(int, string.split())
    
    f = fp[:10 * n]
    p = fp[10 * n:]
    ans = -n * 10**7
    """
    for o in product([0, 1], repeat=10):
        if sum(o) == 0:
            continue
        
        tmp = [sum([for ]) for _f in f]
        ans = max(ans, sum([p[11 * i + t] for i, t in enumerate(tmp)]))
    return str(ans)
    """
    int_f = [int("".join(map(str, f[10 * i:10 * (i + 1)])), 2) for i in range(n)]
    for o in range(1, 2**10):
        tmp = [sum(map(int, "{:b}".format(o & _f))) for _f in int_f]
        ans = max(ans, sum([p[11 * i + t] for i, t in enumerate(tmp)]))
    return str(ans)


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(2 * n)])))

Solution (Python):
from itertools import product
import numpy as np


def solve(string):
    n, *fp = map(int, string.split())
    f = np.asarray(fp[:10 * n]).reshape((n, 10))
    p = fp[10 * n:]
    ans = -n * 10**7
    for o in product([0, 1], repeat=10):
        if sum(o) == 0:
            continue
        tmp = np.dot(f, np.asanyarray(o).T)
        ans = max(ans, sum([p[11 * i + t] for i, t in enumerate(tmp)]))
    return str(ans)


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(2 * n)])))

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

f = []

for i in range(n):
    f.append(list(map(int,input().split())))
c = []
for i in range(n):
    c.append(list(map(int,input().split())))
res = -10**19
for i in range(1,1024):
    s = format(i,'
    money = 0
    for k in range(n):
        acc = 0
        for j in range(10):
            acc += f[k][j] and int(s[j])
        
        money += c[k][acc]
    
    res = max(res,money)
print(res)

Solution (Python):
import itertools
import math
from collections import deque
from collections import defaultdict
from itertools import permutations
import heapq
import bisect
INF = float("inf")

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 = -INF
for i in range(1,1024):
    profit = 0
    for j in range(n):
        cnt = 0
        for x in range(10):
            if (i >> x) %2 == 1 and F[j][x] == 1:
                cnt += 1
        profit += P[j][cnt]
    ans = max(ans,profit)
print(ans)

Solution (Python):

n = int(input())
arr = [list(map(int, input().split())) for i in range(n)]
arm = [list(map(int, input().split())) for j in range(n)]  

ans = -9999999999  
for item in range(1, 1024):  
    fund = 0
    for i in range(n):  
        cou = 0  
        for x in range(10):  
            if (item >> x) % 2 == 1 and arr[i][x] == 1:  
                cou += 1
        fund += arm[i][cou]
    ans = max(ans, fund)  

print(ans)

Solution (Python):
n=int(input())
shop=[]
profit=[]
for i in range(n):
  k=list(map(int,input().split()))
  shop.append(k)
for i in range(n):
  k=list(map(int,input().split()))
  profit.append(k)
def dfs(i,flag):
  if i!=10:
    return max(dfs(i+1,flag),dfs(i+1,flag|2**i))
  if flag==0:
    return -10**18
  prof=0
  store=[0]*n
  for j in range(10):
    if (flag)&(2**j)>0:
      for k in range(n):
        store[k]+=shop[k][j]
  for k in range(n):
    prof+=profit[k][store[k]]
  return prof
print(dfs(0,0))

Solution (Python):
N = int(input())
F = [list(map(int, input().split())) for i in range(N)]
P = [list(map(int, input().split())) for j in range(N)]
m = -float("INF")
for i in range(1, 1024):
    n = 0
    for j in range(N):
        c = 0
        for k in range(10):
            if i >> k & 1:
                if F[j][k] == 1:
                    c += 1
        n += P[j][c]
    m = max(m, n)
print(m)

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

m = -float("INF")
for i in range(1,1024):
    n = 0
    for j in range(N):
        c = 0
        for k in range(10):
            if i >> k & 1:
                if F[j][k] == 1:
                    c += 1
        n += P[j][c]
    m = max(m, n)
print(m)

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


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


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

'''考え方
各開店パターン毎に「その時の利益」を計算する
'''

from itertools import product

list_01 = [0,1]
array_prd = list(product(list_01,repeat=10))
max_prof = - 10 ** 18

for i in range(1024):
  if array_prd[i] == (0,0,0,0,0,0,0,0,0,0):
    continue
    
  tmp = 0
  
  for j in range(N):
    cnt_open = sum([ary * int(open_or_close) for ary,open_or_close in zip(array_prd[i],list_f[j])])
    tmp += list_p[j][cnt_open]
  
  if tmp > max_prof:
    max_prof = tmp

print(max_prof)

Solution (Python):
from itertools import product

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 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):
        now = sum([ptn[x] * F[i][x] for x in range(10)])
        tmp += P[i][now]
    ans = max(tmp, ans)

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)]
def dfs(cur):
    if len(cur)==10:
        ans = 0
        if sum(cur)==0:
            return -(10**9)
        for i in range(n):
            match=0
            for j in range(10):
                if cur[j]==f[i][j]==1:
                    match+=1
            ans+=p[i][match]
        return ans
    ret1 = dfs(cur+[0])
    ret2 = dfs(cur+[1])
    return max(ret1,ret2)
print(dfs([]))

Solution (Python):
import itertools
n = int(input())
p,f = [],[]

for i in range(n):
    f.append(list(map(int,input().split())))
for i in range(n):
    p.append(list(map(int,input().split())))

a = [0,1]
ans = -10**15
for v in itertools.product(a,repeat = 10):
    if sum(v) != 0:
        s = []
        for a in range(n):
            k = 0
            for b in range(10):
                if f[a][b] == v[b] and v[b] == 1:
                    k += 1
            s.append(k)

        x = 0
        for a in range(n):
            x += p[a][s[a]]
        if x > ans:
            
            ans = x

print(ans)

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

openptn=np.array([[int(s) for s in list('{0:010b}'.format(i))] for i in range(1,2**10)])


dualopenfreq=np.array([np.sum(ptn*F, axis=1) for ptn in openptn])


profit=np.array([np.sum(np.array([P[i][freq[i]] for i in range(N)]))  for freq in dualopenfreq])

print(np.max(profit))

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 = []
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.append(res)
print(max(ans))

Solution (Python):
import sys
input=sys.stdin.readline
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**9
for i in range(1,2**10):
  tmp=0
  for j in range(n):
    f,p=F[j],P[j]
    cnt=0
    for k in range(10):
      if (i>>k)&1 and f[k]:
        cnt+= 1
    tmp+=p[cnt]
  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=-10**9
for i in range(1,2**10):
  tmp=0
  for j in range(n):
    cnt=0
    f=F[j]
    p=P[j]
    for k in range(10):
      if (i>>k)&1:
        cnt+= 1 if f[k] else 0
    tmp+=p[cnt]
  ans=max(ans,tmp)
print(ans)

Solution (Python):
N = int(input())
F = [''.join(list(map(str, input().split()))) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]
ans = [0]*((1<<10)-1)
for i in range(1, 1<<10):
    count = 0
    for j in range(N):
        count += P[j][format(int(F[j], 2)&i, 'b').count('1')]
    ans[i-1] = count
print(max(ans))

Solution (Python):
N = int(input())
L = []
for i in range(N):
  L.append(list(map(int,input().split())))
P = []
for i in range(N):
  P.append(list(map(int,input().split())))
def Base_10_to_n(X,n):
  if (int(X/n)):
    return Base_10_to_n(int(X/n),n)+str(X%n)
  return str(X%n)
n = 2
ans = -(10**10)
for X in range(1,n**10+1):
  STR = Base_10_to_n(X,n).zfill(10)
  cur = 0
  for i in range(N):
    cnt = 0
    for j in range(10):
      if int(STR[j]) == L[i][j] == 1:
        cnt += 1
    cur += P[i][cnt]
  if ans <= cur:
    ans = cur
print(ans)

Solution (Python):
def main():
    n = int(input())
    f = []
    for _ in range(n):
        x = [int(s) for s in input().split()]
        p = 0
        for y in x:
            p <<= 1
            p |= y
        f.append(p)
    p = [[int(s) for s in input().split()] for _ in range(n)]
    print(solve(n, f, p))

def solve(n, f, p):
    m = float('-inf') 
    for i in range(1, 1024):
        q = 0
        for j in range(n):
            c = ones(f[j] & i)
            q += p[j][c]
        m = max(m, q)
    return m

def ones(n):
    m = 0
    while n != 0:
        if n & 0x01 != 0:
            m += 1
        n >>= 1
    return m

main()

Solution (Python):
MAX_TIME = 10

N = int(input())




F = [sum(v << MAX_TIME - k - 1 for k, v
         in enumerate(map(int, input().split())))
     for i in range(N)]



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


def main():
    
    pattern = [sum(i >> j & 1 for j in range(MAX_TIME))
               for i in range(2 ** MAX_TIME)]

    
    
    print(max(sum(
        P[j][pattern[F[j] & i]] for j in range(N))
        for i in range(1, 2 ** MAX_TIME)))

    return


main()

Solution (Python):
MAX_TIME = 10

N = int(input())

F = [int(input().replace(" ", ""), 2) for i in range(N)]

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


def main():
    
    
    

    
    
    

    
    
    print(max(sum(
        [p[bin(f & i).count("1")] for f, p in zip(F, P)])
        for i in range(1, 2 ** MAX_TIME)))

    return


main()

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



'''
n=int(input())
for i in range(n):
    a[i]=int(input())
    a[i],b[i]=map(int,input().split())
a=[int(x) for x in input().split()]
n,m=map(int,input.split())
from operator import itemgetter
a = [(1, "c", 1), (1, "b", 3), (2, "a", 0), (1, "a", 2)]
print(sorted(a))  
print(sorted(a, key=itemgetter(0)))  
print(sorted(a, key=itemgetter(0, 2)))  
print(sorted(a, key=lambda x: x[0] * x[2]))  
print(sorted(a, reverse=True))  
a.sort()  
try: 
    for i in range():
        k=b[i]
except IndexError as e:
    print(i)
'''

test_data1 = '''\
1
1 1 0 1 0 0 0 1 0 1
3 4 5 6 7 8 9 -2 -3 4 -2
'''

test_data2 = '''\
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
'''

test_data3 = '''\

'''
td_num=1

def GetTestData(index):
    if index==1:
        return test_data1
    if index==2:
        return test_data2
    if index==3:
        return test_data3

if False:
    with open("../test.txt", mode='w') as f:
        f.write(GetTestData(td_num))
    with open("../test.txt") as f:
        
        n=int(f.readline())
        g=[[] for x in range(n)]
        p=[[] for x in range(n)]
        for i in range(n):
            g[i]=[int(x) for x in f.readline().split()]
        for i in range(n):
            p[i]=[int(x) for x in f.readline().split()]
        
else:
    for i in range(1):
        
        n=int(input())
        g=[[] for x in range(n)]
        p=[[] for x in range(n)]
        for i in range(n):
            g[i]=[int(x) for x in input().split()]
        for i in range(n):
            p[i]=[int(x) for x in input().split()]
        

o=[0]*10
ans=-10**17
try: 

    for i in range(1,2**10):
        e=0
        for shop in range(n):
            cnt=0
            for t in range(10):
                o[t]=(i%(2**(t+1))) // (2**t)
                cnt+=g[shop][t]*o[t]
            e+=p[shop][cnt]
        ans=max(ans,e)
        
    print(ans)
except IndexError as e:
    print(i,shop,cnt)