#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 500001;

int two[10],dp[MAX_N];

int solve(const vi& b)
{
    int n = len(b);
    int sm = accumulate(all(b),0);
    rep(i,sm+1){
        dp[i] = -1;
    }
    dp[0] = 0;
    rep(i,n){
        for(int j = sm/b[i]*b[i]; j >= b[i]; j -= b[i]){
            if(dp[j-b[i]] >= 0){
                cmx(dp[j],dp[j-b[i]]+1);
            }
        }
    }
    int res = 0, nw = 1;
    while(nw <= sm){
        cmx(res,dp[nw]);
        nw *= 2;
    }
    return res;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    two[0] = 1;
    rep(i,9){
        two[i+1] = two[i] * 2;
    }
    while(1){
        int n;
        cin >> n;
        if(n == 0) break;
        vi a(n);
        rep(i,n){
            cin >> a[i];
        }
        int ans = 1;
        srep(i,1,501){
            vi b;
            bool ok = false;
            rep(j,n){
                if(a[j] % i == 0){
                    rep(k,9){
                        if(i*two[k] == a[j]){
                            b.pb(two[k]);
                            if(!k) ok = true;
                        }
                    }
                }
            }
            if(ok) cmx(ans,solve(b));
        }
        cout << ans << "\n";
    }
    return 0;
}

