#include <bits/stdc++.h>
using namespace std;
const int B = 32;
long long P[B];
void init() {
  P[0] = 1;
  for (int i = 1; i < B; i++) P[i] = P[i - 1] * 2;
}
int main() {
  init();
  int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++) cin >> arr[i];
  long long ans = 0;
  for (int i = 1; i < B; i++) {
    map<long long, int> cnt;
    for (int j = 0; j < n; j++) {
      ans += cnt[P[i] - arr[j]];
      cnt[arr[j]]++;
    }
  }
  cout << ans << "\n";
  return 0;
}
