#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const double PI = acos(-1.0);
const int INF = 1e9 + 7;
const int N = int(2e5 + 7);
int n, a[N];
map<int, int> m;
long long ans;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    for (long long j = 1; j <= 4e9; j <<= 1) ans += m[j - a[i]];
    m[a[i]]++;
  }
  cout << ans;
  return 0;
}
