#include<cstdio>
#include<algorithm>
#include<map>
using namespace std;
int n,a[200005],ans;
map<int,int>f;
int main()
{
	scanf("%d",&n);for(int i=1;i<=n;++i) {scanf("%d",&a[i]);f[a[i]]++;}
	sort(a+1,a+1+n);
	for(int i=n;i;--i) {
		if(!f[a[i]]) continue;
		for(int j=1;j<=30;++j) {
			if((1<<j)==a[i]+a[i]&&f[a[i]]>1) {f[a[i]]-=2;ans++;}
			else if((1<<j)>a[i]&&f[(1<<j)-a[i]]&&(1<<j)-a[i]<a[i]) {f[a[i]]--;f[(1<<j)-a[i]]--;ans++;}
			if((1<<j)>a[i]&&(1<<j)-a[i]<=a[i]) break;
		}
	}
	printf("%d\n",ans);
	return 0;
}