program tautonym_puzzle
  implicit none
  integer(8) :: n
  integer :: k = 0, l = 1, i
  integer, allocatable :: p(:)
  read(*,*) n
  do while (rshift(n,k) > 0_8)
    k = k+1
  end do
  k = k-2
  p = [integer::]
  do i = k, 0, -1
    p = [p,l]
    l = l+1
    if (btest(n,i)) then
      p = [l,p]
      l = l+1
    end if
  end do
  write(*,'(i0)') 2*(l-1)
  write(*,'(i0)',advance='no') 1
  do i = 2, l-1
    write(*,'(x,i0)',advance='no') i
  end do
  do i = 1, l-1
    write(*,'(x,i0)',advance='no') p(i)
  end do
  write(*,*)
end program tautonym_puzzle