#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
string char_to_str(char c) {
  string tem(1, c);
  return tem;
}
long long max(long long a, long long b) {
  if (a > b) {
    return a;
  }
  return b;
}
long long min(long long a, long long b) {
  if (a < b) {
    return a;
  }
  return b;
}
long long binarySearch(long long arr[], long long l, long long r, long long x) {
  if (r >= l) {
    int mid = l + (r - l) / 2;
    if (arr[mid] == x) {
      return mid;
    }
    if (arr[mid] > x) {
      return binarySearch(arr, l, mid - 1, x);
    }
    return binarySearch(arr, mid + 1, r, x);
  }
  return -1;
}
long long countOccurrences(long long arr[], long long x, long long n) {
  long long *low = lower_bound(arr, arr + n, x);
  if (low == (arr + n) || *low != x) {
    return 0;
  }
  long long *high = upper_bound(low, arr + n, x);
  return high - low;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long n;
  cin >> n;
  long long a[n];
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  sort(a, a + n);
  vector<long long> v;
  long long po = 0;
  long long num = 1;
  long long p = 1000000000;
  while (num < p) {
    num = 2 * num;
    v.push_back(num);
  }
  long long ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < v.size(); ++j) {
      long long t = v[j] - a[i];
      long long found = binarySearch(a, 0, n - 1, t);
      long long occur = countOccurrences(a, t, n);
      if (found != -1) {
        if (t == a[i]) {
          if (occur > 1) {
            ans += occur;
            ans--;
          }
        } else {
          if (occur > 1) {
            ans += occur;
          } else if (occur == 1) {
            ans++;
          }
        }
      }
    }
  }
  cout << (ans / 2);
  return 0;
}
