#include <cstdio>
#include <map>
#include <algorithm>
using namespace std;
const int N=200005;
int n;
int a[N];
int cur,ans;
map <int,int> p;
bool cmp(int x,int y)
{
	return x>y;
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		p[a[i]]++;
	}
	sort(a+1,a+n+1,cmp);
	cur=1<<30;
	for (int i=1;i<=n;i++)
	{
		while (cur>2*a[i])
			cur/=2;
		while (p[a[i]]&&((cur-a[i]==a[i]&&p[cur-a[i]]>=2)||(cur-a[i]!=a[i]&&p[cur-a[i]]>=1)))
		{
			ans++;
			p[a[i]]--;
			p[cur-a[i]]--;
		}
	}
	printf("%d\n",ans);
	return 0;
}