n=gets.to_i d=q=[u=1],1 [u+s=("%b"%u).count(?1),u-s].map{|v|v>n||v<1||d[v]||=d[q<