
"""simple docstring"""

import logging
import random

import ray

from transformers import RagConfig, RagRetriever, RagTokenizer
from transformers.models.rag.retrieval_rag import CustomHFIndex


_A						=			logging.getLogger(__name__)






class 	_lowercase       :




	def __init__(			self )		->							Tuple:
		lowerCamelCase					:      Dict          =   False




	def       _UpperCamelCase   (			self		,			UpperCAmelCase_		,			UpperCAmelCase_		,			UpperCAmelCase_		,			UpperCAmelCase_ )		->							Any:
		if not self.initialized:
			lowerCamelCase					:      Optional[int]          =   RagRetriever(
			    UpperCAmelCase_		,			question_encoder_tokenizer=UpperCAmelCase_		,			generator_tokenizer=UpperCAmelCase_		,			index=UpperCAmelCase_		,			init_retrieval=UpperCAmelCase_		,			)
			lowerCamelCase					:      Union[str, Any]          =   True




	def       _UpperCamelCase   (			self )		->							Union[str, Any]:
		self.retriever.index.init_index()




	def       _UpperCamelCase   (			self		,			UpperCAmelCase_		,			UpperCAmelCase_ )		->							str:
		lowerCamelCase					:      int          =   self.retriever._main_retrieve(UpperCAmelCase_		,			UpperCAmelCase_ )
		return doc_ids, retrieved_doc_embeds






class 	_lowercase       (    __UpperCAmelCase		):




	def __init__(			self		,			UpperCAmelCase_		,			UpperCAmelCase_		,			UpperCAmelCase_		,			UpperCAmelCase_		,			UpperCAmelCase_=None )		->							Dict:
		if index is not None and index.is_initialized() and len(UpperCAmelCase_ ) > 0:
			raise ValueError(
			    'When using Ray for distributed fine-tuning, '
			    'you\'ll need to provide the paths instead, '
			    'as the dataset and the index are loaded '
			    'separately. More info in examples/rag/use_own_knowledge_dataset.py ' )
		super().__init__(
		    UpperCAmelCase_		,			question_encoder_tokenizer=UpperCAmelCase_		,			generator_tokenizer=UpperCAmelCase_		,			index=UpperCAmelCase_		,			init_retrieval=UpperCAmelCase_		,			)
		lowerCamelCase					:      List[str]          =   retrieval_workers
		if len(self.retrieval_workers ) > 0:
			ray.get(
			    [
			        worker.create_rag_retriever.remote(UpperCAmelCase_		,			UpperCAmelCase_		,			UpperCAmelCase_		,			UpperCAmelCase_ )
			        for worker in self.retrieval_workers
			    ] )




	def       _UpperCamelCase   (			self )		->							Dict:
		logger.info('initializing retrieval' )

		if len(self.retrieval_workers ) > 0:
			ray.get([worker.init_retrieval.remote() for worker in self.retrieval_workers] )
		else:
			# Non-distributed training. Load index into this same process.
			self.index.init_index()




	def       _UpperCamelCase   (			self		,			UpperCAmelCase_		,			UpperCAmelCase_ )		->							List[Any]:
		if len(self.retrieval_workers ) > 0:
			# Select a random retrieval actor.
			lowerCamelCase					:      Tuple          =   self.retrieval_workers[random.randint(0		,			len(self.retrieval_workers ) - 1 )]
			lowerCamelCase					:      Tuple          =   ray.get(random_worker.retrieve.remote(UpperCAmelCase_		,			UpperCAmelCase_ ) )
		else:
			lowerCamelCase					:      int          =   self._main_retrieve(UpperCAmelCase_		,			UpperCAmelCase_ )
		return retrieved_doc_embeds, doc_ids, self.index.get_doc_dicts(UpperCAmelCase_ )




	@classmethod
	def       _UpperCamelCase   (			cls		,			UpperCAmelCase_		,			UpperCAmelCase_=None		,			**UpperCAmelCase_ )		->							Dict:
		return super(UpperCAmelCase_		,			cls ).get_tokenizers(UpperCAmelCase_		,			UpperCAmelCase_		,			**UpperCAmelCase_ )




	@classmethod
	def       _UpperCamelCase   (			cls		,			UpperCAmelCase_		,			UpperCAmelCase_		,			UpperCAmelCase_=None		,			**UpperCAmelCase_ )		->							Dict:
		lowerCamelCase					:      str          =   kwargs.pop('config'		,			UpperCAmelCase_ ) or RagConfig.from_pretrained(UpperCAmelCase_		,			**UpperCAmelCase_ )
		lowerCamelCase					:      Any          =   RagTokenizer.from_pretrained(UpperCAmelCase_		,			config=UpperCAmelCase_ )
		lowerCamelCase					:      Any          =   rag_tokenizer.question_encoder
		lowerCamelCase					:      Union[str, Any]          =   rag_tokenizer.generator
		if indexed_dataset is not None:
			lowerCamelCase					:      int          =   'custom'
			lowerCamelCase					:      int          =   CustomHFIndex(config.retrieval_vector_size		,			UpperCAmelCase_ )
		else:
			lowerCamelCase					:      Optional[Any]          =   cls._build_index(UpperCAmelCase_ )
		return cls(
		    UpperCAmelCase_		,			question_encoder_tokenizer=UpperCAmelCase_		,			generator_tokenizer=UpperCAmelCase_		,			retrieval_workers=UpperCAmelCase_		,			index=UpperCAmelCase_		,			)








"""simple docstring"""

def 		UpperCAmelCase (		a_      ):





		'''simple docstring'''


		lowerCamelCase					:      List[Any]          =   1
		for i in range(1,						num + 1      ):
				fact *= i
		return fact
def 		UpperCAmelCase (		a_      ):





		'''simple docstring'''


		lowerCamelCase					:      Optional[Any]          =   0
		while number > 0:
				lowerCamelCase					:      str          =   number % 10
				sum_of_digits += last_digit
				lowerCamelCase					:      Tuple          =   number // 10  # Removing the last_digit from the given number
		return sum_of_digits
def 		UpperCAmelCase (		a_ = 100      ):





		'''simple docstring'''


		lowerCamelCase					:      Optional[Any]          =   factorial(a_      )
		lowerCamelCase					:      int          =   split_and_add(a_      )
		return result


if __name__ == "__main__":
					print(solution(int(input('Enter the Number: ').strip())))






