#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(time(0));
const long long inf = 0x3f3f3f3f3f3f3f3fLL;
const long long N = 3e5 + 10;
const long long MOD = 1e9 + 7;
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  vector<long long> a(n);
  unordered_map<long long, long long> cnt;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    cnt[a[i]]++;
  }
  set<long long> p2;
  for (long long i = 0, c = 1; i < 32; i++, c *= 2) {
    p2.insert(c);
  }
  long long ans = 0;
  for (auto i : cnt) {
    for (long long j : p2) {
      long long x = j - i.first;
      if (cnt.find(x) != cnt.end()) ans += cnt[x] * i.second;
    }
    if (__builtin_popcount(i.first) == 1) ans -= i.second;
  }
  cout << ans / 2;
  return 0;
}
