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

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

def g(sequence)
  table = [0]
  sum = 0
  sequence.each do |x|
    (sum / x * x).step(0, -x) do |a|
      table[a + x] = [table[a] + 1, table[a + x] || 0].max if table[a]
    end
    sum += x
  end

  best = 0
  i = 1
  while i <= sum
    best = [best, table[i]].max if table[i]
    i *= 2
  end
  best
end

def f(sequence)
  best = 0
  numbers = sequence.map{|k| k / max_divisor(k)}.sort.uniq
  numbers.each do |k|
    subsequence = sequence.select{|x| x % k == 0 && power_of_2?(x / k)}
    min = subsequence.min
    test = g(subsequence.map{|x| x / min})
    best = [test, best].max
  end
  best
end

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