#include <bits/stdc++.h>
int main() {
  int n, a, k;
  std::map<int, int> m;
  long long r(0);
  std::scanf("%d", &n);
  while (0 < n--) {
    std::scanf("%d", &a);
    m[a]++;
  }
  for (auto e : m) {
    for (int i(0); i <= 30; ++i) {
      k = (1 << i) - e.first;
      if (e.first < k) break;
      if (m.find(k) != m.end()) {
        if (k != e.first)
          r += e.second * m[k];
        else
          r += (long long)e.second * (e.second - 1) / 2;
      }
    }
  }
  std::cout << r << std::endl;
  return 0;
}
