r=[0]+[p]*n=gets.to_i+1 n.times{|i|r&[i]==[i]&&n.times{|j|r[j]==i&&(x=j<1?0:j-('%b'%j).count(?1) y=j+j-x r[x]||=i+1 y