#include <bits/stdc++.h>
using namespace std;
map<int, int> x;
int arr[100000];
long long sum;
vector<long long> Powers;
int main() {
  long long Count = 1;
  for (int i = 1; i < 32; i++) Count *= 2, Powers.push_back(Count);
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &arr[i]), x[arr[i]]++;
  for (int i = 0; i < n; i++) {
    x[arr[i]]--;
    for (int j = 0; j < Powers.size(); j++)
      if (x.count(Powers[j] - arr[i])) sum += x[Powers[j] - arr[i]];
  }
  cout << sum << endl;
}
