
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ls( s) (s&(-s))
#define ll long long
#define inf 0x3f3f3f3f
#define fast    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int N = 2e5+5;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod =    2019;
int n;
ll ans=0;
multiset<ll> ms;
int main()
{  fast
cin>>n;

vector<ll> v(n);
for(auto&x:v)cin>>x;
for(auto x: v)ms.insert(x);
while(!ms.empty())
{
	ll val=*ms.rbegin();
	ms.erase(ms.find(val));ll y;
	for( y=1;y<=val;y*=2);
		auto it=ms.find(y-val);
		if(it!=ms.end())
		{
			ans++;
			ms.erase(it);

		}
}
cout<<ans;
}

#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cstdint>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

int msb(int x) { return 31 - __builtin_clz(x); }

int main() {
  int N; std::cin >> N;
  std::map<int,int> m;
  for(int i = 0; i < N; ++i) { int A; std::cin >> A; ++m[A]; }
  std::vector<std::pair<int,int>> v(m.begin(), m.end());
  int ans = 0;
  for(int j = v.size()-1; j >= 0; --j) {
    if(v[j].second < 1) continue;
    int val = v[j].first;
    int x = (1 << msb(val)+1) - val;
    if(val == x) { ans += v[j].second/2; continue; }
    int i = std::partition_point(v.begin(), v.end(),
              [&](auto const& p) { return p.first < x;}) - v.begin();
    if(i >= j) continue;
    if(v[i].first != x) continue;
    int n = std::min(v[j].second, v[i].second);
    ans += n;
    v[i].second -= n;
  }
  fin(ans);
  return 0;
}
