
import builtins
import sys

from ...utils.imports import _is_package_available
from . import cursor, input
from .helpers import Direction, clear_line, forceWrite, linebreak, move_cursor, reset_cursor, writeColor
from .keymap import KEYMAP


_a:    List[Any] 							=			False
try:
				_a:    str 							=			_is_package_available("""google.colab""")
except ModuleNotFoundError:
				pass

@input.register
class 						__UpperCamelCase    :




	def __init__(		self	:						Optional[int]		,	lowerCAmelCase	:						Tuple = None		,	lowerCAmelCase	:						Dict = []							):


		'''simple docstring'''







		UpperCAmelCase_       				=			0
		UpperCAmelCase_       				=			choices
		UpperCAmelCase_       				=			prompt
		if sys.platform == "win32":
			UpperCAmelCase_       				=			"""*"""
		else:
			UpperCAmelCase_       				=			"""➔ """




	def       __A					(		self	:						Optional[Any]		,	lowerCAmelCase	:						int		,	lowerCAmelCase	:						List[str] = ""							):


		'''simple docstring'''







		if sys.platform != "win32":
			writeColor(self.choices[index]		,	32		,	_a							)
		else:
			forceWrite(self.choices[index]		,	_a							)




	def       __A					(		self	:						str		,	lowerCAmelCase	:						Any							):


		'''simple docstring'''







		if index == self.position:
			forceWrite(F" {self.arrow_char} "							)
			self.write_choice(_a							)
		else:
			forceWrite(F"    {self.choices[index]}"							)
		reset_cursor()




	def       __A					(		self	:						Union[str, Any]		,	lowerCAmelCase	:						Any		,	lowerCAmelCase	:						Optional[Any] = 1							):


		'''simple docstring'''







		UpperCAmelCase_       				=			self.position
		if direction == Direction.DOWN:
			if self.position + 1 >= len(self.choices							):
				return
			self.position += num_spaces
		else:
			if self.position - 1 < 0:
				return
			self.position -= num_spaces
		clear_line()
		self.print_choice(_a							)
		move_cursor(_a		,	direction.name							)
		self.print_choice(self.position							)




	@input.mark(KEYMAP["up"]							)
	def       __A					(		self	:						str							):


		'''simple docstring'''







		self.move_direction(Direction.UP							)




	@input.mark(KEYMAP["down"]							)
	def       __A					(		self	:						Any							):


		'''simple docstring'''







		self.move_direction(Direction.DOWN							)




	@input.mark(KEYMAP["newline"]							)
	def       __A					(		self	:						str							):


		'''simple docstring'''







		move_cursor(len(self.choices							) - self.position		,	"DOWN"							)
		return self.position




	@input.mark(KEYMAP["interrupt"]							)
	def       __A					(		self	:						str							):


		'''simple docstring'''







		move_cursor(len(self.choices							) - self.position		,	"DOWN"							)
		raise KeyboardInterrupt




	@input.mark_multiple(*[KEYMAP[str(_a							)] for number in range(10							)]							)
	def       __A					(		self	:						str							):


		'''simple docstring'''







		UpperCAmelCase_       				=			int(chr(self.current_selection							)							)
		UpperCAmelCase_       				=			index - self.position
		if index == self.position:
			return
		if index < len(self.choices							):
			if self.position > index:
				self.move_direction(Direction.UP		,	-movement							)
			elif self.position < index:
				self.move_direction(Direction.DOWN		,	_a							)
			else:
				return
		else:
			return




	def       __A					(		self	:						List[Any]		,	lowerCAmelCase	:						str = 0							):


		'''simple docstring'''







		if self.prompt:
			linebreak()
			forceWrite(self.prompt		,	"\n"							)
			if in_colab:
				forceWrite("Please input a choice index (starting from 0), and press enter"		,	"\n"							)
			else:
				forceWrite("Please select a choice using the arrow or number keys, and selecting with enter"		,	"\n"							)
		UpperCAmelCase_       				=			default_choice
		for i in range(len(self.choices							)							):
			self.print_choice(_a							)
			forceWrite("\n"							)
		move_cursor(len(self.choices							) - self.position		,	"UP"							)
		with cursor.hide():
			while True:
				if in_colab:
					try:
						UpperCAmelCase_       				=			int(builtins.input()							)
					except ValueError:
						UpperCAmelCase_       				=			default_choice
				else:
					UpperCAmelCase_       				=			self.handle_input()
				if choice is not None:
					reset_cursor()
					for _ in range(len(self.choices							) + 1							):
						move_cursor(1		,	"UP"							)
						clear_line()
					self.write_choice(_a		,	"\n"							)
					return choice


def       __lowerCAmelCase      (						A    ):
	if len(A    ) <= 1:
		return lst

	UpperCAmelCase_       				=			1

	while i < len(A    ):
		if lst[i - 1] <= lst[i]:
			i += 1
		else:
			UpperCAmelCase_				,   UpperCAmelCase_       				=			lst[i], lst[i - 1]
			i -= 1
			if i == 0:
				UpperCAmelCase_       				=			1

	return lst


if __name__ == "__main__":
				_a:    List[Any] 							=			input("""Enter numbers separated by a comma:\n""").strip()
				_a:    Optional[int] 							=			[int(item) for item in user_input.split(""",""")]
				print(gnome_sort(unsorted))