import math
import numpy as np
from operator import mul

# 整数Nを桁ごとのリストにする
# l = [int(x) for x in list(str(N))]

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)]
c = list(range(N))

for i in range(1,2^10):
    i_bin = format(i, 'b')
    i_list = [int(x) for x in list(str(i_bin))]
    profit = 0 #それぞれの場合の利益を総当り
    max_p = -10^7-1
    for j in range(N):
        # 店jと同時に開いている時間の数を計算
        combine = map(mul, f[j], i_list)
        c[j] = sum(combine)
        profit += p[j][c[j]]
    if profit > max_p:
        max_p = profit
print(max_p)

