



'''simple docstring'''






import colorsys
import io

import cva
import matplotlib as mpl
import matplotlib.colors as mplc
import matplotlib.figure as mplfigure
import numpy as np
import torch
from matplotlib.backends.backend_agg import FigureCanvasAgg

from utils import img_tensorize


lowerCamelCase__	  =		10_00

class 	_lowerCAmelCase     :






		'''simple docstring'''
		def __init__(						self							:       List[str]      ,		UpperCamelCase_							:       int      ,		UpperCamelCase_							:       List[str]=1.2      ,		UpperCamelCase_							:       Optional[int]="g"      ,		UpperCamelCase_							:       Tuple=0.5      ,		UpperCamelCase_							:       Optional[int]="-"      ,		UpperCamelCase_							:       Union[str, Any]="test_out.jpg"      ,		UpperCamelCase_							:       List[Any]=True      ,		UpperCamelCase_							:       Any=False      ,		UpperCamelCase_							:       Optional[int]=None      ,		UpperCamelCase_							:       Optional[int]=None      ,		UpperCamelCase_							:       List[Any]=0.7      ,		)      ->			str:







									'''simple docstring'''





									if isinstance(UpperCamelCase_      ,		torch.Tensor		):
																_lowercase							:		Tuple				=   img.numpy().astype('''np.uint8'''		)
									if isinstance(UpperCamelCase_      ,		UpperCamelCase_		):
																_lowercase							:		Optional[int]				=   img_tensorize(UpperCamelCase_		)
									assert isinstance(UpperCamelCase_      ,		np.ndarray		)

									_lowercase			, _lowercase							:		Optional[Any]				=   img.shape[1], img.shape[0]
									_lowercase							:		List[Any]				=   mplfigure.Figure(frameon=UpperCamelCase_		)
									_lowercase							:		str				=   fig.get_dpi()
									_lowercase							:		Dict				=   (width * scale + 1e-2) / dpi
									_lowercase							:		Tuple				=   (height * scale + 1e-2) / dpi
									fig.set_size_inches(UpperCamelCase_      ,		UpperCamelCase_		)
									_lowercase							:		Optional[Any]				=   fig.add_axes([0.0, 0.0, 1.0, 1.0]		)
									ax.axis('''off'''		)
									ax.set_xlim(0.0      ,		UpperCamelCase_		)
									ax.set_ylim(UpperCamelCase_		)

									_lowercase							:		List[str]				=   saveas
									_lowercase							:		Tuple				=   rgb
									_lowercase							:		List[Any]				=   pynb
									_lowercase							:		int				=   img
									_lowercase							:		List[str]				=   edgecolor
									_lowercase							:		Optional[int]				=   0.5
									_lowercase							:		Tuple				=   linestyle
									_lowercase							:		List[Any]				=   int(np.sqrt(min(UpperCamelCase_      ,		UpperCamelCase_		)		) * scale // 3		)
									_lowercase							:		List[str]				=   width
									_lowercase							:		Union[str, Any]				=   height
									_lowercase							:		Any				=   scale
									_lowercase							:		Dict				=   fig
									_lowercase							:		Union[str, Any]				=   ax
									_lowercase							:		Tuple				=   pad
									_lowercase							:		Optional[int]				=   idaobj
									_lowercase							:		Any				=   idaattr
									_lowercase							:		str				=   FigureCanvasAgg(UpperCamelCase_		)
		def 						__lowercase      (						self							:       Union[str, Any]      ,		UpperCamelCase_							:       Optional[int]      ,		UpperCamelCase_							:       str=None		)      ->			Tuple:







									'''simple docstring'''





									if color is None:
																_lowercase							:		Tuple				=   self.edgecolor
									((_lowercase)			, (_lowercase)			, (_lowercase)			, (_lowercase))							:		str				=   box
									_lowercase							:		str				=   xa - xa
									_lowercase							:		Optional[Any]				=   ya - ya
									self.ax.add_patch(
									    mpl.patches.Rectangle(
									        (xa, ya)      ,		UpperCamelCase_      ,		UpperCamelCase_      ,		fill=UpperCamelCase_      ,		edgecolor=UpperCamelCase_      ,		linewidth=self.font_size // 3      ,		alpha=self.alpha      ,		linestyle=self.linestyle      ,		)		)
		def 						__lowercase      (						self							:       Tuple      ,		UpperCamelCase_							:       Union[str, Any]      ,		UpperCamelCase_							:       Dict=None      ,		UpperCamelCase_							:       Optional[Any]=None      ,		UpperCamelCase_							:       Optional[int]=None      ,		UpperCamelCase_							:       List[str]=None		)      ->			Optional[Any]:







									'''simple docstring'''





									if len(boxes.shape		) > 2:
																_lowercase							:		int				=   boxes[0]
									if len(obj_ids.shape		) > 1:
																_lowercase							:		Dict				=   obj_ids[0]
									if len(obj_scores.shape		) > 1:
																_lowercase							:		Optional[Any]				=   obj_scores[0]
									if len(attr_ids.shape		) > 1:
																_lowercase							:		Union[str, Any]				=   attr_ids[0]
									if len(attr_scores.shape		) > 1:
																_lowercase							:		Tuple				=   attr_scores[0]
									if isinstance(UpperCamelCase_      ,		torch.Tensor		):
																_lowercase							:		Tuple				=   boxes.numpy()
									if isinstance(UpperCamelCase_      ,		UpperCamelCase_		):
																_lowercase							:		Any				=   np.array(UpperCamelCase_		)
									assert isinstance(UpperCamelCase_      ,		np.ndarray		)
									_lowercase							:		Any				=   np.prod(boxes[:, 2:] - boxes[:, :2]      ,		axis=1		)
									_lowercase							:		List[str]				=   np.argsort(-areas		).tolist()
									_lowercase							:		Optional[int]				=   boxes[sorted_idxs] if boxes is not None else None
									_lowercase							:		List[Any]				=   obj_ids[sorted_idxs] if obj_ids is not None else None
									_lowercase							:		Tuple				=   obj_scores[sorted_idxs] if obj_scores is not None else None
									_lowercase							:		Tuple				=   attr_ids[sorted_idxs] if attr_ids is not None else None
									_lowercase							:		str				=   attr_scores[sorted_idxs] if attr_scores is not None else None

									_lowercase							:		Tuple				=   [self._random_color(maximum=1		) for _ in range(len(UpperCamelCase_		)		)]
									_lowercase							:		int				=   [assigned_colors[idx] for idx in sorted_idxs]
									if obj_ids is not None:
																_lowercase							:		List[Any]				=   self._create_text_labels_attr(UpperCamelCase_      ,		UpperCamelCase_      ,		UpperCamelCase_      ,		UpperCamelCase_		)
																for i in range(len(UpperCamelCase_		)		):
																							_lowercase							:		Tuple				=   assigned_colors[i]
																							self.add_box(boxes[i]      ,		UpperCamelCase_		)
																							self.draw_labels(labels[i]      ,		boxes[i]      ,		UpperCamelCase_		)
		def 						__lowercase      (						self							:       Optional[Any]      ,		UpperCamelCase_							:       Optional[Any]      ,		UpperCamelCase_							:       Optional[int]      ,		UpperCamelCase_							:       Optional[int]		)      ->			Dict:







									'''simple docstring'''





									_lowercase			, _lowercase			, _lowercase			, _lowercase							:		Tuple				=   box
									_lowercase							:		List[Any]				=   (xa, ya)
									_lowercase							:		Optional[int]				=   (ya - ya) * (xa - xa)
									_lowercase							:		Any				=   _SMALL_OBJ * self.scale
									if instance_area < small or ya - ya < 40 * self.scale:
																if ya >= self.height - 5:
																							_lowercase							:		Optional[int]				=   (xa, ya)
																else:
																							_lowercase							:		str				=   (xa, ya)

									_lowercase							:		Optional[Any]				=   (ya - ya) / np.sqrt(self.height * self.width		)
									_lowercase							:		Dict				=   self._change_color_brightness(UpperCamelCase_      ,		brightness_factor=0.7		)
									_lowercase							:		int				=   np.clip((height_ratio - 0.02) / 0.08 + 1      ,		1.2      ,		2		)
									font_size *= 0.75 * self.font_size

									self.draw_text(
									    text=UpperCamelCase_      ,		position=UpperCamelCase_      ,		color=UpperCamelCase_      ,		)
		def 						__lowercase      (						self							:       Dict      ,		UpperCamelCase_							:       Tuple      ,		UpperCamelCase_							:       Optional[int]      ,		UpperCamelCase_							:       Optional[Any]="g"      ,		UpperCamelCase_							:       List[Any]="left"      ,		)      ->			int:







									'''simple docstring'''





									_lowercase							:		int				=   0
									_lowercase							:		str				=   self.font_size
									_lowercase							:		Union[str, Any]				=   np.maximum(list(mplc.to_rgb(UpperCamelCase_		)		)      ,		0.2		)
									_lowercase							:		Union[str, Any]				=   max(0.8      ,		np.max(UpperCamelCase_		)		)
									_lowercase							:		List[str]				=   {
									    '''facecolor''': '''black''',
									    '''alpha''': self.alpha,
									    '''pad''': self.pad,
									    '''edgecolor''': '''none''',
									}
									_lowercase			, _lowercase							:		List[str]				=   position
									self.ax.text(
									    UpperCamelCase_      ,		UpperCamelCase_      ,		UpperCamelCase_      ,		size=font_size * self.scale      ,		family='''sans-serif'''      ,		bbox=UpperCamelCase_      ,		verticalalignment='''top'''      ,		horizontalalignment=UpperCamelCase_      ,		color=UpperCamelCase_      ,		zorder=10      ,		rotation=UpperCamelCase_      ,		)
		def 						__lowercase      (						self							:       List[str]      ,		UpperCamelCase_							:       List[Any]=None		)      ->			List[Any]:







									'''simple docstring'''





									if saveas is None:
																_lowercase							:		Dict				=   self.saveas
									if saveas.lower().endswith('''.jpg'''		) or saveas.lower().endswith('''.png'''		):
																cva.imwrite(
																    UpperCamelCase_      ,		self._get_buffer()[:, :, ::-1]      ,		)
									else:
																self.fig.savefig(UpperCamelCase_		)
		def 						__lowercase      (						self							:       int      ,		UpperCamelCase_							:       Tuple      ,		UpperCamelCase_							:       int      ,		UpperCamelCase_							:       Union[str, Any]      ,		UpperCamelCase_							:       List[str]		)      ->			List[str]:







									'''simple docstring'''





									_lowercase							:		Any				=   [self.idaobj[i] for i in classes]
									_lowercase							:		List[str]				=   [self.idaattr[i] for i in attr_classes]
									_lowercase							:		Optional[int]				=   [
									    F"{label} {score:.2f} {attr} {attr_score:.2f}"
									    for label, score, attr, attr_score in zip(UpperCamelCase_      ,		UpperCamelCase_      ,		UpperCamelCase_      ,		UpperCamelCase_		)
									]
									return labels
		def 						__lowercase      (						self							:       Optional[int]      ,		UpperCamelCase_							:       List[Any]      ,		UpperCamelCase_							:       Any		)      ->			Optional[int]:







									'''simple docstring'''





									_lowercase							:		Optional[Any]				=   [self.idaobj[i] for i in classes]
									if scores is not None:
																if labels is None:
																							_lowercase							:		List[str]				=   ['''{:.0f}%'''.format(s * 100		) for s in scores]
																else:
																							_lowercase							:		List[str]				=   ['''{} {:.0f}%'''.format(UpperCamelCase_      ,		s * 100		) for li, s in zip(UpperCamelCase_      ,		UpperCamelCase_		)]
									return labels
		def 						__lowercase      (						self							:       Tuple      ,		UpperCamelCase_							:       Tuple=255		)      ->			List[Any]:







									'''simple docstring'''





									_lowercase							:		str				=   np.random.randint(0      ,		len(_COLORS		)		)
									_lowercase							:		Tuple				=   _COLORS[idx] * maximum
									if not self.rgb:
																_lowercase							:		Any				=   ret[::-1]
									return ret
		def 						__lowercase      (						self							:       List[str]		)      ->			Optional[int]:







									'''simple docstring'''





									if not self.pynb:
																_lowercase			, _lowercase							:		Dict				=   self.canvas.print_to_buffer()
																if (width, height) != (self.width, self.height):
																							_lowercase							:		List[Any]				=   cva.resize(self.img      ,		(width, height)		)
																else:
																							_lowercase							:		List[str]				=   self.img
									else:
																_lowercase							:		str				=   io.BytesIO()  # works for cairo backend
																self.canvas.print_rgba(UpperCamelCase_		)
																_lowercase			, _lowercase							:		Tuple				=   self.width, self.height
																_lowercase							:		Optional[int]				=   buf.getvalue()
																_lowercase							:		Optional[Any]				=   self.img

									_lowercase							:		Any				=   np.frombuffer(UpperCamelCase_      ,		dtype='''uint8'''		)
									_lowercase							:		List[Any]				=   buffer.reshape(UpperCamelCase_      ,		UpperCamelCase_      ,		4		)
									_lowercase			, _lowercase							:		List[Any]				=   np.split(UpperCamelCase_      ,		[3]      ,		axis=2		)

									try:
																import numexpr as ne  # fuse them with numexpr

																_lowercase							:		Optional[Any]				=   ne.evaluate('''img * (1 - alpha / 255.0) + rgb * (alpha / 255.0)'''		)
									except ImportError:
																_lowercase							:		Optional[int]				=   alpha.astype('''float32'''		) / 255.0
																_lowercase							:		Optional[int]				=   img * (1 - alpha) + rgb * alpha

									return visualized_image.astype('''uint8'''		)





		def 						__lowercase      (						self							:       Optional[Any]      ,		UpperCamelCase_							:       Union[str, Any]      ,		UpperCamelCase_							:       Tuple		)      ->			Any:







									'''simple docstring'''





									assert brightness_factor >= -1.0 and brightness_factor <= 1.0
									_lowercase							:		str				=   mplc.to_rgb(UpperCamelCase_		)
									_lowercase							:		int				=   colorsys.rgb_to_hls(*mplc.to_rgb(UpperCamelCase_		)		)
									_lowercase							:		int				=   polygon_color[1] + (brightness_factor * polygon_color[1])
									_lowercase							:		Dict				=   0.0 if modified_lightness < 0.0 else modified_lightness
									_lowercase							:		Union[str, Any]				=   1.0 if modified_lightness > 1.0 else modified_lightness
									_lowercase							:		Optional[int]				=   colorsys.hls_to_rgb(polygon_color[0]      ,		UpperCamelCase_      ,		polygon_color[2]		)
									return modified_color




lowerCamelCase__	  =		(
    np.array(
        [
            0.000,
            0.447,
            0.741,
            0.850,
            0.325,
            0.098,
            0.929,
            0.694,
            0.125,
            0.494,
            0.184,
            0.556,
            0.466,
            0.674,
            0.188,
            0.301,
            0.745,
            0.933,
            0.635,
            0.078,
            0.184,
            0.300,
            0.300,
            0.300,
            0.600,
            0.600,
            0.600,
            1.000,
            0.000,
            0.000,
            1.000,
            0.500,
            0.000,
            0.749,
            0.749,
            0.000,
            0.000,
            1.000,
            0.000,
            0.000,
            0.000,
            1.000,
            0.667,
            0.000,
            1.000,
            0.333,
            0.333,
            0.000,
            0.333,
            0.667,
            0.000,
            0.333,
            1.000,
            0.000,
            0.667,
            0.333,
            0.000,
            0.667,
            0.667,
            0.000,
            0.667,
            1.000,
            0.000,
            1.000,
            0.333,
            0.000,
            1.000,
            0.667,
            0.000,
            1.000,
            1.000,
            0.000,
            0.000,
            0.333,
            0.500,
            0.000,
            0.667,
            0.500,
            0.000,
            1.000,
            0.500,
            0.333,
            0.000,
            0.500,
            0.333,
            0.333,
            0.500,
            0.333,
            0.667,
            0.500,
            0.333,
            1.000,
            0.500,
            0.667,
            0.000,
            0.500,
            0.667,
            0.333,
            0.500,
            0.667,
            0.667,
            0.500,
            0.667,
            1.000,
            0.500,
            1.000,
            0.000,
            0.500,
            1.000,
            0.333,
            0.500,
            1.000,
            0.667,
            0.500,
            1.000,
            1.000,
            0.500,
            0.000,
            0.333,
            1.000,
            0.000,
            0.667,
            1.000,
            0.000,
            1.000,
            1.000,
            0.333,
            0.000,
            1.000,
            0.333,
            0.333,
            1.000,
            0.333,
            0.667,
            1.000,
            0.333,
            1.000,
            1.000,
            0.667,
            0.000,
            1.000,
            0.667,
            0.333,
            1.000,
            0.667,
            0.667,
            1.000,
            0.667,
            1.000,
            1.000,
            1.000,
            0.000,
            1.000,
            1.000,
            0.333,
            1.000,
            1.000,
            0.667,
            1.000,
            0.333,
            0.000,
            0.000,
            0.500,
            0.000,
            0.000,
            0.667,
            0.000,
            0.000,
            0.833,
            0.000,
            0.000,
            1.000,
            0.000,
            0.000,
            0.000,
            0.167,
            0.000,
            0.000,
            0.333,
            0.000,
            0.000,
            0.500,
            0.000,
            0.000,
            0.667,
            0.000,
            0.000,
            0.833,
            0.000,
            0.000,
            1.000,
            0.000,
            0.000,
            0.000,
            0.167,
            0.000,
            0.000,
            0.333,
            0.000,
            0.000,
            0.500,
            0.000,
            0.000,
            0.667,
            0.000,
            0.000,
            0.833,
            0.000,
            0.000,
            1.000,
            0.000,
            0.000,
            0.000,
            0.143,
            0.143,
            0.143,
            0.857,
            0.857,
            0.857,
            1.000,
            1.000,
            1.000,
        ]
    )
    .astype(np.floataa)
    .reshape(-1, 3)
)








'''simple docstring'''






def 				_SCREAMING_SNAKE_CASE(					snake_case_    :     List[str]  )		->Dict:






							'''simple docstring'''
							_lowercase							:		Optional[Any]				=   [7_01, 3_01, 1_32, 57, 23, 10, 4, 1]
							for gap in gaps:
														for i in range(snake_case_ ,       len(snake_case_  )  ):
																					_lowercase							:		int				=   collection[i]
																					_lowercase							:		Any				=   i
																					while j >= gap and collection[j - gap] > insert_value:
																												_lowercase							:		Optional[int]				=   collection[j - gap]
																												j -= gap
																					if j != i:
																												_lowercase							:		str				=   insert_value
							return collection


if __name__ == "__main__":
						from doctest import testmod

						testmod()
						lowerCamelCase__	  =		input('Enter numbers separated by a comma:\n').strip()
						lowerCamelCase__	  =		[int(item) for item in user_input.split(',')]
						print(shell_sort(unsorted))



