#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    int N;
    map<ll, int> mp;
    cin >> N;
    for (int i = 0; i < N; i++) {
        ll A;
        cin >> A;
        mp[A]++;
    }
    int ans = 0;
    for (auto ite = mp.rbegin(); ite != mp.rend(); ++ite) {
        if (ite->second == 0) continue;

        ll x = pow(2, floor(log2(ite->first)) + 1);
        auto ite1 = mp.lower_bound(x - ite->first);

        if (ite1->first + ite->first == x) {
            if (ite1->first == ite->first) {
                int c = ite->second / 2;
                ite->second -= c;
                ite1->second -= c;
                ans += c;
            } else {
                int c = min(ite->second, ite1->second);
                ite->second -= c;
                ite1->second -= c;
                ans += c;
            }
        }
    }
    cout << ans << endl;
    return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())outp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<'\n';}}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*modpow(a,b-1)%mod;ll k=modpow(a,b/2);return k*k%mod;}

int main(){
    ll n,ans=0;cin>>n;
    multiset<ll> v;
    rep(i,n){
        ll a;cin>>a;
        v.insert(a);
    }
    while(!v.empty()){
        auto it=v.end();
        it--;
        ll k=1;
        while(k<=*it)k*=2;
        k=k-*it;
        v.erase(it);
        auto w=v.lower_bound(k);
        if(*w==k){
            ans++;
            v.erase(w);
        }
    }
    out(ans);
}