
'''simple docstring'''
from __future__ import annotations

import unittest

import numpy as np

from transformers import OPTConfig, is_tf_available
from transformers.testing_utils import require_sentencepiece, require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
						import tensorflow as tf

						from transformers import GPTaTokenizer, TFOPTForCausalLM, TFOPTModel







def 		A_(     A						:		List[str]		,     A						:		Union[str, Any]		,     A						:		Union[str, Any]=None		,     A						:		str=None):
							if attention_mask is None:
														UpperCamelCase   			=     tf.cast(tf.math.not_equal(__lowercase		,     config.pad_token_id)		,     tf.inta)
							return {"input_ids": input_ids, "attention_mask": attention_mask}


@require_tf
class 			SCREAMING_SNAKE_CASE__      :
				lowerCAmelCase_     			=							OPTConfig
				lowerCAmelCase_     			=							{}
				lowerCAmelCase_     			=							"""gelu"""







				def __init__(       self						,				A_						,				A_=13						,				A_=7						,				A_=True						,				A_=False						,				A_=99						,				A_=16						,				A_=2						,				A_=4						,				A_=4						,				A_="gelu"						,				A_=0.1						,				A_=0.1						,				A_=20						,				A_=2						,				A_=1						,				A_=0						,				A_=16						,				A_=16						,				)->		Optional[int]:







											'''simple docstring'''






											UpperCamelCase   			=     parent
											UpperCamelCase   			=     batch_size
											UpperCamelCase   			=     seq_length
											UpperCamelCase   			=     is_training
											UpperCamelCase   			=     use_labels
											UpperCamelCase   			=     vocab_size
											UpperCamelCase   			=     hidden_size
											UpperCamelCase   			=     num_hidden_layers
											UpperCamelCase   			=     num_attention_heads
											UpperCamelCase   			=     intermediate_size
											UpperCamelCase   			=     hidden_act
											UpperCamelCase   			=     hidden_dropout_prob
											UpperCamelCase   			=     attention_probs_dropout_prob
											UpperCamelCase   			=     max_position_embeddings
											UpperCamelCase   			=     eos_token_id
											UpperCamelCase   			=     pad_token_id
											UpperCamelCase   			=     bos_token_id
											UpperCamelCase   			=     embed_dim
											UpperCamelCase   			=     word_embed_proj_dim
											UpperCamelCase   			=     False







				def 						UpperCAmelCase_    (       self     )->		Optional[Any]:







											'''simple docstring'''






											UpperCamelCase   			=     ids_tensor([self.batch_size, self.seq_length - 1]						,				self.vocab_size     )
											UpperCamelCase   			=     tf.expand_dims(tf.constant([self.eos_token_id] * self.batch_size     )						,				1     )
											UpperCamelCase   			=     tf.concat([input_ids, eos_tensor]						,				axis=1     )

											UpperCamelCase   			=     self.config_cls(
											    vocab_size=self.vocab_size						,				hidden_size=self.hidden_size						,				num_hidden_layers=self.num_hidden_layers						,				num_attention_heads=self.num_attention_heads						,				ffn_dim=self.intermediate_size						,				dropout=self.hidden_dropout_prob						,				attention_dropout=self.attention_probs_dropout_prob						,				max_position_embeddings=self.max_position_embeddings						,				eos_token_id=self.eos_token_id						,				bos_token_id=self.bos_token_id						,				pad_token_id=self.pad_token_id						,				embed_dim=self.embed_dim						,				word_embed_proj_dim=self.word_embed_proj_dim						,				is_encoder_decoder=_UpperCAmelCase						,				**self.config_updates						,				)
											UpperCamelCase   			=     prepare_opt_inputs_dict(_UpperCAmelCase						,				_UpperCAmelCase     )
											return config, inputs_dict







				def 						UpperCAmelCase_    (       self						,				A_						,				A_     )->		List[str]:







											'''simple docstring'''






											UpperCamelCase   			=     TFOPTModel(config=_UpperCAmelCase     )
											UpperCamelCase   			=     inputs_dict['input_ids']

											UpperCamelCase   			=     input_ids[:1, :]
											UpperCamelCase   			=     inputs_dict['attention_mask'][:1, :]
											UpperCamelCase   			=     1

											# first forward pass
											UpperCamelCase   			=     model(_UpperCAmelCase						,				attention_mask=_UpperCAmelCase						,				use_cache=_UpperCAmelCase     )

											UpperCamelCase			,	UpperCamelCase   			=     outputs.to_tuple()

											# create hypothetical next token and extent to next_input_ids
											UpperCamelCase   			=     ids_tensor((self.batch_size, 3)						,				config.vocab_size     )
											UpperCamelCase   			=     tf.cast(ids_tensor((self.batch_size, 3)						,				2     )						,				tf.inta     )

											# append to next input_ids and
											UpperCamelCase   			=     tf.concat([input_ids, next_tokens]						,				axis=-1     )
											UpperCamelCase   			=     tf.concat([attention_mask, next_attn_mask]						,				axis=-1     )

											UpperCamelCase   			=     model(_UpperCAmelCase						,				attention_mask=_UpperCAmelCase     )[0]
											UpperCamelCase   			=     model(_UpperCAmelCase						,				attention_mask=_UpperCAmelCase						,				past_key_values=_UpperCAmelCase     )[0]

											self.parent.assertEqual(next_tokens.shape[1]						,				output_from_past.shape[1]     )

											# select random slice
											UpperCamelCase   			=     int(ids_tensor((1,)						,				output_from_past.shape[-1]     )     )
											UpperCamelCase   			=     output_from_no_past[:, -3:, random_slice_idx]
											UpperCamelCase   			=     output_from_past[:, :, random_slice_idx]

											# test that outputs are equal for slice
											tf.debugging.assert_near(_UpperCAmelCase						,				_UpperCAmelCase						,				rtol=1e-3     )


@require_tf
class 			SCREAMING_SNAKE_CASE__      (     UpperCAmelCase__							,       UpperCAmelCase__							,       unittest.TestCase):
				lowerCAmelCase_     			=							(TFOPTModel, TFOPTForCausalLM) if is_tf_available() else ()
				lowerCAmelCase_     			=							(TFOPTForCausalLM,) if is_tf_available() else ()
				lowerCAmelCase_     			=							(
				    {"""feature-extraction""": TFOPTModel, """text-generation""": TFOPTForCausalLM} if is_tf_available() else {}
				)
				lowerCAmelCase_     			=							False
				lowerCAmelCase_     			=							False
				lowerCAmelCase_     			=							False
				lowerCAmelCase_     			=							10







				def 						UpperCAmelCase_    (       self     )->		Optional[Any]:







											'''simple docstring'''






											UpperCamelCase   			=     TFOPTModelTester(self     )
											UpperCamelCase   			=     ConfigTester(self						,				config_class=_UpperCAmelCase     )







				def 						UpperCAmelCase_    (       self     )->		Dict:







											'''simple docstring'''






											self.config_tester.run_common_tests()







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







											'''simple docstring'''






											UpperCamelCase   			=     self.model_tester.prepare_config_and_inputs_for_common()
											self.model_tester.check_decoder_model_past_large_inputs(*_UpperCAmelCase     )







				def 						UpperCAmelCase_    (       self     )->		Dict:







											'''simple docstring'''






											UpperCamelCase			,	UpperCamelCase   			=     self.model_tester.prepare_config_and_inputs_for_common()

											def _get_word_embedding_weight(A_						,				A_     ):
																		if hasattr(_UpperCAmelCase						,				'weight'     ):
																									return embedding_layer.weight
																		else:
																									# Here we build the word embeddings weights if not exists.
																									# And then we retry to get the attribute once built.
																									model.build()
																									if hasattr(_UpperCAmelCase						,				'weight'     ):
																																return embedding_layer.weight
																									else:
																																return None

											for model_class in self.all_model_classes:
																		for size in [config.vocab_size - 10, config.vocab_size + 10]:
																									# build the embeddings
																									UpperCamelCase   			=     model_class(config=_UpperCAmelCase     )
																									UpperCamelCase   			=     _get_word_embedding_weight(_UpperCAmelCase						,				model.get_input_embeddings()     )
																									UpperCamelCase   			=     _get_word_embedding_weight(_UpperCAmelCase						,				model.get_output_embeddings()     )

																									# reshape the embeddings
																									model.resize_token_embeddings(_UpperCAmelCase     )
																									UpperCamelCase   			=     _get_word_embedding_weight(_UpperCAmelCase						,				model.get_input_embeddings()     )
																									UpperCamelCase   			=     _get_word_embedding_weight(_UpperCAmelCase						,				model.get_output_embeddings()     )

																									# check that the resized embeddings size matches the desired size.
																									UpperCamelCase   			=     size if size is not None else config.vocab_size

																									self.assertEqual(new_input_embeddings.shape[0]						,				_UpperCAmelCase     )

																									# check that weights remain the same after resizing
																									UpperCamelCase   			=     True
																									for pa, pa in zip(old_input_embeddings.value()						,				new_input_embeddings.value()     ):
																																if tf.math.reduce_sum(tf.math.abs(pa - pa     )     ) > 0:
																																							UpperCamelCase   			=     False
																									self.assertTrue(_UpperCAmelCase     )

																									if old_output_embeddings is not None and new_output_embeddings is not None:
																																self.assertEqual(new_output_embeddings.shape[0]						,				_UpperCAmelCase     )

																																UpperCamelCase   			=     True
																																for pa, pa in zip(old_output_embeddings.value()						,				new_output_embeddings.value()     ):
																																							if tf.math.reduce_sum(tf.math.abs(pa - pa     )     ) > 0:
																																														UpperCamelCase   			=     False
																																self.assertTrue(_UpperCAmelCase     )







def 		A_(     A						:		Optional[int]):
							return tf.constant(__lowercase		,     dtype=tf.intaa)


@require_tf
class 			SCREAMING_SNAKE_CASE__      (     unittest.TestCase):
				lowerCAmelCase_     			=							99







				def 						UpperCAmelCase_    (       self     )->		List[str]:







											'''simple docstring'''






											UpperCamelCase   			=     tf.ones((4, 1)						,				dtype=tf.intaa     ) * 2
											UpperCamelCase   			=     tf.concat([ids_tensor((4, 6)						,				self.vocab_size - 3     ) + 3, eos_column_vector]						,				axis=1     )
											UpperCamelCase   			=     input_ids.shape[0]
											UpperCamelCase   			=     OPTConfig(
											    vocab_size=self.vocab_size						,				hidden_size=24						,				num_hidden_layers=2						,				num_attention_heads=2						,				ffn_dim=32						,				max_position_embeddings=48						,				eos_token_id=2						,				pad_token_id=1						,				bos_token_id=0						,				)
											return config, input_ids, batch_size


@require_sentencepiece
@require_tf
class 			SCREAMING_SNAKE_CASE__      (     unittest.TestCase):







				@slow
				def 						UpperCAmelCase_    (       self     )->		Dict:







											'''simple docstring'''






											UpperCamelCase   			=     TFOPTModel.from_pretrained('facebook/opt-350m'     )
											UpperCamelCase   			=     _long_tensor([[0, 31414, 232, 328, 740, 1140, 12695, 69, 46078, 1588, 2]]     )
											UpperCamelCase   			=     tf.not_equal(_UpperCAmelCase						,				model.config.pad_token_id     )
											with tf.GradientTape():
																		UpperCamelCase   			=     model(input_ids=_UpperCAmelCase						,				attention_mask=_UpperCAmelCase     ).last_hidden_state
											UpperCamelCase   			=     (1, 11, 512)
											self.assertEqual(output.shape						,				_UpperCAmelCase     )
											UpperCamelCase   			=     tf.constant(
											    [[-0.2_873, -1.9_218, -0.3_033], [-1.2_710, -0.1_338, -0.1_902], [0.4_095, 0.1_214, -1.3_121]]     )
											self.assertTrue(np.allclose(output[:, :3, :3]						,				_UpperCAmelCase						,				atol=4e-3     )     )

											UpperCamelCase   			=     tf.function(_UpperCAmelCase						,				jit_compile=_UpperCAmelCase     )
											UpperCamelCase   			=     xla_generate(_UpperCAmelCase						,				_UpperCAmelCase     )[0]
											self.assertTrue(np.allclose(output[:, :3, :3]						,				_UpperCAmelCase						,				atol=4e-2     )     )


@require_tf
@slow
class 			SCREAMING_SNAKE_CASE__      (     unittest.TestCase):







				def 						UpperCAmelCase_    (       self     )->		Tuple:







											'''simple docstring'''






											super().setUp()
											UpperCamelCase   			=     'facebook/opt-350m'







				def 						UpperCAmelCase_    (       self     )->		Optional[int]:







											'''simple docstring'''






											UpperCamelCase   			=     TFOPTForCausalLM.from_pretrained(self.path_model     )
											UpperCamelCase   			=     GPTaTokenizer.from_pretrained(self.path_model     )

											UpperCamelCase   			=     [
											    'Today is a beautiful day and I want to',
											    'In the city of',
											    'Paris is the capital of France and',
											    'Computers and mobile phones have taken',
											]
											# verify that prompt without BOS token is identical to Metaseq -> add_special_tokens=False
											UpperCamelCase   			=     tokenizer(_UpperCAmelCase						,				return_tensors='tf'						,				padding=_UpperCAmelCase						,				add_special_tokens=_UpperCAmelCase     )
											UpperCamelCase   			=     tf.math.reduce_mean(model(inputs.input_ids						,				attention_mask=inputs.attention_mask     )[0]						,				axis=-1     )
											UpperCamelCase   			=     tf.constant(
											    [
											        [1.3_851, -13.8923, -10.5229, -10.7533, -0.2_309, -10.2384, -0.5_365, -9.0_947, -5.1_670],
											        [-4.7_073, -10.6276, -3.9_415, -21.5242, -0.2_822, -0.2_822, -0.2_822, -0.2_822, -0.2_822],
											        [0.6_247, -3.4_229, -8.9_179, -1.4_297, -14.1650, 1.4_146, -9.0_218, -0.2_703, -0.2_703],
											        [6.4_783, -1.9_913, -10.7926, -2.3_336, 1.5_092, -0.9_974, -6.8_213, 1.3_477, 1.3_477],
											    ]     )
											self.assertTrue(np.allclose(_UpperCAmelCase						,				_UpperCAmelCase						,				atol=1e-4     )     )

											UpperCamelCase   			=     tf.function(_UpperCAmelCase						,				jit_compile=_UpperCAmelCase     )
											UpperCamelCase   			=     tf.math.reduce_mean(xla_generate(inputs.input_ids						,				attention_mask=inputs.attention_mask     )[0]						,				axis=-1     )
											self.assertTrue(np.allclose(_UpperCAmelCase						,				_UpperCAmelCase						,				atol=1e-4     )     )


@require_tf
@slow
class 			SCREAMING_SNAKE_CASE__      (     unittest.TestCase):







				@property
				def 						UpperCAmelCase_    (       self     )->		Any:







											'''simple docstring'''






											return [
											    "Today is a beautiful day and I want",
											    "In the city of",
											    "Paris is the capital of France and",
											    "Computers and mobile phones have taken",
											]







				def 						UpperCAmelCase_    (       self     )->		Any:







											'''simple docstring'''






											UpperCamelCase   			=     'facebook/opt-125m'

											UpperCamelCase   			=     [
											    'Today is a beautiful day and I want to',
											    'In the city of New York, the city',
											    'Paris is the capital of France and the capital',
											    'Computers and mobile phones have taken over the',
											]

											UpperCamelCase   			=     []
											UpperCamelCase   			=     GPTaTokenizer.from_pretrained(_UpperCAmelCase     )
											UpperCamelCase   			=     TFOPTForCausalLM.from_pretrained(_UpperCAmelCase     )

											for prompt in self.prompts:
																		UpperCamelCase   			=     tokenizer(_UpperCAmelCase						,				return_tensors='tf'     ).input_ids

																		UpperCamelCase   			=     model.generate(_UpperCAmelCase						,				max_length=10     )

																		UpperCamelCase   			=     tokenizer.batch_decode(_UpperCAmelCase						,				skip_special_tokens=_UpperCAmelCase     )
																		predicted_outputs += generated_string

											self.assertListEqual(_UpperCAmelCase						,				_UpperCAmelCase     )







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







											'''simple docstring'''






											UpperCamelCase   			=     'facebook/opt-350m'

											UpperCamelCase   			=     GPTaTokenizer.from_pretrained(_UpperCAmelCase     )
											UpperCamelCase   			=     TFOPTForCausalLM.from_pretrained(_UpperCAmelCase     )

											UpperCamelCase   			=     'left'

											# use different length sentences to test batching
											UpperCamelCase   			=     [
											    'Hello, my dog is a little',
											    'Today, I',
											]

											UpperCamelCase   			=     tokenizer(_UpperCAmelCase						,				return_tensors='tf'						,				padding=_UpperCAmelCase     )
											UpperCamelCase   			=     inputs['input_ids']

											UpperCamelCase   			=     model.generate(input_ids=_UpperCAmelCase						,				attention_mask=inputs['attention_mask']     )

											UpperCamelCase   			=     tokenizer(sentences[0]						,				return_tensors='tf'     ).input_ids
											UpperCamelCase   			=     model.generate(input_ids=_UpperCAmelCase     )

											UpperCamelCase   			=     inputs_non_padded.shape[-1] - tf.math.reduce_sum(
											    tf.cast(inputs['attention_mask'][-1]						,				tf.intaa     )     )
											UpperCamelCase   			=     tokenizer(sentences[1]						,				return_tensors='tf'     ).input_ids
											UpperCamelCase   			=     model.generate(input_ids=_UpperCAmelCase						,				max_length=model.config.max_length - num_paddings     )

											UpperCamelCase   			=     tokenizer.batch_decode(_UpperCAmelCase						,				skip_special_tokens=_UpperCAmelCase     )
											UpperCamelCase   			=     tokenizer.decode(output_non_padded[0]						,				skip_special_tokens=_UpperCAmelCase     )
											UpperCamelCase   			=     tokenizer.decode(output_padded[0]						,				skip_special_tokens=_UpperCAmelCase     )

											UpperCamelCase   			=     [
											    'Hello, my dog is a little bit of a dork.\nI\'m a little bit',
											    'Today, I was in the middle of a conversation with a friend about the',
											]
											self.assertListEqual(_UpperCAmelCase						,				_UpperCAmelCase     )
											self.assertListEqual(_UpperCAmelCase						,				[non_padded_sentence, padded_sentence]     )







				def 						UpperCAmelCase_    (       self     )->		int:







											'''simple docstring'''






											UpperCamelCase   			=     'facebook/opt-350m'

											UpperCamelCase   			=     [
											    'Today is a beautiful day and I want to',
											    'In the city of San Francisco, the city',
											    'Paris is the capital of France and the capital',
											    'Computers and mobile phones have taken over the',
											]

											UpperCamelCase   			=     []
											UpperCamelCase   			=     GPTaTokenizer.from_pretrained(_UpperCAmelCase     )
											UpperCamelCase   			=     TFOPTForCausalLM.from_pretrained(_UpperCAmelCase     )

											for prompt in self.prompts:
																		UpperCamelCase   			=     tokenizer(_UpperCAmelCase						,				return_tensors='tf'     ).input_ids

																		UpperCamelCase   			=     model.generate(_UpperCAmelCase						,				max_length=10     )

																		UpperCamelCase   			=     tokenizer.batch_decode(_UpperCAmelCase						,				skip_special_tokens=_UpperCAmelCase     )
																		predicted_outputs += generated_string

											self.assertListEqual(_UpperCAmelCase						,				_UpperCAmelCase     )












def      _snake_case     (__lowercase):
   UpperCamelCase_						=  1
   for i in range(1     ,   num + 1):
      fact *= i
   return fact






def      _snake_case     (__lowercase):
   UpperCamelCase_						=  0
   while number > 0:
      UpperCamelCase_						=  number % 10
      sum_of_digits += last_digit
      UpperCamelCase_						=  number // 10  # Removing the last_digit from the given number
   return sum_of_digits






def      _snake_case     (__lowercase = 100):
   UpperCamelCase_						=  factorial(__lowercase)
   UpperCamelCase_						=  split_and_add(__lowercase)
   return result


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





