def num_of_bits(bits)
  bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555)
  bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333)
  bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f)
  bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff)
  (bits & 0x0000ffff) + (bits >> 16 & 0x0000ffff)
end

N = gets.to_i
Fs = Array.new(N) { gets.split.join.to_i(2) }
Pss = Array.new(N) { gets.split.map(&:to_i) }

S = 1 << 10

ans = -1e9
(1...S).each do |s|
  sum = 0
  N.times do |i|
    sum += Pss[i][num_of_bits(Fs[i] & s)]
  end
  ans = [ans, sum].max
end

puts ans
