#include<bits/stdc++.h>
using namespace std;
int a[200010];
int n,sum;
map<int,int>mp;
map<int,int>s;
bool pan(int x)
{
	int t=1;
	while (t<=x) t*=2;
	if (mp[t-x]) {
		mp[t-x]--; s[t-x]++; return 1;
	} else return 0;
}
int main()
{
	scanf("%d",&n);
    for (int i=1;i<=n;i++) scanf("%d",&a[i]);
    sort(a+1,a+n+1);
    for (int i=1;i<=n;i++) mp[a[i]]++;
    for (int i=n;i>=1;i--) 
     {
     	if (!s[a[i]]) 
     	{
		 mp[a[i]]--; 
		 if (pan(a[i])) sum++;
	    } 
		 else s[a[i]]--;
     	
	 }
    cout << sum << endl; 
}