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]+a[j]==2**s
      c+=1
      i+=1
      a.delete_at i-1
      if i==j
        a.delete_at j
        break
      else
        j-=1
        a.delete_at j+1
      end
    elsif a[i]+a[j]<2**s
      i+=1
    else
      j-=1
    end
  end
}
p c
