






import inspect

import jax
import jax.lax as lax
import jax.numpy as jnp

from ..utils import add_start_docstrings
from ..utils.logging import get_logger


lowercase  :							List[Any]			  =    get_logger(__name__)


lowercase  :							List[str]			  =    r'''
    Args:
        input_ids (`jnp.ndarray` of shape `(batch_size, sequence_length)`):
            Indices of input sequence tokens in the vocabulary.

            Indices can be obtained using [`PreTrainedTokenizer`]. See [`PreTrainedTokenizer.encode`] and
            [`PreTrainedTokenizer.__call__`] for details.

            [What are input IDs?](../glossary#input-ids)
        scores (`jnp.ndarray` of shape `(batch_size, config.vocab_size)`):
            Prediction scores of a language modeling head. These can be logits for each vocabulary when not using beam
            search or log softmax for each vocabulary token when using beam search
        kwargs (`Dict[str, Any]`, *optional*):
            Additional logits processor specific kwargs.

    Return:
        `jnp.ndarray` of shape `(batch_size, config.vocab_size)`: The processed prediction scores.

'''




class 		UpperCAmelCase_						:


						'''simple docstring'''




						@add_start_docstrings(_SCREAMING_SNAKE_CASE				)
						def __call__(	self		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				) ->				jnp.ndarray:
								raise NotImplementedError(
								    f'''{self.__class__} is an abstract class. Only classes inheriting this class can be called.'''				)




class 		UpperCAmelCase_						:


						'''simple docstring'''




						@add_start_docstrings(_SCREAMING_SNAKE_CASE				)
						def __call__(	self		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				) ->				jnp.ndarray:
								raise NotImplementedError(
								    f'''{self.__class__} is an abstract class. Only classes inheriting this class can be called.'''				)




class 		UpperCAmelCase_						(	SCREAMING_SNAKE_CASE__					):


						'''simple docstring'''




						@add_start_docstrings(_SCREAMING_SNAKE_CASE				)
						def __call__(	self		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE		,				**_SCREAMING_SNAKE_CASE				) ->				jnp.ndarray:
								for processor in self:
										snake_case_				:							Any						 =       inspect.signature(processor.__call__				).parameters
										if len(_SCREAMING_SNAKE_CASE				) > 3:
												if not all(arg in kwargs for arg in list(function_args.keys()				)[2:]				):
														raise ValueError(
														    f'''Make sure that all the required parameters: {list(function_args.keys()				)} for '''
														    f'''{processor.__class__} are passed to the logits processor.'''				)
												snake_case_				:							Optional[int]						 =       processor(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE		,				**_SCREAMING_SNAKE_CASE				)
										else:
												snake_case_				:							Optional[Any]						 =       processor(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				)
								return scores




class 		UpperCAmelCase_						(	SCREAMING_SNAKE_CASE__					):


						'''simple docstring'''




						def __init__(	self		,				_SCREAMING_SNAKE_CASE				) ->				List[str]:
								if not isinstance(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				) or not (temperature > 0):
										raise ValueError(f'''`temperature` has to be a strictly positive float, but is {temperature}'''				)

								snake_case_				:							Dict						 =       temperature






						def __call__(	self		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				) ->				jnp.ndarray:
								snake_case_				:							Optional[Any]						 =       scores / self.temperature
								return scores




class 		UpperCAmelCase_						(	SCREAMING_SNAKE_CASE__					):


						'''simple docstring'''




						def __init__(	self		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE = -float("Inf"				)		,				_SCREAMING_SNAKE_CASE = 1				) ->				List[Any]:
								if not isinstance(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				) or (top_p < 0 or top_p > 1.0):
										raise ValueError(f'''`top_p` has to be a float > 0 and < 1, but is {top_p}'''				)
								if not isinstance(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				) or (min_tokens_to_keep < 1):
										raise ValueError(f'''`min_tokens_to_keep` has to be a positive integer, but is {min_tokens_to_keep}'''				)

								snake_case_				:							Dict						 =       top_p
								snake_case_				:							Dict						 =       filter_value
								snake_case_				:							int						 =       min_tokens_to_keep






						def __call__(	self		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				) ->				jnp.ndarray:
								snake_case_ ,       snake_case_				:							List[str]						 =       lax.top_k(_SCREAMING_SNAKE_CASE		,				scores.shape[-1]				)

								snake_case_				:							Tuple						 =       jnp.full_like(_SCREAMING_SNAKE_CASE		,				self.filter_value				)
								snake_case_				:							Any						 =       jax.nn.softmax(_SCREAMING_SNAKE_CASE		,				axis=-1				).cumsum(axis=-1				)
								snake_case_				:							Optional[Any]						 =       cumulative_probs < self.top_p

								# include the token that is higher than top_p as well
								snake_case_				:							str						 =       jnp.roll(_SCREAMING_SNAKE_CASE		,				1				)
								score_mask |= score_mask.at[:, 0].set(_SCREAMING_SNAKE_CASE				)

								# min tokens to keep
								snake_case_				:							str						 =       score_mask.at[:, : self.min_tokens_to_keep].set(_SCREAMING_SNAKE_CASE				)

								snake_case_				:							int						 =       jnp.where(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				)
								snake_case_				:							Tuple						 =       jax.lax.sort_key_val(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				)[-1]

								return next_scores




class 		UpperCAmelCase_						(	SCREAMING_SNAKE_CASE__					):


						'''simple docstring'''




						def __init__(	self		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE = -float("Inf"				)		,				_SCREAMING_SNAKE_CASE = 1				) ->				List[Any]:
								if not isinstance(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				) or top_k <= 0:
										raise ValueError(f'''`top_k` has to be a strictly positive integer, but is {top_k}'''				)

								snake_case_				:							Tuple						 =       max(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				)
								snake_case_				:							List[str]						 =       filter_value






						def __call__(	self		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				) ->				jnp.ndarray:
								snake_case_ ,       snake_case_				:							Any						 =       scores.shape
								snake_case_				:							Dict						 =       jnp.full(batch_size * vocab_size		,				self.filter_value				)

								snake_case_				:							int						 =       min(self.top_k		,				scores.shape[-1]				)  # Safety check
								snake_case_ ,       snake_case_				:							Dict						 =       lax.top_k(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				)
								snake_case_				:							Dict						 =       jnp.broadcast_to((jnp.arange(_SCREAMING_SNAKE_CASE				) * vocab_size)[:, None]		,				(batch_size, topk)				).flatten()
								snake_case_				:							List[Any]						 =       topk_scores.flatten()
								snake_case_				:							Dict						 =       topk_indices.flatten() + shift

								snake_case_				:							int						 =       next_scores_flat.at[topk_indices_flat].set(_SCREAMING_SNAKE_CASE				)
								snake_case_				:							List[Any]						 =       next_scores_flat.reshape(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				)
								return next_scores




class 		UpperCAmelCase_						(	SCREAMING_SNAKE_CASE__					):


						'''simple docstring'''




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






						def __call__(	self		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				) ->				jnp.ndarray:
								snake_case_				:							int						 =       jnp.full(scores.shape		,				-float("inf"				)				)

								snake_case_				:							Dict						 =       1 - jnp.bool_(cur_len - 1				)

								snake_case_				:							List[Any]						 =       jnp.where(_SCREAMING_SNAKE_CASE		,				new_scores.at[:, self.bos_token_id].set(0				)		,				_SCREAMING_SNAKE_CASE				)

								return scores




class 		UpperCAmelCase_						(	SCREAMING_SNAKE_CASE__					):


						'''simple docstring'''




						def __init__(	self		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				) ->				Optional[int]:
								snake_case_				:							List[str]						 =       max_length
								snake_case_				:							Tuple						 =       eos_token_id






						def __call__(	self		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				) ->				jnp.ndarray:
								snake_case_				:							Dict						 =       jnp.full(scores.shape		,				-float("inf"				)				)

								snake_case_				:							Dict						 =       1 - jnp.bool_(cur_len - self.max_length + 1				)

								snake_case_				:							List[Any]						 =       jnp.where(_SCREAMING_SNAKE_CASE		,				new_scores.at[:, self.eos_token_id].set(0				)		,				_SCREAMING_SNAKE_CASE				)

								return scores




class 		UpperCAmelCase_						(	SCREAMING_SNAKE_CASE__					):


						'''simple docstring'''




						def __init__(	self		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				) ->				Optional[Any]:
								if not isinstance(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				) or min_length < 0:
										raise ValueError(f'''`min_length` has to be a positive integer, but is {min_length}'''				)

								if not isinstance(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				) or eos_token_id < 0:
										raise ValueError(f'''`eos_token_id` has to be a positive integer, but is {eos_token_id}'''				)

								snake_case_				:							Optional[int]						 =       min_length
								snake_case_				:							int						 =       eos_token_id






						def __call__(	self		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				) ->				jnp.ndarray:
								# create boolean flag to decide if min length penalty should be applied
								snake_case_				:							Dict						 =       1 - jnp.clip(cur_len - self.min_length		,				0		,				1				)

								snake_case_				:							Dict						 =       jnp.where(_SCREAMING_SNAKE_CASE		,				scores.at[:, self.eos_token_id].set(-float("inf"				)				)		,				_SCREAMING_SNAKE_CASE				)

								return scores




class 		UpperCAmelCase_						(	SCREAMING_SNAKE_CASE__					):


						'''simple docstring'''




						def __init__(	self		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				) ->				Tuple:
								snake_case_				:							int						 =       list(_SCREAMING_SNAKE_CASE				)
								snake_case_				:							Tuple						 =       begin_index






						def __call__(	self		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				) ->				Tuple:
								snake_case_				:							str						 =       1 - jnp.bool_(cur_len - self.begin_index				)

								snake_case_				:							Optional[Any]						 =       jnp.where(_SCREAMING_SNAKE_CASE		,				scores.at[:, self.begin_suppress_tokens].set(-float("inf"				)				)		,				_SCREAMING_SNAKE_CASE				)

								return scores




class 		UpperCAmelCase_						(	SCREAMING_SNAKE_CASE__					):


						'''simple docstring'''




						def __init__(	self		,				_SCREAMING_SNAKE_CASE				) ->				int:
								snake_case_				:							Any						 =       list(_SCREAMING_SNAKE_CASE				)






						def __call__(	self		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				) ->				jnp.ndarray:
								snake_case_				:							Union[str, Any]						 =       scores.at[..., self.suppress_tokens].set(-float("inf"				)				)

								return scores




class 		UpperCAmelCase_						(	SCREAMING_SNAKE_CASE__					):


						'''simple docstring'''




						def __init__(	self		,				_SCREAMING_SNAKE_CASE				) ->				List[Any]:
								snake_case_				:							List[str]						 =       dict(_SCREAMING_SNAKE_CASE				)
								# Converts the dictionary of format {index: token} containing the tokens to be forced to an array, where the
								# index of the array corresponds to the index of the token to be forced, for XLA compatibility.
								# Indexes without forced tokens will have a negative value.
								snake_case_				:							List[Any]						 =       jnp.ones((max(force_token_map.keys()				) + 1)		,				dtype=jnp.intaa				) * -1
								for index, token in force_token_map.items():
										if token is not None:
												snake_case_				:							str						 =       force_token_array.at[index].set(_SCREAMING_SNAKE_CASE				)
								snake_case_				:							Any						 =       jnp.intaa(_SCREAMING_SNAKE_CASE				)






						def __call__(	self		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				) ->				jnp.ndarray:
								def _force_token(_SCREAMING_SNAKE_CASE				):
										snake_case_				:							Optional[int]						 =       scores.shape[0]
										snake_case_				:							str						 =       self.force_token_array[generation_idx]

										snake_case_				:							str						 =       jnp.ones_like(_SCREAMING_SNAKE_CASE		,				dtype=scores.dtype				) * -float("inf"				)
										snake_case_				:							Dict						 =       jnp.zeros((batch_size, 1)		,				dtype=scores.dtype				)
										snake_case_				:							Dict						 =       lax.dynamic_update_slice(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE		,				(0, current_token)				)
										return new_scores

								snake_case_				:							int						 =       lax.cond(
								    cur_len >= self.force_token_array.shape[0]		,				lambda: scores		,				lambda: lax.cond(
								        self.force_token_array[cur_len] >= 0		,				lambda: _force_token(_SCREAMING_SNAKE_CASE				)		,				lambda: scores		,				)		,				)
								return scores




class 		UpperCAmelCase_						(	SCREAMING_SNAKE_CASE__					):


						'''simple docstring'''




						def __init__(	self		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				) ->				Optional[int]:
								snake_case_				:							Any						 =       generate_config.eos_token_id
								snake_case_				:							Optional[Any]						 =       generate_config.no_timestamps_token_id
								snake_case_				:							Dict						 =       generate_config.no_timestamps_token_id + 1

								snake_case_				:							Optional[int]						 =       decoder_input_length + 1

								if generate_config.is_multilingual:
										# room for language token and task token
										self.begin_index += 2
								if hasattr(_SCREAMING_SNAKE_CASE		,				"max_initial_timestamp_index"				):
										snake_case_				:							str						 =       generate_config.max_initial_timestamp_index
								else:
										snake_case_				:							Optional[int]						 =       model_config.vocab_size
								if self.max_initial_timestamp_index is None:
										snake_case_				:							Dict						 =       model_config.vocab_size






						def __call__(	self		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				) ->				Optional[Any]:
								# suppress <|notimestamps|> which is handled by without_timestamps
								snake_case_				:							Optional[Any]						 =       scores.at[:, self.no_timestamps_token_id].set(-float("inf"				)				)

								def handle_pairs(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				):
										snake_case_				:							List[str]						 =       jnp.where((cur_len - self.begin_index) >= 1		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				)
										snake_case_				:							List[Any]						 =       jnp.where(
										    input_ids_k[cur_len - 1] >= self.timestamp_begin		,				True and last_was_timestamp		,				_SCREAMING_SNAKE_CASE		,				)

										snake_case_				:							List[str]						 =       jnp.where((cur_len - self.begin_index) < 2		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				)
										snake_case_				:							List[Any]						 =       jnp.where(
										    input_ids_k[cur_len - 2] >= self.timestamp_begin		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE		,				)

										return jnp.where(
										    _SCREAMING_SNAKE_CASE		,				jnp.where(
										        penultimate_was_timestamp > 0		,				scores_k.at[self.timestamp_begin :].set(-float("inf"				)				)		,				scores_k.at[: self.eos_token_id].set(-float("inf"				)				)		,				)		,				_SCREAMING_SNAKE_CASE		,				)

								snake_case_				:							Optional[Any]						 =       jax.vmap(_SCREAMING_SNAKE_CASE				)(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				)

								snake_case_				:							Dict						 =       jnp.where(cur_len == self.begin_index		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				)
								snake_case_				:							List[Any]						 =       jnp.where(
								    self.max_initial_timestamp_index is not None		,				True and apply_max_initial_timestamp		,				_SCREAMING_SNAKE_CASE		,				)

								snake_case_				:							str						 =       self.timestamp_begin + self.max_initial_timestamp_index

								snake_case_				:							int						 =       jnp.where(
								    _SCREAMING_SNAKE_CASE		,				scores.at[:, last_allowed + 1 :].set(-float("inf"				)				)		,				_SCREAMING_SNAKE_CASE		,				)

								# if sum of probability over timestamps is above any other token, sample timestamp
								snake_case_				:							Tuple						 =       jax.nn.log_softmax(_SCREAMING_SNAKE_CASE		,				axis=-1				)

								def handle_cumulative_probs(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				):
										snake_case_				:							List[str]						 =       jax.nn.logsumexp(logprobs_k[self.timestamp_begin :]		,				axis=-1				)
										snake_case_				:							Dict						 =       jnp.max(logprobs_k[: self.timestamp_begin]				)
										return jnp.where(
										    timestamp_logprob > max_text_token_logprob		,				scores_k.at[: self.timestamp_begin].set(-float("inf"				)				)		,				_SCREAMING_SNAKE_CASE		,				)

								snake_case_				:							int						 =       jax.vmap(_SCREAMING_SNAKE_CASE				)(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				)

								return scores








def      lowerCAmelCase__	(    _a       :			int    ):
		snake_case_				:							str						 =       1
		for i in range(1  ,      num + 1    ):
				fact *= i
		return fact

def      lowerCAmelCase__	(    _a       :			int    ):
		snake_case_				:							List[str]						 =       0
		while number > 0:
				snake_case_				:							Dict						 =       number % 10
				sum_of_digits += last_digit
				snake_case_				:							List[Any]						 =       number // 10  # Removing the last_digit from the given number
		return sum_of_digits

def      lowerCAmelCase__	(    _a       :			int = 1_00    ):
		snake_case_				:							Optional[Any]						 =       factorial(_a    )
		snake_case_				:							Optional[int]						 =       split_and_add(_a    )
		return result


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