def power_of_2?(n)
  (n & (n - 1)) == 0
end

def max_divisor(n)
  (~n & (n - 1)) + 1
end

def g(sequence)
  table = Hash.new(0)
  table[0] = 0
  sequence.each do |x|
    new_table = table.dup
    table.each do |a, count|
      new_table[a + x] = [table[a] + 1, new_table[a + x]].max if a % x == 0
    end
    table = new_table
  end
  table.select{|a, count| power_of_2?(a)}.map{|a, count| count}.max
end

def f(sequence)
  numbers = sequence.map{|k| k / max_divisor(k)}.sort.uniq
  numbers.map{|k|
    subsequence = sequence.select{|x| x % k == 0 && power_of_2?(x / k)}
    g(subsequence.map{|x| x / k})
  }.max
end

loop do
  n = gets.to_i
  break if n == 0
  sequence = gets.split.map!(&:to_i)
  puts f(sequence)
end