CodeEff/ECCO huggingface dataset:
# Original solution
# 写経

n = int(eval(input()))
lst_F = [list(map(int, input().split())) for _ in range(n)]
lst_P = [list(map(int, input().split())) for _ in range(n)]


ans = -float("INF")
for b in range(1, 2**10):
    tmp = 0
    for i in range(n):
        c = 0
        for k in range(10):
            if b&(1<<k) and lst_F[i][k]:
                c += 1
        tmp += lst_P[i][c]
    ans = max(tmp, ans)


print(ans)

# Optimized solution
N = int(eval(input()))
lst_F = [list(map(int, input().split())) for _ in range(N)]
lst_P = [list(map(int, input().split())) for _ in range(N)]
n_timetable = 10
lst_joisino = [None] * n_timetable


def score(src, F, P):
    cnt = 0
    for i, j in zip(src, F):
        if i == j == 1:
            cnt += 1
    return P[cnt]


def dfs(pos):
    if pos == n_timetable:
        ret = 0
        for i in range(N):
            if lst_joisino == [0] * n_timetable:
                return -float("INF")
            p = score(lst_joisino, lst_F[i], lst_P[i])
            ret += p
        return ret
    lst_joisino[pos] = 0
    ret0 = dfs(pos + 1)
    lst_joisino[pos] = 1
    ret1 = dfs(pos + 1)
    return max(ret0, ret1)


print((dfs(0)))
# Original solution
import sys
input=sys.stdin.readline

def main():
    N = int(eval(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())))

    ans = -10**7*N
    for i in range(1, 1<<10):
        tmp = 0
        for s,f in enumerate(F):
            c = 0
            for j in range(10):
                if (i>>j)&1&f[j]:
                    c += 1
            tmp += P[s][c]
        ans = max(ans, tmp)
    print(ans)

if __name__ == '__main__':
    main()


# Optimized solution
import sys
input=sys.stdin.readline

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

    ans = -10**7*N
    for i in range(1, 1<<10):
        tmp = 0
        for j,f in enumerate(F):
            c = bin(i&f).count("1")
            tmp += P[j][c]
        ans = max(ans, tmp)
    print(ans)

if __name__ == '__main__':
    main()
# Original solution
# ABC080C - Shopping Street
import sys
input = sys.stdin.readline

from itertools import product

def main():
    N = int(eval(input()))
    F = tuple(tuple(map(int, input().split())) for _ in range(N))
    P = tuple(tuple(map(int, input().split())) for _ in range(N))
    ans = []
    for b in tuple(product((0, 1), repeat=10))[1:]:
        cnt = 0
        for f, p in zip(F, P):
            opening = sum(b[i] == 1 and b[i] == f[i] for i in range(10))
            cnt += p[opening]
        ans += [cnt]
    print((max(ans)))


if __name__ == "__main__":
    main()

# Optimized solution
# ABC080C - Shopping Street
import sys
input = sys.stdin.readline

from itertools import product

def main():
    N = int(eval(input()))
    F = tuple(tuple(map(int, input().split())) for _ in range(N))
    P = tuple(tuple(map(int, input().split())) for _ in range(N))
    ans = []
    for b in tuple(product((0, 1), repeat=10))[1:]:
        cnt = 0
        for f, p in zip(F, P):
            opening = sum(i & j for i, j in zip(b, f))
            cnt += p[opening]
        ans += [cnt]
    print((max(ans)))


if __name__ == "__main__":
    main()
# Original solution
# ABC080C - Shopping Street
import sys
input = sys.stdin.readline

from itertools import product

def main():
    N = int(eval(input()))
    F = tuple(tuple(map(int, input().split())) for _ in range(N))
    P = tuple(tuple(map(int, input().split())) for _ in range(N))
    ans = []
    for b in product((0, 1), repeat=10):
        if 1 not in b:
            continue
        cnt = 0
        for f, p in zip(F, P):
            opening = sum(i & j for i, j in zip(b, f))
            cnt += p[opening]
        ans += [cnt]
    print((max(ans)))


if __name__ == "__main__":
    main()

# Optimized solution
# ABC080C - Shopping Street
import sys
input = sys.stdin.readline

from itertools import product


def main():
    N = int(eval(input()))
    F = tuple(int(input().replace(" ", ""), 2) for _ in range(N))
    P = tuple(tuple(map(int, input().split())) for _ in range(N))
    ans = []
    for i in range(1, 2 ** 10):
        cnt = sum(p[bin(i & f).count("1")] for f, p in zip(F, P))
        ans += [cnt]
    print((max(ans)))


if __name__ == "__main__":
    main()
# Original solution
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    N=int(readline())
    F=[]
    for i in range(N):
        f=list(map(int,readline().split()))
        F.append(f)
    P=[]
    for i in range(N):
        p=list(map(int,readline().split()))
        P.append(p)
    
    max_res=-float("inf")
    for i in range(1<<10):
        if i==0:
            continue
        else:
            output=[]
            for j in range(10):
                if(i>>j)&1:
                    output.append(j)

            oc=[0]*10  #open or close
            for j in output:
                oc[j]=1
            
            res=0
            for j in range(N):
                c=0
                for k in range(10):
                    if oc[k]==1 and F[j][k]==1:
                        c+=1
                res+=P[j][c]
            max_res=max(res,max_res)

    print(max_res)
    
if __name__=="__main__":
    main()

# Optimized solution
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    N=int(readline())
    F=[]
    for i in range(N):
        f=int("".join(readline().strip().split(" ")),2)
        F.append(f)
    P=[]
    for i in range(N):
        p=list(map(int,readline().split()))
        P.append(p)
    
    max_res=float("-inf")
    for output in range(1,1<<10):
        res=0
        for j in range(N):
            c=bin(output&F[j]).count("1")
            res+=P[j][c]
        max_res=max(res,max_res)

    print(max_res)
    
if __name__=="__main__":
    main()
# Original solution
n = int(eval(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**12
for i in range(1,1024):
    #print("i=",i)
    temp = 0
    for j in range(n): #j = 0,1,2,..,n-1で店番号
        fi = f[j]
        ci = sum([1 for k in range(10) if (i>>k)&1==1 and fi[9-k]==1])
        temp += p[j][ci]
    #print(temp)
    ans = max(ans,temp)
print(ans)


# Optimized solution
n = int(eval(input()))
f = [int(input().replace(" ",""),2) for i in range(n)] #数にしてしまう
p = [list(map(int,input().split())) for i in range(n)]
ans = -10**12
for i in range(1,1024):
    #print("i=",i)
    temp = 0
    for j in range(n): #j = 0,1,2,..,n-1で店番号
        fi = f[j]
        ci = bin(fi&i).count("1") #bin()は2進法表記のstrになる。
        #print("ci=",ci)
        temp += p[j][ci]
    #print(temp)
    #print(temp)
    ans = max(ans,temp)
print(ans)
# Original solution
f=lambda:[list(map(int,input().split())) for _ in range(n)]
n=int(eval(input()))
llf,llp=f(),f()
a=-10**9
import itertools as it
for t in it.product([0,1],repeat=10):
  if sum(t):
    lc=[sum(t[i]*lf[i] for i in range(10)) for lf in llf]
    a=max(a,sum(llp[i][lc[i]] for i in range(n)))
print(a)

# Optimized solution
I=input;R=range;n=int(I())
lf=[int(I()[::2],2) for _ in R(n)]
lp=[list(map(int,I().split())) for _ in R(n)]
print((max(sum(p[bin(i&f).count('1')] for f,p in zip(lf,lp)) for i in R(1,1024))))
# Original solution
def getN():
    return int(eval(input()))
def getNM():
    return list(map(int, input().split()))
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(eval(input())) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import copy
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

N = getN()
F = []
for i in range(N):
    # 各数字をstrに変換
    f = list(map(str, input().split()))
    # join
    falta = ''.join(f)
    # 二進数に変換
    F.append(int(falta, 2))
P = []
for i in range(N):
    p = getList()
    P.append(p)
ans = -10 ** 24
# 状態を生成
# 0000000000はダメ（必ず店は開く）
for bit in range(1, 1 << 10):
    sum = 0
    # 各お店と照合
    for i in range(N):
        open = F[i] & bit
        # 二進数表記でのフラグの数をカウント
        index = str(bin(open)).count('1')
        sum += P[i][index]
    ans = max(ans, sum)
print(ans)

# Optimized solution
def getN():
    return int(eval(input()))
def getNM():
    return list(map(int, input().split()))
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(eval(input())) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import copy
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

N = getN()
F = []
for i in range(N):
    # 各数字をstrに変換
    f = list(map(str, input().split()))
    # join
    falta = ''.join(f)
    # 二進数に変換
    F.append(int(falta, 2))
P = []
for i in range(N):
    p = getList()
    P.append(p)
# -10 ** 7ぐらいだとばか小さい数にならずWA
# ばかでかい数、ばか小さい数にするときは思いっきりばかでかく、小さくしよう
ans = -10 ** 24
# bit全探索するため状態を生成
# 0000000000はダメ（必ず店は開く）
for bit in range(1, 1 << 10):
    sum = 0
    # 各お店と照合
    for i in range(N):
        open = F[i] & bit
        # 二進数表記でのフラグの数をカウント
        index = str(bin(open)).count('1')
        sum += P[i][index]
    ans = max(ans, sum)
print(ans)
# Original solution
n = int(eval(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)

# Optimized solution
def solve():
    n = int(eval(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()
# Original solution
#!/usr/bin/env python3
#ABC80 C

from operator import itemgetter
import collections

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

ma = -float('inf')
for i in range(1,2**10):
    b = [0]*10
    s = 0
    sum = 0
    for j in range(10):
        if (i>>j) & 1:
            b[j] = 1
    for j in range(n):
        for k in range(10):
            if f[j][k] & b[k]:
                s += 1
        sum += p[j][s]
        s = 0
    ma = max(ma,sum)
print(ma)


# Optimized solution
#!/usr/bin/env python3
#ABC80 C

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
f = [LI() for _ in range(n)]
p = [LI() for _ in range(n)]
ans = -inf
for i in range(1,2**10):
    b = [0]*10
    for j in range(10):
        if (i >> j) & 1:
            b[j] = 1
    tmp = 0
    for i in range(n):
        cnt = 0
        for j in range(10):
            if b[j] == 1 and f[i][j] == 1:
                cnt += 1
        tmp += p[i][cnt]
    ans = max(ans,tmp)
print(ans)
# Original solution
n=int(eval(input()))
S=[list(map(str,input().split())) for _ in range(n)]
C=[list(map(int,input().split())) for _ in range(n)]
A=[]
for i in range(1,2**10):
    ans=0
    X=format(i,'b').zfill(10)
    for j in range(n):
        cnt=0
        for k in range(10):
            if S[j][k]=='1' and X[k]=='1':
                cnt+=1
        ans+=C[j][cnt]
    A.append(ans)
print((max(A)))   

# Optimized solution
n=int(eval(input()))
S=[int(input().replace(' ',''),2) for _ in range(n)]
C=[list(map(int,input().split())) for _ in range(n)]
A=[]
for i in range(1,2**10):
    ans=0
    for j in range(n):
        cnt=bin(S[j]&i).count('1')
        ans+=C[j][cnt]
    A.append(ans)
print((max(A)))
# Original solution
import sys
import itertools

# import collections
# import math
# import string
# import bisect
# import re
# import itertools
# import statistics


# bit を使ってci を管理する

def toBit(n): 
    return bin(eval('0b' + str(n)))

def main():

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

    schedule = [toBit(''.join(str(x) for x in sys.stdin.readline().split())) for _ in range(n)]
    profit_table = [[int(x) for x in sys.stdin.readline().split()] for _ in range(n)]

    maximum_profit = -10**10
    for open_pattern in itertools.product('01', repeat=10):
        open_pattern = toBit(''.join(open_pattern))
        if open_pattern == '0b0':
            continue
        profit = 0
        for i in range(n):
            checked = schedule[i]
            number_of_periods = bin(eval(checked) & eval(open_pattern)).count('1')
            profit += profit_table[i][number_of_periods]
        maximum_profit = max(maximum_profit, profit)

    print(maximum_profit)

if __name__ == "__main__":
    # execute only if run as a script
    main()


# Optimized solution
import sys
import itertools

# import collections
# import math
# import string
# import bisect
# import re
# import itertools
# import statistics


# bit を使ってci を管理する

def toBit(n): 
    return eval('0b' + n)

def main():

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

    schedule = [toBit(''.join(str(x) for x in sys.stdin.readline().split())) for _ in range(n)]
    profit_table = [[int(x) for x in sys.stdin.readline().split()] for _ in range(n)]

    maximum_profit = -10**10
    for open_pattern in itertools.product('01', repeat=10):
        open_pattern = toBit(''.join(open_pattern))
        if open_pattern == 0:
            continue
        profit = 0
        for i in range(n):
            checked = schedule[i]
            number_of_periods = bin(checked & open_pattern).count('1')
            profit += profit_table[i][number_of_periods]
        maximum_profit = max(maximum_profit, profit)

    print(maximum_profit)

if __name__ == "__main__":
    # execute only if run as a script
    main()
# Original solution
N = int(eval(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 #店iとjoisinoのかぶっている数
  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]]
      #tmp += P[k][counter[k]]
  ans = max(tmp,ans)
print(ans)

# Optimized solution
n = int(eval(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)
# Original solution
N=int(eval(input()))
M=[[0 for i in range(2**10)] for j in range(N)]
K=[0]*(2**10)
F=[list(map(int,input().split())) for _ in range(N)]
P=[list(map(int,input().split())) for _ in range(N)]

for i in range(2**10):
  for j in range(10):
    for k in range(N):
      if (i>>9-j)&1 and F[k][j]:
        #print(i,j)
        M[k][i]+=1

for i in range(2**10):
  for k in range(N):
    K[i]+=P[k][M[k][i]]
print((max(K[1:])))

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

answer = []
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 and F[j][k]:
        cnt += 1
    tmp += P[j][cnt]
  answer.append(tmp)
  
print((max(answer)))
# Original solution
N = int(eval(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 range(1, 1024):
    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]
    result = max(result, t)
print(result)


# Optimized solution
# ビット全探索
from itertools import product

N = int(eval(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)
# Original solution
N = int(eval(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)


# Optimized solution
N = int(eval(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)
# Original solution
N = int(eval(input()))
F = [[0 for _ in range(10)] for _ in range(N)]
P = [[0 for _ in range(10)] 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()))

ans = -float('inf')
for mask in range(1, 2**10) :
    profit = 0
    for shop in range(N) :
        count = 0
        for time in range(10) :
            if (mask & (1 << time) != 0) and F[shop][time] == 1 :
                count += 1
        profit += P[shop][count]
    ans = max(ans, profit)

print(ans)

# Optimized solution
N = int(eval(input()))

F = []
for _ in range(N):
    mask = 0
    for f in map(int, input().split()):
        mask <<= 1
        mask |= f
    F.append(mask)

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

def calc(state):
    ret = 0
    for f, ps in zip(F, P):
        f &= state
        cnt = 0
        while f > 0:
            cnt += f % 2
            f //= 2
        ret += ps[cnt]
    return ret

ans = -10**18
for state in range(1, 1 << 10):
    ans = max(ans, calc(state))
print(ans)
# Original solution
import sys
from itertools import product

input = sys.stdin.readline

N = int(eval(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 = float('-inf')
for ptn in product([0, 1], repeat=10):
    if sum(ptn) == 0:
        continue

    res = 0
    for i in range(N):
        cnt = 0
        for j in range(10):
            cnt += F[i][j] * ptn[j]
        res += P[i][cnt]
    ans = max(ans, res)
print(ans)


# Optimized solution
import sys

input = sys.stdin.readline

N = int(eval(input()))
F = [int(input().replace(' ', ''), 2) for _ in range(N)]
P = [[int(x) for x in input().split()] for _ in range(N)]

ans = float('-inf')
for i in range(1, 2**10):
    res = 0
    for f, p in zip(F, P):
        cnt = bin(i & f).count('1')
        res += p[cnt]
    ans = max(ans, res)
print(ans)
# Original solution
from operator import mul
 
n = int(eval(input()))
cof = [1 << x for x in range(10)]
fs = [sum(map(mul, list(map(int, input().split())), cof)) for _ in range(n)]
ps = [list(map(int, input().split())) for _ in range(n)]
ans = float('-inf')
for g in range(1, 1024):
    ans = max(ans, sum(p[bin(f & g).count('1')] for f, p in zip(fs, ps)))
print(ans)

# Optimized solution
N=int(eval(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))))
# Original solution
n = int(eval(input()))
F = []
# for _ in range(n):
#     f = list(map(int, input().split()))
#     # print(f)
#     F.append([\
#         [f[0],f[1]],\
#         [f[2],f[3]],\
#         [f[4],f[5]],\
#         [f[6],f[7]],\
#         [f[8],f[9]]\
#     ])

for _ in range(n):
    f = list(map(int, input().split()))
    F.append(f)

# print(*F,sep='\n')

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

# print(*P,sep='\n')

def c(i, open_my_shop):
    ret = 0
    for j in range(10):
        if open_my_shop>>j & 1: #open my shop
            if F[i][j]: # open your shop
                ret += 1
    return ret

ans = -10*10000000*10
# for i in range(1, 1<<10): # [0~1,1~1] 10bit
#     s = 0
#     for j in range(10): # open time zone
#         if i>>j & 1: # my shop (j+1) open
#             for k in range(n): # your shop
#                 ck = c(k, i)
#                 s += P[k][ck]
#     ans = max(ans ,s)

for i in range(1, 1<<10): # [0~1,1~1] 10bit
    s = 0
    for j in range(n): # your shop
        cj = c(j, i)
        s += P[j][cj]
    ans = max(ans ,s)

print(ans)


# Optimized solution
n = int(eval(input()))
F = [[*list(map(int, input().split()))] for _ in range(n)]
P = [[*list(map(int, input().split()))] for _ in range(n)]

def c(i, open_patern):
    ret = 0
    for j in range(10):
        if open_patern>>j & 1: #open my shop
            if F[i][j]: ret += 1 # open your shop
    return ret

ans = -10000000*100
for i in range(1, 1<<10): # open pattern 10bit, i:[0~1,1~1]
    s = 0
    for j in range(n): # your shop
        cj = c(j, i)
        s += P[j][cj]
    ans = max(ans ,s)
print(ans)
# Original solution
import sys
input = sys.stdin.readline
from itertools import combinations

def readlines(n):
    for _ in range(n):
        yield list(map(int,input().split()))

def bene(me, f, p):
    a = sum(1 if f[m] == 1 else 0 for m in me)
    return p[a]

def main():
    n = int(eval(input()))
    F = list(readlines(n))
    P = list(readlines(n))

    for i in range(1, 11):
        for comb in combinations(list(range(10)), i):
            yield sum(bene(comb, f, p) for f, p in zip(F,P))

    
print((max(main())))

# Optimized solution
import sys
input = sys.stdin.readline
from itertools import combinations

def readlines(n):
    for _ in range(n):
        yield list(map(int,input().split()))

def bene(me, f, p):
    a = len([0 for m in me if f[m] == 1])
    return p[a]

def main():
    n = int(eval(input()))
    F = list(readlines(n))
    P = list(readlines(n))

    for i in range(1, 11):
        for comb in combinations(list(range(10)), i):
            yield sum(bene(comb, f, p) for f, p in zip(F,P))

    
print((max(main())))