#include <bits/stdc++.h>
//#include "Header.h"

#define ll long long

#define fori(n) for(long long i=0;i<n;i++)
#define forj(n,i) for(long long j=i+1;j<n;j++)

using namespace std;

void merge(long long arr[], long long l, long long  m, long long  r)
{
    long long  i, j, k;
    long long  n1 = m - l + 1;
    long long  n2 =  r - m;

    long long  L[n1], R[n2];

    for (i = 0; i < n1; i++)
        L[i] = arr[l + i];
    for (j = 0; j < n2; j++)
        R[j] = arr[m + 1+ j];

    i = 0; // Initial index of first subarray
    j = 0; // Initial index of second subarray
    k = l; // Initial index of merged subarray
    while (i < n1 && j < n2)
    {
        if (L[i] <= R[j])
        {
            arr[k] = L[i];
            i++;
        }
        else
        {
            arr[k] = R[j];
            j++;
        }
        k++;
    }
    while (i < n1)
    {
        arr[k] = L[i];
        i++;
        k++;
    }

    while (j < n2)
    {
        arr[k] = R[j];
        j++;
        k++;
    }
}
void mergeSort(long long arr[], long long  l, long long  r)
{
    if (l < r)
    {
        long long  m = l+(r-l)/2;

        mergeSort(arr, l, m);
        mergeSort(arr, m+1, r);

        merge(arr, l, m, r);
    }
}

int isPrime(long long k){
    if(k<=1){
        return 0;
    }
    if(k==2){
        return 1;
    }
    if(k%2==0){
        return 0;
    }
    long long i = 3;

    while (i*i <= k) {
        if (k % i == 0) {
            return 0;
        }
        i += 2;
    }
return 1;
}

int isVAL(ll m){
    if((m&(m-1))==0){return 1;}
    return 0;
}

int main(int argc, const char * argv[]) {

//cout<<"Om\n";
    ll n,count=0,sum=0,chk;
    cin>>n;
    ll arr[n];
    for(long long i=0;i<n;i++){
        cin>>arr[i];
    }
    //cout<<(6&2)<<" ";
    for(ll i=0;i<n-1;i++){
        for(ll j=i+1;j<n;j++){
            sum=arr[i]+arr[j];if(sum%2!=0){continue;}
            chk=isVAL(sum);//cout<<sum<<":"<<chk<<".";
            if(chk==1){
                count=count+1;
            }
        }
    }
    cout<<count;

return 0;
}


#include <bits/stdc++.h>
//#include "Header.h"

#define ll long long

#define fori(n) for(long long i=0;i<n;i++)
#define forj(n,i) for(long long j=i+1;j<n;j++)

using namespace std;

int isVAL(ll m){
    if((m&(m-1))==0){return 1;}
    return 0;
}

int main(int argc, const char * argv[]) {

//cout<<"Om\n";
    ll n,count=0,sum=0,chk;
    cin>>n;
    ll arr[n];
    for(long long i=0;i<n;i++){
        cin>>arr[i];
    }
    //cout<<(6&2)<<" ";
    for(ll i=0;i<n-1;i++){
        for(ll j=i+1;j<n;j++){
            sum=arr[i]+arr[j];if(sum%2==0){
            chk=isVAL(sum);//cout<<sum<<":"<<chk<<".";
            if(chk==1){
                count=count+1;
            }
            }
        }
    }
    cout<<count;

return 0;
}


#include <bits/stdc++.h>
//#include "Header.h"

#define ll long long

#define fori(n) for(long long i=0;i<n;i++)
#define forj(n,i) for(long long j=i+1;j<n;j++)

using namespace std;

void merge(long long arr[], long long l, long long  m, long long  r)
{
    long long  i, j, k;
    long long  n1 = m - l + 1;
    long long  n2 =  r - m;

    long long  L[n1], R[n2];

    for (i = 0; i < n1; i++)
        L[i] = arr[l + i];
    for (j = 0; j < n2; j++)
        R[j] = arr[m + 1+ j];

    i = 0; // Initial index of first subarray
    j = 0; // Initial index of second subarray
    k = l; // Initial index of merged subarray
    while (i < n1 && j < n2)
    {
        if (L[i] <= R[j])
        {
            arr[k] = L[i];
            i++;
        }
        else
        {
            arr[k] = R[j];
            j++;
        }
        k++;
    }
    while (i < n1)
    {
        arr[k] = L[i];
        i++;
        k++;
    }

    while (j < n2)
    {
        arr[k] = R[j];
        j++;
        k++;
    }
}
void mergeSort(long long arr[], long long  l, long long  r)
{
    if (l < r)
    {
        long long  m = l+(r-l)/2;

        mergeSort(arr, l, m);
        mergeSort(arr, m+1, r);

        merge(arr, l, m, r);
    }
}

int isPrime(long long k){
    if(k<=1){
        return 0;
    }
    if(k==2){
        return 1;
    }
    if(k%2==0){
        return 0;
    }
    long long i = 3;

    while (i*i <= k) {
        if (k % i == 0) {
            return 0;
        }
        i += 2;
    }
return 1;
}

int isthatso(ll m){
    if(m==1){return 0;}
    ll s;
    s=m;
    while(s!=0){
        if(s!=0 && s%2!=0){return 1;}
        s/=2;
    }
    return 0;
}

int main(int argc, const char * argv[]) {

//cout<<"Om\n";
    ll n,count=0,sum=0;cin>>n;
    ll arr[n];
    for(long long i=0;i<n;i++){
        cin>>arr[i];
    }
    for(ll i=0;i<n-1;i++){
        for(ll j=i+1;j<n;j++){
            sum=arr[i]+arr[j];
            if(isthatso(sum)==0){
                count++;
            }
        }
    }
    cout<<count;

return 0;
}


#include <bits/stdc++.h>
//#include "Header.h"

#define ll long long

#define fori(n) for(long long i=0;i<n;i++)
#define forj(n,i) for(long long j=i+1;j<n;j++)

using namespace std;

void merge(long long arr[], long long l, long long  m, long long  r)
{
    long long  i, j, k;
    long long  n1 = m - l + 1;
    long long  n2 =  r - m;

    long long  L[n1], R[n2];

    for (i = 0; i < n1; i++)
        L[i] = arr[l + i];
    for (j = 0; j < n2; j++)
        R[j] = arr[m + 1+ j];

    i = 0; // Initial index of first subarray
    j = 0; // Initial index of second subarray
    k = l; // Initial index of merged subarray
    while (i < n1 && j < n2)
    {
        if (L[i] <= R[j])
        {
            arr[k] = L[i];
            i++;
        }
        else
        {
            arr[k] = R[j];
            j++;
        }
        k++;
    }
    while (i < n1)
    {
        arr[k] = L[i];
        i++;
        k++;
    }

    while (j < n2)
    {
        arr[k] = R[j];
        j++;
        k++;
    }
}
void mergeSort(long long arr[], long long  l, long long  r)
{
    if (l < r)
    {
        long long  m = l+(r-l)/2;

        mergeSort(arr, l, m);
        mergeSort(arr, m+1, r);

        merge(arr, l, m, r);
    }
}

int isPrime(long long k){
    if(k<=1){
        return 0;
    }
    if(k==2){
        return 1;
    }
    if(k%2==0){
        return 0;
    }
    long long i = 3;

    while (i*i <= k) {
        if (k % i == 0) {
            return 0;
        }
        i += 2;
    }
return 1;
}

int main(int argc, const char * argv[]) {

//cout<<"Om\n";
    ll n,k=1,pow=0,t=0,count=0;
    cin>>n;
    ll arr[n];
    for(long long i=0;i<n;i++){
        cin>>arr[i];
    }
    //cout<<(6&2)<<" ";

    sort(arr, arr+n);
    pow=ceil(log2((double)arr[n-1]));

    for(ll i=0;i<pow;i++){
        k=(k<<1);
        //cout<<k<<" ";
    }
    //cout<<endl;

    for(ll j=n-1;j>0;j--){
        t=ceil(log2((double)arr[j]));
        while(pow!=t && pow>t){
            k=(k>>1);pow--;
        }//cout<<k<<" ";
        if(k==arr[j]){
            k=k<<1;pow++;
        }//cout<<k<<" count="<<count<<" ";
        if(binary_search(arr, arr+j, k-arr[j])){
            count+=upper_bound(arr, arr+j, k-arr[j])-lower_bound(arr, arr+j, k-arr[j]);
        }
    }
    cout<<count;

return 0;
}


#include <bits/stdc++.h>
//#include "Header.h"

#define ll long long

#define fori(n) for(long long i=0;i<n;i++)
#define forj(n,i) for(long long j=i+1;j<n;j++)

using namespace std;

void merge(long long arr[], long long l, long long  m, long long  r)
{
    long long  i, j, k;
    long long  n1 = m - l + 1;
    long long  n2 =  r - m;

    long long  L[n1], R[n2];

    for (i = 0; i < n1; i++)
        L[i] = arr[l + i];
    for (j = 0; j < n2; j++)
        R[j] = arr[m + 1+ j];

    i = 0; // Initial index of first subarray
    j = 0; // Initial index of second subarray
    k = l; // Initial index of merged subarray
    while (i < n1 && j < n2)
    {
        if (L[i] <= R[j])
        {
            arr[k] = L[i];
            i++;
        }
        else
        {
            arr[k] = R[j];
            j++;
        }
        k++;
    }
    while (i < n1)
    {
        arr[k] = L[i];
        i++;
        k++;
    }

    while (j < n2)
    {
        arr[k] = R[j];
        j++;
        k++;
    }
}
void mergeSort(long long arr[], long long  l, long long  r)
{
    if (l < r)
    {
        long long  m = l+(r-l)/2;

        mergeSort(arr, l, m);
        mergeSort(arr, m+1, r);

        merge(arr, l, m, r);
    }
}

int isPrime(long long k){
    if(k<=1){
        return 0;
    }
    if(k==2){
        return 1;
    }
    if(k%2==0){
        return 0;
    }
    long long i = 3;

    while (i*i <= k) {
        if (k % i == 0) {
            return 0;
        }
        i += 2;
    }
return 1;
}
ll bincount(ll arr[],ll j,ll n,ll k){
    if(binary_search(arr, arr+j, k-arr[j])){
        ll *p=lower_bound(arr, arr+j, k-arr[j]);
        ll c=0;
        while(*p==k-arr[j]){
            if(p==arr+j){break;}
            p++;c++;
        }
        return c;
    }
    return 0;
}

int main(int argc, const char * argv[]) {

//cout<<"Om\n";
    ll n,k=1,pow=0,t=0,count=0;
    cin>>n;
    ll arr[n];
    for(long long i=0;i<n;i++){
        cin>>arr[i];
    }
    //cout<<(6&2)<<" ";

    sort(arr, arr+n);
    pow=ceil(log2((double)arr[n-1]));

    for(ll i=0;i<pow;i++){
        k=(k<<1);
        //cout<<k<<" ";
    }
    //cout<<endl;

    for(ll j=n-1;j>0;j--){
        t=ceil(log2((double)arr[j]));
        while(pow!=t && pow>t){
            k=(k>>1);pow--;
        }//cout<<k<<" ";
        if(k==arr[j]){
            k=k<<1;
        }//cout<<k<<" ";
        //cout<<"."<<bincount(arr, j, n, k)<<". ";
        count+=bincount(arr,j,n,k);
    }
    cout<<count;

return 0;
}


#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;
#define LLM (ll)1e17
const int  N = 1e5 + 10;

int n;
int a[N];
map <int , int>freq;
int dp[62], dp_idx = 0;

int get(int a)
{
	for (int i = 1; i <= dp_idx; i++) {
		if (a - dp[i] < 0)
			return dp[i] - a;
	}
	return -1;
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	dp[0] = 1;
	ll pu = 0;
	for (int i = 1; i < 62; i++) {
		pu = 2 * dp[i - 1];
		if (pu <= 1e9) dp[i] = pu;
		else { dp_idx = i;dp[i] = pu; break; }
	}
	cin >> n;
	if (n == 1) { cout << 0; return 0; }
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		++freq[a[i]];
	}
	sort(a, a + n, greater<>());
	int ans = 0;
	for (int i = 0; i < n; i++) {
		int need = get(a[i]);
		--freq[a[i]];
		if (need == -1)continue;
		int l = i + 1, r = n - 1, mid;
		while (l <= r) {
			mid = (r + l) / 2;
			// cout << i << endl;
			if (a[mid] == need)
			{
				ans += freq[a[mid]];
				break;
			}
			else if (a[mid] > need)l = mid + 1;
			else r = mid - 1;
		}
	}
	cout << ans;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;
#define LLM (ll)1e17
const int  N = 1e5 + 10;

int n;
int a[N];
map <int , int>freq;
int dp[62], dp_idx = 0;

int get(int a)
{
	for (int i = 1; i <= dp_idx; i++) {
		if (a - dp[i] < 0)
			return dp[i] - a;
	}
	return -1;
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	dp[0] = 1;
	ll pu = 0;
	for (int i = 1; i < 62; i++) {
		pu = 2 * dp[i - 1];
		if (pu <= 1e9) dp[i] = pu;
		else { dp_idx = i; break; }
	}
	cin >> n;
	if (n == 1) { cout << 0; return 0; }
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		++freq[a[i]];
	}
	sort(a, a + n, greater<>());
	int ans = 0;
	for (int i = 0; i < n; i++) {
		int need = get(a[i]);
		--freq[a[i]];
		if (need == -1)continue;
		int l = i + 1, r = n - 1, mid;
		while (l <= r) {
			mid = (r + l) / 2;
			// cout << i << endl;
			if (a[mid] == need)
			{
				ans += freq[a[mid]];
				break;
			}
			else if (a[mid] > need)l = mid + 1;
			else r = mid - 1;
		}
	}
	cout << ans;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;
#define LLM (ll)1e17
const int  N = 1e5 + 10;

void read(int& number)
{
	bool negative = false;
	register int c;
	number = 0;
	c = getchar();
	if (c == '-')
	{
		negative = true;
		c = getchar();
	}
	for (; (c > 47 && c < 58); c = getchar())
		number = number * 10 + c - 48;
	if (negative)
		number *= -1;
}

int n;
int a[N], freq[N];
bool himself[N];
int dp[62], dp_idx = 0;

int get(int a)
{
	for (int i = 1; i <= dp_idx; i++) {
		if (a - dp[i] < 0)
			return dp[i] - a;
	}
	return -1;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	dp[0] = 1;
	ll pu = 0;
	for (int i = 1; i < 62; i++) {
		pu = 2 * dp[i - 1];
		if (pu <= 1e9) dp[i] = pu;
		else { dp_idx = i; break; }
	}
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		++freq[a[i]];
	}
	sort(a, a + n, greater<>());
	int ans = 0;
	for (int i = 0; i < n; i++) {
		int need = get(a[i]);
		if (need == -1)continue;
		int l = i + 1, r = n - 1, mid;
		while (l <= r) {
			mid = (r + l) / 2;
			// cout << i << endl;
			if (a[mid] == need && himself[a[mid]]) break;
			else if (a[mid] == need)
			{
				ans += freq[a[mid]];
				if (need == a[i])himself[a[i]] = true;
				break;
			}
			else if (a[mid] > need)l = mid + 1;
			else r = mid - 1;
		}
	}
	cout << ans;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;
#define LLM (ll)1e17
const int  N = 1e5 + 10;

void read(int& number)
{
	bool negative = false;
	register int c;
	number = 0;
	c = getchar();
	if (c == '-')
	{
		negative = true;
		c = getchar();
	}
	for (; (c > 47 && c < 58); c = getchar())
		number = number * 10 + c - 48;
	if (negative)
		number *= -1;
}

int n;
int a[N];
map <int , int>freq, himself;

int dp[62], dp_idx = 0;

int get(int a)
{
	for (int i = 1; i <= dp_idx; i++) {
		if (a - dp[i] < 0)
			return dp[i] - a;
	}
	return -1;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	dp[0] = 1;
	ll pu = 0;
	for (int i = 1; i < 62; i++) {
		pu = 2 * dp[i - 1];
		if (pu <= 1e9) dp[i] = pu;
		else { dp_idx = i; break; }
	}
	cin >> n;
	if (n == 1) { cout << 0; return 0; }
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		++freq[a[i]];
	}
	sort(a, a + n, greater<>());
	int ans = 0;
	for (int i = 0; i < n; i++) {
		int need = get(a[i]);
		if (need == -1)continue;
		int l = i + 1, r = n - 1, mid;
		while (l <= r) {
			mid = (r + l) / 2;
			// cout << i << endl;
			if (a[mid] == need && himself[a[mid]]) break;
			else if (a[mid] == need)
			{
				ans += freq[a[mid]];
				if (need == a[i])himself[a[i]] = true;
				break;
			}
			else if (a[mid] > need)l = mid + 1;
			else r = mid - 1;
		}
	}
	cout << ans;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;
#define LLM (ll)1e17
const int  N = 1e5 + 10;

ll n;
ll a[N];
map <ll , ll>freq;
int dp[62], dp_idx = 0;

ll get(ll a)
{
	for (int i = 1; i <= dp_idx; i++) {
		if (a - dp[i] < 0)
			return dp[i] - a;
	}
	return -1;
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	dp[0] = 1;
	ll pu = 0;
	for (int i = 1; i < 62; i++) {
		pu = 2 * dp[i - 1];
		if (pu <= 1e9) dp[i] = pu;
		else { dp_idx = i;dp[i] = pu; break; }
	}
	cin >> n;
	if (n == 1) { cout << 0; return 0; }
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		++freq[a[i]];
	}
	sort(a, a + n, greater<>());
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		ll need = get(a[i]);
		--freq[a[i]];
		if (need == -1)continue;
		int l = i + 1, r = n - 1, mid;
		while (l <= r) {
			mid = (r + l) / 2;
			// cout << i << endl;
			if (a[mid] == need)
			{
				ans += freq[a[mid]];
				break;
			}
			else if (a[mid] > need)l = mid + 1;
			else r = mid - 1;
		}
	}
	cout << ans;
	return 0;
}


// author-Shivam gupta

#include <bits/stdc++.h>

using namespace std;

#define MEM(a, b) memset(a, (b), sizeof(a))

#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)

#define IN(A, B, C) assert( B <= A && A <= C)

#define MP make_pair
#define FOR(i,a) for(int i=0;i<a;i++)

#define FOR1(i,j,a) for(int i=j;i<a;i++)

#define EB emplace_back

#define INF (int)1e9

#define EPS 1e-9

#define PI 3.1415926535897932384626433832795

#define MOD 10000000007

#define read(type) readInt<type>()
#define max1 10000001
#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
const double pi=acos(-1.0);

typedef pair<int, int> PII;

typedef vector<int> VI;

typedef vector<string> VS;

typedef vector<PII> VII;

typedef vector<VI> VVI;

typedef map<int,int> MPII;

typedef set<int> SETI;

typedef multiset<int> MSETI;

typedef long int li;

typedef unsigned long int uli;

typedef long long int ll;

typedef unsigned long long int  ull;

bool isPowerOfTwo (int x)
{
  /* First x in the below expression is
    for the case when x is 0 */
  return x && (!(x&(x-1)));
}
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
ll power(ll x, ll y, ll p)
{
    ll res = 1;      // Initialize result

    x = x % p;  // Update x if it is more than or
                // equal to p

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}

// Returns n^(-1) mod p
ll modInverse(ll n, ll p)
{
    return power(n, p-2, p);
}

// Returns nCr % p using Fermat's little
// theorem.
ll ncr(ll n, ll r,ll p)
{
   // Base case
   if (r==0)
      return 1;

    // Fill factorial array so that we
    // can find all factorial of r, n
    // and n-r
    ll fac[n+1];
    fac[0] = 1;
    for (ll i=1 ; i<=n; i++)
        fac[i] = fac[i-1]*i%p;

    return (fac[n]* modInverse(fac[r], p) % p *
            modInverse(fac[n-r], p) % p) % p;
}

int main(){
    fast();
 int n;
cin>>n;
ll a[n];
unordered_map<ll,ll> m;
FOR(i,n){cin>>a[i];m[a[i]]++;}
ll sum=1;
sort(a,a+n);
ll cnt=0;
while(1){
    sum=sum*(ll)2;
    if(sum>MOD){break;}
    for(auto it=m.begin();it!=m.end();it++){
    if(sum==2*it->first && 2<=it->second){cnt+=(it->second*(it->second-1));}
    else if(sum==2*it->first && it->first<sum && m.find(sum-it->first)!=m.end()){cnt+=it->second*m[sum-it->first];}
    }
}
out(cnt/2);

}
/*

           .$                                  $.
          /:;                                  :;\
         : $                                    $ ;
         ;:$                                    $;:
        : $:              ________              ;$ ;
        ; $;;     _..gg$$SSP^^^^T$S$$pp.._     ::$ :
       : :$;|  .g$$$$$$SSP"      "TS$$$$$$$p.  |:$; ;
       ; :$;:.d$$$$$$$SSS          SS$$$$$$$$b.;:$; :
      :  :$$$$$$$$$$$$SSS          SS$$$$$$$$$$$$$;  ;
      ;  $$$$$$$$$$$$$$SSb.      .dS$$$$$$$$$$$$$$;  :
     :  :S$$$$$$$$$$$$$$SSSSppggSSS$$$$$$$$$$$$$$$;   ;
     |  :SS$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$;   :
     |  :SS$$$$$$$$$$$$$$$$$^^^^^^^^^$$$$$$$$$$$$$$   :
     ;   SS$$$$$$$$$$P^"                 "^T$$$$$$$   :
    :    :SS$$$$$$$$$                       T$$$$$;   :
    |     SSS$$$$$$$;                        T$$$$    :
    |     :SSS$$$$$$;                        :$$$;    :
    ;      SSS$$$$$$;                        :S$$;    :
    ;      :SS$$P"^P                          S$$;    :
    ;    ..d$$$P    `                         S$$$    :
    ;     T$$$P                          dS   T$$$b.  :
    ;    :$$$$.     .                   dSS;   $$$$$b.:
    ;    :$$$$$b     Tb.   .          .dSS$$b.d$$$$$$$:
    :    $$$$$$$b     TSb   Tb..g._, :$$SS$$$$$$SSS$$$:
    :   :$$$$$$$$b     SSb   T$SS$P   "^TS$$$$$$P"TS$$:
    :   $$$$$$$$$$b._.dS$$b _ T$$P _     TSS$SSP  :SS$:
    :  :$$$$SSS$$$$$$$$$P" d$b. _.d$P     TSSP"    SS$:
    :  :P"TSSP"^T$$$$$$P  :$$$$$$$$P d$$b          $S$;
    :  :b.dS^^-.  ""^^"    $b T d$$$s$$$$b __..--""$ $;
    :  :$$$S    ""^^..ggSS$$$$$$$$$$$$$$P^^""     .$ $;
    :   $$$$$pp..__   `j$$$$$$^$$$$$b. d....ggppTSSS$$;
    :   $$$$SP     """t  :$$$$ $$$$$$$b.  d$b    `TSS$;
    :  \:$$SP   _.gd$$P_d$$$$$ $$$$$$$$$bd$P'    .dSPd;
    :   \"^S     "^T$$$$$$$$$$ $$$$$SS$$$$b.    dSS'd$;
    $    $. "-.__.gd$$$$$$$SP:S$$P  TSS$$$$$bssS^".d$$:
   :$    $$b.   ""^^T$$$$SP' :S$P    TSSSP^^""  .d$$$$:
   :$   :$$$P        "^SP'   :S;     .^"`.     $$$$$$$:
   $;   :$$$            "-.  :S;  .-"     \    :$$$$$$:
  .$ :  $$$;   :           `.:S;.'         ;    $$$$$$:;
 .P :S  $$$    ;             `^'                :$$$$$:;
.P  S;.d$$;   :               -'                 $$$$$:;
$  :SS$$$$    ;     __....----  --...____        :$$$ :S
$  $SSS$$;    :  ; d$$$$$$$pppqqqq$$$$$$L;       :$$$ SS
: :SSSSS$$     ; : \ "^T$$$$$$$$$$$$$P' .':      $PT$ SS;
 $SP^"^TSP\    :  \ "-.  """"""""""" .-"  ;     /   $ SSSb.
 :S     S  \           "--...___..--"    /  :  /    :gSSSSSb.
  T bug T   \       `.      _____       /   ; /
   `         \ :      "==="""""""""===""   : /
              `:                           ;'
                "-.                     .-"
                   ""--..         ..--""
*/


// author-Shivam gupta

#include <bits/stdc++.h>

using namespace std;

#define MEM(a, b) memset(a, (b), sizeof(a))

#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)

#define IN(A, B, C) assert( B <= A && A <= C)

#define MP make_pair
#define FOR(i,a) for(int i=0;i<a;i++)

#define FOR1(i,j,a) for(int i=j;i<a;i++)

#define EB emplace_back

#define INF (int)1e9

#define EPS 1e-9

#define PI 3.1415926535897932384626433832795

#define MOD 1000000007

#define read(type) readInt<type>()
#define max1 10000001
#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
const double pi=acos(-1.0);

typedef pair<int, int> PII;

typedef vector<int> VI;

typedef vector<string> VS;

typedef vector<PII> VII;

typedef vector<VI> VVI;

typedef map<int,int> MPII;

typedef set<int> SETI;

typedef multiset<int> MSETI;

typedef long int li;

typedef unsigned long int uli;

typedef long long int ll;

typedef unsigned long long int  ull;

bool isPowerOfTwo (int x)
{
  /* First x in the below expression is
    for the case when x is 0 */
  return x && (!(x&(x-1)));
}
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
ll power(ll x, ll y, ll p)
{
    ll res = 1;      // Initialize result

    x = x % p;  // Update x if it is more than or
                // equal to p

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}

// Returns n^(-1) mod p
ll modInverse(ll n, ll p)
{
    return power(n, p-2, p);
}

// Returns nCr % p using Fermat's little
// theorem.
ll ncr(ll n, ll r,ll p)
{
   // Base case
   if (r==0)
      return 1;

    // Fill factorial array so that we
    // can find all factorial of r, n
    // and n-r
    ll fac[n+1];
    fac[0] = 1;
    for (ll i=1 ; i<=n; i++)
        fac[i] = fac[i-1]*i%p;

    return (fac[n]* modInverse(fac[r], p) % p *
            modInverse(fac[n-r], p) % p) % p;
}

int main(){
    fast();
 int n;
cin>>n;
ll a[n];
unordered_map<ll,ll> m;
FOR(i,n){cin>>a[i];m[a[i]]++;}
ll sum=1;
sort(a,a+n);
ll cnt=0;
while(1){
    sum=sum*(ll)2;
    if(sum>MOD){break;}
    for(auto it=m.begin();it!=m.end();it++){
    if(sum==(ll)2*it->first && (ll)2<=it->second){cnt+=(it->second*(it->second-1));}
    else if(sum!=(ll)2*it->first && it->first<sum && m.find(sum-it->first)!=m.end()){cnt+=it->second*m[sum-it->first];}
    }
}
out(cnt/(ll)2);

}
/*

           .$                                  $.
          /:;                                  :;\
         : $                                    $ ;
         ;:$                                    $;:
        : $:              ________              ;$ ;
        ; $;;     _..gg$$SSP^^^^T$S$$pp.._     ::$ :
       : :$;|  .g$$$$$$SSP"      "TS$$$$$$$p.  |:$; ;
       ; :$;:.d$$$$$$$SSS          SS$$$$$$$$b.;:$; :
      :  :$$$$$$$$$$$$SSS          SS$$$$$$$$$$$$$;  ;
      ;  $$$$$$$$$$$$$$SSb.      .dS$$$$$$$$$$$$$$;  :
     :  :S$$$$$$$$$$$$$$SSSSppggSSS$$$$$$$$$$$$$$$;   ;
     |  :SS$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$;   :
     |  :SS$$$$$$$$$$$$$$$$$^^^^^^^^^$$$$$$$$$$$$$$   :
     ;   SS$$$$$$$$$$P^"                 "^T$$$$$$$   :
    :    :SS$$$$$$$$$                       T$$$$$;   :
    |     SSS$$$$$$$;                        T$$$$    :
    |     :SSS$$$$$$;                        :$$$;    :
    ;      SSS$$$$$$;                        :S$$;    :
    ;      :SS$$P"^P                          S$$;    :
    ;    ..d$$$P    `                         S$$$    :
    ;     T$$$P                          dS   T$$$b.  :
    ;    :$$$$.     .                   dSS;   $$$$$b.:
    ;    :$$$$$b     Tb.   .          .dSS$$b.d$$$$$$$:
    :    $$$$$$$b     TSb   Tb..g._, :$$SS$$$$$$SSS$$$:
    :   :$$$$$$$$b     SSb   T$SS$P   "^TS$$$$$$P"TS$$:
    :   $$$$$$$$$$b._.dS$$b _ T$$P _     TSS$SSP  :SS$:
    :  :$$$$SSS$$$$$$$$$P" d$b. _.d$P     TSSP"    SS$:
    :  :P"TSSP"^T$$$$$$P  :$$$$$$$$P d$$b          $S$;
    :  :b.dS^^-.  ""^^"    $b T d$$$s$$$$b __..--""$ $;
    :  :$$$S    ""^^..ggSS$$$$$$$$$$$$$$P^^""     .$ $;
    :   $$$$$pp..__   `j$$$$$$^$$$$$b. d....ggppTSSS$$;
    :   $$$$SP     """t  :$$$$ $$$$$$$b.  d$b    `TSS$;
    :  \:$$SP   _.gd$$P_d$$$$$ $$$$$$$$$bd$P'    .dSPd;
    :   \"^S     "^T$$$$$$$$$$ $$$$$SS$$$$b.    dSS'd$;
    $    $. "-.__.gd$$$$$$$SP:S$$P  TSS$$$$$bssS^".d$$:
   :$    $$b.   ""^^T$$$$SP' :S$P    TSSSP^^""  .d$$$$:
   :$   :$$$P        "^SP'   :S;     .^"`.     $$$$$$$:
   $;   :$$$            "-.  :S;  .-"     \    :$$$$$$:
  .$ :  $$$;   :           `.:S;.'         ;    $$$$$$:;
 .P :S  $$$    ;             `^'                :$$$$$:;
.P  S;.d$$;   :               -'                 $$$$$:;
$  :SS$$$$    ;     __....----  --...____        :$$$ :S
$  $SSS$$;    :  ; d$$$$$$$pppqqqq$$$$$$L;       :$$$ SS
: :SSSSS$$     ; : \ "^T$$$$$$$$$$$$$P' .':      $PT$ SS;
 $SP^"^TSP\    :  \ "-.  """"""""""" .-"  ;     /   $ SSSb.
 :S     S  \           "--...___..--"    /  :  /    :gSSSSSb.
  T bug T   \       `.      _____       /   ; /
   `         \ :      "==="""""""""===""   : /
              `:                           ;'
                "-.                     .-"
                   ""--..         ..--""
*/


// author-Shivam gupta

#include <bits/stdc++.h>

using namespace std;

#define MEM(a, b) memset(a, (b), sizeof(a))

#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)

#define IN(A, B, C) assert( B <= A && A <= C)

#define MP make_pair
#define FOR(i,a) for(int i=0;i<a;i++)

#define FOR1(i,j,a) for(int i=j;i<a;i++)

#define EB emplace_back

#define INF (int)1e9

#define EPS 1e-9

#define PI 3.1415926535897932384626433832795

#define MOD 10000000007

#define read(type) readInt<type>()
#define max1 10000001
#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
const double pi=acos(-1.0);

typedef pair<int, int> PII;

typedef vector<int> VI;

typedef vector<string> VS;

typedef vector<PII> VII;

typedef vector<VI> VVI;

typedef map<int,int> MPII;

typedef set<int> SETI;

typedef multiset<int> MSETI;

typedef long int li;

typedef unsigned long int uli;

typedef long long int ll;

typedef unsigned long long int  ull;

bool isPowerOfTwo (int x)
{
  /* First x in the below expression is
    for the case when x is 0 */
  return x && (!(x&(x-1)));
}
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
ll power(ll x, ll y, ll p)
{
    ll res = 1;      // Initialize result

    x = x % p;  // Update x if it is more than or
                // equal to p

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}

// Returns n^(-1) mod p
ll modInverse(ll n, ll p)
{
    return power(n, p-2, p);
}

// Returns nCr % p using Fermat's little
// theorem.
ll ncr(ll n, ll r,ll p)
{
   // Base case
   if (r==0)
      return 1;

    // Fill factorial array so that we
    // can find all factorial of r, n
    // and n-r
    ll fac[n+1];
    fac[0] = 1;
    for (ll i=1 ; i<=n; i++)
        fac[i] = fac[i-1]*i%p;

    return (fac[n]* modInverse(fac[r], p) % p *
            modInverse(fac[n-r], p) % p) % p;
}

int main(){
    fast();
int n;
cin>>n;
ll a[n];
unordered_map<ll,ll> m;
FOR(i,n){cin>>a[i];m[a[i]]++;}
ll sum=1;
sort(a,a+n);
ll cnt=0;
while(1){
    sum=sum*(ll)2;
    if(sum>MOD){break;}
    for(auto it=m.begin();it!=m.end();it++){
    if(sum==(ll)2*it->first && (ll)2<=it->second){cnt+=(it->second*(it->second-1));}
    else if(sum!=(ll)2*it->first && it->first<sum && m.find(sum-it->first)!=m.end()){cnt+=it->second*m[sum-it->first];}
    }
}
out(cnt/(ll)2);

}
/*

           .$                                  $.
          /:;                                  :;\
         : $                                    $ ;
         ;:$                                    $;:
        : $:              ________              ;$ ;
        ; $;;     _..gg$$SSP^^^^T$S$$pp.._     ::$ :
       : :$;|  .g$$$$$$SSP"      "TS$$$$$$$p.  |:$; ;
       ; :$;:.d$$$$$$$SSS          SS$$$$$$$$b.;:$; :
      :  :$$$$$$$$$$$$SSS          SS$$$$$$$$$$$$$;  ;
      ;  $$$$$$$$$$$$$$SSb.      .dS$$$$$$$$$$$$$$;  :
     :  :S$$$$$$$$$$$$$$SSSSppggSSS$$$$$$$$$$$$$$$;   ;
     |  :SS$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$;   :
     |  :SS$$$$$$$$$$$$$$$$$^^^^^^^^^$$$$$$$$$$$$$$   :
     ;   SS$$$$$$$$$$P^"                 "^T$$$$$$$   :
    :    :SS$$$$$$$$$                       T$$$$$;   :
    |     SSS$$$$$$$;                        T$$$$    :
    |     :SSS$$$$$$;                        :$$$;    :
    ;      SSS$$$$$$;                        :S$$;    :
    ;      :SS$$P"^P                          S$$;    :
    ;    ..d$$$P    `                         S$$$    :
    ;     T$$$P                          dS   T$$$b.  :
    ;    :$$$$.     .                   dSS;   $$$$$b.:
    ;    :$$$$$b     Tb.   .          .dSS$$b.d$$$$$$$:
    :    $$$$$$$b     TSb   Tb..g._, :$$SS$$$$$$SSS$$$:
    :   :$$$$$$$$b     SSb   T$SS$P   "^TS$$$$$$P"TS$$:
    :   $$$$$$$$$$b._.dS$$b _ T$$P _     TSS$SSP  :SS$:
    :  :$$$$SSS$$$$$$$$$P" d$b. _.d$P     TSSP"    SS$:
    :  :P"TSSP"^T$$$$$$P  :$$$$$$$$P d$$b          $S$;
    :  :b.dS^^-.  ""^^"    $b T d$$$s$$$$b __..--""$ $;
    :  :$$$S    ""^^..ggSS$$$$$$$$$$$$$$P^^""     .$ $;
    :   $$$$$pp..__   `j$$$$$$^$$$$$b. d....ggppTSSS$$;
    :   $$$$SP     """t  :$$$$ $$$$$$$b.  d$b    `TSS$;
    :  \:$$SP   _.gd$$P_d$$$$$ $$$$$$$$$bd$P'    .dSPd;
    :   \"^S     "^T$$$$$$$$$$ $$$$$SS$$$$b.    dSS'd$;
    $    $. "-.__.gd$$$$$$$SP:S$$P  TSS$$$$$bssS^".d$$:
   :$    $$b.   ""^^T$$$$SP' :S$P    TSSSP^^""  .d$$$$:
   :$   :$$$P        "^SP'   :S;     .^"`.     $$$$$$$:
   $;   :$$$            "-.  :S;  .-"     \    :$$$$$$:
  .$ :  $$$;   :           `.:S;.'         ;    $$$$$$:;
 .P :S  $$$    ;             `^'                :$$$$$:;
.P  S;.d$$;   :               -'                 $$$$$:;
$  :SS$$$$    ;     __....----  --...____        :$$$ :S
$  $SSS$$;    :  ; d$$$$$$$pppqqqq$$$$$$L;       :$$$ SS
: :SSSSS$$     ; : \ "^T$$$$$$$$$$$$$P' .':      $PT$ SS;
 $SP^"^TSP\    :  \ "-.  """"""""""" .-"  ;     /   $ SSSb.
 :S     S  \           "--...___..--"    /  :  /    :gSSSSSb.
  T bug T   \       `.      _____       /   ; /
   `         \ :      "==="""""""""===""   : /
              `:                           ;'
                "-.                     .-"
                   ""--..         ..--""
*/


// author-Shivam gupta

#include <bits/stdc++.h>

using namespace std;

#define MEM(a, b) memset(a, (b), sizeof(a))

#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)

#define IN(A, B, C) assert( B <= A && A <= C)

#define MP make_pair
#define FOR(i,a) for(int i=0;i<a;i++)

#define FOR1(i,j,a) for(int i=j;i<a;i++)

#define EB emplace_back

#define INF (int)1e9

#define EPS 1e-9

#define PI 3.1415926535897932384626433832795

#define MOD 1000000007

#define read(type) readInt<type>()
#define max1 10000001
#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
const double pi=acos(-1.0);

typedef pair<int, int> PII;

typedef vector<int> VI;

typedef vector<string> VS;

typedef vector<PII> VII;

typedef vector<VI> VVI;

typedef map<int,int> MPII;

typedef set<int> SETI;

typedef multiset<int> MSETI;

typedef long int li;

typedef unsigned long int uli;

typedef long long int ll;

typedef unsigned long long int  ull;

bool isPowerOfTwo (int x)
{
  /* First x in the below expression is
    for the case when x is 0 */
  return x && (!(x&(x-1)));
}
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
ll power(ll x, ll y, ll p)
{
    ll res = 1;      // Initialize result

    x = x % p;  // Update x if it is more than or
                // equal to p

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}

// Returns n^(-1) mod p
ll modInverse(ll n, ll p)
{
    return power(n, p-2, p);
}

// Returns nCr % p using Fermat's little
// theorem.
ll ncr(ll n, ll r,ll p)
{
   // Base case
   if (r==0)
      return 1;

    // Fill factorial array so that we
    // can find all factorial of r, n
    // and n-r
    ll fac[n+1];
    fac[0] = 1;
    for (ll i=1 ; i<=n; i++)
        fac[i] = fac[i-1]*i%p;

    return (fac[n]* modInverse(fac[r], p) % p *
            modInverse(fac[n-r], p) % p) % p;
}

int main(){
    fast();
    vector<ll>s;
unordered_map<ll,ll>M;

ll val=1;
	while(val<MOD){
		s.EB(val);
		val*=2;
	}
	int n;
	cin>>n;
	FOR(i,n){
		cin>>val;
		M[val]++;
	}
	ll ans=0;
	for(auto par: M){
		for(ll lel: s){
			ll dif=lel-par.first;
			if(dif<=0)continue;
			if(dif!=par.first){
				if(dif<par.first)continue;
				if(M.count(dif)) ans+=M[par.first]*M[dif];
			}
			else{
				ans+=(M[par.first]*(M[dif]-1))/2;
			}

}
}
out(ans);

}
/*

           .$                                  $.
          /:;                                  :;\
         : $                                    $ ;
         ;:$                                    $;:
        : $:              ________              ;$ ;
        ; $;;     _..gg$$SSP^^^^T$S$$pp.._     ::$ :
       : :$;|  .g$$$$$$SSP"      "TS$$$$$$$p.  |:$; ;
       ; :$;:.d$$$$$$$SSS          SS$$$$$$$$b.;:$; :
      :  :$$$$$$$$$$$$SSS          SS$$$$$$$$$$$$$;  ;
      ;  $$$$$$$$$$$$$$SSb.      .dS$$$$$$$$$$$$$$;  :
     :  :S$$$$$$$$$$$$$$SSSSppggSSS$$$$$$$$$$$$$$$;   ;
     |  :SS$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$;   :
     |  :SS$$$$$$$$$$$$$$$$$^^^^^^^^^$$$$$$$$$$$$$$   :
     ;   SS$$$$$$$$$$P^"                 "^T$$$$$$$   :
    :    :SS$$$$$$$$$                       T$$$$$;   :
    |     SSS$$$$$$$;                        T$$$$    :
    |     :SSS$$$$$$;                        :$$$;    :
    ;      SSS$$$$$$;                        :S$$;    :
    ;      :SS$$P"^P                          S$$;    :
    ;    ..d$$$P    `                         S$$$    :
    ;     T$$$P                          dS   T$$$b.  :
    ;    :$$$$.     .                   dSS;   $$$$$b.:
    ;    :$$$$$b     Tb.   .          .dSS$$b.d$$$$$$$:
    :    $$$$$$$b     TSb   Tb..g._, :$$SS$$$$$$SSS$$$:
    :   :$$$$$$$$b     SSb   T$SS$P   "^TS$$$$$$P"TS$$:
    :   $$$$$$$$$$b._.dS$$b _ T$$P _     TSS$SSP  :SS$:
    :  :$$$$SSS$$$$$$$$$P" d$b. _.d$P     TSSP"    SS$:
    :  :P"TSSP"^T$$$$$$P  :$$$$$$$$P d$$b          $S$;
    :  :b.dS^^-.  ""^^"    $b T d$$$s$$$$b __..--""$ $;
    :  :$$$S    ""^^..ggSS$$$$$$$$$$$$$$P^^""     .$ $;
    :   $$$$$pp..__   `j$$$$$$^$$$$$b. d....ggppTSSS$$;
    :   $$$$SP     """t  :$$$$ $$$$$$$b.  d$b    `TSS$;
    :  \:$$SP   _.gd$$P_d$$$$$ $$$$$$$$$bd$P'    .dSPd;
    :   \"^S     "^T$$$$$$$$$$ $$$$$SS$$$$b.    dSS'd$;
    $    $. "-.__.gd$$$$$$$SP:S$$P  TSS$$$$$bssS^".d$$:
   :$    $$b.   ""^^T$$$$SP' :S$P    TSSSP^^""  .d$$$$:
   :$   :$$$P        "^SP'   :S;     .^"`.     $$$$$$$:
   $;   :$$$            "-.  :S;  .-"     \    :$$$$$$:
  .$ :  $$$;   :           `.:S;.'         ;    $$$$$$:;
 .P :S  $$$    ;             `^'                :$$$$$:;
.P  S;.d$$;   :               -'                 $$$$$:;
$  :SS$$$$    ;     __....----  --...____        :$$$ :S
$  $SSS$$;    :  ; d$$$$$$$pppqqqq$$$$$$L;       :$$$ SS
: :SSSSS$$     ; : \ "^T$$$$$$$$$$$$$P' .':      $PT$ SS;
 $SP^"^TSP\    :  \ "-.  """"""""""" .-"  ;     /   $ SSSb.
 :S     S  \           "--...___..--"    /  :  /    :gSSSSSb.
  T bug T   \       `.      _____       /   ; /
   `         \ :      "==="""""""""===""   : /
              `:                           ;'
                "-.                     .-"
                   ""--..         ..--""
*/


// author-Shivam gupta

#include <bits/stdc++.h>

using namespace std;

#define MEM(a, b) memset(a, (b), sizeof(a))

#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)

#define IN(A, B, C) assert( B <= A && A <= C)

#define MP make_pair
#define FOR(i,a) for(int i=0;i<a;i++)

#define FOR1(i,j,a) for(int i=j;i<a;i++)

#define EB emplace_back

#define INF (int)1e9

#define EPS 1e-9

#define PI 3.1415926535897932384626433832795

#define MOD 1000000007

#define read(type) readInt<type>()
#define max1 10000001
#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
const double pi=acos(-1.0);

typedef pair<int, int> PII;

typedef vector<int> VI;

typedef vector<string> VS;

typedef vector<PII> VII;

typedef vector<VI> VVI;

typedef map<int,int> MPII;

typedef set<int> SETI;

typedef multiset<int> MSETI;

typedef long int li;

typedef unsigned long int uli;

typedef long long int ll;

typedef unsigned long long int  ull;

bool isPowerOfTwo (int x)
{
  /* First x in the below expression is
    for the case when x is 0 */
  return x && (!(x&(x-1)));
}
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
ll power(ll x, ll y, ll p)
{
    ll res = 1;      // Initialize result

    x = x % p;  // Update x if it is more than or
                // equal to p

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}

// Returns n^(-1) mod p
ll modInverse(ll n, ll p)
{
    return power(n, p-2, p);
}

// Returns nCr % p using Fermat's little
// theorem.
ll ncr(ll n, ll r,ll p)
{
   // Base case
   if (r==0)
      return 1;

    // Fill factorial array so that we
    // can find all factorial of r, n
    // and n-r
    ll fac[n+1];
    fac[0] = 1;
    for (ll i=1 ; i<=n; i++)
        fac[i] = fac[i-1]*i%p;

    return (fac[n]* modInverse(fac[r], p) % p *
            modInverse(fac[n-r], p) % p) % p;
}

int main(){
    fast();
 int n;
cin>>n;
ll a[n];
unordered_map<ll,ll> m;
FOR(i,n){cin>>a[i];m[a[i]]++;}
ll sum=1;
sort(a,a+n);
ll cnt=0;
while(1){
    sum=sum*(ll)2;
    if(sum>MOD){break;}
    for(auto it=m.begin();it!=m.end();it++){
    if(sum==2*it->first && 2<=it->second){cnt+=(it->second*(it->second-1));}
    else if(sum!=2*it->first && it->first<sum && m.find(sum-it->first)!=m.end()){cnt+=it->second*m[sum-it->first];}
    }
}
out(cnt/2);

}
/*

           .$                                  $.
          /:;                                  :;\
         : $                                    $ ;
         ;:$                                    $;:
        : $:              ________              ;$ ;
        ; $;;     _..gg$$SSP^^^^T$S$$pp.._     ::$ :
       : :$;|  .g$$$$$$SSP"      "TS$$$$$$$p.  |:$; ;
       ; :$;:.d$$$$$$$SSS          SS$$$$$$$$b.;:$; :
      :  :$$$$$$$$$$$$SSS          SS$$$$$$$$$$$$$;  ;
      ;  $$$$$$$$$$$$$$SSb.      .dS$$$$$$$$$$$$$$;  :
     :  :S$$$$$$$$$$$$$$SSSSppggSSS$$$$$$$$$$$$$$$;   ;
     |  :SS$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$;   :
     |  :SS$$$$$$$$$$$$$$$$$^^^^^^^^^$$$$$$$$$$$$$$   :
     ;   SS$$$$$$$$$$P^"                 "^T$$$$$$$   :
    :    :SS$$$$$$$$$                       T$$$$$;   :
    |     SSS$$$$$$$;                        T$$$$    :
    |     :SSS$$$$$$;                        :$$$;    :
    ;      SSS$$$$$$;                        :S$$;    :
    ;      :SS$$P"^P                          S$$;    :
    ;    ..d$$$P    `                         S$$$    :
    ;     T$$$P                          dS   T$$$b.  :
    ;    :$$$$.     .                   dSS;   $$$$$b.:
    ;    :$$$$$b     Tb.   .          .dSS$$b.d$$$$$$$:
    :    $$$$$$$b     TSb   Tb..g._, :$$SS$$$$$$SSS$$$:
    :   :$$$$$$$$b     SSb   T$SS$P   "^TS$$$$$$P"TS$$:
    :   $$$$$$$$$$b._.dS$$b _ T$$P _     TSS$SSP  :SS$:
    :  :$$$$SSS$$$$$$$$$P" d$b. _.d$P     TSSP"    SS$:
    :  :P"TSSP"^T$$$$$$P  :$$$$$$$$P d$$b          $S$;
    :  :b.dS^^-.  ""^^"    $b T d$$$s$$$$b __..--""$ $;
    :  :$$$S    ""^^..ggSS$$$$$$$$$$$$$$P^^""     .$ $;
    :   $$$$$pp..__   `j$$$$$$^$$$$$b. d....ggppTSSS$$;
    :   $$$$SP     """t  :$$$$ $$$$$$$b.  d$b    `TSS$;
    :  \:$$SP   _.gd$$P_d$$$$$ $$$$$$$$$bd$P'    .dSPd;
    :   \"^S     "^T$$$$$$$$$$ $$$$$SS$$$$b.    dSS'd$;
    $    $. "-.__.gd$$$$$$$SP:S$$P  TSS$$$$$bssS^".d$$:
   :$    $$b.   ""^^T$$$$SP' :S$P    TSSSP^^""  .d$$$$:
   :$   :$$$P        "^SP'   :S;     .^"`.     $$$$$$$:
   $;   :$$$            "-.  :S;  .-"     \    :$$$$$$:
  .$ :  $$$;   :           `.:S;.'         ;    $$$$$$:;
 .P :S  $$$    ;             `^'                :$$$$$:;
.P  S;.d$$;   :               -'                 $$$$$:;
$  :SS$$$$    ;     __....----  --...____        :$$$ :S
$  $SSS$$;    :  ; d$$$$$$$pppqqqq$$$$$$L;       :$$$ SS
: :SSSSS$$     ; : \ "^T$$$$$$$$$$$$$P' .':      $PT$ SS;
 $SP^"^TSP\    :  \ "-.  """"""""""" .-"  ;     /   $ SSSb.
 :S     S  \           "--...___..--"    /  :  /    :gSSSSSb.
  T bug T   \       `.      _____       /   ; /
   `         \ :      "==="""""""""===""   : /
              `:                           ;'
                "-.                     .-"
                   ""--..         ..--""
*/


// author-Shivam gupta

#include <bits/stdc++.h>

using namespace std;

#define MEM(a, b) memset(a, (b), sizeof(a))

#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)

#define IN(A, B, C) assert( B <= A && A <= C)

#define MP make_pair
#define FOR(i,a) for(int i=0;i<a;i++)

#define FOR1(i,j,a) for(int i=j;i<a;i++)

#define EB emplace_back

#define INF (int)1e9

#define EPS 1e-9

#define PI 3.1415926535897932384626433832795

#define MOD 10000000007

#define read(type) readInt<type>()
#define max1 10000001
#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
const double pi=acos(-1.0);

typedef pair<int, int> PII;

typedef vector<int> VI;

typedef vector<string> VS;

typedef vector<PII> VII;

typedef vector<VI> VVI;

typedef map<int,int> MPII;

typedef set<int> SETI;

typedef multiset<int> MSETI;

typedef long int li;

typedef unsigned long int uli;

typedef long long int ll;

typedef unsigned long long int  ull;

bool isPowerOfTwo (int x)
{
  /* First x in the below expression is
    for the case when x is 0 */
  return x && (!(x&(x-1)));
}
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
ll power(ll x, ll y, ll p)
{
    ll res = 1;      // Initialize result

    x = x % p;  // Update x if it is more than or
                // equal to p

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}

// Returns n^(-1) mod p
ll modInverse(ll n, ll p)
{
    return power(n, p-2, p);
}

// Returns nCr % p using Fermat's little
// theorem.
ll ncr(ll n, ll r,ll p)
{
   // Base case
   if (r==0)
      return 1;

    // Fill factorial array so that we
    // can find all factorial of r, n
    // and n-r
    ll fac[n+1];
    fac[0] = 1;
    for (ll i=1 ; i<=n; i++)
        fac[i] = fac[i-1]*i%p;

    return (fac[n]* modInverse(fac[r], p) % p *
            modInverse(fac[n-r], p) % p) % p;
}

int main(){
    fast();
 int n;
cin>>n;
ll a[n];
unordered_map<ll,ll> m;
FOR(i,n){cin>>a[i];m[a[i]]++;}
ll sum=1;
sort(a,a+n);
ll cnt=0;
while(1){
    sum=sum*(ll)2;
    if(sum>MOD){break;}
    for(auto it=m.begin();it!=m.end();it++){
    if(sum==2*it->first && 2<=it->second){cnt+=(it->second*(it->second-1));}
    else if(sum==2*it->first && it->first<sum && m.find(sum-it->first)!=m.end()){cnt+=it->second*m[sum-it->first];out1(it->first);out1(sum);out(cnt);}
    }
}
out(cnt/2);

}
/*

           .$                                  $.
          /:;                                  :;\
         : $                                    $ ;
         ;:$                                    $;:
        : $:              ________              ;$ ;
        ; $;;     _..gg$$SSP^^^^T$S$$pp.._     ::$ :
       : :$;|  .g$$$$$$SSP"      "TS$$$$$$$p.  |:$; ;
       ; :$;:.d$$$$$$$SSS          SS$$$$$$$$b.;:$; :
      :  :$$$$$$$$$$$$SSS          SS$$$$$$$$$$$$$;  ;
      ;  $$$$$$$$$$$$$$SSb.      .dS$$$$$$$$$$$$$$;  :
     :  :S$$$$$$$$$$$$$$SSSSppggSSS$$$$$$$$$$$$$$$;   ;
     |  :SS$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$;   :
     |  :SS$$$$$$$$$$$$$$$$$^^^^^^^^^$$$$$$$$$$$$$$   :
     ;   SS$$$$$$$$$$P^"                 "^T$$$$$$$   :
    :    :SS$$$$$$$$$                       T$$$$$;   :
    |     SSS$$$$$$$;                        T$$$$    :
    |     :SSS$$$$$$;                        :$$$;    :
    ;      SSS$$$$$$;                        :S$$;    :
    ;      :SS$$P"^P                          S$$;    :
    ;    ..d$$$P    `                         S$$$    :
    ;     T$$$P                          dS   T$$$b.  :
    ;    :$$$$.     .                   dSS;   $$$$$b.:
    ;    :$$$$$b     Tb.   .          .dSS$$b.d$$$$$$$:
    :    $$$$$$$b     TSb   Tb..g._, :$$SS$$$$$$SSS$$$:
    :   :$$$$$$$$b     SSb   T$SS$P   "^TS$$$$$$P"TS$$:
    :   $$$$$$$$$$b._.dS$$b _ T$$P _     TSS$SSP  :SS$:
    :  :$$$$SSS$$$$$$$$$P" d$b. _.d$P     TSSP"    SS$:
    :  :P"TSSP"^T$$$$$$P  :$$$$$$$$P d$$b          $S$;
    :  :b.dS^^-.  ""^^"    $b T d$$$s$$$$b __..--""$ $;
    :  :$$$S    ""^^..ggSS$$$$$$$$$$$$$$P^^""     .$ $;
    :   $$$$$pp..__   `j$$$$$$^$$$$$b. d....ggppTSSS$$;
    :   $$$$SP     """t  :$$$$ $$$$$$$b.  d$b    `TSS$;
    :  \:$$SP   _.gd$$P_d$$$$$ $$$$$$$$$bd$P'    .dSPd;
    :   \"^S     "^T$$$$$$$$$$ $$$$$SS$$$$b.    dSS'd$;
    $    $. "-.__.gd$$$$$$$SP:S$$P  TSS$$$$$bssS^".d$$:
   :$    $$b.   ""^^T$$$$SP' :S$P    TSSSP^^""  .d$$$$:
   :$   :$$$P        "^SP'   :S;     .^"`.     $$$$$$$:
   $;   :$$$            "-.  :S;  .-"     \    :$$$$$$:
  .$ :  $$$;   :           `.:S;.'         ;    $$$$$$:;
 .P :S  $$$    ;             `^'                :$$$$$:;
.P  S;.d$$;   :               -'                 $$$$$:;
$  :SS$$$$    ;     __....----  --...____        :$$$ :S
$  $SSS$$;    :  ; d$$$$$$$pppqqqq$$$$$$L;       :$$$ SS
: :SSSSS$$     ; : \ "^T$$$$$$$$$$$$$P' .':      $PT$ SS;
 $SP^"^TSP\    :  \ "-.  """"""""""" .-"  ;     /   $ SSSb.
 :S     S  \           "--...___..--"    /  :  /    :gSSSSSb.
  T bug T   \       `.      _____       /   ; /
   `         \ :      "==="""""""""===""   : /
              `:                           ;'
                "-.                     .-"
                   ""--..         ..--""
*/


#include <iostream>
#include <set>

int main()
{
    using std::multiset;

    int n, i, x;
    long long ans = 0;
    multiset<int> arr;

    std::cin >> n;
    for(i = 0; i < n; i++)
    {
        std::cin >> x;
        arr.insert(x);
    }

    for(auto pt = arr.begin(); pt != arr.end(); ++pt)
    {
        x = 1;
        while(x <= *pt) x *= 2;
        while(x - *pt <= *arr.rbegin())
        {
            ans += arr.count(x - *pt);
            if(x - *pt == *pt) --ans;
            x *= 2;
        }
    }

    std::cout << ans / 2;

    return 0;
}


#include <iostream>
#include <map>

inline long long sum(long long x){return x * (x - 1);}

int main()
{
    using std::map;

    long long n, i, x;
    long long ans = 0;
    map<long long, int> arr;
    std::cin >> n;

    for(i = 0; i < n; i++)
    {
        std::cin >> x;
        arr[x]++;
    }

    for(auto pt = arr.begin(); pt != arr.end(); pt++)
    {
        long long x = 1;
        while(x <= pt->first) x *= 2;
        while(x < 3e9)
        {
            auto p = arr.find(x - pt->first);
            if(p == pt) ans += sum(pt->second);
            else if(p != arr.end()) ans += p->second;
            x *= 2;
        }
    }

    std::cout << ans / 2;

    return 0;
}


#include <iostream>
#include <set>
#include <vector>

long long sum(int);

int main()
{
    using std::multiset;
    using std::pair;
    using std::vector;

    long long n, i, x;
    long long ans = 0;
    multiset<long long> a;
    vector<pair<int, int>> arr;

    std::cin >> n;
    for(i = 0; i < n; i++)
    {
        std::cin >> x;
        a.insert(x);
    }

    pair<int, int>* temp = new pair<int, int>{*a.begin(), 1};
    for(auto p2 = a.begin(), p1 = p2++; p2 != a.end(); p1++, p2++)
    {
        if(*p1 == *p2) temp->second++;
        else
        {
            arr.push_back(*temp);
            temp->first = *p2;
            temp->second = 1;
        }
    }
    arr.push_back(*temp);
    delete temp;

    for(i = 0; i < arr.size(); i++)
    {
        x = 1;
        while(x <= arr[i].first) x *= 2;
        while(arr.rbegin()->first >= x - arr[i].first)
        {
            if(x == arr[i].first * 2) ans += sum(arr[i].second);
            else
            {
                int l = i, r = arr.size(), m;
                while(r - l > 1)
                {
                    m = (l + r) / 2;
                    if(arr[m].first > x - arr[i].first) r = m;
                    else l = m;
                }
                if(arr[l].first == x - arr[i].first) ans += arr[l].second;
            }
            x *= 2;
        }
    }

    std::cout << ans;

    return 0;
}

long long sum(int x)
{
    return (long long)x * (x - 1) / 2;
}


#include <iostream>
#include <map>

inline long long sum(int);

int main()
{
    using std::map;

    int n, i, x;
    long long ans = 0;
    map<int, int> arr;
    std::cin >> n;

    for(i = 0; i < n; i++)
    {
        std::cin >> x;
        arr[x]++;
    }

    for(auto pt = arr.begin(); pt != arr.end(); pt++)
    {
        long long x = 1;
        while(x <= pt->first) x *= 2;
        while(pt->first + arr.rbegin()->first >= x)
        {
            auto p = arr.find(x - pt->first);
            if(p == pt) ans += sum(pt->second);
            else if(p != arr.end()) ans += p->second;
            x *= 2;
        }
    }

    std::cout << ans / 2;

    return 0;
}

long long sum(int x)
{
    return (long long)x * (x - 1);
}


#include <iostream>
#include <set>
#include <vector>

long long sum(int);

int main()
{
    using std::multiset;
    using std::pair;
    using std::vector;

    int n, i, x;
    long long ans = 0;
    multiset<int> a;
    vector<pair<int, int>> arr;

    std::cin >> n;
    for(i = 0; i < n; i++)
    {
        std::cin >> x;
        a.insert(x);
    }

    pair<int, int>* temp = new pair<int, int>{*a.begin(), 1};
    for(auto p2 = a.begin(), p1 = p2++; p2 != a.end(); p1++, p2++)
    {
        if(*p1 == *p2) temp->second++;
        else
        {
            arr.push_back(*temp);
            temp->first = *p2;
            temp->second = 1;
        }
    }
    arr.push_back(*temp);
    delete temp;

    for(i = 0; i < arr.size(); i++)
    {
        x = 1;
        while(x <= arr[i].first) x *= 2;
        while(arr.rbegin()->first >= x - arr[i].first)
        {
            if(x == arr[i].first * 2) ans += sum(arr[i].second);
            else
            {
                int l = i, r = arr.size(), m;
                while(r - l > 1)
                {
                    m = (l + r) / 2;
                    if(arr[m].first > x - arr[i].first) r = m;
                    else l = m;
                }
                if(arr[l].first == x - arr[i].first) ans += arr[l].second;
            }
            x *= 2;
        }
    }

    std::cout << ans;

    return 0;
}

long long sum(int x)
{
    return (long long)x * (x - 1) / 2;
}


#include <iostream>
#include <map>

inline long long sum(long long x){return x * (x - 1);}

int main()
{
    using std::map;

    long long n, i, x;
    long long ans = 0;
    map<long long, int> arr;
    std::cin >> n;

    for(i = 0; i < n; i++)
    {
        std::cin >> x;
        arr[x]++;
    }

    for(auto pt = arr.begin(); pt != arr.end(); pt++)
    {
        long long x = 1;
        while(x <= pt->first) x *= 2;
        while(pt->first + arr.rbegin()->first >= x)
        {
            auto p = arr.find(x - pt->first);
            if(p == pt) ans += sum(pt->second);
            else if(p != arr.end()) ans += p->second * pt->second;
            x *= 2;
        }
    }

    std::cout << ans / 2;

    return 0;
}


#include <iostream>
#include <map>

inline long long sum(long long x){return x * (x - 1);}

int main()
{
    using std::map;

    long long n, i, x;
    long long ans = 0;
    map<long long, int> arr;
    std::cin >> n;

    for(i = 0; i < n; i++)
    {
        std::cin >> x;
        arr[x]++;
    }

    for(auto pt = arr.begin(); pt != arr.end(); pt++)
    {
        long long x = 1;
        while(x <= pt->first) x *= 2;
        while(pt->first + arr.rbegin()->first >= x)
        {
            auto p = arr.find(x - pt->first);
            if(p == pt) ans += sum(pt->second);
            else if(p != arr.end()) ans += p->second;
            x *= 2;
        }
    }

    std::cout << ans / 2;

    return 0;
}


#include<iostream>
#include<algorithm>
#include<set>
#include<vector>
#include<queue>
#include<cmath>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<ctime>
#include<map>
#include<stack>
#include<string>
using namespace std;

#define eps 1e-8
#define inf 0x3f3f3f3f
#define INF 1e18
#define PI acos(-1.0)
#define mem(a,x) memset(a,x,sizeof(a))
#define zero(x) (((x)>0?(x):-(x))<eps)
#define fl() cout<<"flag!!"<<endl
#define ull unsigned long long
#define ll long long

#define fr(i,j,k) for(int i=j;i<k;i++)
#define ufr(i,j,k) for(int i=j;i>=k;i--)
#define sfi(x) scanf("%d",&x)
#define sfl(x) scanf(%I64d,&x)
#define sfs(x) scanf("%s",x)
#define sfc(x) scanf("%c",&x)
#define sfd(x) scanf("%lf",&x)
#define sfu(x) scanf("%I64u",&x)
#define pri(x) printf("%d\n",x)
#define prs(x) printf("%s\n",x)
#define prd(x) printf("%lf\n",x)
#define prl(x) printf("%I64d\n",x)
#define prul(x) printf("%I64u\n",x)

const int maxn=1e5+9;
map<int,int>mp;
int a[maxn];
int main()
{
	int n;
	cin>>n;
	fr(i,0,n)
	{
		cin>>a[i];
		mp[a[i]]++;
	}
	ull ans=0;
	fr(i,0,n)
	{
		fr(j,1,31)
		{
			int num=(1<<j)-a[i];
			if(mp[num])
			{
				if(num==a[i])
				{
					ans=ans+mp[num]-1;
				}
				else
				{
					ans=ans+mp[num];
				}
			}
		}
	}
	cout<<ans/2<<endl;
	return 0;
}


#include<iostream>
#include<algorithm>
#include<set>
#include<vector>
#include<queue>
#include<cmath>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<ctime>
#include<map>
#include<stack>
#include<string>
using namespace std;

#define eps 1e-8
#define inf 0x3f3f3f3f
#define INF 1e18
#define PI acos(-1.0)
#define mem(a,x) memset(a,x,sizeof(a))
#define zero(x) (((x)>0?(x):-(x))<eps)
#define fl() cout<<"flag!!"<<endl
#define ull unsigned long long
#define ll long long

#define fr(i,j,k) for(int i=j;i<k;i++)
#define ufr(i,j,k) for(int i=j;i>=k;i--)
#define sfi(x) scanf("%d",&x)
#define sfl(x) scanf(%I64d,&x)
#define sfs(x) scanf("%s",x)
#define sfc(x) scanf("%c",&x)
#define sfd(x) scanf("%lf",&x)
#define sfu(x) scanf("%I64u",&x)
#define pri(x) printf("%d\n",x)
#define prs(x) printf("%s\n",x)
#define prd(x) printf("%lf\n",x)
#define prl(x) printf("%I64d\n",x)
#define prul(x) printf("%I64u\n",x)

int getint()
{
    char c=getchar();
    int t=0;
    while (c<'0' || c>'9')
    {
        c=getchar();
    }
    while (c>='0' && c<='9')
    {
        t=t*10+c-'0';
        c=getchar();
    }
    return t;
}

const int maxn=1e5+9;
map<int,int>mp;
int a[maxn];
int main()
{
	int n;
	n=getint();
	fr(i,0,n)
	{
		a[i]=getint();
		mp[a[i]]++;
	}
	ull ans=0;
	fr(i,0,n)
	{
		fr(j,1,31)
		{
			int num=(1<<j)-a[i];
			if(mp[num])
			{
				if(num==a[i])
				{
					ans=ans+mp[num]-1;
				}
				else
				{
					ans=ans+mp[num];
				}
			}
		}
	}
	prul(ans/2);
	return 0;
}


#include<algorithm>
#include<set>
#include<vector>
#include<queue>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<set>
#include<vector>
#include<queue>
#include<cmath>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<ctime>
#include<map>
#include<stack>
#include<string>
using namespace std;

#define sfi(i) scanf("%d",&i)
#define sfl(i) scanf("%lld",&i)
#define pri(i) printf("%d\n",i)
#define sff(i) scanf("%lf",&i)
#define ll long long
#define mem(x,y) memset(x,y,sizeof(x))
#define INF 0x3f3f3f3f
#define eps 1e-6
#define PI acos(-1)
#define lowbit(x) ((x)&(-x))
#define fl() printf("flag\n")
ll gcd(ll a,ll b){while(b^=a^=b^=a%=b);return a;}
const int maxn=1e5+9;
const int mod=1e7+9;

ll p[maxn];
int a[maxn];
map<int ,int>mp;
int main()
{

    ios::sync_with_stdio(false);
    int cnt=0;
    for(ll i=2;i<2e9+5;i*=2)
    {
        p[cnt++]=i;
    }
    //for(int i=0;i<cnt;i++) cout<<p[i]<<" ";
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        mp[a[i]]++;
    }
    sort(a+1,a+n+1);
    int ans=0;
    for(int i=1;i<=(n)/2;i++)
    {
        for(int j=0;j<cnt;j++)
        {
            if(  (mp[p[j]-a[i]]!=0))
            {
                if(p[j]-a[i]<a[i]) continue;
                if(mp[p[j]-a[i]]==1&&p[j]-a[i]==a[i]) continue;
                //cout<<a[i]<<" "<<p[j]-a[i]<<endl;
                ans=ans+mp[p[j]-a[i]];
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


#include<iostream>
#include<algorithm>
#include<set>
#include<vector>
#include<queue>
#include<cmath>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<ctime>
#include<map>
#include<stack>
#include<string>
using namespace std;

#define eps 1e-8
#define inf 0x3f3f3f3f
#define INF 1e18
#define PI acos(-1.0)
#define mem(a,x) memset(a,x,sizeof(a))
#define zero(x) (((x)>0?(x):-(x))<eps)
#define fl() cout<<"flag!!"<<endl
#define ull unsigned long long
#define ll long long

#define fr(i,j,k) for(int i=j;i<k;i++)
#define ufr(i,j,k) for(int i=j;i>=k;i--)
#define sfi(x) scanf("%d",&x)
#define sfl(x) scanf(%I64d,&x)
#define sfs(x) scanf("%s",x)
#define sfc(x) scanf("%c",&x)
#define sfd(x) scanf("%lf",&x)
#define sfu(x) scanf("%I64u",&x)
#define pri(x) printf("%d\n",x)
#define prs(x) printf("%s\n",x)
#define prd(x) printf("%lf\n",x)
#define prl(x) printf("%I64d\n",x)
#define prul(x) printf("%I64u\n",x)

const int maxn=1e5+9;
int a[maxn],b[40];

int main()
{
	b[0]=1;
	fr(i,1,31)
	{
		b[i]=b[i-1]*2;
	}
	int n;
	while(~sfi(n))
	{
		fr(i,0,n)
		{
			sfi(a[i]);
		}
		sort(a,a+n);
		ull ans=0;
		fr(i,0,n)
		{
			fr(j,1,31)
			{
				int num=b[j]-a[i];
				if(num<=0) continue;
				int le=lower_bound(a+i+1,a+n,num)-a;
				int ri=upper_bound(a+i+1,a+n,num)-a;
				if(ri-le>0)
				{
					ans+=ri-le;
				}
			}
		}
		prul(ans);
	}

	return 0;
}


#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#define mann 100005
using namespace std;
int a[mann],b[32],aa[mann];
int main()
{
    int n;
    b[0]=1;
    for(int i=1;i<32;i++)
        b[i]=b[i-1]*2;
    while(~scanf("%d",&n))
    {
        long long ans=0;
        for(int i=0;i<n;i++)
            scanf("%d",&a[i]);
            sort(a,a+n);
         for(int i=0;i<n;i++)
         {
             for(int j=0;j<32;j++)
             {
                 // d为a[i]固定后应该找的a[k]
                 int d=b[j]-a[i];
                 //cout<<d<<endl;
                 if(d<=0)
                    continue;
                 else
                 {
                  // 查找a[k]的上/下界
                     int la=lower_bound(a+i+1,a+n,d)-a;
                     int ra=upper_bound(a+i+1,a+n,d)-a;
                     //cout<<"la="<<la<<" ra="<<ra<<endl;
                     if(ra-la>0)
                        ans+=ra-la;
                 }
             }
         }
         printf("%I64d\n",ans);
    }
    return 0;
}


# include <iostream>
# include <map>
using namespace std;
map<int, int > m;
int c[100010], a[100010];
int main(){
	int n, i, j, k;
	cin>>n;
	for(i=1; i<=n; i++){
		cin>>a[i];
		m[a[i]]++;
	}
	long long int cnt=0;
	for(i=1; i<=n; i++){
		for(j=1; j<=30; j++){
			int num=(1<<j)-a[i];
			if(m[num]){
				if(num==a[i]){
					cnt=cnt+m[num]-1;
				}
				else{
					cnt=cnt+m[num];
				}
			}
		}
	}
	cout<<cnt/2;
	return 0;
}


#include<algorithm>
#include<set>
#include<vector>
#include<queue>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<set>
#include<vector>
#include<queue>
#include<cmath>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<ctime>
#include<map>
#include<stack>
#include<string>
using namespace std;

#define sfi(i) scanf("%d",&i)
#define sfl(i) scanf("%lld",&i)
#define pri(i) printf("%d\n",i)
#define sff(i) scanf("%lf",&i)
#define ll long long
#define mem(x,y) memset(x,y,sizeof(x))
#define INF 0x3f3f3f3f
#define eps 1e-6
#define PI acos(-1)
#define lowbit(x) ((x)&(-x))
#define fl() printf("flag\n")
ll gcd(ll a,ll b){while(b^=a^=b^=a%=b);return a;}
const int maxn=1e5+9;
const int mod=1e7+9;

int p[maxn];
int a[maxn];
map<int ,int>mp;
int main()
{

    ios::sync_with_stdio(false);
    int cnt=0;
    for(int i=2;i<1e9+5;i*=2)
    {
        p[cnt++]=i;
    }
    //for(int i=0;i<cnt;i++) cout<<p[i]<<" ";
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        mp[a[i]]++;
    }
    sort(a+1,a+n+1);
    int ans=0;
    for(int i=1;i<=n/2;i++)
    {
        for(int j=0;j<cnt;j++)
        {
            if(  (mp[p[j]-a[i]]!=0))
            {
                if(mp[p[j]-a[i]]==1&&p[j]-a[i]==a[i]) continue;
                //cout<<a[i]<<" "<<p[j]-a[i]<<endl;
                ans=ans+mp[p[j]-a[i]];
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


#include<iostream>
#include<algorithm>
#include<set>
#include<vector>
#include<queue>
#include<cmath>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<ctime>
#include<map>
#include<stack>
#include<string>
using namespace std;

#define eps 1e-8
#define inf 0x3f3f3f3f
#define INF 1e18
#define PI acos(-1.0)
#define mem(a,x) memset(a,x,sizeof(a))
#define zero(x) (((x)>0?(x):-(x))<eps)
#define fl() cout<<"flag!!"<<endl
#define ull unsigned long long
#define ll long long

#define fr(i,j,k) for(int i=j;i<k;i++)
#define ufr(i,j,k) for(int i=j;i>=k;i--)
#define sfi(x) scanf("%d",&x)
#define sfl(x) scanf(%I64d,&x)
#define sfs(x) scanf("%s",x)
#define sfc(x) scanf("%c",&x)
#define sfd(x) scanf("%lf",&x)
#define sfu(x) scanf("%I64u",&x)
#define pri(x) printf("%d\n",x)
#define prs(x) printf("%s\n",x)
#define prd(x) printf("%lf\n",x)
#define prl(x) printf("%I64d\n",x)
#define prul(x) printf("%I64u\n",x)

int getint()
{
    char c=getchar();
    int t=0;
    while (c<'0' || c>'9')
    {
        c=getchar();
    }
    while (c>='0' && c<='9')
    {
        t=t*10+c-'0';
        c=getchar();
    }
    return t;
}

const int maxn=1e5+9;
map<int,int>mp;
int a[maxn];
int main()
{
	int n;
	n=getint();
	fr(i,0,n)
	{
		a[i]=getint();
		mp[a[i]]++;
	}
	ull ans=0;
	fr(i,0,n)
	{
		fr(j,1,31)
		{
			int num=(1<<j)-a[i];
			if(mp[num])
			{
				if(num==a[i])
				{
					ans=ans+mp[num]-1;
				}
				else
				{
					ans=ans+mp[num];
				}
			}
		}
	}
	pri(ans/2);
	return 0;
}


#include<iostream>
#include<algorithm>
#include<set>
#include<vector>
#include<queue>
#include<cmath>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<ctime>
#include<map>
#include<stack>
#include<string>
using namespace std;

#define eps 1e-8
#define inf 0x3f3f3f3f
#define INF 1e18
#define PI acos(-1.0)
#define mem(a,x) memset(a,x,sizeof(a))
#define zero(x) (((x)>0?(x):-(x))<eps)
#define fl() cout<<"flag!!"<<endl
#define ull unsigned long long
#define ll long long

#define fr(i,j,k) for(int i=j;i<k;i++)
#define ufr(i,j,k) for(int i=j;i>=k;i--)
#define sfi(x) scanf("%d",&x)
#define sfl(x) scanf(%I64d,&x)
#define sfs(x) scanf("%s",x)
#define sfc(x) scanf("%c",&x)
#define sfd(x) scanf("%lf",&x)
#define sfu(x) scanf("%I64u",&x)
#define pri(x) printf("%d\n",x)
#define prs(x) printf("%s\n",x)
#define prd(x) printf("%lf\n",x)
#define prl(x) printf("%I64d\n",x)
#define prul(x) printf("%I64u\n",x)

const int maxn=1e5+9;
map<int,int>mp;
int a[maxn],b[40];

int main()
{
	b[0]=1;
	fr(i,1,31)
	{
		b[i]=b[i-1]*2;
	}
	int n;
	while(~sfi(n))
	{
		mp.clear();
		fr(i,0,n)
		{
			sfi(a[i]);
			mp[a[i]]++;
		}
		ull ans=0;
		fr(i,0,n)
		{
			fr(j,1,31)
			{
				int num=b[j]-a[i];
				if(mp[num])
				{
					if(num==a[i])
					{
						ans=ans+mp[num]-1;
					}
					else
					{
						ans=ans+mp[num];
					}
				}
			}
		}
		prul(ans/2);
	}

	return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define nl '\n'
#define vi vector<ll>
#define pb push_back
#define F first
#define S second
#define all(c)  c.begin(), c.end()
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pi 3.141592653589793238462643383279502884197169399
const ll N = 1e9+7;
const ll mod = 1e9+7;
using namespace std;
bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
}
bool prime(ll n)
{

        if (n <= 1)  return false;
        if (n <= 3)  return true;

        if (n%2 == 0 || n%3 == 0) return false;

        for (ll i=5; i*i<=n; i=i+6)
            if (n%i == 0 || n%(i+2) == 0)
               return false;

        return true;
}
bool isPowerOfTwo(ll n)
{
       if(n==0)
       return false;

       return (ceil(log2(n)) == floor(log2(n)));
}

void SieveOfEratosthenes(ll n)
{

     bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (ll p=2; p*p<=n; p++)
    {

        if (prime[p] == true)
        {

            for (ll i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }

    for (ll p=2; p<=n; p++)
       if (prime[p])
          cout << p << " ";
}
ll modularinv(ll x,ll n)
{
    if(n==0)
      return 1;
      else if(n%2==0)
      return modularinv((x*x)%mod,n/2);
      else
      return (x*modularinv((x*x)%mod,(n-1)/2))%mod;

}
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
map<ll,ll> mpp;
void primeFactors(ll n)
{

    while (n % 2 == 0)
    {
        mpp[2]++;
        n = n/2;
    }

    for (int i = 3; i <= sqrt(n); i = i + 2)
    {

        while (n % i == 0)
        {
            mpp[i]++;
            n = n/i;
        }
    }

    if (n > 2)
        mpp[n]++;
}
ll check(vi v,ll k)
{
   set<ll> s;
   for(auto x:v)
   s.insert(x);
    return s.size();

}
int main()
{
       io;
       ll t,n,i,x,m,k,y,p,w,h,j,a,b,c,q,d,n1;
       //cin>>t;
       t=1;
       while(t--)
       {
         cin>>n;
         vi v(n);
         map<ll,ll> mpp;
         for(i=0;i<n;i++)
         {
            cin>>v[i];
            mpp[v[i]]++;
         }
         ll count=0;
         vi v1(33);
         ll k=1;
         for(i=0;i<33;i++)
         {
           v1[i]=k;
           k*=2;
         }
         set<pair<ll,ll>> s;
         for(i=0;i<n;i++)
         {
            ll d=v[i];
            for(j=0;j<33;j++)
            {
              ll g=abs(v[i]-v1[i]);
              if(isPowerOfTwo(g))
              {
                 if(mpp[g])
                 {

                   if(s.find({d,g})!=s.end()||s.find({g,d})!=s.end());
                   else
                   {
                      count+=mpp[g];
                      s.insert({d,g});
                   }
                 }

              }

            }

         }
         cout<<count<<nl;

       }

}


#include<bits/stdc++.h>
#define ll long long int
#define nl '\n'
#define vi vector<ll>
#define pb push_back
#define F first
#define S second
#define all(c)  c.begin(), c.end()
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pi 3.141592653589793238462643383279502884197169399
const ll N = 1e9+7;
const ll mod = 1e9+7;
using namespace std;
bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
}
bool prime(ll n)
{

        if (n <= 1)  return false;
        if (n <= 3)  return true;

        if (n%2 == 0 || n%3 == 0) return false;

        for (ll i=5; i*i<=n; i=i+6)
            if (n%i == 0 || n%(i+2) == 0)
               return false;

        return true;
}
bool isPowerOfTwo(ll n)
{
       if(n==0)
       return false;

       return (ceil(log2(n)) == floor(log2(n)));
}

void SieveOfEratosthenes(ll n)
{

     bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (ll p=2; p*p<=n; p++)
    {

        if (prime[p] == true)
        {

            for (ll i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }

    for (ll p=2; p<=n; p++)
       if (prime[p])
          cout << p << " ";
}
ll modularinv(ll x,ll n)
{
    if(n==0)
      return 1;
      else if(n%2==0)
      return modularinv((x*x)%mod,n/2);
      else
      return (x*modularinv((x*x)%mod,(n-1)/2))%mod;

}
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
map<ll,ll> mpp;
void primeFactors(ll n)
{

    while (n % 2 == 0)
    {
        mpp[2]++;
        n = n/2;
    }

    for (int i = 3; i <= sqrt(n); i = i + 2)
    {

        while (n % i == 0)
        {
            mpp[i]++;
            n = n/i;
        }
    }

    if (n > 2)
        mpp[n]++;
}
ll check(vi v,ll k)
{
   set<ll> s;
   for(auto x:v)
   s.insert(x);
    return s.size();

}
int main()
{
       io;
       ll t,n,i,x,m,k,y,p,w,h,j,a,b,c,q,d,n1;
       //cin>>t;
       t=1;
       while(t--)
       {
         cin>>n;
         vi v(n);
         map<ll,ll> mpp;
         for(i=0;i<n;i++)
         {
            cin>>v[i];
            mpp[v[i]]++;
         }
         ll count=0;
         vi v1(40);
         ll k=1;
         for(i=0;i<40;i++)
         {
           v1[i]=k;
           //cout<<k<<nl;
           k*=2;
         }
         set<pair<ll,ll>> s;
         for(i=0;i<n;i++)
         {
            ll d=v[i];
            for(j=0;j<40;j++)
            {
              ll g=abs(v[i]-v1[j]);

              if(isPowerOfTwo(d+g))
              {  //cout<<g<<nl;
                 if(mpp[g])
                 {
                   if(d==g&&mpp[g]==1);
                   else
                   {
                   if(s.find({d,g})!=s.end()||s.find({g,d})!=s.end());
                   else
                   {
                      count+=mpp[g];
                      s.insert({d,g});
                      //cout<<d<<" "<<g<<nl;
                   }
                   }
                 }

              }

            }

         }
         cout<<count<<nl;

       }

}


#include<bits/stdc++.h>
#define ll long long int
#define nl '\n'
#define vi vector<ll>
#define pb push_back
#define F first
#define S second
#define all(c)  c.begin(), c.end()
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pi 3.141592653589793238462643383279502884197169399
const ll N = 1e9+7;
const ll mod = 1e9+7;
using namespace std;
bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
}
bool prime(ll n)
{

        if (n <= 1)  return false;
        if (n <= 3)  return true;

        if (n%2 == 0 || n%3 == 0) return false;

        for (ll i=5; i*i<=n; i=i+6)
            if (n%i == 0 || n%(i+2) == 0)
               return false;

        return true;
}
bool isPowerOfTwo(ll n)
{
       if(n==0)
       return false;

       return (ceil(log2(n)) == floor(log2(n)));
}

void SieveOfEratosthenes(ll n)
{

     bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (ll p=2; p*p<=n; p++)
    {

        if (prime[p] == true)
        {

            for (ll i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }

    for (ll p=2; p<=n; p++)
       if (prime[p])
          cout << p << " ";
}
ll modularinv(ll x,ll n)
{
    if(n==0)
      return 1;
      else if(n%2==0)
      return modularinv((x*x)%mod,n/2);
      else
      return (x*modularinv((x*x)%mod,(n-1)/2))%mod;

}
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
map<ll,ll> mpp;
void primeFactors(ll n)
{

    while (n % 2 == 0)
    {
        mpp[2]++;
        n = n/2;
    }

    for (int i = 3; i <= sqrt(n); i = i + 2)
    {

        while (n % i == 0)
        {
            mpp[i]++;
            n = n/i;
        }
    }

    if (n > 2)
        mpp[n]++;
}
ll check(vi v,ll k)
{
   set<ll> s;
   for(auto x:v)
   s.insert(x);
    return s.size();

}
int main()
{
       io;
       ll t,n,i,x,m,k,y,p,w,h,j,a,b,c,q,d,n1;
       //cin>>t;
       t=1;
       while(t--)
       {
         cin>>n;
         vi v(n);
         map<ll,ll> mpp;
         for(i=0;i<n;i++)
         {
            cin>>v[i];
            mpp[v[i]]++;
         }
         ll count=0;
         vi v1(40);
         ll k=1;
         for(i=0;i<40;i++)
         {
           v1[i]=k;
           //cout<<k<<nl;
           k*=2;
         }
         set<pair<ll,ll>> s;
         for(i=0;i<n;i++)
         {
            ll d=v[i];
            for(j=0;j<40;j++)
            {
              ll g=abs(v[i]-v1[j]);

              if(isPowerOfTwo(d+g))
              {  //cout<<g<<nl;
                 if(mpp[g])
                 {
                   if(d==g&&mpp[g]==1);
                   else
                   {
                   if(s.find({d,g})!=s.end()||s.find({g,d})!=s.end());
                   else
                   {
                      ll r=mpp[g]*mpp[d];
                      if(d==g)
                      {
                        r=mpp[g]*(mpp[g]-1);
                        r/=2;
                      }
                      count+=r;
                      s.insert({d,g});
                      //cout<<d<<" "<<g<<nl;
                   }
                   }
                 }

              }

            }

         }
         cout<<count<<nl;

       }

}


#include<bits/stdc++.h>
#define ll long long int
#define nl '\n'
#define vi vector<ll>
#define pb push_back
#define F first
#define S second
#define all(c)  c.begin(), c.end()
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pi 3.141592653589793238462643383279502884197169399
const ll N = 1e9+7;
const ll mod = 1e9+7;
using namespace std;
bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
}
bool prime(ll n)
{

        if (n <= 1)  return false;
        if (n <= 3)  return true;

        if (n%2 == 0 || n%3 == 0) return false;

        for (ll i=5; i*i<=n; i=i+6)
            if (n%i == 0 || n%(i+2) == 0)
               return false;

        return true;
}
bool isPowerOfTwo(ll n)
{
       if(n==0)
       return false;

       return (ceil(log2(n)) == floor(log2(n)));
}

void SieveOfEratosthenes(ll n)
{

     bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (ll p=2; p*p<=n; p++)
    {

        if (prime[p] == true)
        {

            for (ll i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }

    for (ll p=2; p<=n; p++)
       if (prime[p])
          cout << p << " ";
}
ll modularinv(ll x,ll n)
{
    if(n==0)
      return 1;
      else if(n%2==0)
      return modularinv((x*x)%mod,n/2);
      else
      return (x*modularinv((x*x)%mod,(n-1)/2))%mod;

}
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
map<ll,ll> mpp;
void primeFactors(ll n)
{

    while (n % 2 == 0)
    {
        mpp[2]++;
        n = n/2;
    }

    for (int i = 3; i <= sqrt(n); i = i + 2)
    {

        while (n % i == 0)
        {
            mpp[i]++;
            n = n/i;
        }
    }

    if (n > 2)
        mpp[n]++;
}
ll check(vi v,ll k)
{
   set<ll> s;
   for(auto x:v)
   s.insert(x);
    return s.size();

}
int main()
{
       io;
       ll t,n,i,x,m,k,y,p,w,h,j,a,b,c,q,d,n1;
       //cin>>t;
       t=1;
       while(t--)
       {
         cin>>n;
         vi v(n);
         map<ll,ll> mpp;
         for(i=0;i<n;i++)
         {
            cin>>v[i];
            mpp[v[i]]++;
         }
         ll count=0;
         vi v1(40);
         ll k=1;
         for(i=0;i<40;i++)
         {
           v1[i]=k;
           //cout<<k<<nl;
           k*=2;
         }
         set<pair<ll,ll>> s;
         for(i=0;i<n;i++)
         {
            ll d=v[i];
            for(j=0;j<40;j++)
            {
              ll g=abs(v[i]-v1[j]);

              if(isPowerOfTwo(d+g))
              {  //cout<<g<<nl;
                 if(mpp[g])
                 {
                   if(d==g&&mpp[g]==1);
                   else
                   {
                   if(s.find({d,g})!=s.end()||s.find({g,d})!=s.end());
                   else
                   {
                      ll r=mpp[g];
                      if(d==g)
                      {
                        r=r*(r-1);
                        r/=2;
                      }
                      count+=r;
                      s.insert({d,g});
                      //cout<<d<<" "<<g<<nl;
                   }
                   }
                 }

              }

            }

         }
         cout<<count<<nl;

       }

}


#include<bits/stdc++.h>
#define ll long long int
#define nl '\n'
#define vi vector<ll>
#define pb push_back
#define F first
#define S second
#define all(c)  c.begin(), c.end()
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pi 3.141592653589793238462643383279502884197169399
const ll N = 1e9+7;
const ll mod = 1e9+7;
using namespace std;
bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
}
bool prime(ll n)
{

        if (n <= 1)  return false;
        if (n <= 3)  return true;

        if (n%2 == 0 || n%3 == 0) return false;

        for (ll i=5; i*i<=n; i=i+6)
            if (n%i == 0 || n%(i+2) == 0)
               return false;

        return true;
}
bool isPowerOfTwo(ll n)
{
       if(n==0)
       return false;

       return (ceil(log2(n)) == floor(log2(n)));
}

void SieveOfEratosthenes(ll n)
{

     bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (ll p=2; p*p<=n; p++)
    {

        if (prime[p] == true)
        {

            for (ll i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }

    for (ll p=2; p<=n; p++)
       if (prime[p])
          cout << p << " ";
}
ll modularinv(ll x,ll n)
{
    if(n==0)
      return 1;
      else if(n%2==0)
      return modularinv((x*x)%mod,n/2);
      else
      return (x*modularinv((x*x)%mod,(n-1)/2))%mod;

}
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
map<ll,ll> mpp;
void primeFactors(ll n)
{

    while (n % 2 == 0)
    {
        mpp[2]++;
        n = n/2;
    }

    for (int i = 3; i <= sqrt(n); i = i + 2)
    {

        while (n % i == 0)
        {
            mpp[i]++;
            n = n/i;
        }
    }

    if (n > 2)
        mpp[n]++;
}
ll check(vi v,ll k)
{
   set<ll> s;
   for(auto x:v)
   s.insert(x);
    return s.size();

}
int main()
{
       io;
       ll t,n,i,x,m,k,y,p,w,h,j,a,b,c,q,d,n1;
       //cin>>t;
       t=1;
       while(t--)
       {
         cin>>n;
         vi v(n);
         map<ll,ll> mpp;
         for(i=0;i<n;i++)
         {
            cin>>v[i];
            mpp[v[i]]++;
         }
         ll count=0;
         vi v1(40);
         ll k=1;
         for(i=0;i<40;i++)
         {
           v1[i]=k;
           //cout<<k<<nl;
           k*=2;
         }
         set<pair<ll,ll>> s;
         for(i=0;i<n;i++)
         {
            ll d=v[i];
            for(j=0;j<40;j++)
            {
              ll g=abs(v[i]-v1[j]);

              {  //cout<<g<<nl;
                 if(mpp[g])
                 {

                   if(s.find({d,g})!=s.end()||s.find({g,d})!=s.end());
                   else
                   {
                      count+=mpp[g];
                      s.insert({d,g});
                      //cout<<d<<" "<<g<<nl;
                   }
                 }

              }

            }

         }
         cout<<count<<nl;

       }

}


#include <iostream>
#include <cmath>
#include <vector>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
#include <stack>
#include <utility>
#include <cstring>
using namespace std;
#define ll long long
typedef vector<int> vi;
#define all(v) ((v).begin()),((v).end())
void fast();
long long power(ll n, ll k){
    if(k==0) return 1;
    ll sq=power(n,k/2);
    sq=sq*sq;
    if(k%2==1)
        sq=sq*n;
    return sq;
}
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
// freopen("input.txt" ,"r",stdin );
// freopen("output.txt","w",stdout);
vector<int> v;
map<int,int> mp;
int main()
{
    fast();
    int n,x; cin>>n;
    for(int i=0;i<n;i++) cin>>x,v.push_back(x),mp[x]++;
    sort(v.begin(),v.end());
    ll count=0;
    for(int i=1;i<=31;i++){
        ll p=power(2,i);
        for(int j=0;j<(int)v.size();j++){
            int k=lower_bound(v.begin(),v.end(),int(p-v[j]))-v.begin();
            if(v[k]==p-v[j]){
            if(k<n && k!=j && v[k]!=v[j]){
                if(mp[v[k]]>0&&j<k)
                count++;
                mp[v[k]]--;
            }
            else if(k<n && k!=j && v[k]==v[j]){
                int mo=mp[v[k]];
                count+=mo*(mo-1)/2;
                mp[v[k]]=0;
            }
            }
        }
    }
    cout<<count;
    return 0;
}
void fast()
{std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
}


#include <iostream>
#include <cmath>
#include <vector>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
#include <stack>
#include <utility>
#include <cstring>
using namespace std;
#define ll long long
typedef vector<int> vi;
#define all(v) ((v).begin()),((v).end())
void fast();
long long power(ll n, ll k){
    long long power=1;
    for(int i=0;i<k;i++){
        power=power*n;
    }
    return power;
}
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
// freopen("input.txt" ,"r",stdin );
// freopen("output.txt","w",stdout);
ll arr[100000+50];
int main()
{
    fast();
    ll n,k; cin>>n;
    for(int i=0;i<n;i++) cin>>arr[i];
    sort(arr,arr+n);
    ll cnt=0;
    for(int i=0;i<n;i++){
        for(int j=1;j<=21;j++){
            ll x=power(2,j)-arr[i];
            if(binary_search(arr,arr+n,x)){
                cnt++; arr[i]=-15000000; break;
            }
        }
    }
    cout<<cnt;
    return 0;
}
void fast()
{std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
}


#include <iostream>
#include <cmath>
#include <vector>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
#include <stack>
#include <utility>
#include <cstring>
using namespace std;
#define ll long long
typedef vector<int> vi;
#define all(v) ((v).begin()),((v).end())
void fast();
long long power(ll n, ll k){
    if(k==0) return 1;
    ll sq=power(n,k/2);
    sq=sq*sq;
    if(k%2==1)
        sq=sq*n;
    return sq;
}
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
// freopen("input.txt" ,"r",stdin );
// freopen("output.txt","w",stdout);
vector<int> v;
map<int,int> mp;
int main()
{
    fast();
    int n,x; cin>>n;
    for(int i=0;i<n;i++) cin>>x,v.push_back(x),mp[x]++;
    sort(v.begin(),v.end());
    ll count=0;
    for(int i=1;i<=31;i++){
        ll p=power(2,i);
        for(int j=0;j<(int)v.size();j++){
            int k=int(p-v[j]);
            //cout<<k<<" ";
            int start=0,ende=n-1;
            int ans=-1;
            while(start<=ende){
                int mid=(start+ende)/2;
                if(v[mid]>k) ende=mid-1;
                else if(v[mid]<k) start=mid+1;
                else {ans=mid; break;}
            }
            if(ans!=-1){
            if(ans<n && ans!=j && v[ans]!=v[j]){
                if(mp[v[ans]]>0&&j<ans)
                    count+=mp[v[ans]];
            }
            else if(ans<n && j<ans&& v[ans]==v[j]){
                int mo=mp[v[ans]];
                count+=mo*(mo-1)/2;
                mp[v[ans]]=0;
            }
            }
        }
    }
    cout<<count;
    return 0;
}
void fast()
{std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
}


#include <iostream>
#include <cmath>
#include <vector>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
#include <stack>
#include <utility>
#include <cstring>
using namespace std;
#define ll long long
typedef vector<int> vi;
#define all(v) ((v).begin()),((v).end())
void fast();
long long power(ll n, ll k){
    if(k==0) return 1;
    ll sq=power(n,k/2);
    sq=sq*sq;
    if(k%2==1)
        sq=sq*n;
    return sq;
}
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
// freopen("input.txt" ,"r",stdin );
// freopen("output.txt","w",stdout);
vector<int> v;
map<int,int> mp;
int main()
{
    fast();
    int n,x; cin>>n;
    for(int i=0;i<n;i++) cin>>x,v.push_back(x),mp[x]++;
    sort(v.begin(),v.end());
    ll count=0;
    for(int i=1;i<=31;i++){
        ll p=power(2,i);
        for(int j=0;j<(int)v.size();j++){
            int k=int(p-v[j]);
            //cout<<k<<" ";
            int start=0,ende=n-1;
            int ans=-1;
            while(start<=ende){
                int mid=(start+ende)/2;
                if(v[mid]>k) ende=mid-1;
                else if(v[mid]<k) start=mid+1;
                else {ans=mid; break;}
            }
            if(ans!=-1){
            if(v[ans]!=v[j]){
                if(mp[v[ans]]>0&&j<ans)
                    count+=mp[v[ans]];
            }
            else if(v[ans]==v[j]){
                count+=--mp[v[ans]];
            }
            }
        }
    }
    cout<<count;
    return 0;
}
void fast()
{std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
}


#include <iostream>
#include <cmath>
#include <vector>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
#include <stack>
#include <utility>
#include <cstring>
using namespace std;
#define ll long long
typedef vector<int> vi;
#define all(v) ((v).begin()),((v).end())
void fast();
long long power(ll n, ll k){
    if(k==0) return 1;
    ll sq=power(n,k/2);
    sq=sq*sq;
    if(k%2==1)
        sq=sq*n;
    return sq;
}
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
// freopen("input.txt" ,"r",stdin );
// freopen("output.txt","w",stdout);
vector<int> v;
map<int,int> mp;
int main()
{
    fast();
    int n,x; cin>>n;
    for(int i=0;i<n;i++) cin>>x,v.push_back(x),mp[x]++;
    sort(v.begin(),v.end());
    ll count=0;
    for(int i=1;i<=31;i++){
        ll p=power(2,i);
        for(int j=0;j<(int)v.size();j++){
            int k=int(p-v[j]);
            //cout<<k<<" ";
            int start=0,ende=n-1;
            int ans=-1;
            while(start<=ende){
                int mid=(start+ende)/2;
                if(v[mid]>k) ende=mid-1;
                else if(v[mid]<k) start=mid+1;
                else {ans=mid; break;}
            }
            if(ans!=-1){
            if(v[ans]!=v[j]){
                    count+=mp[v[ans]];
            }
            else if(v[ans]==v[j]){
                count+=--mp[v[ans]];
            }
            }
        }
    }
    cout<<count;
    return 0;
}
void fast()
{std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
}


#include <iostream>
#include <cmath>
#include <vector>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
#include <stack>
#include <utility>
#include <cstring>
using namespace std;
#define ll long long
typedef vector<int> vi;
#define all(v) ((v).begin()),((v).end())
void fast();
long long power(ll n, ll k){
    if(k==0) return 1;
    ll sq=power(n,k/2);
    sq=sq*sq;
    if(k%2==1)
        sq=sq*n;
    return sq;
}
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
// freopen("input.txt" ,"r",stdin );
// freopen("output.txt","w",stdout);
vector<int> v;
map<int,int> mp;
int main()
{
    fast();
    int n,x; cin>>n;
    for(int i=0;i<n;i++) cin>>x,v.push_back(x),mp[x]++;
    sort(v.begin(),v.end());
    ll count=0;
    for(int i=1;i<=31;i++){
        ll p=power(2,i);
        for(int j=0;j<(int)v.size();j++){
            int k=int(p-v[j]);
            //cout<<k<<" ";
            int start=0,ende=n-1;
            int ans=-1;
            while(start<=ende){
                int mid=(start+ende)/2;
                if(v[mid]>k) ende=mid-1;
                else if(v[mid]<k) start=mid+1;
                else {ans=mid; break;}
            }
            if(ans!=-1){
            if(ans<n && ans!=j && v[ans]!=v[j]){
                if(mp[v[ans]]>0&&j<ans)
                    count+=mp[v[ans]];
            }
            else if(ans<n && ans!=j &&j<ans&& v[ans]==v[j]){
                int mo=mp[v[ans]];
                count+=mo*(mo-1)/2;
                mp[v[ans]]=1;
            }
            }
        }
    }
    cout<<count;
    return 0;
}
void fast()
{std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
}


#include <iostream>
#include <cmath>
#include <vector>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
#include <stack>
#include <utility>
#include <cstring>
using namespace std;
#define ll long long
typedef vector<int> vi;
#define all(v) ((v).begin()),((v).end())
void fast();
long long power(ll n, ll k){
    if(k==0) return 1;
    ll sq=power(n,k/2);
    sq=sq*sq;
    if(k%2==1)
        sq=sq*n;
    return sq;
}
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
// freopen("input.txt" ,"r",stdin );
// freopen("output.txt","w",stdout);
vector<int> v;
map<int,int> mp;
int main()
{
    fast();
    int n,x; cin>>n;
    for(int i=0;i<n;i++) cin>>x,v.push_back(x),mp[x]++;
    sort(v.begin(),v.end());
    ll count=0;
    for(int i=1;i<=31;i++){
        ll p=power(2,i);
        for(int j=0;j<(int)v.size();j++){
            int k=int(p-v[j]);
            //cout<<k<<" ";
            int start=0,ende=n-1;
            int ans=-1;
            while(start<=ende){
                int mid=(start+ende)/2;
                if(v[mid]>k) ende=mid-1;
                else if(v[mid]<k) start=mid+1;
                else {ans=mid; break;}
            }
            if(ans!=-1){
            if(v[ans]!=v[j]){
                    count+=mp[v[ans]];
            }
            else if(v[ans]==v[j]){
                int mo=mp[v[ans]];
                count+=mo*(mo-1)/2;
                mp[v[ans]]=0;
            }
            }
        }
    }
    cout<<count;
    return 0;
}
void fast()
{std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
}


#include <iostream>
#include <cmath>
#include <vector>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
#include <stack>
#include <utility>
#include <cstring>
using namespace std;
#define ll long long
typedef vector<int> vi;
#define all(v) ((v).begin()),((v).end())
void fast();
long long power(ll n, ll k){
    if(k==0) return 1;
    ll sq=power(n,k/2);
    sq=sq*sq;
    if(k%2==1)
        sq=sq*n;
    return sq;
}
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
// freopen("input.txt" ,"r",stdin );
// freopen("output.txt","w",stdout);
vector<int> v;
map<int,int> mp;
int main()
{
    fast();
    int n,x; cin>>n;
    for(int i=0;i<n;i++) cin>>x,v.push_back(x),mp[x]++;
    sort(v.begin(),v.end());
    ll count=0;
    for(int i=1;i<=30;i++){
        int p=power(2,i);
        for(int j=0;j<(int)v.size();j++){
            int k=lower_bound(v.begin(),v.end(),p-v[j])-v.begin();
            if(v[k]==p-v[j]){
            if(k<n && k!=j && v[k]!=v[j]){
                if(mp[v[k]]>0&&j<k)
                count++;
                mp[v[k]]--;
            }
            else if(k<n && k!=j && v[k]==v[j]){
                int mo=mp[v[k]];
                count+=mo*(mo-1)/2;
                mp[v[k]]=0;
            }
            }
        }
    }
    cout<<count;
    return 0;
}
void fast()
{std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
}


#include <iostream>
#include <cmath>
#include <vector>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
#include <stack>
#include <utility>
#include <cstring>
using namespace std;
#define ll long long
typedef vector<int> vi;
#define all(v) ((v).begin()),((v).end())
void fast();
long long power(ll n, ll k){
    if(k==0) return 1;
    ll sq=power(n,k/2);
    sq=sq*sq;
    if(k%2==1)
        sq=sq*n;
    return sq;
}
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
// freopen("input.txt" ,"r",stdin );
// freopen("output.txt","w",stdout);
vector<int> v;
map<int,int> mp;
int main()
{
    fast();
    int n,x; cin>>n;
    for(int i=0;i<n;i++) cin>>x,v.push_back(x),mp[x]++;
    sort(v.begin(),v.end());
    ll count=0;
    for(int i=1;i<=31;i++){
        ll p=power(2,i);
        for(int j=0;j<(int)v.size();j++){
            int k=int(p-v[j]);
            //cout<<k<<" ";
            int start=0,ende=n-1;
            int ans=-1;
            while(start<=ende){
                int mid=(start+ende)/2;
                if(v[mid]>k) ende=mid-1;
                else if(v[mid]<k) start=mid+1;
                else {ans=mid; break;}
            }
            if(ans!=-1){
            if(ans<n && ans!=j && v[ans]!=v[j]){
                if(mp[v[ans]]>0&&j<ans)
                    count+=mp[v[ans]];
            }
            else if(ans<n && j<ans&& v[ans]==v[j]){
                ll mo=mp[v[ans]];
                count+=mo*(mo-1)/2;
                mp[v[ans]]=0;
            }
            }
        }
    }
    cout<<count;
    return 0;
}
void fast()
{std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
}


#include <iostream>
#include <cmath>
#include <vector>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
#include <stack>
#include <utility>
#include <cstring>
using namespace std;
#define ll long long
typedef vector<int> vi;
#define all(v) ((v).begin()),((v).end())
void fast();
long long power(ll n, ll k){
    if(k==0) return 1;
    ll sq=power(n,k/2);
    sq=sq*sq;
    if(k%2==1)
        sq=sq*n;
    return sq;
}
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
// freopen("input.txt" ,"r",stdin );
// freopen("output.txt","w",stdout);
vector<int> v;
map<int,int> mp;
int main()
{
    fast();
    int n,x; cin>>n;
    for(int i=0;i<n;i++) cin>>x,v.push_back(x),mp[x]++;
    sort(v.begin(),v.end());
    ll count=0;
    for(int i=1;i<=31;i++){
        ll p=power(2,i);
        for(int j=0;j<(int)v.size();j++){
            int k=int(p-v[j]);
            //cout<<k<<" ";
            int start=j+1,ende=n-1;
            int ans=-1;
            while(start<=ende){
                int mid=(start+ende)/2;
                if(v[mid]>k) ende=mid-1;
                else if(v[mid]<k) start=mid+1;
                else {ans=mid; break;}
            }
            if(ans!=-1){
            if(ans<n && ans!=j && v[ans]!=v[j]){
                if(mp[v[ans]]>0&&j<ans)
                    count+=mp[v[ans]];
            }
            else if(ans<n && j<ans&& v[ans]==v[j]){
                int mo=mp[v[ans]];
                count+=--mo;
                --mp[v[ans]];
            }
            }
        }
    }
    cout<<count;
    return 0;
}
void fast()
{std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
}


#include <iostream>
#include <cmath>
#include <vector>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
#include <stack>
#include <utility>
#include <cstring>
using namespace std;
#define ll long long
typedef vector<int> vi;
#define all(v) ((v).begin()),((v).end())
void fast();
long long power(ll n, ll k){
    if(k==0) return 1;
    ll sq=power(n,k/2);
    sq=sq*sq;
    if(k%2==1)
        sq=sq*n;
    return sq;
}
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
// freopen("input.txt" ,"r",stdin );
// freopen("output.txt","w",stdout);
vector<int> v;
map<int,int> mp;
int main()
{
    fast();
    int n,x; cin>>n;
    for(int i=0;i<n;i++) cin>>x,v.push_back(x),mp[x]++;
    sort(v.begin(),v.end());
    ll count=0;
    for(int i=1;i<=31;i++){
        ll p=power(2,i);
        for(int j=0;j<(int)v.size();j++){
            int k=int(p-v[j]);
            int start=j+1,ende=n-1;
            int ans=-1;
            while(start<=ende){
                int mid=(start+ende)/2;
                if(v[mid]>k) ende=mid-1;
                else if(v[mid]<k) start=mid+1;
                else {ans=mid; break;}
            }
            if(ans!=-1){
            if(ans<n && ans!=j && v[ans]!=v[j]){
                if(mp[v[ans]]>0&&j<ans)
                    count+=mp[v[ans]];
            }
            else if(ans<n && j<ans&& v[ans]==v[j]){
                int mo=mp[v[ans]];
                count+=mo*(mo-1)/2;
                mp[v[ans]]=0;
            }
            }
        }
    }
    cout<<count;
    return 0;
}
void fast()
{std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
}


#include <iostream>
#include <cmath>
#include <vector>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
#include <stack>
#include <utility>
#include <cstring>
using namespace std;
#define ll long long
typedef vector<int> vi;
#define all(v) ((v).begin()),((v).end())
void fast();
long long power(ll n, ll k){
    if(k==0) return 1;
    ll sq=power(n,k/2);
    sq=sq*sq;
    if(k%2==1)
        sq=sq*n;
    return sq;
}
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
// freopen("input.txt" ,"r",stdin );
// freopen("output.txt","w",stdout);
vector<int> v;
map<int,int> mp;
int main()
{
    fast();
    int n,x; cin>>n;
    for(int i=0;i<n;i++) cin>>x,v.push_back(x),mp[x]++;
    sort(v.begin(),v.end());
    ll count=0;
    for(int i=1;i<=31;i++){
        ll p=power(2,i);
        for(int j=0;j<(int)v.size();j++){
            int k=int(p-v[j]);
            //cout<<k<<" ";
            int start=0,ende=n-1;
            int ans=-1;
            while(start<=ende){
                int mid=(start+ende)/2;
                if(v[mid]>k) ende=mid-1;
                else if(v[mid]<k) start=mid+1;
                else {ans=mid; break;}
            }
            if(ans!=-1){
            if(ans<n && ans!=j && v[ans]!=v[j]){
                if(mp[v[ans]]>0&&j<ans)
                count++;
            }
            else if(ans<n && ans!=j &&j<ans&& v[ans]==v[j]){
                int mo=mp[v[ans]];
                count+=mo*(mo-1)/2;
                mp[v[ans]]=1;
            }
            }
        }
    }
    cout<<count;
    return 0;
}
void fast()
{std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
}