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 0 1 0 0 0 1 0 1
3 4 5 6 7 8 9 -2 -3 4 -2

-----Sample Output-----
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.

Difficulty: introductory

Starter code:

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

total = -10**9
for i in range(1,2**10):
    pgain = 0
    for f,p in zip(F,P):
        pgain += p[bin(f&i).count("1")]
    if total < pgain:
        total = pgain
        k = i
print(total)

n = int(input())
f = []
ans = -10**9

for i in range(n):
    a = input().split()
    f.append(a)

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

for i in range(1, 2**10):
    ref = 0
    i = str(bin(i))[2:].zfill(10)
    for j in range(n):
        cnt = 0
        for k in range(10):
            if i[k] == f[j][k] == "1":
                cnt += 1
        ref += p[j][cnt]
    else:
        ans = max(ans, ref)

print(ans)

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

import numpy as np
import heapq as hq
N = int(input())
F = np.array([[int(x) for x in input().split()] for _ in range(N)])
P = np.array([[int(x) for x in input().split()] for _ in range(N)])

Profit = []
for i in range(1,2**10): #bit全探索
    Open = np.array([int(x) for x in format(i, '010b')]) #2進数をベクトルに変換
    prf = 0
    for f, p in zip(F, P):
        cnt = np.dot(Open, f)
        prf += p[cnt]
    hq.heappush(Profit, -prf)
print((-Profit[0]))


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

ans = -10**10

for a in range(2**10):
    t = [(a>>b)&1 for b in range(10)]
    if 1 not in t:
        continue
    
    p = 0
    for i in range(N):
        p += P[i][sum(t[j] and F[i][j] for j in range(10))]

    ans = max(p, ans)

print(ans)

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, 2**10):
    tf = [False]*10
    for j in range(10):
        if (i>>j)&1:
            tf[j] = True
    cnt1 = 0
    for j in range(n):
        cnt2 = 0
        for k in range(10):
            if tf[k] and f[j][k]:
                cnt2 += 1
        cnt1 += p[j][cnt2]
    ans = max(ans, cnt1)
print(ans)

import sys
mod=10**9+7 ; inf=float("inf")
from math import sqrt, ceil
from collections import deque, Counter, defaultdict #すべてのkeyが用意されてる defaultdict(int)で初期化
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from decimal import ROUND_HALF_UP,Decimal  #変換後の末尾桁を0や0.01で指定
  #Decimal((str(0.5)).quantize(Decimal('0'), rounding=ROUND_HALF_UP))
from functools import lru_cache
from bisect import bisect_left as bileft, bisect_right as biright
#メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10)
#引数にlistはだめ
#######ここまでテンプレ#######
#ソート、"a"+"b"、再帰ならPython3の方がいい
#######ここから天ぷら########

n=int(input());ans=-inf
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())))

for bit in range(1,1<<10):
    L=[(bit>>i)&1 for i in range(10)]
    now=0
    for i in range(n):
        cnt=0
        for cc in range(10):
            if (F[i][cc]==1 and L[cc]==1) : cnt+=1
        now+=P[i][cnt]
    ans=max(ans,now)
print(ans)


from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
f = []
for i in range(n):
    f.append(LIST())
p = []
for i in range(n):
    p.append(LIST())

ans = -inf
for x in product([0, 1], repeat=10):
    if sum(x) != 0:
        tmp = 0
        for j in range(n):
            count = 0
            for k in range(10):
                count += f[j][k]*x[k]
            tmp += p[j][count]
        ans = max(ans, tmp)
print(ans)

def dfs(s,N):
    if len(s)==10:
        if "1" in s:
            cal(s,N)
        return
    dfs(s+"0",N)
    dfs(s+"1",N)

def cal(s,N):
    p = 0
    for i in range(N):
        c=0
        for j in range(10):
            c+=F[i][j]*int(s[j])
        p+=P[i][c]
    profit.append(p)
    return

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

dfs("",N)
print(max(profit))

n = int(input())

L,score = [],[]
for i in range(n):
    L.append(list(map(int,input().split())))
    
for i in range(n):
    score.append(list(map(int,input().split())))

ans = -10**32
 
for k in range(1,1<<10):
    sc = 0
    
    for i in range(n):
        cnt = 0
        for j in range(10):
            if L[i][j] and k>>j&1:
                cnt +=1
        #print(L[i],v,cnt,i,score,score[i][cnt])
        sc += score[i][cnt]
            #print(L[i],v,cnt,i,score,score[i][cnt])
    ans = max(ans,sc)

print(ans)

#coding: utf-8
from collections import deque

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

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

ret = None
for bit in range(1, 2**10):
    nWork = [0] * N
    for i in range(10):
        if (bit >> i) & 1:
            for shop in range(N):
                if F[shop][i] == 1:
                    nWork[shop] += 1

    cand = 0
    for i in range(N):
        cand += P[i][nWork[i]]
    if ret == None or cand > ret:
        ret = cand
print(ret)



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

ans=-10**9
for i in range(2**10-1):
    Bit=[1]*10
    for j in range(10):
        if (i>>j)&1:
            Bit[j]=0
    count=0
    for k in range(N):
        op=sum(b&f for b,f in zip(Bit,F[k]))
        count+=P[k][op]
    ans=max(ans,count)
print(ans)

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

from itertools import product
bits_l=list(product([0,1], repeat=10))
bits_l.remove((0,0,0,0,0,0,0,0,0,0))

ans=-float("inf")
for bits in bits_l:
    tmp_ans=0
    for shop in range(n):
        tmp_cnt=0
        for i, bit in enumerate(bits):
            if bit==1 and f[shop][i]==1:
                tmp_cnt+=1
        tmp_ans+=p[shop][tmp_cnt]
    ans=max(ans, tmp_ans)

print(ans)

n = int(input())
F = [int("".join(input().split()), 2) for _ in range(n)]
P = [list(map(int, input().split())) for _ in range(n)]
num = 1 << 10
ans = -(10 ** 10)


def popcnt(n):
    c = (n & 0x5555555555555555) + ((n >> 1) & 0x5555555555555555)
    c = (c & 0x3333333333333333) + ((c >> 2) & 0x3333333333333333)
    c = (c & 0x0F0F0F0F0F0F0F0F) + ((c >> 4) & 0x0F0F0F0F0F0F0F0F)
    c = (c & 0x00FF00FF00FF00FF) + ((c >> 8) & 0x00FF00FF00FF00FF)
    c = (c & 0x0000FFFF0000FFFF) + ((c >> 16) & 0x0000FFFF0000FFFF)
    c = (c & 0x00000000FFFFFFFF) + ((c >> 32) & 0x00000000FFFFFFFF)
    return c


# print(F)

for i in range(1, num):
    temp = 0
    for j in range(n):
        temp += P[j][popcnt(i & F[j])]
    ans = max(temp, ans)
print(ans)


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

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

ans=-float('inf')
for i in range(1,2**10):
    now=0
    for s in range(n):
        cnt=0
        for j in range(10):
            if ((i>>j) & 1) and f[s][j]==1:
                cnt+=1
        now+=p[s][cnt]
    ans=max(ans,now)
print(ans)

n = int(input())
f = [list(map(int, input().split())) for i in range(n)]
p = [list(map(int, input().split())) for i in range(n)]
ans = -(1 << 30)
for bit in range(1, 1 << 10):
    cnt = 0
    for i in range(n):
        cnt2 = 0
        for j in range(10):
            if (bit >> j & 1) and f[i][j]:
                cnt2 += 1
        cnt += p[i][cnt2]
    if ans < cnt:
        ans = cnt
print(ans)

N = int(input())
F = [list(map(int, input().split())) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]
ans = -9999999999
for i in range(1, 2 ** 10):
    s = 0
    for j in range(N):
        cnt = 0
        for k in range(10):
            if i >> k & 1 and F[j][k] == 1:
                cnt += 1
        s += P[j][cnt]
    ans = max(ans, s)
print(ans)

import sys, math
from functools import lru_cache
from collections import defaultdict
from decimal import Decimal
sys.setrecursionlimit(10**9)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return list(map(int, input().split()))

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    N = ii()
    F = [list(mi()) for i in range(N)]
    P = [list(mi()) for i in range(N)]

    m = -math.inf

    for ptn in range(1, 2**10):
        r = 0
        for i in range(N):
            cnt = 0
            for j in range(10):
                if F[i][j] and (ptn>>j)&1:
                    cnt += 1
            r += P[i][cnt]
        m = max(m, r)

    print(m)


def __starting_point():
    main()

__starting_point()

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(2**10-1):
  Bit = [1]*10
  for j in range(10):
    if (i>>j)&1:
      Bit[j]=0
  count = 0
  for k in range(N):
    op = sum(b&f for b,f in zip(Bit,F[k]))
    count+=P[k][op]
  ans = max(ans,count)
print(ans)

import itertools
N = int(input())
F =[ list(input().split()) for i in range(N)]
P =[ list(input().split()) for i in range(N)]
set01 = list(itertools.product('01',repeat = 10))
counter = []
ans = -10**9
for s01 in set01:
    if s01 != ("0","0","0","0","0","0","0","0","0","0"):
        prof = 0
        for i in range(N):
            counter = 0
            for j in range(10):
                if s01[j] =="1" and F[i][j] == "1":
                    counter += 1
            prof += int(P[i][counter])
        ans = max(ans,prof)
print(ans)

def solve():
    import numpy as np
    n = int(input())
    oc = [[] for _ in range(n)]
    prof = [[] for _ in range(n)]

    for i in range(n):
        oc[i] = list(map(int, input().split()))
    for i in range(n):
        prof[i] = list(map(int, input().split()))

    oc = np.array(oc)
    prof = np.array(prof)

    ans = -9999999999

    for a in range(1, 1 << 10):
        res = np.zeros(n, dtype=np.int64)
        for b in range(10):
            if a >> b & 1:
                res += oc[:, b]
        #print(res)
        tmp = 0
        for i, x in enumerate(res):
            tmp += prof[i, x]
        #print(tmp)
        ans = max(ans, tmp)
    print(ans)


solve()


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)

import numpy as np
N = int(input())
schedules = [list(map(int, input().split())) for _ in range(N)]
prices = [list(map(int, input().split())) for _ in range(N)]
# print(schedules)
# print(prices)
ans = -1 * float('inf')
for i in range(1, 1 << 10):
    my_schedule = list(map(int, bin(i)[2:].zfill(10)))
    score = 0
    for j, schedule in enumerate(schedules):
        count = 0
        for k in range(10):
            if my_schedule[k] == schedule[k] and schedule[k] == 1:
                count += 1
        score += prices[j][count]
    ans = max(ans, score)
print(ans)


def solve():
    import numpy as np
    n = int(input())
    oc = [list(map(int, input().split())) for _ in range(n)]
    prof = [list(map(int, input().split())) for _ in range(n)]

    oc = np.array(oc)
    prof = np.array(prof)

    inf = 10 ** 10
    ans = - inf

    for a in range(1, 1 << 10):
        res = np.zeros(n, dtype=np.int64)
        for b in range(10):
            if a >> b & 1:
                res += oc[:, b]
        tmp = 0
        for i, x in enumerate(res):
            tmp += prof[i, x]
        ans = max(ans, tmp)
    print(ans)


solve()



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 ** 18
for i in range(1, 2 ** 10):
    tmp = [0] * N
    for j in range(10):
        if i >> j & 1:
            for k in range(N):
                tmp[k] += F[k][j]
    res_tmp = 0
    for j in range(N):
        res_tmp += P[j][tmp[j]]
    res = max(res, res_tmp)

print(res)


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 = -10**18
for ci in range(1, 2**10):
    score = 0
    for cn in range(n):
        cnt = 0
        for cj in range(10):
            x = ci >> cj & 1
            if x and f[cn][cj]:
                cnt += 1
        score += p[cn][cnt]
    ans = max(ans, score)
print(ans)


import sys
from itertools import product

input = sys.stdin.readline


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

    ans = -float("inf")
    for comb in product(list(range(2)), repeat=10):
        if sum(comb) == 0:
            continue
        c = [0] * N
        for j, is_open in enumerate(comb):
            if is_open:
                for i in range(N):
                    c[i] += F[i][j]
        profit = sum(P[i][c[i]] for i in range(N))
        ans = max(ans, profit)

    print(ans)


def __starting_point():
    main()

__starting_point()

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

# bit全探索
inf = float("inf")
ans = -inf
for i in range(1, 2**10):
    op = []
    for j in range(10):
        if (i >> j) & 1:
            op.append(1)
        else:
            op.append(0)

    res = 0
    for k in range(N):
        temp = 0
        for l in range(10):
            if op[l] == 1 and F[k][l] == 1:
                temp += 1
        res += P[k][temp]
    ans = max(ans, res)

print(ans)

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

#!/usr/bin/env python
# coding: utf-8

# In[2]:


import itertools


# In[47]:


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


# In[48]:


ans = sum([min(a) for a in P])
for b in range(1,1024):
    b = list(map(int, format(b,"010b")))
    tmp = 0
    for i in range(N):
        cnt = 0
        for j,x in enumerate(b):
            cnt += F[i][j]*x
        tmp += P[i][cnt]
    ans = max(ans, tmp)
print(ans)


# In[ ]:






from itertools import product
n=int(input())
fs=[list(map(int,input().split())) for _ in range(n)]
ps=[list(map(int,input().split())) for _ in range(n)]
ans=-float('inf')
for b in product((0,1),repeat=10):
    if sum(b)==0:
        continue
    v=0
    for f,p in zip(fs,ps):
        cnt=sum([a&b for a,b in zip(b,f)])
        v+=p[cnt]
    ans=max(ans,v)
print(ans)


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,2**10):#joisinoお姉ちゃんが営業するしないの組み合わせ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:#joisino姉の開店と店iの開店が一致
        cou += 1
    fund += arm[i][cou]
  ans = max(ans, fund)

print(ans)

N=int(input())
F=[list(map(int,input().split())) for _ in range(N)]
P=[list(map(int,input().split())) for _ in range(N)]
ans=-1000000000
for i in range(1,1<<10):
    cnt=[0 for _ in range(N)]
    for j in range(10):
        if (i>>j)%2==1:
            for k in range(N):
                cnt[k]+=F[k][j]
    A=[P[j][cnt[j]] for j in range(N)]
    ans=max(ans,sum(A))
print(ans)


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

schejule_list = set(product([0, 1], repeat=10))
ans = - float("inf")
for schedule in schejule_list:
    if schedule == (0, 0, 0, 0, 0, 0, 0, 0, 0, 0):
        continue
    res = 0
    for i in range(n):
        kaburi = 0
        for j in range(10):
            kaburi += f[i][j] * schedule[j]
        res += p[i][kaburi]
    ans = max(ans, res)
print(ans)




n = int(input())
l = []
m = []
ans = -10**9

for i in range(n):
    f = "".join(input().split())
    f = int(f, 2)
    l.append(f)

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

for i in range(1, 2**10):
    ref = 0
    for j in range(n):
        cnt = bin(i & l[j]).count("1")
        ref += m[j][cnt]
    else:
        ans = max(ans, ref)

print(ans)

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)])
ans = -10**18
for i in range(2**10):
    box = []
    for k in range(10):
        if ((i>>k)&1):
            box = [1]+ box
        else:
            box = [0]+ box
    if all(i == 0 for i in box):
        continue
    # box は開業する0~9の候補リスト
    # G は F(0か1の各店開業状況)
    G = np.sum(F*box, axis=1)
    a = 0
    for x,y in zip(G,P):
        a += y[x]
    ans = max(ans, a)
    
print(ans)

import sys
from itertools import product

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


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

    res = -f_inf
    for pattern in product([0, 1], repeat=10):
        if sum(pattern) == 0:
            continue
        tmp = 0
        for i in range(n):
            cnt = 0
            for p, f in zip(pattern, F[i]):
                if p == 1 and f == 1:
                    cnt += 1
            tmp += P[i][cnt]
        res = max(res, tmp)
    print(res)


def __starting_point():
    resolve()

__starting_point()

def pad_zero(s, n):
	s = str(s)
	return ("0" * n + s)[-n:]

def main():
	N = int(input())
	F = [[int(f) for f in input().split(" ")] for i in range(N)]
	P = [[int(p) for p in input().split(" ")] for i in range(N)]

	total_profit = []
	for b in range(1, 2 ** 10):
		sale_bit = list(pad_zero(format(b, 'b'), 10))
		profit = 0
		for i in range(len(F)):
			f = F[i]
			p = P[i]
			profit += p[sum([fjk * int(s) for (fjk, s) in zip(f, sale_bit)])]
		total_profit.append(profit)
	print(max(total_profit))


main()

import itertools
N=int(input())
F=[list(map(int,input().split())) for _ in range(N)]
P=[list(map(int,input().split())) for _ in range(N)]
ans=-10**9
for i in list(itertools.product(range(2),repeat=10)):
  if sum(i)==0:
    continue
  bns=0
  for j in range(N):
    b=0
    for k in range(10):
      if i[k]*F[j][k]==1:
        b+=1
    bns+=P[j][b]
  ans=max(ans,bns)
print(ans)

from itertools import product
def main():
    N = int(input())
    F = []
    for _ in range(N):
        f = list(map(int, input().split()))
        F.append(f)
    P = []
    for _ in range(N):
        p = list(map(int, input().split()))
        P.append(p)
    m = -10**21
    for i in product(list(range(2)), repeat=10):
        if sum(i) == 0:
            continue
        r = 0
        for j in range(N):
            r += P[j][sum(ii&jj for ii, jj in zip(i, F[j]))]
        m = max(r, m)
    return m
print((main()))


n = int(input())
fl = [list(map(int, input().split())) for _ in range(n)]
pl = [list(map(int, input().split())) for _ in range(n)]

ans = -1001001001
for i in range(1, 2**10):
    profit = 0
    cnt = [0]*n
    for j in range(10):
        if (i >> j) & 1 == 1:
            for k in range(n):
                if fl[k][j] == 1:
                    cnt[k] += 1
    for k in range(n):
        profit += pl[k][cnt[k]]
    ans = max(ans, profit)

print(ans)


#coding: utf-8
from itertools import product

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

ret = -10 ** 18

# skip (0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
itr = product([0, 1], repeat=10)
itr.__next__()
for bit in itr:
    cand = sum((P[i][sum((f*b for f, b in zip(F[i], bit)))] for i in range(N)))
    ret = max(ret, cand)

print(ret)


from itertools import combinations

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

ans = - 10 ** 18
for i in range(1, 11):
    for pat in combinations(list(range(10)), i):
        cnt = [0] * n
        for e in pat:
            for j in range(n):
                cnt[j] += f[j][e]

        score = 0
        for i, e in enumerate(cnt):
            score += p[i][e]

        ans = max(ans, score)

print(ans)


import sys

input = sys.stdin.readline

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

    # A: choosen list
    A = list(range(10))
    n = len(A)
    ans = -float('inf')
    for i in range(2 ** n):
        select = []
        score = 0
        for j in range(n):
            if (i >> j) & 1:
                select.append(A[j])
        if len(select) == 0:
            continue
        
        for j in range(N):
            cnt = 0
            for k in select:
                if F[j][k] == 1:
                    cnt += 1
            score += P[j][cnt]
        
        ans = max(ans, score)
    print(ans)

def __starting_point():
    main()

__starting_point()

import sys
from heapq import heappush, heappop
def input(): return sys.stdin.readline().rstrip()
def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return list(mi())


def main():
    n = ii()
    F = []
    P = []
    for _ in range(n):
        F.append(li())
    for _ in range(n):
        P.append(li())
    
    inf = 10 ** 18
    ans = -inf
    for i in range(1, 1<<10):
        c = [0]*(n)
        tmp = 0
        for j in range(10):
            if (i>>j)&1:
                for k in range(n):
                    c[k] += F[k][j]
        for k in range(n):
            tmp += P[k][c[k]]
        ans = max(ans, tmp)
    print(ans)
            
            
        
    




def __starting_point():
    main()
__starting_point()

#!/usr/bin/env python3
import numpy as np
from itertools import product
import sys
sys.setrecursionlimit(10**6)

n = int(input())

data = np.zeros((10, n), dtype=int)
for i in range(n):
    f = np.array(list(map(int, input().split())))
    data[:, i] = f

# print(data)

p = [list(map(int, input().split())) for i in range(n)]
# print(p)

ans = -10**10

for j, i in enumerate(product([0, 1], repeat=10)):
    if j == 0:
        continue

    indices = [x for x, y in enumerate(i) if y == 1]
    # print(indices)

    data_tmp = data[indices]
    data_tmp = np.sum(data_tmp, axis=0)
    ans_tmp = sum([p[a][b] for a, b in enumerate(data_tmp)])
    ans = max(ans, ans_tmp)
print(ans)


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

MAX=-10**12
for p in product(range(2),repeat=10):
  if p==(0,)*10:continue
  SUM=0
  for i in range(N):
    count=0
    for j in range(10):
      if p[j]==1 and F[i][j]==1:
        count+=1
    SUM += P[i][count]
  MAX = max(MAX,SUM)
print(MAX)

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

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

ans = -float("inf")

for j in range(1, 1024):
    ss = 0
    for i in range(N):
        b = format(j, "010b")
        bb = [0] * 10
        for k in range(10):
            bb[k] = F[i][k] * int(b[k])
        ss += P[i][sum(bb)]
    ans = max(ans, ss)

print(ans)

def solve():
    n = int(input())
    oc = [list(map(int, input().split())) for _ in range(n)]
    prof = [list(map(int, input().split())) for _ in range(n)]

    ans = -9999999999

    for a in range(1, 1 << 10):
        res = 0
        for i in range(n):
            cnt = 0
            for x in range(10):
                if (a >> x) % 2 == 1 and oc[i][x] == 1:
                    cnt += 1
            res += prof[i][cnt]
        ans = max(ans, res)
    print(ans)


solve()


import numpy as np
 
N = int(input())
F = np.array([list(map(int, input().split(' '))) for _ in range(N)])
P = np.array([list(map(int, input().split(' '))) for _ in range(N)])
 
ans = - (10 ** 11)
 
for n in range(1, 1024):
    bits = np.array(list(map(int, list('{:010b}'.format(n)))))
    dup = np.sum(F * bits, axis=1)
    ans = max(ans, np.sum(P[range(N), dup]))

print(ans)

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

li = []

for i in range(2**10):
    if i == 0:
        continue
    ans = 0
    co = [0]*n
    for j in range(10):
        if (i>>j &1)==1:
            for k in range(n):
                if f[k][j]==1:
                    co[k] +=1
    #print(i,bin(i),co)
    for l in range(n):
        ans += p[l][co[l]]
    li += [ans]
print(max(li))

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

for b in range(1,1<<10):
  cc = 0
  for i in range(N):
    c = 0
    for j in range(10):
      if (b>>j&1) & F[i][j]:
        c+=1
    cc += P[i][c]
  if res<cc:
    res = cc
    
print(res)


import numpy as np
import heapq as hq
N = int(input())
F = np.array([[int(x) for x in input().split()] for _ in range(N)])
P = np.array([[int(x) for x in input().split()] for _ in range(N)])

Profit = []
for i in range(1,2**10):
    Open = np.array([int(x) for x in format(i, '010b')])
    prf = 0
    for f, p in zip(F, P):
        cnt = np.dot(Open, f)
        prf += p[cnt]
    hq.heappush(Profit, -prf)
print((-Profit[0]))


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

schejule_list = list(product([0, 1], repeat=10))
ans = - float("inf")
for schedule in schejule_list:
    if schedule == (0,0,0,0,0,0,0,0,0,0):
        continue
    res = 0
    for i in range(n):
        kaburi = 0
        for j in range(10):
            kaburi += f[i][j] * schedule[j]
        res += p[i][kaburi]
    ans = max(ans, res)
print(ans)




import numpy as np

def main():
    with open(0) as f:
        N = int(f.readline())
        F = np.array([list(map(int, f.readline().split())) for _ in range(N)])
        P = [list(map(int, f.readline().split())) for _ in range(N)]

    max_profit = -np.inf
    for i in range(1,2**10):
        Open = np.array([(i>>j)&1 for j in range(10)])
        conflict = np.dot(F, Open.T)
        profit = sum(P[i][v] for i,v in enumerate(conflict))
        max_profit = max(max_profit, profit)
    print(max_profit)

main()

N = int(input())
F = []
for i in range(N):
    A = list(map(int, input().split()))
    F.append(A[::-1])

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

result = float("inf")*(-1)
for i in range(1, 2**10):
    ans = 0
    for l in range(N):
        c = 0
        for j in range(10):
            if ((i>>j) & 1):
                if F[l][j] == 1:
                    c += 1
        ans += P[l][c]
    result = max(ans, result)
print(result)


n = int(input())
data1 = [list(map(int,input().split())) for _ in range(n)]
data2 = [list(map(int,input().split())) for _ in range(n)]
ans = []
trans = -1
for i in range(2**10):
    S = [0]*n
    l = 0
    for j in range(10):
        for k in range(n):
            S[k] += data1[k][j]*((i>>j)&1)
    for j in range(n):
        l += data2[j][S[j]]
    ans.append(l)
    if not i:
        trans = l
ans.sort()
print(ans[-1] if ans[-1] != trans else ans[-2])

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

# ビット全探索
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)]

result = -float('inf')
for i in product([True, False], repeat=10):
    if i.count(False) == 10:
        continue
    t = 0
    for j in range(N):
        t += P[j][sum(1 & F[j][k] for k in range(10) if i[k])]
    result = max(result, t)
print(result)


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

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 i in range(1,1024):
    bit=bin(i)[2:].zfill(10)
    a=0
    for j in range(n):
        b=0
        for k in range(10):
            if int(bit[k]) and f[j][k]:
                b+=1
        a+=p[j][b]
    ans=max(ans,a)
print(ans)

n=int(input())
f=[list(map(int,input().split())) for _ in range(n)]
p=[list(map(int,input().split())) for _ in range(n)]
maxp=-float("inf")
for i in range(1,2**10):
  pt=0
  for j in range(n):
    cnt=0
    for k in range(10):
      if (i>>k)&1 and f[j][k]==1:
        cnt+=1
    pt+=p[j][cnt]
  maxp=max(maxp,pt)
print(maxp)

n = int(input())
F = [0]*n
P = [0]*n
for i in range(n):
    F[i] = list(map(int,input().split()))
for i in range(n):
    P[i] = list(map(int,input().split()))
 
ans = -float("Inf")
for i in range(1,2**10):
    L = []
    b = 0
    for j in range(10):
        if (i>>j)&1:
            L.append(j)
    for j in range(n):
        c = 0
        for x in L:
            if F[j][x] == 1:
                c += 1
        b += P[j][c]
        
    ans = max(ans, b)
 
 
print(ans)

n = int(input())
f = []
ans = -10**9

for i in range(n):
    a = "".join(input().split())
    a = int(a, 2)
    f.append(a)

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

for i in range(1, 2**10):
    ref = 0
    for j in range(n):
        cnt = bin(i&f[j]).count("1")
        ref += p[j][cnt]
    else:
        ans = max(ans, ref)

print(ans)

from itertools import product
N = int(input())
lsF = [[]]
for i in range(N):
    lsF.append(list(map(int,input().split())))
lsP = [[]]
for i in range(N):
    lsP.append(list(map(int,input().split())))
bita = list(product(range(2),repeat=10))
bita.pop(0)
ans = -10**10
for bit in bita:
    count = [0 for i in range(N+1)]
    for i in range(10):
        for j in range(1,N+1):
            count[j] += bit[i]*lsF[j][i]
    benifit = 0
    for i in range(1,N+1):
        benifit += lsP[i][count[i]]
    ans = max(ans,benifit)
print(ans)

A=int(input())
shop_l=[list(map(int,input().split())) for i in range(A)]
shop_count_l=[list(map(int,input().split())) for i in range(A)]
ans=-1*10**10
for i in range(1,1024):
   tmp=0
   l=[0]*A
   for j in range(10):
      if (i>>j)&1:
         for k in range(A):
            if shop_l[k][j] == 1:
               l[k]+=1
   for i in range(A):
      tmp+=shop_count_l[i][l[i]]
   ans=max(ans,tmp)
print(ans)

def solve():
    n = int(input())
    oc = [list(map(int, input().split())) for _ in range(n)]
    prof = [list(map(int, input().split())) for _ in range(n)]

    inf = 10 ** 16
    ans = - inf

    for a in range(1, 1 << 10):
        res = 0
        for i in range(n):
            cnt = 0
            for x in range(10):
                if a >> x & 1 and oc[i][x] == 1:
                    cnt += 1
            res += prof[i][cnt]
        ans = max(ans, res)
    print(ans)


solve()


import sys
n = int(input())
F = [list(map(int, sys.stdin.readline().split())) for _ in range(n)]
P = [list(map(int, sys.stdin.readline().split())) for _ in range(n)]
ans = -pow(10,9)-7
for i in range(1,pow(2,10)):
    b = bin(i)[2:].zfill(10)
    t = 0
    for j in range(n):
        c = 0
        for k in range(10):
            if int(b[k]) and F[j][k]:
                c += 1
        t += P[j][c]
    ans = max(ans, t)
print(ans)

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

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

res = - 10 ** 11
for i in range(1, 1 << 10):
    tmp_res = 0
    for j in range(n):
        counter = 0
        for k in range(10):
            if i >> k & f[j][k]:
                counter += 1
        tmp_res += p[j][counter]
    res = max(res, tmp_res)

print(res)


import itertools
n=int(input())
f=[list(map(int,input().split())) for _ in range(n)]
p=[list(map(int,input().split())) for _ in range(n)]
ans=-(10**12)
for i in range(1,11):
    num=list(itertools.combinations(list(range(10)),i))
    for j in range(len(num)):
        cnt=[0]*n
        cnt2=0
        for k in range(i):
            for l in range(n):
                if f[l][num[j][k]]==1:
                    cnt[l]+=1
        for k in range(n):
            cnt2+=p[k][cnt[k]]
        ans=max(cnt2,ans)
print(ans)


import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    F = [LI() for _ in range(N)]
    P = [LI() for _ in range(N)]

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

    print(ans)

def __starting_point():
    resolve()

__starting_point()

n = int(input())
f = []
ans = -10**9

for i in range(n):
    a = "".join(input().split())
    a = int(a, 2)
    f.append(a)

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

for i in range(1, 2**10):
    ref = 0
    for j in range(n):
        cnt = bin(i & f[j]).count("1")
        ref += p[j][cnt]
    else:
        ans = max(ans, ref)

print(ans)

import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


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

    ans = -INF
    for bits in range(1, 1 << 10):
        res = 0
        for i in range(N):
            c = 0
            for j in range(10):
                if F[i][j] and (bits & (1 << j)):
                    c += 1
            res += P[i][c]
        if ans < res:
            ans = res

    print(ans)
    return


def __starting_point():
    main()

__starting_point()

n = int(input())
F = [0]*n
P = [0]*n
for i in range(n):
    F[i] = list(map(int,input().split()))
for i in range(n):
    P[i] = list(map(int,input().split()))

ans = -float("Inf")
for i in range(1,2**10):
    L = []
    b = 0
    for j in range(10):
        if (i>>j)&1:
            L.append(j)
    for j in range(n):
        c = 0
        for x in L:
            if F[j][x] == 1:
                c += 1
        b += P[j][c]
        
    ans = max(ans, b)


print(ans)

def count_set_bits(n):
    count = 0
    while n:
        count += n & 1
        n >>= 1
    return count


N = int(input())
F = [int("".join(input().split()), 2) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]
ans = -float("inf")
for i in range(1, 1 << 10):
    tmp = 0
    for j in range(N):
        tmp += P[j][count_set_bits(i & F[j])]
    ans = max(ans, tmp)
print(ans)


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

ans = -float('inf')

for i in range(1, 2**10):
    res = 0
    for k in range(N):
        p = i & F[k]
        cnt = 0
        for j in range(10):
            if (p >> j) & 1:
                cnt += 1
        res += P[k][cnt]
    ans = max(ans, res)

print(ans)

n = int(input())

f = [list(map(int, input().split())) for _ in range(n)]
# f = zip(*f)

p = [list(map(int, input().split())) for _ in range(n)]
# p = zip(*p)

ans = -10**10
for i in range(1,1<<10):
    c = [0] * n # 同時に店を開いている時間帯数
    for j in range(10):
        if i & (1<<j):
            for k,F in enumerate(f):
                if F[j]:
                    c[k] += 1
    profit = 0
    for j in range(n):
        profit += p[j][c[j]]
    ans = max(ans, profit)

print(ans)

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

for i in range(1,1024):
  p = 0
  for j in range(N):
    c = 0
    for k in range(10):
      if (i>>k&1) & F[j][k]:
        c+=1
    p+=P[j][c]
  ans+=[p]
    
print(max(ans))

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

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

#print(F, P)
#print(4 >> 1)
ans = - 10 ** 10
#print(ans)
for i in range(1, 2 ** 10):#bit全探索 #0は空いてる時間帯がないのでカット
  open_n = [0] * N
  profit = 0
  for j in range(10):#10240通り
    if ((i >> j) & 1):#jの時間帯に空いてる
      for k in range(N):#100
        if F[k][j] == 1:
          open_n[k] += 1
  for l in range(N):
    profit += P[l][open_n[l]]
  if ans < profit:
    ans = profit
          
print(ans) 


import numpy as np
import heapq as hq
N = int(input())
F = np.array([[int(x) for x in input().split()] for _ in range(N)])
P = np.array([[int(x) for x in input().split()] for _ in range(N)])

Profit = []
for i in range(1,2**10): #営業時間帯についてbit全探索
    Open = np.array([int(x) for x in format(i, '010b')]).T #2進数を縦ベクトルに変換
    c = np.dot(F, Open) #店別に被る時間帯の個数をベクトルとして算出
    hq.heappush(Profit, -sum(P[i, c[i]] for i in range(N))) #-1倍した利益をProfitにpush。
print((-Profit[0])) #heapから最小値を取得


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

bh=[0]*n
c=[0]*n
for i,s in enumerate(f):
  for j,h in enumerate(s):
    bh[i]|=h<<j

maxp=-float('inf')
for mbh in range(1,2**10):
  for i in range(n):
    intsect=mbh&bh[i]
    c[i]=sum(intsect>>k&1 for k in range(10))
  maxp=max(maxp,sum(p[i][c[i]] for i in range(n)))
print(maxp)

#
# abc080 c
#
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """1
1 1 0 1 0 0 0 1 0 1
3 4 5 6 7 8 9 -2 -3 4 -2"""
        output = """8"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """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"""
        output = """-2"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """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"""
        output = """23"""
        self.assertIO(input, output)


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

    ans = sum([min(p) for p in P])
    for bit in range(1, 1 << 10):
        lbit = list(map(int, format(bit, "b").zfill(10)))
        p = 0
        for i, f in enumerate(F):
            n = 0
            for j in range(10):
                if lbit[j] == f[j] == 1:
                    n += 1
            p += P[i][n]
        ans = max(ans, p)

    print(ans)


def __starting_point():
    # unittest.main()
    resolve()

__starting_point()

import numpy as np
N = int(input())

F = np.empty((N,10))
P = np.empty((N,11))
for i in range(N):
  Flist = np.array(list(map(int, input().split())), dtype = int)
  F[i] = Flist
for i in range(N):
  Plist = np.array(list(map(int, input().split())), dtype = int)
  P[i] = Plist
BenefitMax = 0

for i in range(1,1024):
  A = np.zeros(10)
  iForBin = i
  for j in range(10):
    if iForBin %2 == 1:
      A[j] = 1
    iForBin = iForBin // 2
  ADotF = np.tensordot(A,F,((0),(1)))
  Benefit = 0
  for j in range(N):
    Benefit += P[j,int(ADotF[j])]
  if i == 1:
    BenefitMax = Benefit
  else:
    if BenefitMax < Benefit:
      BenefitMax = Benefit

print(int(BenefitMax))

n=int(input())
import numpy as np
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())))
x=np.asarray(f)
mx=-10**9
for i in range(1,2**10):
    y=np.asarray([int(x) for x in list(format(i,'010b'))])
    z=x*y
    can=np.sum(z,axis=1)
    c=0
    for j in range(n):
        c += p[j][can[j]]
    mx=max(c,mx)
print(mx)

def bitcount(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f #8bitごと
    x = x + (x >> 8) #16bitごと
    x = x + (x >> 16) #32bitごと
    x = x + (x >> 32) #64bitごと = 全部の合計
    return x & 0x0000007f

def binary_to_int(x):
    temp = 0
    for i in range(len(str(x))):
        temp += 2**(len(str(x))-i-1) * int(str(x[i]))
    return temp

n = int(input())
shops = []
for i in range(n):
    shops.append(binary_to_int("".join(input().split())))
p = []
for i in range(n):
    p.append(list(map(int, input().split())))

for i in range(1, 2**10):
    temp = 0
    for j in range(n):
        temp += p[j-1][bitcount(i & shops[j-1])]
    if i == 1:
        ans = temp
    elif temp > ans:
        ans = temp

print(ans)

N = int(input())
F = [int("".join(input().split()),2) for n in range(N)]
P = [list(map(int,input().split())) for n in range(N)]
print(max(sum(p[bin(n&f).count("1")]for f,p in zip(F,P)) for n in range(1,1024)))

def ForBaseConvert(Roop,MaxD,Base):
    if all(type(TT) is int for TT in [Roop,MaxD,Base]):
        if Base>=2 and MaxD>=1:
            ConvertN = []
            while Roop>0:
                ConvertN.append(Roop%Base)
                Roop = Roop//Base

            BaseConv = [0]*(MaxD-len(ConvertN))+ConvertN[::-1]
            BaseSInd = [[] for TB in range(0,Base)]
            for TB in range(0,Base):
                BaseSInd[TB] = [SInd for SInd,SNum in enumerate(BaseConv) if SNum==TB]
            return BaseConv,BaseSInd
        else:
            return []
    else:
        return []
      
N = int(input())
F = [[] for TF in range(0,N)]
for TF in range(0,N):
    F[TF] = [int(T) for T in input().split()]
P = [[] for TP in range(0,N)]
for TP in range(0,N):
    P[TP] = [int(T) for T in input().split()]
    
MAXB = -10**9
for TB in range(1,2**10):
    BaseConv,BaseSInd = ForBaseConvert(TB,10,2)
    Benefit = 0
    for TN in range(0,N):        
        Count = sum(1 if F[TN][TT]==1 else 0 for TT in BaseSInd[1])
        Benefit += P[TN][Count]
    if MAXB<Benefit:
        MAXB = Benefit
print(MAXB)

import itertools
n=int(input())
f=[list(map(int,input().split())) for _ in range(n)]
p=[list(map(int,input().split())) for _ in range(n)]
ans=-(10**12)
for i in range(1,11):
    num=list(itertools.combinations(list(range(10)),i))
    for j in range(len(num)):
        cnt=[0]*n
        cnt2=0
        for k in range(i):
            for l in range(n):
                if f[l][num[j][k]]==1:
                    cnt[l]+=1
        for k in range(n):
            cnt2+=p[k][cnt[k]]
        ans=max(cnt2,ans)
print(ans)


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

max_prof = -float('inf')

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

    sum_prof = 0
    for store_no in range(N):
        state = s

        time_zone = 0
        both_open_cnt = 0
        while state > 0:
            if (state & 1) and F[store_no][time_zone]:
                both_open_cnt += 1

            state >>= 1
            time_zone += 1

        sum_prof += P[store_no][both_open_cnt]

    max_prof = max(max_prof, sum_prof)


print(max_prof)


from math import inf

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

ans = -inf
for bit in range(1,1024):
    res = 0
    for j in range(n):
        c = 0
        for k in range(10):
            mask = 1 << k
            if f[j][k] and bit&mask:
                c+=1
        res += p[j][c]
    ans = max(ans, res)
print(ans)




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)]
A = [0, 1]
M = -10**18
Pr = list(product(A, repeat=10))
Pr.remove((0,0,0,0,0,0,0,0,0,0))
for I in Pr:
  s = 0
  for i in range(N):
    s += P[i][sum(i*f for i, f in zip(I, F[i]))]
  M = max(M, s)
print(M)

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):
    score = 0
    jonson = [0 for _ in range(10)]

    #jonsonがお店を開く時間を決める
    for j in range(10):
        if ((i >> j)&1):
            jonson[j] = 1
    #他のお店とオープンがかぶっている時間を調べる
    for k in range(N):
        cnt = 0
        for l in range(10):
            if F[k][l] == jonson[l] == 1:
                cnt += 1
        score += P[k][cnt]

    ans = max(score, ans)

print(ans)

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


import itertools

N = int(input())
M = 10
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 s in itertools.product([0, 1], repeat=M):
    if max(s) == 0:
        continue
    score = 0
    for i in range(N):
        cnt = 0
        for j in range(M):
            if s[j] and F[i][j]:
                cnt += 1
        score += P[i][cnt]
    ans = max(ans, score)
print(ans)


from itertools import product

ans = -10**9 - 1

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

all_x = True
for ox in product((0, 1), repeat=10):
  if all_x:
    all_x = False
  else:
    temp = 0
    for n in range(N):
      cnt = 0
      for i, j in zip(F[n], ox):
        cnt += i*j
      temp += P[n][cnt]
    ans = max(ans, temp)

print(ans)