#include <bits/stdc++.h>
using namespace std;
int arr[100005];
int main() {
  int n;
  cin >> n;
  long long res = 0;
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    for (int j = 0; j <= 31; j++) {
      res += mp[(int)((1LL << j) - arr[i])];
    }
    mp[arr[i]]++;
  }
  cout << res << endl;
  return 0;
}
