#include <bits/stdc++.h>
using namespace std;
vector<long long> vec[200002];
vector<long long> vec2;
vector<vector<long> > vvv(183);
queue<long> qu;
map<long long, long long> mp;
map<long, long>::iterator iter;
bool ch[200002] = {false};
long long height[200002] = {0};
queue<pair<int, pair<int, int> > > que;
pair<int, pair<int, int> > pp;
pair<int, int> p;
const int INF = 1000000005;
set<int> myset;
set<int>::iterator it;
int main() {
  long long n, temp, cnt = 0;
  cin >> n;
  long long a[n + 1];
  for (int i = 0; i < n; i++) {
    cin >> temp;
    for (int i = 0; i < 32; i++) {
      cnt += (mp[((long long)1 << i) - temp]);
    }
    mp[temp]++;
  }
  cout << cnt << endl;
  return 0;
}
