#include<bits/stdc++.h>
using namespace std;
int n,p,res;
long long g;
map<int,int> mp;
int a[200005];
void sc(int k)
{
	g=1;
	for (int i=1;i<=31;i++)
	{
		g*=2;
		if (g>=k)
		{
			p=i;
			break;	
		}
	}
}
int main()
{
	scanf("%d",&n);
	for (int i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		mp[a[i]]++;
	}
	sort(a,a+n);
	int f=1;
	for (int i=n;i>=0;i--)
	{
		if (mp[a[i]]==0)
			continue;
		if (f==1)
		{
			sc(a[i]);
			f++;		
		}
		long long t=g;
		for (int j=p;j>=0;j--)
		{
			if (t<a[i])
			{
				break;
			}
			if ((mp[t-a[i]]>0 && t-a[i]!=a[i]) || (mp[t-a[i]]>1 && t-a[i]==a[i]))
			{
				mp[t-a[i]]--;
				mp[a[i]]--;
				res++;
//				cout<<t-a[i]<<" "<<a[i]<<" ";
			}
			t/=2;
		}
	}
	printf("%d",res);
	return 0;
}