#include <bits/stdc++.h>
int pow2[31];
int N;
int val[100005];
void input() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++) scanf("%d", val + i);
}
long long solve() {
  long long ans(0LL);
  std::sort(val, val + N);
  pow2[0] = 1;
  for (int i = 1; i <= 30; i++) pow2[i] = pow2[i - 1] << 1;
  for (int i = 0; i < N; i++) {
    int f = std::upper_bound(pow2, pow2 + 31, val[i]) - pow2;
    for (int j = f; j <= 30; j++)
      ans += (std::upper_bound(val + i + 1, val + N, pow2[j] - val[i]) -
              std::lower_bound(val + i + 1, val + N, pow2[j] - val[i]));
  }
  return ans;
}
int main() {
  input();
  printf("%I64d\n", solve());
  return 0;
}
