local mfl, mma = math.floor, math.max
local n = io.read("*n")
local f = {}
for i = 1, n * 10 do
  f[i] = (io.read("*n") == 1)
end
local p = {}
for i = 1, n * 11 do
  p[i] = io.read("*n")
end

local score = {}
for i = 1, 1023 do
  local cnt = {}
  local ti = i
  for k = 1, n do cnt[k] = 1 end
  for j = 1, 10 do
    local flg = ti % 2
    ti = mfl(ti / 2)
    if flg == 1 then
      for k = 1, n do
        if f[(k - 1) * 10 + j] then
          cnt[k] = cnt[k] + 1
        end
      end
    end
  end
  score[i] = 0
  for k = 1, n do
    score[i] = score[i] + p[(k - 1) * 11 + cnt[k]]
  end
end
local ret = score[1]
for i = 2, 1023 do
  ret = mma(ret, score[i])
end
print(ret)
