void main() {
  import std.stdio, std.string, std.conv, std.algorithm;

  int n;
  rd(n);
  auto a = readln.split.to!(int[]);

  sort(a);
  int[int] freq;
  foreach (x; a) {
    if (x in freq) {
      freq[x]++;
    } else {
      freq[x] = 1;
    }
  }
  auto mx = reduce!max(a);
  int ans = 0;
  foreach (x; a) {
    int p2 = 1;
    int[] cand;
    while (p2 <= mx) {
      if (p2 - x >= 1) {
        cand ~= (p2 - x);
      }
      p2 *= 2;
    }
    foreach_reverse (y; cand) {
      if (y in freq) {
        ans++;
        if ((--freq[y]) == 0) {
          freq.remove(y);
        }
      }
    }
  }
  writeln(ans);
}

void rd(T...)(ref T x) {
  import std.stdio, std.string, std.conv;

  auto l = readln.split;
  assert(l.length == x.length);
  foreach (i, ref e; x)
    e = l[i].to!(typeof(e));
}
