#include <bits/stdc++.h>
using namespace std;
const int MAXX = 1e5 + 10;
long long n, a[MAXX], ans;
map<int, int> cnt;
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i], cnt[a[i]]++;
  for (int i = 0; i < n; i++)
    for (long long mask = 1; mask <= (1 << 30); mask *= 2)
      if (a[i] <= mask && cnt.find(mask - a[i]) != cnt.end())
        ans += cnt[(mask - a[i])] - (mask - a[i] == a[i]);
  return cout << ans / 2 << endl, 0;
}
