#include <bits/stdc++.h>
using namespace std;

multiset<int> PQ;

int N, Ans;

int main() {
	ios::sync_with_stdio(false);

	cin >> N;
	for(int i = 0, c; i < N; i++) {
		cin >> c;
		PQ.insert(c);
	}

	for(int c; !PQ.empty();) {
		c = *prev(PQ.end());
		PQ.erase(prev(PQ.end()));
		for(int j = 1, t; j <= 31; j++) {
			t = (1ll<<j) - c;
			auto it = PQ.find(t);
			if(PQ.end() == it) continue;
			PQ.erase(it);
			Ans++;
			break;
		}
	}

	cout << Ans << endl;
	return 0;
}