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

int power[55], a[100005];
map <int, int> mp;
int ans;

void work_power ()
{
	power[0] = 1;
	for (int i=1; i<=31; i++)
		power[i] = power[i-1] * 2;
}

bool cmp (int a, int b)
{
	return a > b;
}

int main()
{
	work_power ();
	int n;
	cin >> n;
	for (int i=1; i<=n; i++){
		cin >> a[i];
		mp[a[i]]++;
	}
	
	sort (a+1, a+n+1, cmp);
	
	for (int i=1; i<=n; i++){
		if (!mp[a[i]])  continue;
		for (int j=0; j<=31; j++){
			if (power[j] > a[i])  continue;
			if (!mp[a[i]-power[j]])  continue;
			int t=min (mp[a[i]-power[j]], mp[a[i]]);
			
			mp[a[i]-power[j]] -= t;
			mp[a[i]] -= t;
			ans += t;
		}
	}
	
	cout << ans << endl;
	return 0;
}