#include <bits/stdc++.h>
using namespace std;
int a[100005], b[32], aa[100005];
int lower_bound(int l, int r, int target, int k) {
  int mid = (l + r) >> 1;
  while (r > l) {
    if (a[mid] >= target)
      r = mid;
    else
      l = mid + 1;
    mid = (l + r) >> 1;
  }
  return mid;
}
int upper_bound(int l, int r, int target, int k) {
  int mid = (l + r) >> 1;
  while (r > l) {
    if (a[mid] > target)
      r = mid;
    else
      l = mid + 1;
    mid = (l + r) >> 1;
  }
  return mid;
}
int main() {
  int n;
  b[0] = 1;
  for (int i = 1; i < 32; i++) b[i] = b[i - 1] * 2;
  while (~scanf("%d", &n)) {
    long long ans = 0;
    for (int i = 0; i < n; i++) scanf("%d", &a[i]);
    sort(a, a + n);
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < 32; j++) {
        int d = b[j] - a[i];
        if (d <= 0)
          continue;
        else {
          int la = lower_bound(i + 1, n, d, 1);
          int ra = upper_bound(i + 1, n, d, 1);
          if (ra - la > 0) ans += ra - la;
        }
      }
    }
    printf("%I64d\n", ans);
  }
  return 0;
}
