





"""simple docstring"""





import itertools
import random
import unittest

import numpy as np

from transformers import is_speech_available
from transformers.testing_utils import require_torch, require_torchaudio

from ...test_sequence_feature_extraction_common import SequenceFeatureExtractionTestMixin


if is_speech_available():
       from transformers import SpeechaTextFeatureExtractor

SCREAMING_SNAKE_CASE__					=   random.Random()


def 			UpperCAmelCase__							(  SCREAMING_SNAKE_CASE     :						Optional[Any]							,						SCREAMING_SNAKE_CASE     :						Any=1.0							,						SCREAMING_SNAKE_CASE     :						List[Any]=None							,						SCREAMING_SNAKE_CASE     :						str=None			):







      '''simple docstring'''




      if rng is None:
            lowerCAmelCase  						=       global_rng

      lowerCAmelCase  						=       []
      for batch_idx in range(shape[0]			):
            values.append([]			)
            for _ in range(shape[1]			):
                  values[-1].append(rng.random() * scale			)

      return values

@require_torch
@require_torchaudio
class 		lowercase					(					unittest.TestCase					):





      def __init__(       self      ,						lowercase      ,						lowercase=7      ,						lowercase=400      ,						lowercase=2_000      ,						lowercase=24      ,						lowercase=24      ,						lowercase=0.0      ,						lowercase=16_000      ,						lowercase=True      ,						lowercase=True      ,						)		->     Union[str, Any]:
            lowerCAmelCase  						=       parent
            lowerCAmelCase  						=       batch_size
            lowerCAmelCase  						=       min_seq_length
            lowerCAmelCase  						=       max_seq_length
            lowerCAmelCase  						=       (self.max_seq_length - self.min_seq_length) // (self.batch_size - 1)
            lowerCAmelCase  						=       feature_size
            lowerCAmelCase  						=       num_mel_bins
            lowerCAmelCase  						=       padding_value
            lowerCAmelCase  						=       sampling_rate
            lowerCAmelCase  						=       return_attention_mask
            lowerCAmelCase  						=       do_normalize





      def     _snake_case			(       self )		->     Optional[Any]:
            return {
                "feature_size": self.feature_size,
                "num_mel_bins": self.num_mel_bins,
                "padding_value": self.padding_value,
                "sampling_rate": self.sampling_rate,
                "return_attention_mask": self.return_attention_mask,
                "do_normalize": self.do_normalize,
            }





      def     _snake_case			(       self      ,						lowercase=False      ,						lowercase=False )		->     Optional[Any]:






            def _flatten(lowercase ):
                  return list(itertools.chain(*lowercase_ ) )

            if equal_length:
                  lowerCAmelCase  						=       [floats_list((self.max_seq_length, self.feature_size) ) for _ in range(self.batch_size )]
            else:
                  # make sure that inputs increase in size
                  lowerCAmelCase  						=       [
                      floats_list((x, self.feature_size) )
                      for x in range(self.min_seq_length      ,						self.max_seq_length      ,						self.seq_length_diff )
                  ]
            if numpify:
                  lowerCAmelCase  						=       [np.asarray(lowercase_ ) for x in speech_inputs]
            return speech_inputs







@require_torch
@require_torchaudio
class 		lowercase					(					lowerCamelCase__     ,  unittest.TestCase					):
      _SCREAMING_SNAKE_CASE					=      SpeechaTextFeatureExtractor if is_speech_available() else None





      def     _snake_case			(       self )		->     Dict:
            lowerCAmelCase  						=       SpeechaTextFeatureExtractionTester(self )





      def     _snake_case			(       self      ,						lowercase )		->     int:
            self.assertTrue(np.all(np.mean(lowercase_      ,						axis=0 ) < 1e-3 ) )
            self.assertTrue(np.all(np.abs(np.var(lowercase_      ,						axis=0 ) - 1 ) < 1e-3 ) )





      def     _snake_case			(       self )		->     Optional[int]:
            lowerCAmelCase  						=       self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict() )
            # create three inputs of length 800, 1000, and 1200
            lowerCAmelCase  						=       [floats_list((1, x) )[0] for x in range(800      ,						1_400      ,						200 )]
            lowerCAmelCase  						=       [np.asarray(lowercase_ ) for speech_input in speech_inputs]

            # Test feature size
            lowerCAmelCase  						=       feature_extractor(lowercase_      ,						padding=lowercase_      ,						return_tensors="""np""" ).input_features
            self.assertTrue(input_features.ndim == 3 )
            self.assertTrue(input_features.shape[-1] == feature_extractor.feature_size )

            # Test not batched input
            lowerCAmelCase  						=       feature_extractor(speech_inputs[0]      ,						return_tensors="""np""" ).input_features
            lowerCAmelCase  						=       feature_extractor(np_speech_inputs[0]      ,						return_tensors="""np""" ).input_features
            self.assertTrue(np.allclose(lowercase_      ,						lowercase_      ,						atol=1e-3 ) )

            # Test batched
            lowerCAmelCase  						=       feature_extractor(lowercase_      ,						return_tensors="""np""" ).input_features
            lowerCAmelCase  						=       feature_extractor(lowercase_      ,						return_tensors="""np""" ).input_features
            for enc_seq_a, enc_seq_a in zip(lowercase_      ,						lowercase_ ):
                  self.assertTrue(np.allclose(lowercase_      ,						lowercase_      ,						atol=1e-3 ) )

            # Test 2-D numpy arrays are batched.
            lowerCAmelCase  						=       [floats_list((1, x) )[0] for x in (800, 800, 800)]
            lowerCAmelCase  						=       np.asarray(lowercase_ )
            lowerCAmelCase  						=       feature_extractor(lowercase_      ,						return_tensors="""np""" ).input_features
            lowerCAmelCase  						=       feature_extractor(lowercase_      ,						return_tensors="""np""" ).input_features
            for enc_seq_a, enc_seq_a in zip(lowercase_      ,						lowercase_ ):
                  self.assertTrue(np.allclose(lowercase_      ,						lowercase_      ,						atol=1e-3 ) )





      def     _snake_case			(       self )		->     List[Any]:
            lowerCAmelCase  						=       self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict() )
            lowerCAmelCase  						=       [floats_list((1, x) )[0] for x in range(800      ,						1_400      ,						200 )]

            lowerCAmelCase  						=       ["""longest""", """max_length""", """do_not_pad"""]
            lowerCAmelCase  						=       [None, 16, None]
            for max_length, padding in zip(lowercase_      ,						lowercase_ ):
                  lowerCAmelCase  						=       feature_extractor(
                      lowercase_      ,						padding=lowercase_      ,						max_length=lowercase_      ,						return_attention_mask=lowercase_ )
                  lowerCAmelCase  						=       inputs.input_features
                  lowerCAmelCase  						=       inputs.attention_mask
                  lowerCAmelCase  						=       [np.sum(lowercase_ ) for x in attention_mask]

                  self._check_zero_mean_unit_variance(input_features[0][: fbank_feat_lengths[0]] )
                  self._check_zero_mean_unit_variance(input_features[1][: fbank_feat_lengths[1]] )
                  self._check_zero_mean_unit_variance(input_features[2][: fbank_feat_lengths[2]] )





      def     _snake_case			(       self )		->     str:
            lowerCAmelCase  						=       self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict() )
            lowerCAmelCase  						=       [floats_list((1, x) )[0] for x in range(800      ,						1_400      ,						200 )]

            lowerCAmelCase  						=       ["""longest""", """max_length""", """do_not_pad"""]
            lowerCAmelCase  						=       [None, 16, None]
            for max_length, padding in zip(lowercase_      ,						lowercase_ ):
                  lowerCAmelCase  						=       feature_extractor(
                      lowercase_      ,						max_length=lowercase_      ,						padding=lowercase_      ,						return_tensors="""np"""      ,						return_attention_mask=lowercase_ )
                  lowerCAmelCase  						=       inputs.input_features
                  lowerCAmelCase  						=       inputs.attention_mask
                  lowerCAmelCase  						=       [np.sum(lowercase_ ) for x in attention_mask]

                  self._check_zero_mean_unit_variance(input_features[0][: fbank_feat_lengths[0]] )
                  self.assertTrue(input_features[0][fbank_feat_lengths[0] :].sum() < 1e-6 )
                  self._check_zero_mean_unit_variance(input_features[1][: fbank_feat_lengths[1]] )
                  self.assertTrue(input_features[0][fbank_feat_lengths[1] :].sum() < 1e-6 )
                  self._check_zero_mean_unit_variance(input_features[2][: fbank_feat_lengths[2]] )





      def     _snake_case			(       self )		->     Union[str, Any]:
            lowerCAmelCase  						=       self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict() )
            lowerCAmelCase  						=       [floats_list((1, x) )[0] for x in range(800      ,						1_400      ,						200 )]
            lowerCAmelCase  						=       feature_extractor(
                lowercase_      ,						padding="""max_length"""      ,						max_length=4      ,						truncation=lowercase_      ,						return_tensors="""np"""      ,						return_attention_mask=lowercase_      ,						)
            lowerCAmelCase  						=       inputs.input_features
            lowerCAmelCase  						=       inputs.attention_mask
            lowerCAmelCase  						=       np.sum(attention_mask == 1      ,						axis=1 )

            self._check_zero_mean_unit_variance(input_features[0, : fbank_feat_lengths[0]] )
            self._check_zero_mean_unit_variance(input_features[1] )
            self._check_zero_mean_unit_variance(input_features[2] )





      def     _snake_case			(       self )		->     Dict:
            lowerCAmelCase  						=       self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict() )
            lowerCAmelCase  						=       [floats_list((1, x) )[0] for x in range(800      ,						1_400      ,						200 )]
            lowerCAmelCase  						=       feature_extractor(
                lowercase_      ,						padding="""longest"""      ,						max_length=4      ,						truncation=lowercase_      ,						return_tensors="""np"""      ,						return_attention_mask=lowercase_      ,						)
            lowerCAmelCase  						=       inputs.input_features
            lowerCAmelCase  						=       inputs.attention_mask
            lowerCAmelCase  						=       np.sum(attention_mask == 1      ,						axis=1 )

            self._check_zero_mean_unit_variance(input_features[0, : fbank_feat_lengths[0]] )
            self._check_zero_mean_unit_variance(input_features[1, : fbank_feat_lengths[1]] )
            self._check_zero_mean_unit_variance(input_features[2] )

            # make sure that if max_length < longest -> then pad to max_length
            self.assertEqual(input_features.shape      ,						(3, 4, 24) )

            lowerCAmelCase  						=       [floats_list((1, x) )[0] for x in range(800      ,						1_400      ,						200 )]
            lowerCAmelCase  						=       feature_extractor(
                lowercase_      ,						padding="""longest"""      ,						max_length=16      ,						truncation=lowercase_      ,						return_tensors="""np"""      ,						return_attention_mask=lowercase_      ,						)
            lowerCAmelCase  						=       inputs.input_features
            lowerCAmelCase  						=       inputs.attention_mask
            lowerCAmelCase  						=       np.sum(attention_mask == 1      ,						axis=1 )

            self._check_zero_mean_unit_variance(input_features[0, : fbank_feat_lengths[0]] )
            self._check_zero_mean_unit_variance(input_features[1, : fbank_feat_lengths[1]] )
            self._check_zero_mean_unit_variance(input_features[2] )

            # make sure that if max_length < longest -> then pad to max_length
            self.assertEqual(input_features.shape      ,						(3, 6, 24) )





      def     _snake_case			(       self )		->     Tuple:
            import torch

            lowerCAmelCase  						=       self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict() )
            lowerCAmelCase  						=       np.random.rand(100      ,						32 ).astype(np.floataa )
            lowerCAmelCase  						=       np_speech_inputs.tolist()

            for inputs in [py_speech_inputs, np_speech_inputs]:
                  lowerCAmelCase  						=       feature_extractor.pad([{"""input_features""": inputs}]      ,						return_tensors="""np""" )
                  self.assertTrue(np_processed.input_features.dtype == np.floataa )
                  lowerCAmelCase  						=       feature_extractor.pad([{"""input_features""": inputs}]      ,						return_tensors="""pt""" )
                  self.assertTrue(pt_processed.input_features.dtype == torch.floataa )





      def     _snake_case			(       self      ,						lowercase )		->     Optional[Any]:
            from datasets import load_dataset

            lowerCAmelCase  						=       load_dataset("""hf-internal-testing/librispeech_asr_dummy"""      ,						"""clean"""      ,						split="""validation""" )
            # automatic decoding with librispeech
            lowerCAmelCase  						=       ds.sort("""id""" ).select(range(lowercase_ ) )[:num_samples]["""audio"""]

            return [x["array"] for x in speech_samples]





      def     _snake_case			(       self )		->     Dict:
            lowerCAmelCase  						=       np.array([
                -1.5_745, -1.7_713, -1.7_020, -1.6_069, -1.2_250, -1.1_105, -0.9_072, -0.8_241,
                -1.2_310, -0.8_098, -0.3_320, -0.4_101, -0.7_985, -0.4_996, -0.8_213, -0.9_128,
                -1.0_420, -1.1_286, -1.0_440, -0.7_999, -0.8_405, -1.2_275, -1.5_443, -1.4_625,
            ] )
            # fmt: on

            lowerCAmelCase  						=       self._load_datasamples(1 )
            lowerCAmelCase  						=       self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict() )
            lowerCAmelCase  						=       feature_extractor(lowercase_      ,						return_tensors="""pt""" ).input_features
            self.assertEquals(input_features.shape      ,						(1, 584, 24) )
            self.assertTrue(np.allclose(input_features[0, 0, :30]      ,						lowercase_      ,						atol=1e-4 ) )









from math import factorial




def 			UpperCAmelCase__				(			_A      : int = 1_00							):





  '''simple docstring'''







  return sum(int(_A							) for x in str(factorial(_A							)							)							)


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