#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
#include <random>
#include <cassert>
using namespace std;

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<int, ll> i_ll;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int v; ll w; };

const int MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;
int INF = INT_MAX / 2;

int main() {
	for (;;) {
		int N; cin >> N;
		if (!N) break;
		vector<int> a(N);
		rep(i, N) scanf("%d", &a[i]);
		vector<vector<int> > as(501);
		for (int x: a) {
			int y;
			for (y = x; y % 2 == 0; y /= 2);
			as[y].pb(x / y);
		}
		int ans = 0;
		for (vector<int> a: as) {
			if (a.empty()) continue;
			int M = 0;
			for (int x: a) M += x;
			vector<int> dp(M + 1, -INF);
			dp[0] = 0;
			for (int x: a)
				for (int S = M / x * x; S >= x; S -= x)
					dp[S] = max(dp[S], dp[S - x] + 1);
			for (int S = 1; S <= M; S *= 2)
				ans = max(ans, dp[S]);
		}
		cout << ans << endl;
	}
}