object Main extends App {
  private def func(s:Seq[Int]):Int = {
    //println(s)
    val init = s.toSet
    var st = init
    //println(st)
    var count = 0
    
    init.foreach{ h =>
      //val h = st.head
      //nextst = st
      //st = st.tail
      //println(st)
      
      var i=1
      var find = false
      while(i<32 && !find){
        val t2 = (2<<i) - h
        if(st.contains(t2) && st.contains(h)){
          st -= t2
          st -= h
          count += 1
          find = true
        }
        i += 1
      }
    }
    count
  }
  println(func(io.Source.stdin.getLines.toIndexedSeq.tail.head.split(' ').map(_.toInt)))
}
