#include <bits/stdc++.h>
using namespace std;
const int nax = 1e5 + 7;
map<long long, long long> psnt;
long long arr[nax];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
  }
  long long ans = 0;
  psnt.clear();
  for (int i = 0; i < n; ++i) {
    for (long long j = 1; j <= 2e9; j += j) {
      ans += psnt[j - arr[i]];
    }
    psnt[arr[i]]++;
  }
  cout << ans;
  return 0;
}
