#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<long long int> A;
  long long int n, i, ans, j, P[40], x;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> ans;
    A.push_back(ans);
  }
  sort(A.begin(), A.end());
  for (i = 0, x = 1; i < 32; i++) {
    P[i] = x;
    x = x << 1;
  }
  for (i = 0, ans = 0; i < n; i++) {
    for (j = 0; j < 32; j++) {
      if (binary_search(A.begin() + i + 1, A.end(), P[j] - A[i])) {
        if ((lower_bound(A.begin(), A.end(), P[j] - A[i]) - A.begin()) <= i + 1)
          ans += ((upper_bound(A.begin(), A.end(), P[j] - A[i]) - A.begin()) -
                  i - 1);
        else
          ans += (upper_bound(A.begin(), A.end(), P[j] - A[i]) -
                  lower_bound(A.begin(), A.end(), P[j] - A[i]));
      }
    }
  }
  cout << ans << endl;
}
