n=gets.to_i
a=gets.split.map &:to_i
a.sort!
c=0
31.downto(1){|s|
  i=0
  j=a.size-1
  while i<j
    if !a[i]
      i+=1
    elsif !a[j]
      j-=1
    else
      k=a[i]+a[j]-2**s
      if k<0
        i+=1
      elsif k>0
        j-=1
      else
        c+=1
        a[i]=a[j]=0
        i+=1
        j-=1
      end
    end
  end
}
p c
