"use strict";

function binarySearch(arr, val) {
  let start = 0;
  let end = arr.length - 1;

  while (start <= end) {
    let mid = Math.floor((start + end) / 2);

    if (arr[mid] === val) {
      return mid;
    }
    if (val > arr[mid]) {
      end = mid - 1;
    } else {
      start = mid + 1;
    }
  }
  return -1;
}

function getPair(num) {
  return Math.pow(2, num.toString(2).length) - num;
}

function main(input) {
  const inputs = input.split("\n").filter(x => x !== "");
  const A = inputs[1].split(" ").map(Number);

  let sortedA = A.sort((a, b) => b - a);
  let count = 0;
  while (sortedA.length > 0) {
    let i = sortedA[0];
    sortedA.splice(0, 1);

    let j = getPair(i);
    let indexJ = binarySearch(sortedA, j);

    if (indexJ >= 0) {
      sortedA.splice(indexJ, 1);
      count++;
    }
  }

  console.log(count);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));
