#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<map>
#define N 200005
using namespace std;
int n,a[N],ans;
map<int,int> s;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]),s[a[i]]++;
	sort(a+1,a+1+n);
	for(int i=n;i;i--)
		if(s[a[i]]>0){
			int t=(1<<((int)log2(a[i])+1))-a[i];
			if((a[i]!=t && s[t]>0) || (a[i]==t && s[t]>1)){
				ans++;
				s[a[i]]--;
				s[t]--;
			}
		}
	printf("%d\n",ans);
	return 0;
}