
from random import randint, random
def  lowerCAmelCase__			(  SCREAMING_SNAKE_CASE_       ,							SCREAMING_SNAKE_CASE_       ,							SCREAMING_SNAKE_CASE_       ,							SCREAMING_SNAKE_CASE_ = False       ,							SCREAMING_SNAKE_CASE_ = False       ,							SCREAMING_SNAKE_CASE_ = 5       ,							)				->		list:
			lowerCAmelCase__      :      List[str]         =		[[-1] * number_of_cells]  # Create a highway without any car
			lowerCAmelCase__      :      Optional[Any]         =		0
			lowerCAmelCase__      :      str         =		max(SCREAMING_SNAKE_CASE_       ,							0     )
			while i < number_of_cells:
						lowerCAmelCase__      :      int         =		(
						    randint(0       ,							SCREAMING_SNAKE_CASE_     ) if random_speed else initial_speed
						)  # Place the cars
						i += (
						    randint(1       ,							max_speed * 2     ) if random_frequency else frequency
						)  # Arbitrary number, may need tuning
			return highway
def  lowerCAmelCase__			(  SCREAMING_SNAKE_CASE_       ,							SCREAMING_SNAKE_CASE_     )				->		int:
			lowerCAmelCase__      :      Dict         =		0
			lowerCAmelCase__      :      Union[str, Any]         =		highway_now[car_index + 1 :]
			for cell in range(len(SCREAMING_SNAKE_CASE_     )     ):  # May need a better name for this
						if cells[cell] != -1:  # If the cell is not empty then
									return distance  # we have the distance we wanted
						distance += 1
			# Here if the car is near the end of the highway
			return distance + get_distance(SCREAMING_SNAKE_CASE_       ,							-1     )
def  lowerCAmelCase__			(  SCREAMING_SNAKE_CASE_       ,							SCREAMING_SNAKE_CASE_       ,							SCREAMING_SNAKE_CASE_     )				->		list:
			lowerCAmelCase__      :      Dict         =		len(SCREAMING_SNAKE_CASE_     )
			# Beforce calculations, the highway is empty
			lowerCAmelCase__      :      str         =		[-1] * number_of_cells

			for car_index in range(SCREAMING_SNAKE_CASE_     ):
						if highway_now[car_index] != -1:
									# Add 1 to the current speed of the car and cap the speed
									lowerCAmelCase__      :      Tuple         =		min(highway_now[car_index] + 1       ,							SCREAMING_SNAKE_CASE_     )
									# Number of empty cell before the next car
									lowerCAmelCase__      :      Dict         =		get_distance(SCREAMING_SNAKE_CASE_       ,							SCREAMING_SNAKE_CASE_     ) - 1
									# We can't have the car causing an accident
									lowerCAmelCase__      :      Optional[int]         =		min(next_highway[car_index]       ,							SCREAMING_SNAKE_CASE_     )
									if random() < probability:
												# Randomly, a driver will slow down
												lowerCAmelCase__      :      Any         =		max(next_highway[car_index] - 1       ,							0     )
			return next_highway
def  lowerCAmelCase__			(  SCREAMING_SNAKE_CASE_       ,							SCREAMING_SNAKE_CASE_       ,							SCREAMING_SNAKE_CASE_       ,							SCREAMING_SNAKE_CASE_     )				->		list:
			lowerCAmelCase__      :      Optional[int]         =		len(highway[0]     )

			for i in range(SCREAMING_SNAKE_CASE_     ):
						lowerCAmelCase__      :      Tuple         =		update(highway[i]       ,							SCREAMING_SNAKE_CASE_       ,							SCREAMING_SNAKE_CASE_     )
						lowerCAmelCase__      :      Optional[int]         =		[-1] * number_of_cells

						for car_index in range(SCREAMING_SNAKE_CASE_     ):
									lowerCAmelCase__      :      List[str]         =		next_speeds_calculated[car_index]
									if speed != -1:
												# Change the position based on the speed (with % to create the loop)
												lowerCAmelCase__      :      Union[str, Any]         =		(car_index + speed) % number_of_cells
												# Commit the change of position
												lowerCAmelCase__      :      Optional[Any]         =		speed
						highway.append(SCREAMING_SNAKE_CASE_     )

			return highway


if __name__ == "__main__":
					import doctest

					doctest.testmod()

class      A__							:






				def __init__(						self					:      Optional[Any]    ,     a					:      list   ):






							'''simple docstring'''







							lowerCAmelCase__      :      Dict         =		set_counts
							lowerCAmelCase__      :      str         =		max(a   )
							lowerCAmelCase__      :      Any         =		len(a   )
							lowerCAmelCase__      :      List[str]         =		[1] * num_sets
							lowerCAmelCase__      :      Dict         =		list(range(a   )   )






				def 							_lowerCamelCase		(						self					:      Dict    ,     a					:      int    ,     a					:      int   ):






							'''simple docstring'''







							lowerCAmelCase__      :      Optional[Any]         =		self.get_parent(a   )
							lowerCAmelCase__      :      Tuple         =		self.get_parent(a   )

							if src_parent == dst_parent:
										return False

							if self.ranks[dst_parent] >= self.ranks[src_parent]:
										self.set_counts[dst_parent] += self.set_counts[src_parent]
										lowerCAmelCase__      :      Tuple         =		0
										lowerCAmelCase__      :      str         =		dst_parent
										if self.ranks[dst_parent] == self.ranks[src_parent]:
													self.ranks[dst_parent] += 1
										lowerCAmelCase__      :      List[Any]         =		self.set_counts[dst_parent]
							else:
										self.set_counts[src_parent] += self.set_counts[dst_parent]
										lowerCAmelCase__      :      Optional[int]         =		0
										lowerCAmelCase__      :      Tuple         =		src_parent
										lowerCAmelCase__      :      Optional[int]         =		self.set_counts[src_parent]

							lowerCAmelCase__      :      Optional[Any]         =		max(self.max_set    ,     a   )
							return True






				def 							_lowerCamelCase		(						self					:      Any    ,     a					:      int   ):






							'''simple docstring'''







							if self.parents[disj_set] == disj_set:
										return disj_set
							lowerCAmelCase__      :      Tuple         =		self.get_parent(self.parents[disj_set]   )
							return self.parents[disj_set]