
"""simple docstring"""






import os
import pathlib
import tempfile
import uuid

import numpy as np

from ..utils import is_soundfile_availble, is_torch_available, is_vision_available, logging


__UpperCAmelCase 					=    logging.get_logger(__name__)

if is_vision_available():
				import PIL.Image
				from PIL import Image
				from PIL.Image import Image as ImageType
else:
				__UpperCAmelCase 					=    object

if is_torch_available():
				import torch

if is_soundfile_availble():
				import soundfile as sf




class      _SCREAMING_SNAKE_CASE   :






			def __init__(   self			,  __A			)     ->	Dict:
						lowerCAmelCase_       :List[Any]     	=    value






			def __str__(   self			)     ->	List[Any]:
						return self.to_string()






			def 					__lowerCAmelCase					(   self			)     ->	Dict:
						logger.error(
						    """This is a raw AgentType of unknown type. Display in notebooks and string conversion will be unreliable"""			)
						return self._value






			def 					__lowerCAmelCase					(   self			)     ->	str:
						logger.error(
						    """This is a raw AgentType of unknown type. Display in notebooks and string conversion will be unreliable"""			)
						return str(self._value			)




class      _SCREAMING_SNAKE_CASE   (     A__      ,					A__				):






			def 					__lowerCAmelCase					(   self			)     ->	str:
						return self._value






			def 					__lowerCAmelCase					(   self			)     ->	Tuple:
						return self._value




class      _SCREAMING_SNAKE_CASE   (     A__      ,					A__				):






			def __init__(   self			,  __A			)     ->	Union[str, Any]:
						super().__init__(__A			)

						if not is_vision_available():
									raise ImportError("""PIL must be installed in order to handle images."""			)

						lowerCAmelCase_       :Optional[int]     	=    None
						lowerCAmelCase_       :Union[str, Any]     	=    None
						lowerCAmelCase_       :int     	=    None

						if isinstance(__A			,  __A			):
									lowerCAmelCase_       :Union[str, Any]     	=    value
						elif isinstance(__A			,  (str, pathlib.Path)			):
									lowerCAmelCase_       :List[str]     	=    value
						elif isinstance(__A			,  torch.Tensor			):
									lowerCAmelCase_       :Dict     	=    value
						else:
									raise ValueError(f"""Unsupported type for {self.__class__.__name__}: {type(__A			)}"""			)






			def 					__lowerCAmelCase					(   self			,  __A=None			,  __A=None			)     ->	Dict:
						from IPython.display import Image, display

						display(Image(self.to_string()			)			)






			def 					__lowerCAmelCase					(   self			)     ->	Any:
						if self._raw is not None:
									return self._raw

						if self._path is not None:
									lowerCAmelCase_       :List[Any]     	=    Image.open(self._path			)
									return self._raw






			def 					__lowerCAmelCase					(   self			)     ->	Any:
						if self._path is not None:
									return self._path

						if self._raw is not None:
									lowerCAmelCase_       :Tuple     	=    tempfile.mkdtemp()
									lowerCAmelCase_       :List[Any]     	=    os.path.join(__A			,  str(uuid.uuida()			) + """.png"""			)
									self._raw.save(self._path			)

									return self._path

						if self._tensor is not None:
									lowerCAmelCase_       :Tuple     	=    self._tensor.cpu().detach().numpy()

									# There is likely simpler than load into image into save
									lowerCAmelCase_       :Union[str, Any]     	=    Image.fromarray((array * 255).astype(np.uinta			)			)

									lowerCAmelCase_       :List[Any]     	=    tempfile.mkdtemp()
									lowerCAmelCase_       :List[Any]     	=    os.path.join(__A			,  str(uuid.uuida()			) + """.png"""			)

									img.save(self._path			)

									return self._path




class      _SCREAMING_SNAKE_CASE   (     A__				):






			def __init__(   self			,  __A			,  __A=1_6000			)     ->	Any:
						super().__init__(__A			)

						if not is_soundfile_availble():
									raise ImportError("""soundfile must be installed in order to handle audio."""			)

						lowerCAmelCase_       :List[str]     	=    None
						lowerCAmelCase_       :Dict     	=    None

						lowerCAmelCase_       :Optional[int]     	=    samplerate

						if isinstance(__A			,  (str, pathlib.Path)			):
									lowerCAmelCase_       :List[Any]     	=    value
						elif isinstance(__A			,  torch.Tensor			):
									lowerCAmelCase_       :Optional[int]     	=    value
						else:
									raise ValueError(f"""Unsupported audio type: {type(__A			)}"""			)






			def 					__lowerCAmelCase					(   self			,  __A=None			,  __A=None			)     ->	Dict:
						from IPython.display import Audio, display

						display(Audio(self.to_string()			,  rate=self.samplerate			)			)






			def 					__lowerCAmelCase					(   self			)     ->	Optional[Any]:
						if self._tensor is not None:
									return self._tensor

						if self._path is not None:
									lowerCAmelCase_	,			lowerCAmelCase_       :Any     	=    sf.read(self._path			)
									lowerCAmelCase_       :Any     	=    torch.tensor(__A			)
									return self._tensor






			def 					__lowerCAmelCase					(   self			)     ->	List[str]:
						if self._path is not None:
									return self._path

						if self._tensor is not None:
									lowerCAmelCase_       :List[str]     	=    tempfile.mkdtemp()
									lowerCAmelCase_       :Any     	=    os.path.join(__A			,  str(uuid.uuida()			) + """.wav"""			)
									sf.write(self._path			,  self._tensor			,  samplerate=self.samplerate			)
									return self._path




__UpperCAmelCase 					=    {'text': AgentText, 'image': AgentImage, 'audio': AgentAudio}
__UpperCAmelCase 					=    {str: AgentText}

if is_vision_available():
				__UpperCAmelCase 					=    AgentImage






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


			'''simple docstring'''





			lowerCAmelCase_       :List[str]     	=    [(arg.to_raw() if isinstance(lowercase__ ,	lowercase__						) else arg) for arg in args]
			lowerCAmelCase_       :Union[str, Any]     	=    {k: (v.to_raw() if isinstance(lowercase__ ,	lowercase__						) else v) for k, v in kwargs.items()}
			return args, kwargs






def 		_snake_case			(      lowercase__						:    Any ,	lowercase__						:    Optional[int]=None						)    ->							Dict:


			'''simple docstring'''





			if isinstance(lowercase__ ,	lowercase__						):
						lowerCAmelCase_       :Dict     	=    {}
						for i, (k, v) in enumerate(outputs.items()						):
									if output_types is not None:
												# If the class has defined outputs, we can map directly according to the class definition
												if output_types[i] in AGENT_TYPE_MAPPING:
															lowerCAmelCase_       :List[Any]     	=    AGENT_TYPE_MAPPING[output_types[i]](lowercase__						)
												else:
															lowerCAmelCase_       :Any     	=    AgentType(lowercase__						)

									else:
												# If the class does not have defined output, then we map according to the type
												for _k, _v in INSTANCE_TYPE_MAPPING.items():
															if isinstance(lowercase__ ,	_k						):
																		lowerCAmelCase_       :Optional[Any]     	=    _v(lowercase__						)
												if k not in decoded_outputs:
															lowerCAmelCase_       :List[Any]     	=    AgentType[v]

			elif isinstance(lowercase__ ,	(list, tuple)						):
						lowerCAmelCase_       :List[Any]     	=    type(lowercase__						)()
						for i, v in enumerate(lowercase__						):
									if output_types is not None:
												# If the class has defined outputs, we can map directly according to the class definition
												if output_types[i] in AGENT_TYPE_MAPPING:
															decoded_outputs.append(AGENT_TYPE_MAPPING[output_types[i]](lowercase__						)						)
												else:
															decoded_outputs.append(AgentType(lowercase__						)						)
									else:
												# If the class does not have defined output, then we map according to the type
												lowerCAmelCase_       :List[Any]     	=    False
												for _k, _v in INSTANCE_TYPE_MAPPING.items():
															if isinstance(lowercase__ ,	_k						):
																		decoded_outputs.append(_v(lowercase__						)						)
																		lowerCAmelCase_       :str     	=    True

												if not found:
															decoded_outputs.append(AgentType(lowercase__						)						)

			else:
						if output_types[0] in AGENT_TYPE_MAPPING:
									# If the class has defined outputs, we can map directly according to the class definition
									lowerCAmelCase_       :List[Any]     	=    AGENT_TYPE_MAPPING[output_types[0]](lowercase__						)

						else:
									# If the class does not have defined output, then we map according to the type
									for _k, _v in INSTANCE_TYPE_MAPPING.items():
												if isinstance(lowercase__ ,	_k						):
															return _v(lowercase__						)
									return AgentType(lowercase__						)

			return decoded_outputs








"""simple docstring"""






import math






def 		_snake_case			(      lowercase__						:    int						)    ->							int:


			'''simple docstring'''





			return sum(int(lowercase__						) for digit in str(lowercase__						)						)






def 		_snake_case			(      lowercase__						:    int = 3_0						)    ->							int:


			'''simple docstring'''





			lowerCAmelCase_       :Union[str, Any]     	=    []
			for digit in range(2 ,	1_0_0						):
						for power in range(2 ,	1_0_0						):
									lowerCAmelCase_       :Tuple     	=    int(math.pow(lowercase__ ,	lowercase__						)						)
									if digit == digit_sum(lowercase__						):
												digit_to_powers.append(lowercase__						)

			digit_to_powers.sort()
			return digit_to_powers[n - 1]


if __name__ == "__main__":
				print(solution())






