#pragma GCC optimize ("O3")
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#include<bits/stdc++.h>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ll long long
#define ld long double
#define all(a) a.begin(),a.end()
#define endl '\n'
#define ull unsigned long long
#define y1 ljhadglkjsadf
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define iter multiset<int>::iterator
#define iter1 set<int>::iterator
#define int long long
using namespace std;
using namespace __gnu_pbds;

template<class T>
using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

template<class T>
using ordered_multiset=tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rnd1(chrono::steady_clock::now().time_since_epoch().count());

//find_by_order
//order_of_key

const int N=2e5+7;
const int inf=1e18+1e9;
const int mod=1e9+7;
const ld eps=1e-9;

//const int MAX_MEM=4e8;
//int mpos=0;
//char mem[MAX_MEM];
//
//inline void * operator new(size_t n){
//    char *res=mem+mpos;
//    mpos+=n;
//    if (mpos>=MAX_MEM){
//        cout<<"BAD"<<endl;
//        exit(0);
//    }
//    return (void*)res;
//}
//
//inline void operator delete(void *) {}

int st[50];

main ()
{
    st[0]=1;
    for (int i=1;i<35;++i){
        st[i]=st[i-1]*2;
    }
    ios;
    int n;
    multiset<int>setik;
    cin>>n;
    for (int i=1;i<=n;++i){
        int x;
        cin>>x;
        setik.insert(x);
    }
    int ans=0;
    while(setik.size()>0){
        iter it=setik.end();
        --it;
        int x=(*it);
        setik.erase(it);
        int k=0;
        while(st[k]<=x)++k;
        int l=st[k]-x;
        iter it1=setik.find(l);
        if (it1!=setik.end()){
            ++ans;
            setik.erase(it1);
        }
    }
    cout<<ans<<endl;
}
//1
//3 15
//1 4
//3 5

#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tl3;

//typedef modint998244353 mint;

const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;

const ll MAX = 1e9 + 5;

int main() {
	int n;
	cin >> n;
	map<int, int> m;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		m[a]++;
	}

	int cnt = 0;
	for (auto it = m.rbegin(); it != m.rend(); it++) {
		ll p2 = 1;
		ll num = it->first;
		while (p2 <= num) {
			p2 *= 2;
		}

		//cout << num << endl;
		
		auto it1 = m.find(p2 - num);
		if (it1 != m.end()) {
			
			if (it1->first == num) {
				cnt += it->second / 2;
			}
			else {
				int c = min(it1->second, it->second);
				it1->second -= c;
				cnt += c;

				if (it1->second == 0) {
					m.erase(it1);
				}

			}
			
			
		}
	}
	cout << cnt << endl;
}