AtCoder Beginner Contest 080 - Shopping Street

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.

Source: atcoder | Difficulty: EASY


Solutions:
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))))


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):
	now = 0
	for j in range(n):
		cou = 0
		for k in range(10):
			if i >> k & f[j][k] == 1:
				cou += 1
		now += p[j][cou]
	ans = max(ans, now)
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 as pr
x = -10 ** 9
for ch in list(pr([0, 1], repeat=10)):
	if 1 not in ch:
		continue
	s = 0
	for j in range(n):
		c = 0
		t = f[j]
		for k in range(10):
			if ch[k] and t[k]:
				c += 1
		s += p[j][c]
	x = max(x, s)
print(x)


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


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
	for l in range(n):
		ans += p[l][co[l]]
	li += [ans]
print(max(li))


n = int(input())
f = [int(input().replace(' ', ''), 2) for i in range(n)]
p = [list(map(int, input().split())) for i in range(n)]
prof = -10 ** 10
for i in range(1, 1 << 10):
	prof1 = 0
	for (j, time) in enumerate(f):
		prof1 += p[j][bin(i & time).count('1')]
	prof = max(prof, prof1)
print(prof)


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


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)


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


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 = [int(input().replace(' ', ''), 2) for j in range(n)]
p = [[int(i) for i in input().split()] for i in range(n)]
out = float('-inf')
for i in range(1, 1024):
	b = 0
	for j in range(n):
		b += p[j][bin(f[j] & i).count('1')]
	out = max(b, out)
print(out)


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)]
cd = []
for i in product([0, 1], repeat=10):
	if i == (0, 0, 0, 0, 0, 0, 0, 0, 0, 0):
		continue
	s = 0
	for (idx, j) in enumerate(f):
		s += p[idx][sum((k * l for (k, l) in zip(i, j)))]
	cd.extend([s])
print(max(cd))


N = int(input())
F = [int('0b' + ''.join(list(input().split(' '))), 0) for i in range(N)]
P = [list(map(int, input().split(' '))) for i in range(N)]
ans = -float('inf')
for i in range(1, 1024):
	tmp = 0
	for (j, k) in zip(P, F):
		tmp += j[str(bin(i & k)).count('1')]
	ans = max(tmp, ans)
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())
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)


N = int(input())
r = range
F = [int(input()[::2], 2) for _ in r(N)]
P = [list(map(int, input().split(' '))) for _ in range(N)]
print(max((sum((p[bin(i & f).count('1')] for (f, p) in zip(F, P))) for i in r(1, 1024))))


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


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)


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)]
print(max((sum((p[j][sum((i >> k & 1 and f[j][k] for k in range(10)))] for j in range(n))) for i in range(1, 2 ** 10))))


N = int(input())
F = [int(input().replace(' ', ''), 2) for i in range(N)]
P = [list(map(int, input().split())) for i in range(N)]
print(max((sum([p[bin(f & i).count('1')] for (f, p) in zip(F, P)]) for i in range(1, 2 ** 10))))


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 = [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 = [int(''.join(input().split()), 2) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]
ans = -10 ** 9
for bit in range(1, 1 << 10):
	money = 0
	for i in range(N):
		cnt = format(bit & F[i], 'b').count('1')
		money += P[i][cnt]
	ans = max(money, 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 ** 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)


import sys
mod = 10 ** 9 + 7
inf = float('inf')
from math import sqrt, ceil
from collections import deque, Counter, defaultdict
input = lambda : sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from decimal import ROUND_HALF_UP, Decimal
from functools import lru_cache
from bisect import bisect_left as bileft, bisect_right as biright
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)


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


def main():
	N = int(input())
	F = [int(input().replace(' ', ''), 2) for _ in range(N)]
	P = [list(map(int, input().split())) for _ in range(N)]
	ans = -10 ** 10
	for i in range(1, 2 ** 10):
		c = 0
		for (f, p) in zip(F, P):
			c += p[bin(f & i).count('1')]
		ans = max(ans, c)
	print(ans)
main()


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


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):
	ff = list(map(int, input().split()))
	f.append(ff)
p = []
for i in range(n):
	pp = list(map(int, input().split()))
	p.append(pp)
ans = -10 ** 10
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 and f[j][k] == 1:
				c += 1
		tmp += p[j][c]
	ans = max(ans, tmp)
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 = [[int(x) for x in input().split()] for i in range(n)]
P = [[int(x) for x in input().split()] for i in range(n)]
res = -10 ** 12
for bit in range(1, 2 ** 10):
	cc = 0
	for i in range(n):
		cc += P[i][sum([F[i][j] == 1 and 1 & bit >> j == True for j in range(10)])]
	res = max(res, cc)
print(res)


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


n = int(input())
f = [int(input().replace(' ', ''), 2) for i in range(n)]
p = []
for i in range(n):
	p.append([int(v) for v in input().split()])
ans = -10000000000
for store in range(1, 1024):
	p_sum = 0
	for (i, v) in enumerate(f):
		c = v & store
		p_sum += p[i][bin(c).count('1')]
	ans = max(ans, p_sum)
print(ans)


N = int(input())
F = [[int(i) for i in input().split()] for j in range(N)]
P = [[int(i) for i in input().split()] for j in range(N)]
print(max([sum([P[shop][sum([i * j for (i, j) in zip([i >> k & 1 for k in range(10)], F[shop])])] for shop in range(N)]) for i in range(1, 1024)]))


N = int(input())
F = [[int(i) for i in input().split()] for j in range(N)]
P = [[int(i) for i in input().split()] for k in range(N)]
x = -10 ** 10
for i in range(1, 2 ** 10):
	L = [int(b) for b in '{:0>10}'.format(str(bin(i))[2:])]
	y = 0
	for n in range(N):
		m = sum([l & f for (l, f) in zip(L, F[n])])
		y += P[n][m]
	x = max(x, y)
print(x)


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


n = int(input())
F = [int(input().replace(' ', ''), 2) for _ in range(n)]
P = [list(map(int, input().split())) for _ in range(n)]
ans = -10 ** 10
for sp in range(1, 1024):
	total = 0
	for i in range(n):
		b = bin(F[i] & sp)
		total += P[i][b.count('1')]
	ans = max(ans, total)
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 = -10 ** 18
for i in range(1, 2 ** 10):
	x = 0
	for n in range(N):
		c = 0
		for j in range(10):
			if i >> j & F[n][j]:
				c += 1
		x += P[n][c]
	ans = max(ans, x)
print(ans)


from operator import mul
n = int(input())
cof = [1 << x for x in range(10)]
fs = [sum(map(mul, map(int, input().split()), cof)) for _ in range(n)]
ps = [list(map(int, input().split())) for _ in range(n)]
ans = float('-inf')
for g in range(1, 1024):
	ans = max(ans, sum((p[bin(f & g).count('1')] for (f, p) in zip(fs, ps))))
print(ans)


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


N = int(input())
F = [int(input().replace(' ', ''), 2) for i in range(N)]
P = [[int(j) for j in input().split()] for j in range(N)]
ans = -float('inf')
for i in range(1, 2 ** 10):
	temp = 0
	for j in range(N):
		temp += P[j][bin(i & F[j]).count('1')]
	ans = max(ans, temp)
print(ans)


N = int(input())
F = [int(input().replace(' ', ''), 2) for i in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]
ans = -10 ** 18
for i in range(1, 2 ** 10):
	s = 0
	for (f, p) in zip(F, P):
		s += p[bin(f & i).count('1')]
	ans = max(ans, s)
print(ans)


n = int(input())
f = [[int(x) for x in input().split()] for i in range(n)]
p = [[int(x) for x in input().split()] for i in range(n)]
t = {i: 0 for i in range(1, 2 ** 10)}
for i in range(1, 2 ** 10):
	(d, b) = ({j: 0 for j in range(n)}, format(i, '010b'))
	for j in range(n):
		for k in range(10):
			if (i >> k) % 2 & f[j][k] == 1:
				d[j] += 1
		t[i] += p[j][d[j]]
print(max(t.values()))


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 = [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)


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


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)


n = int(input())
f = [list(input().split()) for _ in range(n)]
p = [list(map(int, input().split())) for _ in range(n)]
result = []
for i in range(1, 2 ** 10):
	b = format(i, '010b')
	r = 0
	for j in range(n):
		c = [1 for I in range(10) if b[I] == f[j][I] == '1']
		r += p[j][len(c)]
	result.append(r)
print(max(result))


N = int(input())
F = [list(map(int, input().split())) for i in range(2 * N)]
(F, P) = (F[:N], F[N:])
from itertools import product
r = -10 ** 9
for i in range(1, 1024):
	x = [(i >> 9 - j) % 2 for j in range(10)]
	r = max(r, sum([P[j][sum([F[j][i] * x[i] for i in range(10)])] for j in range(N)]))
print(r)


n = int(input())
f = [list(map(int, input().split())) for _ in [0] * n]
p = [list(map(int, input().split())) for _ in [0] * n]
s = -float('inf')
for i in range(1, 2 ** 10):
	l = list(map(int, '0' * (12 - len(bin(i))) + bin(i)[2:]))
	s = max(s, sum((p[j][sum((l[i] and f[j][i] for i in range(10)))] for j in range(n))))
print(s)


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)


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


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)


import sys
input = sys.stdin.readline
n = int(input())
f = [int(''.join(input().split()), base=2) for _ in range(n)]
p = [list(map(int, input().split())) for _ in range(n)]
ans = -10 ** 10
for i in range(1, 1 << 10):
	profit = 0
	for j in range(n):
		cnt = bin(i & f[j]).count('1')
		profit += p[j][cnt]
	ans = max(ans, profit)
print(ans)


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

def cost(i):
	tem = 0
	for j in range(N):
		d = bin(i & F2[j]).count('1')
		tem += P[j][d]
	return tem
for i in range(1, 2 ** 10):
	ans = max(ans, cost(i))
print(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 = []
for _ in range(N):
	f = input().split()
	fn = int(''.join(f), 2)
	F.append(fn)
P = [list(map(int, input().split())) for _ in range(N)]
ans = -100000000000
for k in range(1, 2 ** 10):
	val = 0
	for i in range(N):
		c = bin(k & F[i]).count('1')
		val += P[i][c]
	ans = max(ans, val)
print(ans)


n = int(input())
f = []
for _ in [0] * n:
	f += [list(map(int, input().split()))]
p = []
for _ in [0] * n:
	p += [list(map(int, input().split()))]
m = -10000001 * n
for x in range(1, 1024):
	k = 0
	s = format(x, '010b')
	for t in range(n):
		k += p[t][sum([int(s[i]) * f[t][i] for i in range(10)])]
	m = max(m, k)
print(m)


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 = -(1 << 30)
for b in range(1, 1 << 10):
	tmp = 0
	for i in range(N):
		cnt = 0
		for j in range(10):
			if b >> j & 1 and F[i][j]:
				cnt += 1
		tmp += P[i][cnt]
	ans = max(ans, tmp)
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, 1024):
	tmp = 0
	for j in range(N):
		cnt = 0
		for k in range(10):
			if i >> k & 1 & F[j][k]:
				cnt += 1
		tmp += P[j][cnt]
	ans = max(ans, tmp)
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)


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)


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 range(1, 1024):
	t = 0
	for j in range(N):
		t += P[j][sum((i >> k & 1 & F[j][k] for k in range(10)))]
	if t > result:
		result = t
print(result)


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 = [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 = []
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 i in range(n)]
P = [list(map(int, input().split())) for i in range(n)]
ans = -float('inf')
for j in range(1, 2 ** 10):
	A = list(str(bin(j))[2:])
	for i in range(10 - len(A)):
		A.insert(0, '0')
	prof = 0
	for i in range(n):
		k = sum((int(p) * q for (p, q) in zip(A, F[i])))
		prof += P[i][k]
	ans = max(ans, prof)
print(ans)


n = int(input())
F = [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):
	cnt = 0
	num = format(i, 'b').zfill(10)
	for (j, k) in enumerate(F):
		cnt += P[j][len([True for m in range(10) if k[m] == num[m] == '1'])]
	ans = max(ans, cnt)
print(ans)


n = int(input())
F = []
for i in range(n):
	F.append(input().replace(' ', ''))
P = []
for i in range(n):
	P.append(list(map(int, input().split())))
ans = -10000000000.0
for i in range(1, 2 ** 10):
	s = 0
	for j in range(n):
		tmp = int(F[j], 2)
		tmp = i & tmp
		c = bin(tmp).count('1')
		s += P[j][c]
	if s > ans:
		ans = s
print(ans)


n = int(input())
f = [[int(i) for i in input().split()] for _ in range(n)]
p = [[int(i) for i in input().split()] for _ in range(n)]
ans = -float('inf')
for x in range(1, 1 << 10):
	res = 0
	for i in range(n):
		cnt = 0
		for j in range(10):
			if x >> j & 1 and f[i][j]:
				cnt += 1
		res += p[i][cnt]
	ans = max(ans, res)
print(ans)


N = int(input())
F = [int(''.join(input().split()), 2) for i in range(N)]
P = [list(map(int, input().split())) for i in range(N)]
ans = float('-inf')
for bit in range(1, 1024):
	sum_p = 0
	for shop in range(N):
		time = bin(F[shop] & bit).count('1')
		sum_p += P[shop][time]
	ans = max(sum_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 bit in range(1, 1 << 10):
	cc = 0
	for i in range(n):
		c = 0
		for j in range(10):
			if bit >> j & 1 and f[i][j]:
				c += 1
		cc += p[i][c]
	ans = max(ans, cc)
print(ans)


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)


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 bit in range(1, 1 << 10):
	a = 0
	for i in range(n):
		b = 0
		for j in range(10):
			if bit & 1 << j:
				b += f[i][j]
		a += p[i][b]
	ans = max(a, ans)
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()


N = int(input())
F = [tuple(map(int, input().split())) for i in range(N)]
P = [tuple(map(int, input().split())) for i in range(N)]
ans = -10 ** 18
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 F[i][k]:
				c += 1
		tmp += P[i][c]
	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()


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


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

def SL():
	return input().split()

def I():
	return int(input())

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


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


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 i in range(n)]
p = [list(map(int, input().split())) for j in range(n)]
l = []
for k in range(1, 1024):
	l.append(format(k, '010b'))
L = []
for m in range(1023):
	C = 0
	for q in range(n):
		c = 0
		for r in range(10):
			if f[q][r] * int(l[m][r]) == 1:
				c += 1
		C += p[q][c]
	L.append(C)
print(max(L))


N = int(input())
F = [int(input().replace(' ', ''), 2) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]
ans = -10 ** 10
for i in range(1, 1 << 10):
	ans = max(ans, sum((P[n][bin(i & F[n]).count('1')] for n in range(N))))
print(ans)


N = int(input())
(F, P) = ([], [])
for _ in range(N):
	F.append(int(''.join(list(map(str, input().split()))), 2))
for _ in range(N):
	P.append(list(map(int, input().split())))
ans = -10000000000.0
for i in range(1, 2 ** 10):
	temp = 0
	for j in range(N):
		temp += P[j][bin(i & F[j]).count('1')]
	if temp > ans:
		ans = temp
print(ans)


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


N = int(input())
F = [int(input().replace(' ', ''), 2) for _ in [0] * N]
P = [list(map(int, input().split())) for _ in [0] * N]
print(max([sum([P[j][bin(i & F[j]).count('1')] for j in range(N)]) for i in range(1, 1024)]))


N = int(input())
S = []
for _ in range(N):
	s = int(''.join(input().split()), 2)
	S.append(s)
P = []
for _ in range(N):
	p = [int(i) for i in input().split()]
	P.append(p)
ans = -10 ** 20
for i in range(1, 2 ** 10):
	c = 0
	for j in range(N):
		c += P[j][bin(S[j] & i).count('1')]
	ans = max(ans, c)
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)]
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)


from itertools import product
from operator import and_
N = int(input())
F = [tuple(map(lambda s: s == '1', input().split())) for _ in range(N)]
P = [tuple(map(int, input().split())) for _ in range(N)]
print(max((sum((P[i][sum(map(and_, F[i], prod))] for i in range(N))) for prod in product((True, False), repeat=10) if sum(prod))))


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


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


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)


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')]).T
	c = np.dot(F, Open)
	hq.heappush(Profit, -sum((P[i, c[i]] for i in range(N))))
print(-Profit[0])


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)


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 k in range(1, 2 ** 10):
	(*bi,) = map(int, bin(k).zfill(10).replace('b', '0')[::-1])
	ans = max(ans, sum([p[i][[bi[j] & f[i][j] for j in range(10)].count(1)] for i in range(n)]))
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):
	i = list(map(int, list(bin(i)[2:].zfill(10))))
	(x, y) = (0, 0)
	for j in range(n):
		y = 0
		for k in range(10):
			if i[k] == f[j][k] == 1:
				y += 1
		x += p[j][y]
	ans = max(ans, x)
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 = -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 _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]
ans = float('-inf')
for i in range(1, 1 << 10):
	res = 0
	for n in range(N):
		count = 0
		for j in range(10):
			if i & F[n][j] << j:
				count += 1
		res += P[n][count]
	ans = max(res, ans)
print(ans)


N = int(input())
F = [int(input().replace(' ', ''), 2) for _ in range(N)]
P = [list((int(i) for i in input().split())) for _ in range(N)]
ans = -10 ** 10
for i in range(1, 1 << 10):
	prof = 0
	for (j, f) in enumerate(F):
		prof += P[j][bin(i & f).count('1')]
	ans = max(ans, prof)
print(ans)


import itertools
n = int(input())
lf = [list(map(int, input().split())) for _ in range(n)]
lp = [list(map(int, input().split())) for _ in range(n)]
lit = list(itertools.product([0, 1], repeat=10))[1:]
ans = -10 ** 9
for i in lit:
	tmp = 0
	for (num, j) in enumerate(lf):
		com = sum([k * l for (k, l) in zip(i, j)])
		tmp += lp[num][com]
	ans = max(ans, tmp)
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)]
l = [0] * 1024
for i in range(1024):
	I = format(i, 'b').zfill(10)
	for k in range(n):
		c = 0
		for j in range(10):
			if I[j] == '1' and f[k][j] == 1:
				c += 1
		l[i] += p[k][c]
print(max(l[1:]))


n = int(input())
F = []
P = []
for _ in range(n):
	b = ''.join(input().split())
	F.append(int(b, 2))
for _ in range(n):
	inp = list(map(int, input().split()))
	P.append(inp)
ans = -10 ** 18
for i in range(1, 1024):
	earn = 0
	for (j, f) in enumerate(F):
		same = bin(i & f)[2:].zfill(10)
		same = same.count('1')
		earn += P[j][same]
	ans = max(ans, earn)
print(ans)


n = int(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))


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)


N = int(input())
SO = [int(input().replace(' ', ''), 2) for i in range(N)]
PT = [list(map(int, input().split())) for i in range(N)]
ret = -10 ** 7 * N
for sp in range(1, 2 ** 10):
	r = 0
	for i in range(N):
		r += PT[i][bin(SO[i] & sp).count('1')]
	ret = max(ret, r)
print(ret)


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)


n = int(input())
F = [list(map(int, input().split())) for _ in range(n)]
P = [list(map(int, input().split())) for _ in range(n)]
m = -10 ** 10
for i in range(1, 1024):
	r = 0
	for (f, p) in zip(F, P):
		r += p[bin(i & int(''.join((str(_) for _ in f)), 2))[2:].count('1')]
	m = max(r, m)
print(m)


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)


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)


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)


N = int(input())
F = [int(input().replace(' ', ''), 2) for _ in range(N)]
P = [tuple(map(int, input().split())) for _ in range(N)]
ans = -(10 ** 7 * N)
for o in range(1, 1 << 10):
	p = 0
	for i in range(N):
		p += P[i][bin(F[i] & o).count('1')]
	ans = max(ans, p)
print(ans)


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\n1 1 0 1 0 0 0 1 0 1\n3 4 5 6 7 8 9 -2 -3 4 -2'
		output = '8'
		self.assertIO(input, output)

	def test_入力例_2(self):
		input = '2\n1 1 1 1 1 0 0 0 0 0\n0 0 0 0 0 1 1 1 1 1\n0 -2 -2 -2 -2 -2 -1 -1 -1 -1 -1\n0 -2 -2 -2 -2 -2 -1 -1 -1 -1 -1'
		output = '-2'
		self.assertIO(input, output)

	def test_入力例_3(self):
		input = '3\n1 1 1 1 1 1 0 0 1 1\n0 1 0 1 1 1 1 0 1 0\n1 0 1 1 0 1 0 1 0 1\n-8 6 -2 -8 -8 4 8 7 -6 2 2\n-9 2 0 1 7 -5 0 -2 -6 5 5\n6 -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():
	resolve()
__starting_point()


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 ** 10
for f in list(itertools.product([0, 1], repeat=10))[1:]:
	p = sum([P[i][sum([F[i][j] * f[j] for j in range(10)])] for i in range(N)])
	ans = max(ans, p)
print(ans)


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


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


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)


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


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 = [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)


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)


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 = -10 ** 9
for i in range(1, 1 << 10):
	r = 0
	for j in range(n):
		r += P[j][str(bin(i & F[j])).count('1')]
	ans = max(ans, r)
print(ans)


n = int(input())
F = [int(input().replace(' ', ''), 2) for _ in range(n)]
P = [list(map(int, input().split())) for _ in range(n)]
answer = -float('inf')
for i in range(1, 2 ** 10):
	temporary = 0
	for j in range(n):
		c = bin(i & F[j]).count('1')
		temporary += P[j][c]
	answer = max(answer, temporary)
print(answer)


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


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


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)


n = int(input())
F = []
ans = -float('inf')
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):
	tmp = 0
	for j in range(n):
		cnt = bin(i & F[j]).count('1')
		tmp += p[j][cnt]
	else:
		ans = max(ans, tmp)
print(ans)


N = int(input())
f = [int(input().replace(' ', ''), 2) for _ in range(N)]
p = [list(map(int, input().split())) for _ in range(N)]
g = -9999999999
for i in range(1, 1024):
	gg = 0
	for j in range(N):
		s = format(i & f[j], 'b').zfill(10)
		c = s.count('1')
		gg += p[j][c]
	g = max(g, gg)
print(g)


n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
b = [list(map(int, input().split())) for _ in range(n)]
ans = []
for i in range(1, 2 ** 10):
	dp = [0] * n
	for j in range(10):
		if i >> j & 1:
			for k in range(n):
				dp[k] += a[k][j]
	ans.append(sum([b[x][y] for (x, y) in enumerate(dp)]))
print(max(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 ** 18
for i in range(1, 2 ** 10):
	op = [0] * 10
	res = 0
	for j in range(10):
		if i >> j & 1:
			op[j] = 1
	for j in range(n):
		cnt = 0
		for k in range(10):
			if op[k] & f[j][k]:
				cnt += 1
		res += p[j][cnt]
	ans = max(ans, res)
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 = -10 ** 15
for i in range(1, 2 ** 10):
	tmp = 0
	for k in range(N):
		c = 0
		for j in range(10):
			if i >> j & 1 and F[k][j]:
				c += 1
		tmp += P[k][c]
	ans = max(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)]
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 = [list(map(int, input().split())) for _ in range(n)]
p = [list(map(int, input().split())) for _ in range(n)]
ans = []
for i in range(1, 2 ** 10):
	a = [0] * n
	for j in range(10):
		if i >> j & 1:
			for k in range(n):
				a[k] += f[k][j]
	ans.append(sum([p[i][a[i]] for i in range(n)]))
print(max(ans))


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, 2 ** 10):
	t = 0
	for j in range(n):
		c = bin(F[j] & i).count('1')
		t += P[j][c]
	ans = max(ans, t)
print(ans)


import sys
r = sys.stdin.readline
N = int(r())
F = [int(r().replace(' ', ''), 2) for _ in [0] * N]
P = [list(map(int, r().split())) for _ in [0] * N]
print(max((sum([p[bin(f & i).count('1')] for (f, p) in zip(F, P)]) for i in range(1, 2 ** 10))))


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)


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 = -10 ** 10
for i in range(1, 2 ** 10):
	open_n = [0] * N
	profit = 0
	for j in range(10):
		if i >> j & 1:
			for k in range(N):
				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)


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(1, pow(2, 10)):
	res = 0
	for j in range(n):
		cnt = 0
		for k in range(10):
			if i >> k & 1 and f[j][k]:
				cnt += 1
		res += p[j][cnt]
	ans = max(ans, res)
print(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 = -10 ** 10
for i in range(1, 2 ** 10):
	a = 0
	for (f, p) in zip(F, P):
		a += p[bin(f & i).count('1')]
	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)]
ans = []
for i in range(1, 2 ** 10):
	x = list(map(int, bin(i)[2:].zfill(10)))
	_ans = 0
	for j in range(n):
		c = sum(map(lambda x, y: x * y, x, f[j]))
		_ans += p[j][c]
	ans.append(_ans)
print(max(ans))


N = int(input())
F = [int(input().replace(' ', ''), 2) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]
profit = float('-inf')
for i in range(1, 1024):
	tmp = 0
	tmp2 = 0
	for j in range(N):
		tmp = bin(i & F[j]).count('1')
		tmp2 = tmp2 + P[j][tmp]
	profit = max(profit, tmp2)
print(profit)


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


import sys
sys.setrecursionlimit(2147483647)
INF = float('inf')
MOD = 10 ** 9 + 7
input = sys.stdin.readline

def resolve():
	n = int(input())
	run = [int(input().replace(' ', ''), 2) for _ in range(n)]
	profit = [tuple(map(int, input().split())) for _ in range(n)]
	print(max((sum((profit[j][bin(run[j] & i).count('1')] for j in range(n))) for i in range(1, 1 << 10))))
resolve()


n = int(input())
f = [list(map(int, input().split())) for i in range(n)]
p = [list(map(int, input().split())) for i in range(n)]
ans = -float('inf')
for i in range(1, 1 << 10):
	score = 0
	for j in range(n):
		cnt = 0
		for k in range(10):
			if i & 1 << k and f[j][k] == 1:
				cnt += 1
		score += p[j][cnt]
	ans = max(ans, score)
print(ans)


N = int(input())
F = [list(input().split()) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]
ans = []
for i in range(1, 2 ** 10):
	tmp = 0
	for j in range(N):
		b = ''.join(F[j])
		ct = 0
		for k in range(10):
			if i >> k & int(b[k]):
				ct += 1
		tmp += P[j][ct]
	ans.append(tmp)
print(max(ans))


N = int(input())
F = [int(input().replace(' ', ''), 2) for _ in range(N)]
P = [[int(x) for x in input().split()] for _ in range(N)]
C = [sum(map(int, format(i, 'b'))) for i in range(2 ** 10)]
print(max([sum([p[C[f & i]] for (f, p) in zip(F, P)]) for i in range(1, 2 ** 10)]))


n = int(input())
F = [int('0b' + ''.join(input().split()), 0) for _ in range(n)]
P = [list(map(int, input().split())) for _ in range(n)]
ans = -10000000000.0
for i in range(1, 2 ** 10):
	m = 0
	for (f, p) in zip(F, P):
		m += p[bin(i & f).count('1')]
	ans = max(ans, m)
print(ans)


N = int(input())
F = [''.join(input().split()) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]
x = [int(v, 2) for v in F]
rev = []
for i in range(1, 2 ** 10):
	cnt = [list(bin(i & v)[2:]).count('1') for v in x]
	rev.append(sum([P[j][cnt[j]] for j in range(N)]))
print(max(rev))


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 = [list(map(int, input().split())) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]
(max_first, max_second) = (0, 0)
max_v = -float('inf')
for p in range(1, 1 << 10):
	v = 0
	for n in range(N):
		c = 0
		for m in range(10):
			c += (p & 1 << m != 0) & F[n][m]
		v += P[n][c]
	max_v = max(max_v, v)
print(max_v)


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())
flst = []
for _ in range(n):
	flst.append([int(i) for i in input().split()])
plst = []
for _ in range(n):
	plst.append([int(i) for i in input().split()])
m = -1 << 30
for i in range(1, 1 << 10):
	r = 0
	for j in range(n):
		c = 0
		for k in range(10):
			if i >> k & 1 & flst[j][k]:
				c += 1
		r += plst[j][c]
	m = max(m, r)
print(m)


N = int(input())
F = [int(input().replace(' ', ''), 2) for i in range(N)]
P = [[int(j) for j in input().split()] for j in range(N)]
a = -10 ** 10
for i in range(1, 1024):
	a = max(a, sum([P[j][bin(i & F[j]).count('1')] for j in range(N)]))
print(a)


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 = [int(input().replace(' ', ''), 2) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]
outcome_list = []
for i in range(1, 1 << 10):
	outcome = 0
	for (f, p) in zip(F, P):
		n_store = '{:010b}'.format(i & f).count('1')
		outcome += p[n_store]
	outcome_list.append(outcome)
print(max(outcome_list))


N = int(input())
F = [int(input().replace(' ', ''), 2) for _ in range(N)]
P = [[int(_) for _ in input().split()] for _ in range(N)]
ans = -10 ** 10
for i in range(1, 2 ** 10):
	ans = max(ans, sum([P[j][bin(i & F[j]).count('1')] for j in range(N)]))
print(ans)


n = int(input())
f = [list(input().split()) for _ in range(n)]
p = [list(map(int, input().split())) for _ in range(n)]
print(max((sum((p[j][sum((f[j][x] == '1' and format(i, '010b')[x] == '1' for x in range(10)))] for j in range(n))) for i in range(1, 2 ** 10))))


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)


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)


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


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)


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)


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):
	bit = i
	profit = 0
	for j in range(N):
		cnt = sum((F[j][k] & bit >> k for k in range(10)))
		profit += P[j][cnt]
	ans = max(ans, profit)
print(ans)


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
		sc += score[i][cnt]
	ans = max(ans, sc)
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 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 F[i][k]:
				c += 1
		tmp += P[i][c]
	ans = max(ans, tmp)
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)]
pls = []
for i in range(1, 2 ** 10):
	bin = format(i, 'b').zfill(10)
	pf = 0
	for x in range(n):
		cnt = 0
		for j in range(10):
			if int(bin[j]) == f[x][j] == 1:
				cnt += 1
		pf += p[x][cnt]
	pls.append(pf)
print(max(pls))


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 = 0
for j in range(n):
	ans += p[j][f[j][0] & 1]
for i in range(2, 1024):
	bene = 0
	for j in range(n):
		count = 0
		for k in range(10):
			count += f[j][k] & i >> k
		bene += p[j][count]
	ans = max(ans, bene)
print(ans)


N = int(input())
F_list = [int(input().replace(' ', ''), 2) for _ in range(N)]
P_list = [list(map(int, input().split())) for _ in range(N)]
max_p = float('-inf')
for i in range(1, 1024):
	p = 0
	for j in range(len(F_list)):
		c = format(i & F_list[j], 'b').count('1')
		p += P_list[j][c]
	if p > max_p:
		max_p = p
print(max_p)


import sys
input = sys.stdin.readline
N = int(input())
F = [int(input().replace(' ', ''), 2) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]
ans = -10 ** 18
for i in range(1, 2 ** 10):
	cnt = 0
	for j in range(N):
		cnt += P[j][bin(F[j] & i).count('1')]
	ans = max(ans, cnt)
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)]
max_ans = -float('inf')
for i in range(1, 1024):
	ans = 0
	for j in range(n):
		ans += P[j][list(str(bin(i & F[j]))).count('1')]
	if ans > max_ans:
		max_ans = ans
print(max_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())


import itertools
N = int(input())
F = [list(map(int, input().split())) for i in range(N)]
P = [list(map(int, input().split())) for i in range(N)]
ans = int(-1e+16)
for k in range(1, 11):
	for j in itertools.combinations(range(10), k):
		tmp = 0
		for (f, p) in zip(F, P):
			num = sum([f[cnt] for cnt in j])
			tmp += p[num]
		ans = max(ans, tmp)
print(ans)


N = int(input())
F = [int(input().replace(' ', ''), 2) for _ in range(N)]
P = [[int(a) for a in input().split()] for _ in range(N)]
ma = -(1 << 100)
for k in range(1, 1024):
	s = 0
	for i in range(N):
		s += P[i][bin(F[i] & k).count('1')]
	ma = max(ma, s)
print(ma)


N = int(input())
F = [list(map(int, input().split())) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]
l = [0] * (2 ** 10 - 1)
for i in range(1, 2 ** 10):
	op = list(map(int, list(bin(i)[2:].zfill(10))))
	for n in range(N):
		c = 0
		for o in range(10):
			if op[o] == 1 and F[n][o] == 1:
				c += 1
		l[i - 1] += P[n][c]
print(max(l))


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)


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)


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
	elif BenefitMax < Benefit:
		BenefitMax = Benefit
print(int(BenefitMax))


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


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)


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)


from itertools import product
n = int(input())
fs = [[int(x) for x in input().split()] for _ in range(n)]
ps = [[int(x) for x in input().split()] for _ in range(n)]
xs = product((0, 1), repeat=10)
next(xs)
print(max((sum((p[sum((a == b == 1 for (a, b) in zip(f, x)))] for (f, p) in zip(fs, ps))) for x in xs)))


n = int(input())
f = [int(input()[::2], 2) for i in range(n)]
p = [list(map(int, input().split())) for l in range(n)]
ans = -float('inf')
for h in range(1, 1024):
	ans = max(ans, sum((p[g][sum(list(map(int, bin(f[g] & h)[2:])))] for g in range(n))))
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 = -10000000000
for bit in range(1, 1 << 10):
	now = 0
	for i in range(N):
		c = 0
		for j in range(10):
			if 1 & bit >> j & F[i][j]:
				c += 1
		now += P[i][c]
	ans = max(ans, now)
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 = -(1 << 60)
for bit in range(1, 1 << 10):
	tmp = 0
	for i in range(N):
		cnt = 0
		for j in range(10):
			if bit >> j & 1 and F[i][j]:
				cnt += 1
		tmp += P[i][cnt]
	if ans < tmp:
		ans = tmp
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 _ in range(N):
	f = [int(s) for s in input().split()]
	b = sum([v * (1 << i) for (i, v) in enumerate(f)])
	F.append(b)
P = []
for _ in range(N):
	p = [int(s) for s in input().split()]
	P.append(p)
ans = max([sum([P[j][bin(i & F[j]).count('1')] for j in range(N)]) for i in range(1, 2 ** 10)])
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 = -10 ** 9
for bit in range(1, 2 ** 10):
	cc = 0
	for i in range(n):
		c = 0
		for j in range(10):
			if bit & 1 << j and f[i][j]:
				c += 1
		cc += p[i][c]
	ans = max(ans, cc)
print(ans)


n = int(input())
f_list = [int(''.join(input().split()), 2) for _ in range(n)]
p_list = [[int(x) for x in input().split()] for _ in range(n)]
ans = -10 ** 10
for i in range(1, 2 ** 10):
	temp = 0
	for j in range(n):
		temp += p_list[j][bin(i & f_list[j]).count('1')]
	if temp > ans:
		ans = temp
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, 1024):
	price = 0
	for j in range(n):
		price += p[j][bin(i & f[j]).count('1')]
	ans = max(ans, price)
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 k in range(1, 1 << 10):
	tmp = 0
	for (fs, ps) in zip(F, P):
		cnt = 0
		for b in range(10):
			if k >> b & 1 and fs[b]:
				cnt += 1
		tmp += ps[cnt]
	ans = max(ans, tmp)
print(ans)


def bitcount(x):
	x = x - (x >> 1 & 6148914691236517205)
	x = (x & 3689348814741910323) + (x >> 2 & 3689348814741910323)
	x = x + (x >> 4) & 1085102592571150095
	x = x + (x >> 8)
	x = x + (x >> 16)
	x = x + (x >> 32)
	return x & 127

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 = [tuple(map(int, input().split())) for _ in range(n)]
p = [tuple(map(int, input().split())) for _ in range(n)]
bit = 1 << 10
ans = -10 ** 10
for i in range(1, bit):
	tmp = 0
	for j in range(n):
		cj = 0
		for k in range(10):
			cj += f[j][k] & i >> k
		tmp += p[j][cj]
	ans = max(ans, tmp)
print(ans)


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)


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


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)


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)]
bit = list(itertools.product([0, 1], repeat=10))
bit.pop(0)
ans = -10 ** 10
for i in range(1023):
	a = 0
	for j in range(N):
		t = sum([F[j][k] * bit[i][k] for k in range(10)])
		a += P[j][t]
	ans = max(a, ans)
print(ans)


import sys
input = sys.stdin.readline
N = int(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)


f = lambda : [list(map(int, input().split())) for _ in range(n)]
n = int(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)


n = int(input())
flst = []
for _ in range(n):
	flst.append(int(''.join(input().split()), 2))
plst = []
for _ in range(n):
	plst.append([int(i) for i in input().split()])
m = -1 << 30
for i in range(1, 1 << 10):
	r = 0
	for j in range(n):
		s = i & flst[j]
		c = 0
		while s:
			s &= s - 1
			c += 1
		r += plst[j][c]
	m = max(m, r)
print(m)


n = int(input())
m = 10
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, 2 ** m):
	s = 0
	for j in range(n):
		cnt = 0
		for k in range(m):
			if i >> k & 1 and f[j][k]:
				cnt += 1
		s += p[j][cnt]
	ans = max(s, ans)
print(ans)


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
p = [list(map(int, input().split())) for i in range(n)]
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]
	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)


n = int(input())
F = [int(input().replace(' ', ''), 2) for _ in range(n)]
P = [list(map(int, input().split())) for _ in range(n)]
ans = []
for i in range(1, 1024):
	p = 0
	for j in range(n):
		p += P[j][bin(i & F[j]).count('1')]
	ans.append(p)
print(max(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):
	X = [0] * N
	for j in range(N):
		count = 0
		for k in range(10):
			if i >> k & 1 == 1 and F[j][k] == 1:
				count += 1
		X[j] = P[j][count]
	ans = max(ans, sum(X))
print(ans)


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


N = int(input())
F = [''.join(input().split()) for i in range(N)]
P = [list(map(int, input().split())) for i in range(N)]
ans = -1 * float('inf')
for i in range(1, 2 ** 10):
	tmp = 0
	for j in range(N):
		product = i & int(F[j], base=2)
		c = bin(product).count('1')
		tmp += P[j][c]
	ans = max(ans, tmp)
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)


N = int(input())
F = [list(input().split()) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]
ans = -10 ** 9
for i in range(1, 2 ** 10):
	tmp = 0
	for j in range(N):
		f = int('0b' + ''.join(F[j]), 0)
		tmp += P[j][bin(i & f).count('1')]
	ans = max(ans, tmp)
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, 2 ** 10):
	score = 0
	jonson = [0 for _ in range(10)]
	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 = [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):
	psum = 0
	for j in range(n):
		cnt = 0
		for k in range(10):
			if i >> k & 1 == 1 and f[j][k] == 1:
				cnt += 1
		psum += p[j][cnt]
	ans = max(ans, psum)
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 ** 18
for i in range(1 << 10):
	if i == 0:
		continue
	tp = 0
	for j in range(n):
		tcnt = 0
		for k in range(10):
			if i & 1 << k:
				tcnt += f[j][k]
		tp += p[j][tcnt]
	ans = max(ans, tp)
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()))
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)


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)


from itertools import product

def solve(n, FF, PP):
	return max((sum((P[sum((i & f for (i, f) in zip(I, F)))] for (F, P) in zip(FF, PP))) for I in list(product(range(2), repeat=10))[1:]))
_n = int(input())
_FF = [list(map(int, input().split())) for _ in range(_n)]
_PP = [list(map(int, input().split())) for _ in range(_n)]
print(solve(_n, _FF, _PP))


N = int(input())
ans = -10 ** 9
s = [''.join(list(input().split())) for i in range(N)]
t = [list(map(int, input().split())) for i in range(N)]
for j in range(1, 1024):
	q = 0
	for i in range(len(s)):
		q += t[i][bin(int(s[i], 2) & j).count('1')]
	ans = max(ans, q)
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, 2 ** 10):
	res = 0
	for j in range(n):
		cnt = sum([i >> k & 1 & f[j][k] for k in range(10)])
		res += p[j][cnt]
	ans = max(ans, res)
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)


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)


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 & 6148914691236517205) + (n >> 1 & 6148914691236517205)
	c = (c & 3689348814741910323) + (c >> 2 & 3689348814741910323)
	c = (c & 1085102592571150095) + (c >> 4 & 1085102592571150095)
	c = (c & 71777214294589695) + (c >> 8 & 71777214294589695)
	c = (c & 281470681808895) + (c >> 16 & 281470681808895)
	c = (c & 4294967295) + (c >> 32 & 4294967295)
	return c
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)


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


n = int(input())
f = [list(map(int, input().split())) for _ in range(n)]
p = [list(map(int, input().split())) for _ in range(n)]
ans = -pow(10, 9)
for i in range(1, 2 ** 10):
	s = []
	for j in range(10):
		if i >> j & 1:
			s.append(j)
	ansi = 0
	for j in range(n):
		ansi += p[j][sum([f[j][si] for si in s])]
	ans = max(ans, ansi)
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
	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
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()


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)


n = int(input())
f = ['' for _ in range(n)]
p = [[] for _ in range(n)]
for i in range(n):
	f[i] = int(''.join(input().split()), 2)
for i in range(n):
	p[i] = list(map(int, input().split()))
ans = -10 ** 9
for i in range(1, 1024):
	tmp = 0
	for j in range(n):
		k = str(format(i & f[j], '010b')).count('1')
		tmp += p[j][k]
	ans = max(ans, tmp)
print(ans)


N = int(input())
F = [int(input().replace(' ', ''), 2) for _ in range(N)]
P = [[int(i) for i in input().split()] for _ in range(N)]
ma = -1e+20
for i in range(1, 2 ** 10):
	count = 0
	for (f, p) in zip(F, P):
		count += p[bin(f & i).count('1')]
	ma = max(ma, count)
print(ma)


N = int(input())
F = [int(input().replace(' ', ''), 2) for _ in [0] * N]
P = [list(map(int, input().split())) for _ in [0] * N]
ans = -float('inf')
for i in range(1, 2 ** 10):
	sum = 0
	for k in range(N):
		sum += P[k][bin(F[k] & i).count('1')]
	if ans < sum:
		ans = sum
print(ans)


n = int(input())
f = []
for _ in range(n):
	s = 0
	l = list(map(int, input().split()))
	for i in range(10):
		s += l[i] << i
	f.append(s)
p = [list(map(int, input().split())) for _ in range(n)]
b = []
for i in range(1, 1024):
	w = 0
	for j in range(n):
		idx = format(i & f[j], 'b').count('1')
		w += p[j][idx]
	b.append(w)
print(max(b))