You are given n integers a1, a2, ..., an. Find the number of pairs of indexes i, j (i < j) that ai + aj is a power of 2 (i. e. some integer x exists so that ai + aj = 2x).

Input

The first line contains the single positive integer n (1 ≤ n ≤ 105) — the number of integers.

The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109).

Output

Print the number of pairs of indexes i, j (i < j) that ai + aj is a power of 2.

Examples

Input

4
7 3 2 1


Output

2


Input

3
1 1 1


Output

3

Note

In the first example the following pairs of indexes include in answer: (1, 4) and (2, 4).

In the second example all pairs of indexes (i, j) (where i < j) include in answer.
#include <bits/stdc++.h>
using namespace std;
vector<long long> pw2;
vector<pair<long long, long long> > arr;
int n;
struct sortpl {
  bool operator()(const pair<long long, long long> &a,
                  const pair<long long, long long> &b) {
    if (a.first == b.first) {
      return a.second < b.second;
    }
    return a.first < b.first;
  }
};
bool bsearch(int val) {
  int l = 0;
  int r = n - 1;
  while (l <= r) {
    int m = l + (r - l) / 2;
    if (arr[m].first == val) {
      return true;
    }
    if (arr[m].first < val) {
      l = m + 1;
    } else
      r = m - 1;
  }
  return false;
}
int lwrsearch(int val) {
  int l = 0;
  int r = n - 1;
  while (l <= r) {
    int m = l + (r - l) / 2;
    if ((m == 0 || arr[m - 1].first < val) && arr[m].first == val) {
      return m;
    } else if (arr[m].first < val) {
      l = m + 1;
    } else {
      r = m - 1;
    }
  }
}
int upprsearch(int val, int ind) {
  int l = 0;
  int r = n - 1;
  while (l <= r) {
    int m = l + (r - l) / 2;
    if (arr[m].first == val && arr[m].second < ind &&
        (m == n - 1 || arr[m + 1].first > val || arr[m + 1].second >= ind)) {
      return m;
    } else if (arr[m].first > val ||
               (arr[m].first == val && arr[m].second >= ind)) {
      r = m - 1;
    } else {
      l = m + 1;
    }
  }
  return -1;
}
int main() {
  long long i = 1;
  while (i < 2e9) {
    pw2.push_back(i);
    i *= 2;
  }
  cin >> n;
  for (int i = 0; i < n; i++) {
    int temp;
    cin >> temp;
    arr.push_back(make_pair(temp, i));
  }
  sort(arr.begin(), arr.end(), sortpl());
  long long pairs = 0;
  for (int i = 0; i < n; i++) {
    int j = 0;
    while (pw2[j] <= arr[i].first + arr[n - 1].first) {
      if (pw2[j] > arr[i].first) {
        if (bsearch(pw2[j] - arr[i].first)) {
          int lwrbnd = lwrsearch(pw2[j] - arr[i].first);
          int upprbnd = upprsearch(pw2[j] - arr[i].first, arr[i].second);
          if (upprbnd != -1) {
            pairs += upprbnd - lwrbnd + 1;
          }
        }
      }
      j++;
    }
  }
  cout << pairs;
}
