#include <bits/stdc++.h>
using namespace std;
long long n, a[100005];
map<long long, long long> m;
signed main() {
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long ans = 0;
  for (long long i = n - 1; i >= 0; i--) {
    long long p = 1;
    for (long long j = 0; j <= 30; j++) {
      p *= 2LL;
      ans += m[p - a[i]];
    }
    m[a[i]]++;
  }
  cout << ans << endl;
}
