#include<bits/stdc++.h>

using namespace std;

const int N = 2e5 + 8;
long long a[N] , n , x , cnt , t;
multiset<long long> s;

int main()
{
	cin >> n;
	for(int i = 0 ; i < n ; i++)
	{
		cin >> a[i];
		s.insert(a[i]);
	}
	sort(a , a + n);
	for(int i = n - 1 ; i >= 0 ; i--)
	{
		t = 1;
		if(s.find(a[i]) != s.end())
		{
			s.erase(s.find(a[i]));
			for(int j = 0 ; j < 40 ; j++)
			{
				t *= 2;
				if(s.find(t - a[i]) != s.end())
				{
					cnt++;
					s.erase(s.find(t - a[i]));
					break;
				}
			}
		}
	}
	cout << cnt;
}