#include <bits/stdc++.h>
#define REP(i, a, n) for (ll i = ((ll) a); i < ((ll) n); i++)
using namespace std;
typedef long long ll;

class MaxFlow {
public:
  struct edge { int to, cap, rev; };

  const int INF = 1 << 28;
  int N;
  vector<vector<edge>> E;
  vector<int> level;
  vector<int> iter;

  MaxFlow(int N): N(N), E(N), level(N), iter(N) {}

  void add_directed_edge(int from, int to, int cap) {
    E[from].push_back((edge) { to, cap, (int) E[to].size() });
    E[to].push_back((edge) { from, 0, (int) E[from].size() - 1 });
  }

  void add_undirected_edge(int from, int to, int cap) {
    E[from].push_back((edge) { to, cap, (int) E[to].size() });
    E[to].push_back((edge) { from, cap, (int) E[from].size() - 1 });
  }

  void bfs(int s) {
    for (int i = 0; i < N; i++) level[i] = -1;
    level[s] = 0;

    queue<int> q;
    q.push(s);

    while (!q.empty()) {
      int v = q.front();
      q.pop();

      for (int i = 0; i < E[v].size(); i++) {
        edge &e = E[v][i];
        if (e.cap > 0 && level[e.to] < 0) {
          level[e.to] = level[v] + 1;
          q.push(e.to);
        }
      }
    }
  }

  int dfs(int v, int t, int f) {
    if (v == t) return f;
    for (int &i = iter[v]; i < E[v].size(); i++) {
      edge &e = E[v][i];
      if (e.cap > 0 && level[v] < level[e.to]) {
        int d = dfs(e.to, t, min(f, e.cap));
        if (d > 0) {
          e.cap -= d;
          E[e.to][e.rev].cap += d;
          return d;
        }
      }
    }
    return 0;
  }

  int max_flow(int s, int t) {
    int flow = 0;
    while (1) {
      bfs(s);
      if (level[t] < 0) break;
      for (int i = 0; i < N; i++) iter[i] = 0;
      while (1) {
        int f = dfs(s, t, INF);
        if (f == 0 || f == INF) break;
        flow += f;
      }
    }
    return flow;
  }
};

void dfs(ll v, ll c, vector<vector<ll>> &E, vector<ll> &color) {
  if (color[v] >= 0) {
    assert(color[v] == c);
    return;
  }
  color[v] = c;

  for (ll u : E[v]) {
    dfs(u, 1 - c, E, color);
  }
}

int main(void) {
  ll N;
  cin >> N;
  vector<ll> A(N);
  REP(i, 0, N) cin >> A[i];

  sort(A.begin(), A.end());

  vector<ll> v(A);
  v.erase(unique(v.begin(), v.end()), v.end());

  ll n = v.size();
  vector<ll> cnt(n);
  REP(i, 0, n) {
    cnt[i] = upper_bound(A.begin(), A.end(), v[i]) - lower_bound(A.begin(), A.end(), v[i]);
  }

  vector<vector<ll>> E(n);
  REP(i, 0, n) {
    for (ll t = 1; t <= 100000000000; t *= 2) {
      ll x = t - v[i];
      if (x == v[i]) continue;
      if (binary_search(v.begin(), v.end(), x)) {
        E[i].push_back(lower_bound(v.begin(), v.end(), x) - v.begin());
      }
    }
  }

  vector<ll> color(n);
  REP(i, 0, n) color[i] = -1;
  REP(i, 0, n) {
    if (color[i] == -1) {
      dfs(i, 0, E, color);
    }
  }
  REP(i, 0, n) assert(color[i] >= 0);

  vector<bool> p(n);
  REP(i, 0, n) {
    for (ll t = 1; t <= 100000000000; t *= 2) {
      if (v[i] == t) p[i] = true;
    }
  }

  MaxFlow mf(n + 2);
  ll s = n, t = s + 1;
  REP(i, 0, n) {
    if (p[i]) continue;
    if (color[i] == 0) {
      mf.add_directed_edge(s, i, cnt[i]);
    } else {
      mf.add_directed_edge(i, t, cnt[i]);
    }
  }
  REP(i, 0, n) {
    if (p[i]) continue;
    for (ll u : E[i]) {
      if (p[u]) continue;
      if (color[i] == 0) {
        mf.add_directed_edge(i, u, max(cnt[i], cnt[u]));
      } else {
        mf.add_directed_edge(u, i, max(cnt[i], cnt[u]));
      }
    }
  }
  ll f1 = mf.max_flow(s, t);

  REP(i, 0, n) {
    if (!p[i]) continue;
    assert(mf.E[i].size() == 0);
    if (color[i] == 0) {
      mf.add_directed_edge(s, i, cnt[i]);
    } else {
      mf.add_directed_edge(i, t, cnt[i]);
    }
  }
  REP(i, 0, n) {
    if (!p[i]) continue;
    for (ll u : E[i]) {
      if (color[i] == 0) {
        mf.add_directed_edge(i, u, max(cnt[i], cnt[u]));
      } else {
        mf.add_directed_edge(u, i, max(cnt[i], cnt[u]));
      }
    }
  }
  ll f2 = mf.max_flow(s, t);

  ll ans = f1 + f2;
  REP(i, 0, n) {
    if (!p[i]) continue;
    if (color[i] == 0) {
      ans += mf.E[s][mf.E[i][0].rev].cap / 2;
    } else {
      ans += mf.E[i][0].cap / 2;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 39604