N = int(input())
F = []
P = []
Pre = []
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 loop in range(1,1024):
  rieki = 0
  Fnum = 0
  f = str(format(loop,"b")).rjust(10,"0") #自店の開店時間帯
  for i in range(N): # 全店舗に対し利益計算
    for j in range(10): # 店舗iと同時に営業する時間帯の数
      Fnum = Fnum + F[i][j] * int(f[j])
    #print("時間帯:{}".format(Fnum))
    rieki = rieki + P[i][Fnum] # P行列参照
  #print("rieki is {}".format(rieki))
  Pre.append(rieki) 
print(max(Pre))
  