#include <bits/stdc++.h>
using namespace std;
#define ll long long
int l[200000] = {0};

int main() {
    int N;
    map<int, int> d;

    scanf("%d", &N);
    for(int i=0;i<N;i++) {
        scanf("%d", &l[i]);
    }

    for(int i=0;i<N;i++) {
        auto itr = d.find(l[i]);
        if(itr != d.end()) {
            d[l[i]]++;
        }
        else {
            d[l[i]] = 1;
        }
    }

    int ans = 0;
    for(auto i=d.rbegin();i!=d.rend();i++) {
        while(i->second > 0) {
            int isFinished = 0;
            for(int j=0;j<32;j++) {
                int v = pow(2, j) - i->first;
                if (i->first < v) {
                    break;
                }
                if (d.find(v)!=d.end()) {
                    if ((v!=i->first && d[v]>=1) || (v==i->first && d[v]>=2)) {
                        i->second--;
                        d[v]--;
                        ans++;
                        isFinished = 1;
                        break;
                    }
                }
            }
            if(isFinished==0) {
                break;
            }
        }
    }
    cout << ans << endl;

    return 0;
}
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
signed main()
{
    int n;
    cin >> n;
    vector<ll> A(n);
    rep(i, n) cin >> A[i];

    unordered_map<ll, int> c;
    rep(i, n) c[A[i]] = 0;
    rep(i, n) c[A[i]]++;

    int sum = 0;
    for (auto kv: c) {
        if (kv.second % 2 == 1)
            sum++;
    }    

    put(sum);
    
    return 0;
}