#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n;
  cin >> n;
  vector<long long> v(n);
  for (long long i = 0; i < n; i++) cin >> v[i];
  map<long long, long long> mp;
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j <= 32; j++) {
      long long temp = 1 << j;
      if (mp.count(temp - v[i])) ans += mp[temp - v[i]];
    }
    mp[v[i]] += 1;
  }
  cout << ans << endl;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
}
