//----------------------------おまじない
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")
//----------------------------
#define FOR(i,j,n) for (int i=(j);i<(n);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define REPN(i,n) for (int i=(n);i>0;i--)
#define I(n) scanf("%d", &(n))
#define LL(n) scanf("%lld", &(n))
#define pb(n) push_back((n))
#define mp(i,j) make_pair((i),(j))
#define eb(i,j) emplace_back((i),(j))
#include <bits/stdc++.h>
using namespace std;
//------------------------------typedef集
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef vector<vi> vvi;
typedef vector<vpi> vvpi;
typedef vector<vvi> vvvi;
typedef long long ll;
const int mod = 1000000009;

struct max_flow {
    struct edge { int to, cap, rev; };
    int V;
    vector<vector<edge>> G;
    vector<int> itr, level;

    max_flow(int V) : V(V) { G.assign(V,vector<edge>()); }

    void add_edge(int from, int to, int cap) {
        G[from].push_back((edge) {to, cap, (int) G[to].size()});
        G[to].push_back((edge) {from, 0, (int) G[from].size()-1});
    }

    void bfs(int s) {
        level.assign(V,-1);
        queue<int> q;
        level[s] = 0; q.push(s);
        while (!q.empty()) {
            int v = q.front(); q.pop();
            for(auto &e: G[v]){
                if (e.cap > 0 and level[e.to] < 0) {
                    level[e.to] = level[v] + 1;
                    q.push(e.to);
                }
            }
        }
    }

    int dfs(int v, int t, int f) {
        if (v == t) return f;
    for (int& i = itr[v]; i < (int) G[v].size(); ++i) {
            edge& e = G[v][i];
            if (e.cap > 0 and level[v] < level[e.to]) {
                int d = dfs(e.to, t, min(f, e.cap));
                if (d > 0) {
                    e.cap -= d;
                    G[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }

    int run(int s, int t) {
        int ret = 0, f;
        while (bfs(s), level[t] >= 0) {
            itr.assign(V,0);
            while ((f = dfs(s, t, INT_MAX)) > 0) ret += f;
        }
        return ret;
    }
};

ll n,ret;
vector<ll> a,b;

ll near(ll v){
    ll ret = 1;
    while(v){
        ret *= 2;
        v /= 2;
    }
    if (ret == v) ret *= 2;
    return ret;
}

map<ll,ll> inp;

int main(){
    cin >> n;
    a.resize(n);
    REP(i,n) {
        LL(a[i]);
        inp[a[i]]++;
    }
    // sort(a.begin(),a.end(),greater<ll>());
    // b = vector<ll>(a);
    // sort(b.begin(),b.end());

    // //for (auto v:b) cerr << v << " ";
    // REP(i,n){
    //     ll v = a[i];
    //     if (v == 0) continue;
    //     //cerr << v << endl;
    //     ll cp = near(v) - v;

    //     auto itl = lower_bound(b.begin(),b.end(),cp);
    //     auto itu = upper_bound(b.begin(),b.end(),cp);
    //     if (distance(itl,itu) == 0) continue;


    // }

    auto it = inp.rbegin();
    for(; it != inp.rend(); it++){
        auto i = *it;
        ll iv = i.first;
        ll cp = near(iv) - iv;
        int ct = min(i.second, inp[cp]);
        if (cp == iv) ct /= 2;
        i.second -= ct;
        inp[cp] -= ct;
        ret += ct;
    }

    cout << ret << endl;
    return 0;
}
int hoge(){
    
    cin >> n;
    max_flow mf(n+2);
    a.resize(n);
    map<ll,ll> llm;
    REP(i,n){
        LL(a[i]);
        if (llm[a[i]]){
            llm[a[i]]++;
        } else {
            llm[a[i]] = 1;
        }
    }
    int x = llm.size();
    cerr << x << endl;
    //max_flow mf(2*x + 2);
    int id = 1;
    for (auto pl : llm){
        //cerr << pl.first << " " << pl.second << endl;
        mf.add_edge(0,id,pl.second);
        auto it = llm.lower_bound(near(pl.first) - pl.first);
        auto cp = *it;
        cerr << cp.first << " " << cp.second << endl;
        if (it != llm.end() && near(pl.first) - pl.first == cp.first){
            cerr << "hogre" << endl;
            int cap = near(pl.first) == pl.first*2 ? pl.second/2 : pl.second;
            mf.add_edge(id,1+x+distance(llm.begin(),it), cap);
            //mf.add_edge(distance(llm.begin(),it),id+1+x, cap);
        }
        mf.add_edge(id+1+x, 2*x+1, pl.second);
        id++;
    }
    cout << mf.run(0,2*x+1) << endl;
}

Measured memory_bytes: 87168