#include <bits/stdc++.h>
using namespace std;
long long N, arr[200001],
    p[31] =
        {
            2,
},
    ret;
int main() {
  cin >> N;
  for (int i = 1; i < 30; i++) p[i] = p[i - 1] * 2;
  for (int i = 0; i < N; i++) cin >> arr[i];
  arr[N] = 1 << 30;
  sort(arr, arr + N);
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 30; j++) {
      if (p[j] > arr[i]) {
        auto s = lower_bound(arr + i + 1, arr + N, p[j] - arr[i]),
             e = upper_bound(arr + i + 1, arr + N, p[j] - arr[i]);
        if (*s + arr[i] == p[j]) ret += e - s;
      }
    }
  }
  cout << ret;
}
