
'''simple docstring'''


#
# Sort large text files in a minimum amount of memory
#
import argparse
import os




class     __snake_case			:
		a_          =					"block_{0}.dat"




		def __init__(  self					:Union[str, Any]			,    _SCREAMING_SNAKE_CASE					:Dict)					->			Optional[int]:






								'''simple docstring'''






								UpperCamelCase_     :	int					     =     filename
								UpperCamelCase_     :	List[Any]					     =     []




		def 	_snake_case	(  self					:Dict			,    _SCREAMING_SNAKE_CASE					:Optional[Any]			,    _SCREAMING_SNAKE_CASE					:Any)					->			Optional[Any]:






								'''simple docstring'''






								UpperCamelCase_     :	str					     =     self.BLOCK_FILENAME_FORMAT.format(_SCREAMING_SNAKE_CASE)
								with open(_SCREAMING_SNAKE_CASE			,    """w""") as file:
														file.write(_SCREAMING_SNAKE_CASE)
								self.block_filenames.append(_SCREAMING_SNAKE_CASE)




		def 	_snake_case	(  self					:Optional[Any])					->			Union[str, Any]:






								'''simple docstring'''






								return self.block_filenames




		def 	_snake_case	(  self					:Optional[int]			,    _SCREAMING_SNAKE_CASE					:Tuple			,    _SCREAMING_SNAKE_CASE					:Dict=None)					->			List[str]:






								'''simple docstring'''






								UpperCamelCase_     :	int					     =     0
								with open(self.filename) as file:
														while True:
																				UpperCamelCase_     :	List[str]					     =     file.readlines(_SCREAMING_SNAKE_CASE)

																				if lines == []:
																										break

																				if sort_key is None:
																										lines.sort()
																				else:
																										lines.sort(key=_SCREAMING_SNAKE_CASE)

																				self.write_block("""""".join(_SCREAMING_SNAKE_CASE)			,    _SCREAMING_SNAKE_CASE)
																				i += 1





		def 	_snake_case	(  self					:Dict)					->			Tuple:






								'''simple docstring'''






								map(os.remove			,    self.block_filenames)







class     __snake_case			:




		def 	_snake_case	(  self					:Any			,    _SCREAMING_SNAKE_CASE					:Optional[Any])					->			Union[str, Any]:






								'''simple docstring'''






								UpperCamelCase_     :	List[Any]					     =     -1
								UpperCamelCase_     :	Union[str, Any]					     =     None

								for i in range(len(_SCREAMING_SNAKE_CASE)):
														if min_str is None or choices[i] < min_str:
																				UpperCamelCase_     :	Dict					     =     i

								return min_index







class     __snake_case			:




		def __init__(  self					:str			,    _SCREAMING_SNAKE_CASE					:List[Any])					->			Optional[int]:






								'''simple docstring'''






								UpperCamelCase_     :	Optional[int]					     =     files
								UpperCamelCase_     :	Tuple					     =     set()
								UpperCamelCase_     :	str					     =     len(_SCREAMING_SNAKE_CASE)
								UpperCamelCase_     :	List[Any]					     =     {i: None for i in range(self.num_buffers)}




		def 	_snake_case	(  self					:Union[str, Any])					->			Optional[int]:






								'''simple docstring'''






								return {
								    i: self.buffers[i] for i in range(self.num_buffers) if i not in self.empty
								}




		def 	_snake_case	(  self					:Any)					->			Dict:






								'''simple docstring'''






								for i in range(self.num_buffers):
														if self.buffers[i] is None and i not in self.empty:
																				UpperCamelCase_     :	List[Any]					     =     self.files[i].readline()

																				if self.buffers[i] == "":
																										self.empty.add(_SCREAMING_SNAKE_CASE)
																										self.files[i].close()

								if len(self.empty) == self.num_buffers:
														return False

								return True





		def 	_snake_case	(  self					:List[Any]			,    _SCREAMING_SNAKE_CASE					:Optional[int])					->			List[Any]:






								'''simple docstring'''






								UpperCamelCase_     :	Any					     =     self.buffers[index]
								UpperCamelCase_     :	Dict					     =     None

								return value







class     __snake_case			:




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






								'''simple docstring'''






								UpperCamelCase_     :	int					     =     merge_strategy




		def 	_snake_case	(  self					:List[str]			,    _SCREAMING_SNAKE_CASE					:Optional[Any]			,    _SCREAMING_SNAKE_CASE					:Dict			,    _SCREAMING_SNAKE_CASE					:int)					->			str:






								'''simple docstring'''






								UpperCamelCase_     :	Any					     =     FilesArray(self.get_file_handles(_SCREAMING_SNAKE_CASE			,    _SCREAMING_SNAKE_CASE))
								with open(_SCREAMING_SNAKE_CASE			,    """w"""			,    _SCREAMING_SNAKE_CASE) as outfile:
														while buffers.refresh():
																				UpperCamelCase_     :	Optional[int]					     =     self.merge_strategy.select(buffers.get_dict())
																				outfile.write(buffers.unshift(_SCREAMING_SNAKE_CASE))





		def 	_snake_case	(  self					:Optional[Any]			,    _SCREAMING_SNAKE_CASE					:int			,    _SCREAMING_SNAKE_CASE					:int)					->			str:






								'''simple docstring'''






								UpperCamelCase_     :	Optional[Any]					     =     {}

								for i in range(len(_SCREAMING_SNAKE_CASE)):
														UpperCamelCase_     :	str					     =     open(filenames[i]			,    """r"""			,    _SCREAMING_SNAKE_CASE)  # noqa: UP015

								return files







class     __snake_case			:




		def __init__(  self					:str			,    _SCREAMING_SNAKE_CASE					:Any)					->			Any:






								'''simple docstring'''






								UpperCamelCase_     :	Union[str, Any]					     =     block_size




		def 	_snake_case	(  self					:List[str]			,    _SCREAMING_SNAKE_CASE					:List[Any]			,    _SCREAMING_SNAKE_CASE					:Union[str, Any]=None)					->			Optional[Any]:






								'''simple docstring'''






								UpperCamelCase_     :	Tuple					     =     self.get_number_blocks(_SCREAMING_SNAKE_CASE			,    self.block_size)
								UpperCamelCase_     :	Optional[Any]					     =     FileSplitter(_SCREAMING_SNAKE_CASE)
								splitter.split(self.block_size			,    _SCREAMING_SNAKE_CASE)

								UpperCamelCase_     :	int					     =     FileMerger(NWayMerge())
								UpperCamelCase_     :	List[str]					     =     self.block_size / (num_blocks + 1)
								merger.merge(splitter.get_block_filenames()			,    filename + """.out"""			,    _SCREAMING_SNAKE_CASE)

								splitter.cleanup()





		def 	_snake_case	(  self					:str			,    _SCREAMING_SNAKE_CASE					:List[str]			,    _SCREAMING_SNAKE_CASE					:List[Any])					->			Tuple:






								'''simple docstring'''






								return (os.stat(_SCREAMING_SNAKE_CASE).st_size / block_size) + 1







def 					__magic_name__(       UpperCAmelCase__ :       Dict	):
						if string[-1].lower() == "k":
												return int(string[:-1]	) * 1024
						elif string[-1].lower() == "m":
												return int(string[:-1]	) * 1024 * 1024
						elif string[-1].lower() == "g":
												return int(string[:-1]	) * 1024 * 1024 * 1024
						else:
												return int(UpperCAmelCase__	)
def 					__magic_name__(       ):
						UpperCamelCase_     :	Any					     =     argparse.ArgumentParser()
						parser.add_argument(
						    """-m"""							,				"""--mem"""							,				help="""amount of memory to use for sorting"""							,				default="""100M"""	)
						parser.add_argument(
						    """filename"""							,				metavar="""<filename>"""							,				nargs=1							,				help="""name of file to sort"""	)
						UpperCamelCase_     :	Union[str, Any]					     =     parser.parse_args()

						UpperCamelCase_     :	List[str]					     =     ExternalSort(parse_memory(args.mem	)	)
						sorter.sort(args.filename[0]	)


if __name__ == "__main__":
	main()






'''simple docstring'''


__SCREAMING_SNAKE_CASE						=      [chr(i) for i in range(32, 126)]
__SCREAMING_SNAKE_CASE						=      list(range(len(alphabets)))
__SCREAMING_SNAKE_CASE						=      list(range(len(alphabets)))
__SCREAMING_SNAKE_CASE						=      list(range(len(alphabets)))
__SCREAMING_SNAKE_CASE						=      list(reversed(range(len(alphabets))))
__SCREAMING_SNAKE_CASE						=      []
__SCREAMING_SNAKE_CASE						=      __SCREAMING_SNAKE_CASE						=      __SCREAMING_SNAKE_CASE						=      0
def 					__magic_name__(       ):
						global gear_one_pos
						global gear_two_pos
						global gear_three_pos
						UpperCamelCase_     :	List[Any]					     =     gear_one[0]
						gear_one.append(UpperCAmelCase__	)
						del gear_one[0]
						gear_one_pos += 1
						if gear_one_pos % int(len(UpperCAmelCase__	)	) == 0:
												UpperCamelCase_     :	List[str]					     =     gear_two[0]
												gear_two.append(UpperCAmelCase__	)
												del gear_two[0]
												gear_two_pos += 1
												if gear_two_pos % int(len(UpperCAmelCase__	)	) == 0:
																		UpperCamelCase_     :	List[Any]					     =     gear_three[0]
																		gear_three.append(UpperCAmelCase__	)
																		del gear_three[0]
																		gear_three_pos += 1
def 					__magic_name__(       UpperCAmelCase__ :       int	):
						UpperCamelCase_     :	Any					     =     alphabets.index(UpperCAmelCase__	)
						UpperCamelCase_     :	List[str]					     =     gear_one[target]
						UpperCamelCase_     :	str					     =     gear_two[target]
						UpperCamelCase_     :	int					     =     gear_three[target]
						UpperCamelCase_     :	Union[str, Any]					     =     reflector[target]
						UpperCamelCase_     :	Dict					     =     gear_three.index(UpperCAmelCase__	)
						UpperCamelCase_     :	Optional[int]					     =     gear_two.index(UpperCAmelCase__	)
						UpperCamelCase_     :	Optional[int]					     =     gear_one.index(UpperCAmelCase__	)
						code.append(alphabets[target]	)
						rotator()


if __name__ == "__main__":
	__SCREAMING_SNAKE_CASE						=      list(input("Type your message:\n"))
	while True:
		try:
			__SCREAMING_SNAKE_CASE						=      int(input("Please set token:(must be only digits)\n"))
			break
		except Exception as error:
			print(error)
	for _ in range(token):
		rotator()
	for j in decode:
		engine(j)
	print("\n" + "".join(code))
	print(
	    f"\nYour Token is {token} please write it down.\nIf you want to decode "
	    "this message again you should input same digits as token!"
	)




