#include <iostream>
#include <map>
using namespace std;

map<long, int> mp;
int main() {
	int N; long a; cin >> N;
	for(int i=0; i<N; ++i){
	    cin >> a;
	    ++mp[a];
	}
	int ans=0;
	auto itr=mp.end();
	while(itr!=mp.begin()){
	    --itr;
	    long sum=1;
	    while(sum<=itr->first) sum *= 2;
	    sum -= itr->first;
	    if(sum==itr->first){
	        ans += mp[sum]/2;
	    }
	    else{
	        ans += min(itr->second, mp[sum]);
	        mp[sum] -= min(itr->second, mp[sum]);
	    }
	}
	cout << ans << endl;
	return 0;
}
