#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <typename T>
void DEBUG(string label, T value) {
  cerr << "[" << label << " = " << value << "]\n";
}
void solve() {
  int n;
  cin >> n;
  vector<int> arr(n);
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
  }
  map<ll, int> mp;
  ll ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < 31; ++j) {
      ll cur = (1 << j) - arr[i];
      ans += mp[cur];
    }
    mp[arr[i]]++;
  }
  cout << ans << '\n';
}
int main() {
  int t = 1;
  while (t--) {
    solve();
  }
}
