#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int mod = 1 << 30;
int n;
int main() {
  scanf("%d", &n);
  unsigned long long ans = 0;
  map<int, unsigned long long> mp;
  for (int i = 0; i < n; i++) {
    int a;
    scanf("%d", &a);
    for (int j = 30; j >= 0; j--) {
      if (1 << j <= a) continue;
      ans += mp[(1 << j) - a];
    }
    mp[a]++;
  }
  printf("%I64d\n", ans);
  return 0;
}
