






'''simple docstring'''


from math import ceil







def 	__magic_name__( _A						,      _A					):
						'''simple docstring'''





						UpperCamelCase__         = list(range(0						,      _A					)					)

						UpperCamelCase__         = [item for sublist in list(device_map.values()					) for item in sublist]

						# Duplicate check
						UpperCamelCase__         = []
						for i in device_map_blocks:
												if device_map_blocks.count(_A					) > 1 and i not in duplicate_blocks:
																		duplicate_blocks.append(_A					)
    # Missing blocks
						UpperCamelCase__         = [i for i in blocks if i not in device_map_blocks]
						UpperCamelCase__         = [i for i in device_map_blocks if i not in blocks]

						if len(_A					) != 0:
												raise ValueError(
												    """Duplicate attention blocks specified in device_map. Attention blocks must be specified to one device."""
												    """ These attention blocks were specified more than once: """ + str(_A					)					)
						if len(_A					) != 0:
												raise ValueError(
												    """There are attention blocks for this model that are not specified in the device_map. Add these attention """
												    """blocks to a device on the device_map: """ + str(_A					)					)
						if len(_A					) != 0:
												raise ValueError(
												    """The device_map contains more attention blocks than this model has. Remove these from the device_map:"""
												    + str(_A					)					)







def 	__magic_name__( _A						,      _A					):
						'''simple docstring'''





						UpperCamelCase__         = list(range(_A					)					)
						UpperCamelCase__         = int(ceil(n_layers / len(_A					)					)					)
						UpperCamelCase__         = [layers[i : i + n_blocks] for i in range(0						,      _A						,      _A					)]

						return dict(zip(_A						,      _A					)					)








'''simple docstring'''


from __future__ import annotations

from typing import Any
class    _SCREAMING_SNAKE_CASE							:


			'''simple docstring'''





			def __init__(   self							:						Union[str, Any] ,      lowercase							:						int			)							->    None:

									'''simple docstring'''







									UpperCamelCase__         = num_of_nodes
									UpperCamelCase__         = []
									UpperCamelCase__         = {}






			def 				A      (   self							:						Optional[Any] ,      lowercase							:						int ,      lowercase							:						int ,      lowercase							:						int			)							->    None:

									'''simple docstring'''







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






			def 				A      (   self							:						str ,      lowercase							:						int			)							->    int:

									'''simple docstring'''







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






			def 				A      (   self							:						Union[str, Any] ,      lowercase							:						int			)							->    None:

									'''simple docstring'''







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






			def 				A      (   self							:						Tuple ,      lowercase							:						list[int] ,      lowercase							:						int ,      lowercase							:						int			)							->    None:

									'''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(lowercase			)

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







			def 				A      (   self							:						int			)							->    None:

									'''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(lowercase ,      lowercase			):
																											UpperCamelCase__    ,   UpperCamelCase__    ,   UpperCamelCase__         = edge

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

																											if u_component != v_component:
																																	mst_weight += w
																																	self.union(lowercase ,      lowercase ,      lowercase			)
																																	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 	__magic_name__( ):
						'''simple docstring'''







if __name__ == "__main__":
					import doctest

					doctest.testmod()
