#include <bits/stdc++.h>
using namespace std;
map<long long, long long> a, c;
long long b[30] = {2,        4,         8,         16,        32,
                   64,       128,       256,       512,       1024,
                   2048,     4096,      8192,      16384,     32768,
                   65536,    131072,    262144,    524288,    1048576,
                   2097152,  4194304,   8388608,   16777216,  33554432,
                   67108864, 134217728, 268435456, 536870912, 1073741824};
int main() {
  int n;
  long long k = 0, t;
  cin >> n;
  long long x;
  for (int i = 0; i < n; i++) {
    cin >> x;
    a[x]++;
  }
  c = a;
  for (map<long long, long long>::iterator it = c.begin(); it != c.end();
       it++) {
    t = it->first;
    for (int i = (int)log2(t); i < 30; i++) {
      if (a[b[i] - t] > 0) {
        if (b[i] == t * 2) {
          k += a[b[i] - t] * (a[b[i] - t] - 1) / 2;
        }
        if (t < b[i] - t) k += a[b[i] - t] * a[t];
      }
    }
  }
  cout << k;
}
