N = gets.to_i
F = N.times.map do
  gets.split.join.to_i(2)
end
P = N.times.map do
  gets.split.map(&:to_i)
end

max = -9999999
(1..1023).each do |i|
  sum = 0
  N.times do |n|
    p = (F[n] & i).to_s(2).chars.count("1")
    sum += P[n][p]
  end
  max = [max, sum].max
end

p max

