#include<iostream>
#include<cstdio>
#include<cstring>
#include<map> 
#include<algorithm>
#define maxn 200020
#define ll long long
using namespace std;
int n,a[maxn];
map<int,int>mp;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i)scanf("%d",&a[i]),++mp[a[i]];
	sort(a+1,a+n+1);
	int ans=0;
	for(int i=n;i;--i)
	if(mp[a[i]]>0){
		int x=1;
		while(x<=a[i])x<<=1;
		int bi=x-a[i];
		if(mp.count(bi)&&(mp[bi]>(a[i]==bi)))--mp[bi],--mp[a[i]],++ans;
	}
	printf("%d\n",ans);
	return 0;
}