





def      UpperCAmelCase_    (    _UpperCAmelCase							:dict				)	->				bool:
     '''simple docstring'''


     A_          =       set()
     # To detect a back edge, keep track of vertices currently in the recursion stack
     A_          =       set()
     return any(
         node not in visited and depth_first_search(_UpperCAmelCase  ,						_UpperCAmelCase  ,						_UpperCAmelCase  ,						_UpperCAmelCase				)
         for node in graph				)

def      UpperCAmelCase_    (    _UpperCAmelCase							:dict  ,						_UpperCAmelCase							:int  ,						_UpperCAmelCase							:set  ,						_UpperCAmelCase							:set				)	->				bool:
     '''simple docstring'''


     visited.add(_UpperCAmelCase				)
     rec_stk.add(_UpperCAmelCase				)

     for node in graph[vertex]:
          if node not in visited:
               if depth_first_search(_UpperCAmelCase  ,						_UpperCAmelCase  ,						_UpperCAmelCase  ,						_UpperCAmelCase				):
                    return True
          elif node in rec_stk:
               return True

    # The node needs to be removed from recursion stack before function ends
     rec_stk.remove(_UpperCAmelCase				)
     return False


if __name__ == "__main__":
      from doctest import testmod

      testmod()










def      UpperCAmelCase_    (    _UpperCAmelCase							:Any  ,						_UpperCAmelCase							:Dict				)	->				Union[str, Any]:
     '''simple docstring'''


     A_          =       [1]
     for i in range(2  ,						_UpperCAmelCase				):
          factorials.append(factorials[-1] * i				)
     assert 0 <= k < factorials[-1] * n, "k out of bounds"

     A_          =       []
     A_          =       list(range(_UpperCAmelCase				)				)

     # Find permutation
     while factorials:
          A_          =       factorials.pop()
          A_   ,    A_          =       divmod(_UpperCAmelCase  ,						_UpperCAmelCase				)
          permutation.append(elements[number]				)
          elements.remove(elements[number]				)
     permutation.append(elements[0]				)

     return permutation


if __name__ == "__main__":
      import doctest

      doctest.testmod()



