#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
int arr[200005];
map<int,int> cnt;
int main()
{
	int n,ans=0;
	scanf("%d",&n);
	for (int i=0;i<n;i++)
	{
		scanf("%d",&arr[i]);
		cnt[arr[i]]++;
	}
	sort(arr,arr+n);
	for (int i=n-1;i>=0;i--)
	{
		if (!cnt[arr[i]])
		continue;
		cnt[arr[i]]--;
		int pw=1;
		while (pw<=arr[i])
		pw*=2;
		if (cnt[pw-arr[i]])
		{
			cnt[pw-arr[i]]--;
			ans++;
		}
	}
	printf("%d",ans);
}