def   __A		(			_A							,				_A					):



 """simple docstring"""


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

 __a       =  []
 __a       =  list(range(_A					)					)

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

 return permutation


if __name__ == "__main__":
  import doctest

  doctest.testmod()



from __future__ import annotations
class    A_ :

  def __init__(		self :      Union[str, Any]     ,							__SCREAMING_SNAKE_CASE :      int       ):
   __a       =  order

   # a_{0} ... a_{k}
   __a       =  [1.0] + [0.0] * order
   # b_{0} ... b_{k}
   __a       =  [1.0] + [0.0] * order

   # x[n-1] ... x[n-k]
   __a       =  [0.0] * self.order
   # y[n-1] ... y[n-k]
   __a       =  [0.0] * self.order

  def 		_UpperCAmelCase   (		self :      Union[str, Any]     ,							__SCREAMING_SNAKE_CASE :      list[float]     ,							__SCREAMING_SNAKE_CASE :      list[float]       ):
   if len(__SCREAMING_SNAKE_CASE       ) < self.order:
    __a       =  [1.0, *a_coeffs]

   if len(__SCREAMING_SNAKE_CASE       ) != self.order + 1:
    __a       =  (
        f"""Expected a_coeffs to have {self.order + 1} elements """
        f"""for {self.order}-order filter, got {len(__SCREAMING_SNAKE_CASE       )}"""
    )
    raise ValueError(__SCREAMING_SNAKE_CASE       )

   if len(__SCREAMING_SNAKE_CASE       ) != self.order + 1:
    __a       =  (
        f"""Expected b_coeffs to have {self.order + 1} elements """
        f"""for {self.order}-order filter, got {len(__SCREAMING_SNAKE_CASE       )}"""
    )
    raise ValueError(__SCREAMING_SNAKE_CASE       )

   __a       =  a_coeffs
   __a       =  b_coeffs

  def 		_UpperCAmelCase   (		self :      Optional[Any]     ,							__SCREAMING_SNAKE_CASE :      float       ):
   __a       =  0.0

   # Start at index 1 and do index 0 at the end.
   for i in range(1     ,							self.order + 1       ):
    result += (
        self.b_coeffs[i] * self.input_history[i - 1]
        - self.a_coeffs[i] * self.output_history[i - 1]
    )

   __a       =  (result + self.b_coeffs[0] * sample) / self.a_coeffs[0]

   __a       =  self.input_history[:-1]
   __a       =  self.output_history[:-1]

   __a       =  sample
   __a       =  result

   return result


