





from __future__ import annotations



def 						A_							(	_lowerCAmelCase	)		->					list[int]:  # This function is recursive
 UpperCamelCase      :   Any			      =  len(_lowerCAmelCase	)
 # If the array contains only one element, we return it (it's the stop condition of
 # recursion)
 if array_length <= 1:
  return array
  # Else
 UpperCamelCase      :   Any			      =  array[0]
 UpperCamelCase      :   Optional[int]			      =  False
 UpperCamelCase      :   int			      =  1
 UpperCamelCase      :   list[int]			      =  []
 while not is_found and i < array_length:
  if array[i] < pivot:
   UpperCamelCase      :   List[Any]			      =  True
   UpperCamelCase      :   str			      =  [element for element in array[i:] if element >= array[i]]
   UpperCamelCase      :   Any			      =  longest_subsequence(_lowerCAmelCase	)
   if len(_lowerCAmelCase	) > len(_lowerCAmelCase	):
    UpperCamelCase      :   Tuple			      =  temp_array
  else:
   i += 1

 UpperCamelCase      :   int			      =  [element for element in array[1:] if element >= pivot]
 UpperCamelCase      :   Optional[Any]			      =  [pivot, *longest_subsequence(_lowerCAmelCase	)]
 if len(_lowerCAmelCase	) > len(_lowerCAmelCase	):
  return temp_array
 else:
  return longest_subseq


if __name__ == "__main__":
    import doctest

    doctest.testmod()







def 						A_							(	_lowerCAmelCase				,  _lowerCAmelCase	)		->					Optional[int]:
 UpperCamelCase      :   List[Any]			      =  [1]
 for i in range(2				,  _lowerCAmelCase	):
  factorials.append(factorials[-1] * i	)
 assert 0 <= k < factorials[-1] * n, "k out of bounds"

 UpperCamelCase      :   Tuple			      =  []
 UpperCamelCase      :   str			      =  list(range(_lowerCAmelCase	)	)

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

 return permutation


if __name__ == "__main__":
    import doctest

    doctest.testmod()
