#include <iostream>
#include <sstream>
#include <algorithm>
#include <functional>
#include <iterator>
#include <numeric>
#include <cstdint>
#include <cmath>
#include <bitset>
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

#define N_TIMES(i, n)     for ( uint64_t i = 0;     i <  n; ++i )
#define N_TIMES_REV(i, n) for (  int64_t i = n - 1; i >= 0; --i )

#ifdef __DEBUG__

template<typename T, typename U>
std::ostream& operator<<(std::ostream &os, const std::pair<T, U> &pair)
{
  // os << pair.first << ": " << pair.second;
  os << '(' << pair.first << ", " << pair.second << ')';
  return os;
}

template<class ForwardIterator>
std::ostream& _iterator_to_display(
  std::ostream &os, 
  ForwardIterator begin, ForwardIterator end, 
  const std::string &delim = ", "
)
{
  auto itr = begin;
  while (itr != end) {
    os << *itr;
    ++itr;
    if (itr != end) os << delim;
  }
  return os;
}

template<typename T>
std::ostream& operator<<(std::ostream &os, const std::list<T> &list)
{
  os << '[';
  _iterator_to_display(os, list.begin(), list.end());
  os << ']';
  return os;
}

template<typename T>
std::ostream& operator<<(std::ostream &os, const std::vector<T> &vector)
{
  os << '[';
  _iterator_to_display(os, vector.begin(), vector.end());
  os << ']';
  return os;
}

template<typename T, class C=std::less<T>>
std::ostream& operator<<(std::ostream &os, const std::set<T> &set)
{
  os << '{';
  _iterator_to_display(os, set.begin(), set.end());
  os << '}';
  return os;
}

template<typename T, class C=std::less<T>>
std::ostream& operator<<(std::ostream &os, const std::multiset<T> &set)
{
  os << '{';
  _iterator_to_display(os, set.begin(), set.end());
  os << '}';
  return os;
}

template<typename T, typename U, class C=std::less<T>>
std::ostream& operator<<(std::ostream &os, const std::map<T, U> &map)
{
  os << '{';
  _iterator_to_display(os, map.begin(), map.end());
  os << '}';
  return os;
}

template<typename T, typename U, class C=std::less<T>>
std::ostream& operator<<(std::ostream &os, const std::multimap<T, U> &map)
{
  os << '{';
  _iterator_to_display(os, map.begin(), map.end());
  os << '}';
  return os;
}

#define debug(var) std::cerr << #var" = " << var << std::endl

#endif /* __DEBUG__ */

namespace IntegerMath
{
  int64_t sqrt(int64_t x) {
    return static_cast<int64_t>(
      ::floorl( ::sqrtl( 
        static_cast<long double>(x)
      ) )
    );
  }

  int64_t log2(int64_t x) {
    return static_cast<int64_t>(
      ::floorl( ::log2l( 
        static_cast<long double>(x)
      ) )
    );
  }    

  int64_t log10(int64_t x) {
    return static_cast<int64_t>(
      ::floorl( ::log10l( 
        static_cast<long double>(x)
      ) )
    );
  }

  int64_t number_of_digits(int64_t x) {
    return static_cast<int64_t>(
      ::ceill( ::log10l( 
        static_cast<long double>(x + 1)
      ) )
    );
  }

  uint64_t gcd(uint64_t a, uint64_t b)
  {
    uint64_t n = std::min(a, b), m = std::max(a, b);
    return (n == 0) ? m : gcd(m % n, n);
  }

  uint64_t lcm(uint64_t a, uint64_t b)
  {
    uint64_t d = gcd(a, b);
    return (a % d == 0) ? (a / d) * b : a * (b / d);
  }
};

int main(int argc, char **argv)
{
  uint64_t N;
  std::cin >> N;
  
  std::vector<uint64_t> A(N);
  N_TIMES(n, N) {
    std::cin >> A[n];
  }
  std::sort(A.begin(), A.end(), std::greater<uint64_t>());
  //std::cerr << A << std::endl;
  
  std::map<uint64_t, uint64_t> cache;
  N_TIMES(n, N) {
    auto itr = cache.find(A[n]);
    if (itr == cache.end()) {
      cache.emplace(A[n], 1);
    } else {
      ++cache[A[n]];
    }
  }
  
  uint64_t count = 0;
  N_TIMES(n, N) {
    if (cache[A[n]] == 0) { continue; }
    
    uint64_t k = IntegerMath::log2(2 * A[n]);
    uint64_t p = (1 << k) - A[n];
    
    auto itr = cache.find(p);
    
    if (itr != cache.end() && cache[p] > 0) {
      if ((A[n] != p) || (A[n] == p && cache[A[n]] >= 2)) {
        --cache[A[n]];
        --cache[p];
        
        ++count;
      }
    }
  }
  std::cout << count << std::endl;
  
  return 0;
}

Measured memory_bytes: 14336