#include <bits/stdc++.h>
using namespace std;
char _;
vector<long long> ppow(32, 0);
map<long long, long long> cnt;
int32_t main() {
  long long ans = 0;
  long long n;
  do {
    while ((n = getchar()) < '0')
      ;
    for (n -= '0'; '0' <= (_ = getchar()); n = (n << 3) + (n << 1) + _ - '0')
      ;
  } while (0);
  vector<long long> arr(n + 1);
  ppow[0] = 1;
  for (long long i = 1; i <= 32; i++) {
    ppow[i] = ppow[i - 1] * 2;
  }
  for (long long i = 0; i < n; i++) {
    do {
      while ((arr[i] = getchar()) < '0')
        ;
      for (arr[i] -= '0'; '0' <= (_ = getchar());
           arr[i] = (arr[i] << 3) + (arr[i] << 1) + _ - '0')
        ;
    } while (0);
    cnt[arr[i]]++;
  }
  for (long long i = 0; i < n; i++) {
    cnt[arr[i]]--;
    for (long long pow : ppow) {
      ans += cnt[pow - arr[i]];
    }
  }
  printf("%lld\n", ans);
  return 0;
}
