#include <bits/stdc++.h>
using namespace std;
int exists(vector<long long int> &nums, long long int key, int n, int index,
           bool firstOrLast) {
  int st = 0, en = index - 1, mid;
  while (st < en) {
    mid = (st + en) / 2;
    if (nums[mid] == key) {
      if (firstOrLast) {
        if (mid == 0 || nums[mid - 1] < key)
          return mid;
        else if (nums[mid - 1] == key)
          en = mid - 1;
      } else {
        if (mid == index - 1 || nums[mid + 1] > key)
          return mid;
        else if (nums[mid + 1] == key)
          st = mid + 1;
      }
    } else if (nums[mid] > key)
      en = mid - 1;
    else
      st = mid + 1;
  }
  return nums[st] == key ? st : -1;
}
int main() {
  int n;
  scanf("%d", &n);
  vector<long long int> nums(n);
  for (int i = 0; i < n; i++) {
    cin >> nums[i];
  }
  sort(nums.begin(), nums.end());
  long long int maxpow = ((long long int)log2(nums[n - 1] + nums[n - 2])) + 1;
  long long int curpow, cmaxpow, cn;
  long long int count = 0;
  long long int pow2s[maxpow + 1];
  int j;
  int k1, k2, diff;
  pow2s[0] = 1;
  for (int i = 1; i <= maxpow; i++) {
    pow2s[i] = pow2s[i - 1] * 2;
  }
  for (int i = n - 1; i > 0; i--) {
    cn = nums[i];
    curpow = ((long long int)log2(cn)) + 1;
    cmaxpow = ((long long int)log2(cn + nums[i - 1])) + 1;
    for (j = curpow; j <= cmaxpow; j++) {
      k1 = exists(nums, pow2s[j] - cn, n, i, true);
      k2 = exists(nums, pow2s[j] - cn, n, i, false);
      if (k1 != -1) {
        count += k2 - k1 + 1;
      }
    }
  }
  cout << count << endl;
}
