


"""simple docstring"""


from math import factorial


class 			A__	:


     """simple docstring"""

     def __init__(	self:						Dict     ,		__a:						Tuple     ,		__a:						Optional[Any]	)->    str:
           lowerCamelCase					:					Optional[Any]        =	real
           if isinstance(__a     ,		__a	):
                 lowerCamelCase					:					Tuple        =	[1] * rank
           else:
                 lowerCamelCase					:					Any        =	rank

     def __repr__(	self:						int	)->    Any:
           return (
               f'{self.real}+'
               f'{"+".join(str(__a	)+"E"+str(n+1	)for n,dual in enumerate(self.duals	)	)}'
           )

     def 		a__						(	self:						List[Any]	)->    Union[str, Any]:
           lowerCamelCase					:					Tuple        =	self.duals.copy()
           while cur[-1] == 0:
                 cur.pop(-1	)
           return Dual(self.real     ,		__a	)

     def __add__(	self:						Optional[Any]     ,		__a:						int	)->    Any:
           if not isinstance(__a     ,		__a	):
                 return Dual(self.real + other     ,		self.duals	)
           lowerCamelCase					:					Optional[Any]        =	self.duals.copy()
           lowerCamelCase					:					Any        =	other.duals.copy()
           if len(__a	) > len(__a	):
                 o_dual.extend([1] * (len(__a	) - len(__a	))	)
           elif len(__a	) < len(__a	):
                 s_dual.extend([1] * (len(__a	) - len(__a	))	)
           lowerCamelCase					:					Optional[Any]        =	[]
           for i in range(len(__a	)	):
                 new_duals.append(s_dual[i] + o_dual[i]	)
           return Dual(self.real + other.real     ,		__a	)

     snake_case__	:					List[str]													=__add__

     def __sub__(	self:						str     ,		__a:						List[str]	)->    Any:
           return self + other * -1

     def __mul__(	self:						Optional[int]     ,		__a:						List[Any]	)->    List[Any]:
           if not isinstance(__a     ,		__a	):
                 lowerCamelCase					:					Tuple        =	[]
                 for i in self.duals:
                       new_duals.append(i * other	)
                 return Dual(self.real * other     ,		__a	)
           lowerCamelCase					:					Any        =	[0] * (len(self.duals	) + len(other.duals	) + 1)
           for i, item in enumerate(self.duals	):
                 for j, jtem in enumerate(other.duals	):
                       new_duals[i + j + 1] += item * jtem
           for k in range(len(self.duals	)	):
                 new_duals[k] += self.duals[k] * other.real
           for index in range(len(other.duals	)	):
                 new_duals[index] += other.duals[index] * self.real
           return Dual(self.real * other.real     ,		__a	)

     snake_case__	:					str													=__mul__

     def __truediv__(	self:						Optional[Any]     ,		__a:						Any	)->    List[Any]:
           if not isinstance(__a     ,		__a	):
                 lowerCamelCase					:					List[str]        =	[]
                 for i in self.duals:
                       new_duals.append(i / other	)
                 return Dual(self.real / other     ,		__a	)
           raise ValueError

     def __floordiv__(	self:						List[str]     ,		__a:						Optional[Any]	)->    Tuple:
           if not isinstance(__a     ,		__a	):
                 lowerCamelCase					:					List[Any]        =	[]
                 for i in self.duals:
                       new_duals.append(i // other	)
                 return Dual(self.real // other     ,		__a	)
           raise ValueError







     def __pow__(	self:						List[str]     ,		__a:						Union[str, Any]	)->    List[Any]:
           if n < 0 or isinstance(__a     ,		__a	):
                 raise ValueError("""power must be a positive integer"""	)
           if n == 0:
                 return 1
           if n == 1:
                 return self
           lowerCamelCase					:					int        =	self
           for _ in range(n - 1	):
                 x *= self
           return x




def   snake_case		(     UpperCamelCase__       :						int			,				UpperCamelCase__       :						List[str]			,				UpperCamelCase__       :						Tuple    )   ->      Optional[int]:
      if not callable(UpperCamelCase__    ):
            raise ValueError("""differentiate() requires a function as input for func"""    )
      if not isinstance(UpperCamelCase__			,				(float, int)    ):
            raise ValueError("""differentiate() requires a float as input for position"""    )
      if not isinstance(UpperCamelCase__			,				UpperCamelCase__    ):
            raise ValueError("""differentiate() requires an int as input for order"""    )
      lowerCamelCase					:					Union[str, Any]        =	Dual(UpperCamelCase__			,				1    )
      lowerCamelCase					:					int        =	func(UpperCamelCase__    )
      if order == 0:
            return result.real
      return result.duals[order - 1] * factorial(UpperCamelCase__    )


if __name__ == "__main__":
    import doctest

    doctest.testmod()




    def   snake_case		(     UpperCamelCase__       :						Any    )   ->      Tuple:
          return y**2 * y**4






    print(differentiate(f, 9, 2))








"""simple docstring"""


__lowerCamelCase      :List[Any]	    =		{0: [2, 3], 1: [0], 2: [1], 3: [4], 4: []}

__lowerCamelCase      :Union[str, Any]	    =		{0: [1, 2, 3], 1: [2], 2: [0], 3: [4], 4: [5], 5: [3]}




def   snake_case		(     UpperCamelCase__       :						dict[int, list[int]]			,				UpperCamelCase__       :						int			,				UpperCamelCase__       :						list[bool]    )   ->      list[int]:
      lowerCamelCase					:					Tuple        =	True
      lowerCamelCase					:					Any        =	[]

      for neighbour in graph[vert]:
            if not visited[neighbour]:
                  order += topology_sort(UpperCamelCase__			,				UpperCamelCase__			,				UpperCamelCase__    )

      order.append(UpperCamelCase__    )

      return order




def   snake_case		(     UpperCamelCase__       :						dict[int, list[int]]			,				UpperCamelCase__       :						int			,				UpperCamelCase__       :						list[bool]    )   ->      list[int]:
      lowerCamelCase					:					List[Any]        =	True
      lowerCamelCase					:					int        =	[vert]

      for neighbour in reversed_graph[vert]:
            if not visited[neighbour]:
                  component += find_components(UpperCamelCase__			,				UpperCamelCase__			,				UpperCamelCase__    )

      return component






def   snake_case		(     UpperCamelCase__       :						dict[int, list[int]]    )   ->      list[list[int]]:
      lowerCamelCase					:					int        =	len(UpperCamelCase__    ) * [False]
      lowerCamelCase					:					dict[int, list[int]]        =	{vert: [] for vert in range(len(UpperCamelCase__    )    )}

      for vert, neighbours in graph.items():
            for neighbour in neighbours:
                  reversed_graph[neighbour].append(UpperCamelCase__    )

      lowerCamelCase					:					int        =	[]
      for i, was_visited in enumerate(UpperCamelCase__    ):
            if not was_visited:
                  order += topology_sort(UpperCamelCase__			,				UpperCamelCase__			,				UpperCamelCase__    )

      lowerCamelCase					:					Tuple        =	[]
      lowerCamelCase					:					str        =	len(UpperCamelCase__    ) * [False]

      for i in range(len(UpperCamelCase__    )    ):
            lowerCamelCase					:					Any        =	order[len(UpperCamelCase__    ) - i - 1]
            if not visited[vert]:
                  lowerCamelCase					:					List[str]        =	find_components(UpperCamelCase__			,				UpperCamelCase__			,				UpperCamelCase__    )
                  components_list.append(UpperCamelCase__    )

      return components_list




