n=gets.to_i
a=gets.split.map(&:to_i).sort
power2=[2]
30.times{power2 << power2.last*2}
power2.reverse!
h=Hash.new(0)
a.each{|v|h[v]+=1}
ans=0
a.reverse.each{|v|
  next if h[v]==0
  power2.each{|k|
    break if k<v
    if h[k-v]>0
      if k-v==v
        if h[k-v]>1
          h[v]-=2
        else
          next
        end
      else
        h[v]-=1
        h[k-v]-=1
      end
      ans+=1
      break
    end
  }
}

puts ans