#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

vector<int> nums[500];
int dp[134001];

int go(vector<int> &vec){
  int n = vec.size();
  if(n == 0)return 0;
  fill(dp, dp + 134001, -(1 << 30));
  dp[0] = 0;
  for(int i = 0;i < n;i++){
    for(int j = 134000 / vec[i] * vec[i];j - vec[i] >= 0;j -= vec[i]){
      dp[j] = max(dp[j], dp[j-vec[i]] + 1);
    }
  }
  int res = 0;
  for(int i = 1;i < 134001;i *= 2){
    res = max(res, dp[i]);
  }
  return res;
}

void solve(int n){
  int a;
  int res = 0;
  for(int i = 0;i < 500;i++){
    nums[i].clear();
  }
  for(int i = 0;i < n;i++){
    cin >> a;
    int odd = a / (a & -a);
    int even = a / odd;
    nums[odd].push_back(even);
  }

  for(int i = 0;i < 500;i++){
    res = max(res, go(nums[i]));
  }
  
  cout << res << endl;
}


int main(){
  while(true){
    int n;
    cin >> n;
    if(n == 0)break;
    solve(n);
  }
  return 0;
}