#include <bits/stdc++.h>
using namespace std;
const long long int INF = (1ll << 60) - 1;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int tc = 1;
  while (tc--) {
    long long int dp[31];
    dp[0] = 1;
    dp[1] = 2;
    for (long long int i = 2; i < 31; i++) {
      dp[i] = 1 << i;
    }
    long long int n;
    cin >> n;
    long long int a[n];
    for (long long int i = 0; i < n; i++) cin >> a[i];
    map<long long int, long long int> mp;
    long long int ans = 0;
    for (long long int i = 0; i < n; i++) {
      bool flg = false;
      for (long long int j = 0; j < 31; j++) {
        if (mp[(dp[j] - a[i])] != 0) {
          ans += mp[dp[j] - a[i]];
        }
      }
      mp[a[i]]++;
    }
    cout << ans;
  }
}
