#include <bits/stdc++.h>
using namespace std;
map<int, int> a;
long long step;
long long n, mas[100], ans, x;
int main() {
  int r = 1;
  mas[0] = 1;
  for (; mas[r - 1] <= 2e9; r++) mas[r] = mas[r - 1] * 2;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    for (int j = 0; j < r; j++) ans += a[mas[j] - x];
    a[x]++;
  }
  cout << ans;
}
