program tautonym_puzzle
  implicit none
  integer(8) :: n
  integer :: k = 40, p(80) = 0, i
  read(*,*) n
  do while (k > 0)
    if (n >= lshift(1_8,k)-1_8) exit
    k = k-1
  end do
  do i = 1, k
    p(i) = i
  end do
  n = n-lshift(1_8,k)+1_8
  do i = k-1, 0, -1
    if (n < lshift(1_8,i)) cycle
    p(i+1:k+1) = p(i:k)
    k = k+1
    p(i) = k
    n = n-lshift(1_8,i)
  end do
  do i = 1, k
    p(k+i) = i
  end do
  write(*,'(i0)') 2*k
  write(*,'(i0)',advance='no') p(1)
  do i = 2, 2*k
    write(*,'(x,i0)',advance='no') p(i)
  end do
  write(*,*)
end program tautonym_puzzle