





"""simple docstring"""

from __future__ import annotations

from typing import Any

class __lowerCAmelCase		:





     def __init__(     self     ,					__UpperCAmelCase				):

      '''simple docstring'''




      __UpperCamelCase      =	num_of_nodes
      __UpperCamelCase      =	[]
      __UpperCamelCase      =	{}





     def 						UpperCAmelCase (     self     ,					__UpperCAmelCase     ,					__UpperCAmelCase     ,					__UpperCAmelCase				):

      '''simple docstring'''




      self.m_edges.append([u_node, v_node, weight]				)





     def 						UpperCAmelCase (     self     ,					__UpperCAmelCase				):

      '''simple docstring'''




      if self.m_component[u_node] == u_node:
       return u_node
      return self.find_component(self.m_component[u_node]				)





     def 						UpperCAmelCase (     self     ,					__UpperCAmelCase				):

      '''simple docstring'''




      if self.m_component[u_node] != u_node:
       for k in self.m_component:
        __UpperCamelCase      =	self.find_component(lowerCamelCase_				)





     def 						UpperCAmelCase (     self     ,					__UpperCAmelCase     ,					__UpperCAmelCase     ,					__UpperCAmelCase				):

      '''simple docstring'''




      if component_size[u_node] <= component_size[v_node]:
       __UpperCamelCase      =	v_node
       component_size[v_node] += component_size[u_node]
       self.set_component(lowerCamelCase_				)

      elif component_size[u_node] >= component_size[v_node]:
       __UpperCamelCase      =	self.find_component(lowerCamelCase_				)
       component_size[u_node] += component_size[v_node]
       self.set_component(lowerCamelCase_				)







     def 						UpperCAmelCase (     self				):

      '''simple docstring'''




      __UpperCamelCase      =	[]
      __UpperCamelCase      =	0

      __UpperCamelCase      =	[-1] * self.m_num_of_nodes

      # A list of components (initialized to all of the nodes)
      for node in range(self.m_num_of_nodes				):
       self.m_component.update({node: node}				)
       component_size.append(1				)

      __UpperCamelCase      =	self.m_num_of_nodes

      while num_of_components > 1:
       for edge in self.m_edges:
        __UpperCamelCase  ,     __UpperCamelCase  ,     __UpperCamelCase      =	edge

        __UpperCamelCase      =	self.m_component[u]
        __UpperCamelCase      =	self.m_component[v]

        if u_component != v_component:

         for component in (u_component, v_component):
          if (
              minimum_weight_edge[component] == -1
              or minimum_weight_edge[component][2] > w
          ):
           __UpperCamelCase      =	[u, v, w]

       for edge in minimum_weight_edge:
        if isinstance(lowerCamelCase_     ,					lowerCamelCase_				):
         __UpperCamelCase  ,     __UpperCamelCase  ,     __UpperCamelCase      =	edge

         __UpperCamelCase      =	self.m_component[u]
         __UpperCamelCase      =	self.m_component[v]

         if u_component != v_component:
          mst_weight += w
          self.union(lowerCamelCase_     ,					lowerCamelCase_     ,					lowerCamelCase_				)
          print(F'Added edge [{u} - {v}]\nAdded weight: {w}\n'				)
          num_of_components -= 1

       __UpperCamelCase      =	[-1] * self.m_num_of_nodes
      print(F'The total weight of the minimal spanning tree is: {mst_weight}'				)






def 							A						(    )				->     None:
 pass







if __name__ == "__main__":
      import doctest

      doctest.testmod()





"""simple docstring"""

def 							A						(    snake_case				:int		)				->     int:
 __UpperCamelCase      =	abs(snake_case		)
 __UpperCamelCase      =	0
 while n > 0:
  res += n % 1_0
  n //= 1_0
 return res






def 							A						(    snake_case				:int		)				->     int:
 __UpperCamelCase      =	abs(snake_case		)
 return n if n < 1_0 else n % 1_0 + sum_of_digits(n // 1_0		)






def 							A						(    snake_case				:int		)				->     int:
 return sum(int(snake_case		) for c in str(abs(snake_case		)		)		)






def 							A						(    )				->     None:
 from collections.abc import Callable
 from timeit import timeit

 def benchmark_a_function(snake_case				:Callable    , snake_case				:int		) -> None:
  __UpperCamelCase      =	f'{func.__name__}({value})'
  __UpperCamelCase      =	timeit(f'__main__.{call}'    , setup='import __main__'		)
  print(f'{call:56} = {func(snake_case		)} -- {timing:.4f} seconds'		)

 for value in (2_6_2_1_4_4, 1_1_2_5_8_9_9_9_0_6_8_4_2_6_2_4, 1_2_6_7_6_5_0_6_0_0_2_2_8_2_2_9_4_0_1_4_9_6_7_0_3_2_0_5_3_7_6):
  for func in (sum_of_digits, sum_of_digits_recursion, sum_of_digits_compact):
   benchmark_a_function(snake_case    , snake_case		)
  print()


if __name__ == "__main__":
      import doctest

      doctest.testmod()
      benchmark()



