#include <bits/stdc++.h>
using namespace std;
struct seg {
  int cnt;
  seg* nxt[2];
};
const int MAXN = 1E9;
seg* root = new seg{0, NULL, NULL};
int n, m;
long long ans;
int getcnt(seg* p, int l, int r, int t) {
  if (!p) return 0;
  if (l == r) return p->cnt;
  int mid = (l + r) / 2;
  if (t > mid)
    return getcnt(p->nxt[1], mid + 1, r, t);
  else
    return getcnt(p->nxt[0], l, mid, t);
}
void insrt(seg* p, int l, int r, int t) {
  ++p->cnt;
  if (l == r) return;
  int mid = (l + r) / 2;
  if (!p->nxt[0]) {
    p->nxt[0] = new seg{0, NULL, NULL};
    p->nxt[1] = new seg{0, NULL, NULL};
  }
  if (t > mid)
    insrt(p->nxt[1], mid + 1, r, t);
  else
    insrt(p->nxt[0], l, mid, t);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &m);
    for (int j = 1; j <= 30; ++j)
      if ((1 << j) > m) ans += getcnt(root, 1, MAXN, (1 << j) - m);
    insrt(root, 1, MAXN, m);
  }
  printf("%lld\n", ans);
}
