#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
bool chmin(ll & a, ll  b) { if (b < a) { a = b; return 1; } return 0; }
bool chmax(ll & a, ll b) { if (b > a) { a = b; return 1; } return 0; }
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N=500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
int main() {
    cin>>n;
    vl beki;
    multiset<ll> A;
    beki.push_back(1);
    rep(i,40){
        beki.push_back(beki.back()*2);
    }
    rep(i,n){
        cin>>x;
        A.insert(x);
    }

    while(!A.empty()){
        auto ite=A.end();
        ite--;
        x=*ite;
      	A.erase(ite);
        k=upper_bound(all(beki),x*2)-beki.begin()-1;
        if(!A.empty()&&A.count(beki[k]-x)>0){
            auto ite2=A.lower_bound(beki[k]-x);
            A.erase(ite2);
            ans++;
        }
    }
    cout<<ans<<endl;
}

#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<functional>
using namespace std;
#define maxn long long(5*1e8)

int main(){
	long long n=0;
	scanf("%d",&n);	
	map<long long,long long,greater<long long>> num;
	for(long long i=1;i<=n;++i){
		long long temp=0;
		scanf("%d",&temp);
		num[temp]++;
	}
	long long j=pow(2.0,31),ans=0;
	for(auto iter=num.begin();iter!=num.end();++iter){
		while(iter->first<j/2) j/=2;
		if(num[iter->first]>0&&num[j-iter->first]>0){
				if(j==iter->first*2){
					ans+=num[iter->first]/2;
					num[iter->first]=num[iter->first]%2;
				}
				else{
				ans+=min(num[iter->first],num[j-iter->first]);
				num[j-iter->first]-=min(num[iter->first],num[j-iter->first]);
				}
			}
	}
	cout<<ans<<endl;
}
//5 1 2 2 2 3
