program hanoi
 implicit none
 integer :: i
 read *, i
 if (i>0) call solve(i, 1, 3, 2)
contains
 recursive subroutine solve(n, from, to, tmp)
  integer, intent(in) :: n, from, to, tmp
  if (n>0) then
   call solve(n-1, from, tmp, to)
   print *, "Move disk #", n, " from", from, " to", to
   call solve(n-1, tmp, to, from)
  end if
 end subroutine solve
end program hanoi