// Slower C++ solution:
#include <iostream>

#include <cstdio>

#include <cstring>

#include <algorithm>

#include <cmath>

#include <queue>

#include <stack>

#include <map>

#include <set>

#include <vector>

#include <iomanip>

#define ALL(x) (x).begin(), (x).end()

#define dll(x) scanf("%I64d",&x)

#define xll(x) printf("%I64d\n",x)

#define sz(a) int(a.size())

#define all(a) a.begin(), a.end()

#define rep(i,x,n) for(int i=x;i<n;i++)

#define repd(i,x,n) for(int i=x;i<=n;i++)

#define pii pair<int,int>

#define pll pair<long long ,long long>

#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)

#define MS0(X) memset((X), 0, sizeof((X)))

#define MSC0(X) memset((X), '\0', sizeof((X)))

#define pb push_back

#define mp make_pair

#define fi first

#define se second

#define eps 1e-6

#define gg(x) getInt(&x)

#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;

using namespace std;

typedef long long ll;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll powmod(ll a,ll b,ll MOD){ll ans=1ll;while(b){if(b&1)ans=ans*a%MOD;a=a*a%MOD;b>>=1;}return ans;}

inline void getInt(int* p);

const int maxn=1000010;

const int inf=0x3f3f3f3f;

/*** TEMPLATE CODE * * STARTS HERE ***/

int n;

map<ll,int> st;

ll a[maxn];

ll bin[2334];

int main()

{

//	    freopen("C:\\Users\\DH_M\\Desktop\\code_io\\in.txt.txt","r",stdin);

	//    freopen("C:\\Users\\DH_M\\Desktop\\code_io\\out.txt.txt","w",stdout);

	gbtb;

	cin>>n;

	repd(i,1,n)

	{

		cin>>a[i];

		st[a[i]]+=1;

	}

	sort(a+1,a+1+n);

	bin[0]=1ll;

	repd(i,1,33)

	{

		bin[i]=bin[i-1]*2ll;

	}

	int ans=0;



    for(int j=33;j>=0;j--)

    {

        int l=1;

        int r=n;

        while(l<r)

        {

            if(a[l]==-1||(~a[r]&&a[l]+a[r]<bin[j]))

            {

                l++;

            }else if(a[r]==-1||(a[l]+a[r]>bin[j]))

            {

                r--;

            }

            else

            {

                ans++;

                a[l]=-1;

                a[r]=-1;

            }

        }



	}

	cout<<ans<<endl;



    return 0;

}



inline void getInt(int* p) {char ch;do {ch = getchar();}

while (ch == ' ' || ch == '\n');if (ch == '-') {*p = -(getchar() - '0');

while ((ch = getchar()) >= '0' && ch <= '9') {*p = *p * 10 - ch + '0';}}

else {*p = ch - '0';while ((ch = getchar()) >= '0' && ch <= '9')

{*p = *p * 10 + ch - '0';}}}


// Faster C++ solution for the same problem (measured speedup: 1.0990899383591155x):
#include <cstdio>

#include <cstring>

#include <algorithm>

#include <vector>

#include <map>

#ifdef sahdsg

#define DBG(...) printf(__VA_ARGS__)

#else

#define DBG(...) (void)0

#endif // sahdsg

#define REP(r,x,y) for(register int r=(x); r<y; r++)

using namespace std;

typedef long long LL;

inline void read(int&x) {

	x=0;char ch=getchar(); while(ch<'0') ch=getchar();

	while(ch>='0') x=x*10+ch-'0',ch=getchar();

}

map<int,int> a;

int main()

{

	int n; read(n);

	REP(i,0,n) {

		int t; read(t);

		if(a.count(t)==0) a[t]=0;

		a[t]++;

	}

	int ans=0;

	for(map<int,int>::reverse_iterator it=a.rbegin(); it!=a.rend(); it++) {

		int now=it->first;

		int k=now;

		k|=k>>1;

		k|=k>>2;

		k|=k>>4;

		k|=k>>8;

		k|=k>>16;

		k++;

		k-=now;

		DBG("%d %d %d\n", k, now, a[k]);

		if(k==now) ans+=a[k]/2,it->second%=2;

		else ans+=min(it->second,a[k]),a[k]-=min(it->second,a[k]);

	}

	printf("%d\n", ans);

}