#include <bits/stdc++.h>
using namespace std;
int dx[8] = {-1, 1, 0, 0, 1, 1, -1, -1}, dy[8] = {0, 0, -1, 1, 1, -1, 1, -1};
char dc[4] = {'N', 'S', 'W', 'E'};
long long int a[300005];
map<long long int, long long int> m;
int main() {
  long long int n, p, q, ans = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) {
    p = log2(a[i]);
    for (long long int j = p + 1; j <= 31; j++) {
      q = (1LL << j);
      ans += m[q - a[i]];
    }
    m[a[i]]++;
  }
  cout << ans << endl;
}
