#include <bits/stdc++.h>
using namespace std;
int main() {
  {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  }
  long long n;
  cin >> n;
  long long a[n];
  map<long long, long long> m;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    m[a[i]]++;
  }
  long long ans = 0;
  for (long long d = 1; d < (1LL << 35); d *= 2) {
    for (long long i = 0; i < n; i++) {
      if (d <= a[i]) continue;
      ans += m[d - a[i]];
      if (d == 2 * a[i]) ans--;
    }
  }
  ans /= 2;
  cout << ans << "\n";
}
