#include <bits/stdc++.h>
using namespace std;
inline void fast() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); }
void solve() {
  int n;
  cin >> n;
  vector<long long> arr(n), power2(30);
  map<long long, long long> freq;
  long long i = 0, ans = 0;
  for (int i = 1; i <= 30; i++) power2[i - 1] = (1LL << i);
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    freq[arr[i]]++;
  }
  for (int i = 0; i < arr.size(); i++) {
    for (int j = 0; j < 30; j++) {
      long long temp = power2[j] - arr[i];
      if (!freq[temp])
        continue;
      else {
        ans += freq[temp];
        if (arr[i] == temp) ans--;
      }
    }
  }
  cout << ans / 2 << "\n";
}
int main(void) {
  fast;
  solve();
}
