#include <bits/stdc++.h>
using namespace std;
long long counter = 0;
vector<long long> v, step;
map<long long, long long> mp;
void gen() {
  for (int i = 0; i <= 31; i++) {
    step.push_back(1 << i);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long n;
  cin >> n;
  v.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    mp[v[i]]++;
  }
  sort(v.begin(), v.end());
  gen();
  for (int i = 0; i < n; i++) {
    if (v[i] == v[i - 1]) {
      continue;
    }
    for (int j = 0; j < step.size(); j++) {
      long long h = step[j] - v[i];
      if (h == v[i]) {
        counter += mp[v[i]] * (mp[v[i]] - 1);
      } else {
        counter += mp[v[i]] * mp[h];
      }
    }
  }
  cout << counter / 2;
  return 0;
}
