





import shutil
import tempfile
import unittest

import numpy as np

from transformers.testing_utils import (
    is_pt_tf_cross_test,
    require_tf,
    require_torch,
    require_torchvision,
    require_vision,
)
from transformers.utils import is_tf_available, is_torch_available, is_vision_available


if is_vision_available():
  from PIL import Image

  from transformers import AutoProcessor, SamImageProcessor, SamProcessor

if is_torch_available():
  import torch

if is_tf_available():
  import tensorflow as tf







@require_vision
@require_torchvision
class 	__lowerCAmelCase      (       unittest.TestCase	):





   def 						_snake_case			(			self   )					->	Optional[Any]:
      """simple docstring"""





      a__						:    List[str]   		=	tempfile.mkdtemp()
      a__						:    Optional[Any]   		=	SamImageProcessor()
      a__						:    Tuple   		=	SamProcessor(snake_case   )
      processor.save_pretrained(self.tmpdirname   )





   def 						_snake_case			(			self       ,      **snake_case   )					->	Dict:
      """simple docstring"""





      return AutoProcessor.from_pretrained(self.tmpdirname       ,      **snake_case   ).image_processor





   def 						_snake_case			(			self   )					->	List[str]:
      """simple docstring"""





      shutil.rmtree(self.tmpdirname   )





   def 						_snake_case			(			self   )					->	Dict:
      """simple docstring"""





      a__						:    List[Any]   		=	[np.random.randint(255       ,      size=(3, 30, 400)       ,      dtype=np.uinta   )]

      a__						:    Dict   		=	[Image.fromarray(np.moveaxis(snake_case       ,      0       ,      -1   )   ) for x in image_inputs]

      return image_inputs





   def 						_snake_case			(			self   )					->	Optional[int]:
      """simple docstring"""





      a__						:    Tuple   		=	SamProcessor(image_processor=self.get_image_processor()   )
      processor.save_pretrained(self.tmpdirname   )

      a__						:    Optional[Any]   		=	self.get_image_processor(do_normalize=snake_case       ,      padding_value=1.0   )

      a__						:    Optional[int]   		=	SamProcessor.from_pretrained(self.tmpdirname       ,      do_normalize=snake_case       ,      padding_value=1.0   )

      self.assertEqual(processor.image_processor.to_json_string()       ,      image_processor_add_kwargs.to_json_string()   )
      self.assertIsInstance(processor.image_processor       ,      snake_case   )





   def 						_snake_case			(			self   )					->	int:
      """simple docstring"""





      a__						:    Optional[int]   		=	self.get_image_processor()

      a__						:    int   		=	SamProcessor(image_processor=snake_case   )

      a__						:    Optional[int]   		=	self.prepare_image_inputs()

      a__						:    Any   		=	image_processor(snake_case       ,      return_tensors="np"   )
      a__						:    Any   		=	processor(images=snake_case       ,      return_tensors="np"   )

      input_feat_extract.pop("original_sizes"   )  # pop original_sizes as it is popped in the processor
      input_feat_extract.pop("reshaped_input_sizes"   )  # pop original_sizes as it is popped in the processor

      for key in input_feat_extract.keys():
         self.assertAlmostEqual(input_feat_extract[key].sum()       ,      input_processor[key].sum()       ,      delta=1E-2   )





   @require_torch
   def 						_snake_case			(			self   )					->	Optional[int]:
      """simple docstring"""





      a__						:    Optional[Any]   		=	self.get_image_processor()

      a__						:    Dict   		=	SamProcessor(image_processor=snake_case   )
      a__						:    Dict   		=	[torch.ones((1, 3, 5, 5)   )]

      a__						:    str   		=	[[1_764, 2_646]]

      a__						:    int   		=	[[683, 1_024]]
      a__						:    List[str]   		=	processor.post_process_masks(snake_case       ,      snake_case       ,      snake_case   )
      self.assertEqual(masks[0].shape       ,      (1, 3, 1_764, 2_646)   )

      a__						:    Optional[Any]   		=	processor.post_process_masks(
          snake_case       ,      torch.tensor(snake_case   )       ,      torch.tensor(snake_case   )   )
      self.assertEqual(masks[0].shape       ,      (1, 3, 1_764, 2_646)   )

      # should also work with np
      a__						:    Tuple   		=	[np.ones((1, 3, 5, 5)   )]
      a__						:    Optional[Any]   		=	processor.post_process_masks(snake_case       ,      np.array(snake_case   )       ,      np.array(snake_case   )   )

      self.assertEqual(masks[0].shape       ,      (1, 3, 1_764, 2_646)   )

      a__						:    str   		=	[[1, 0], [0, 1]]
      with self.assertRaises(snake_case   ):
         a__						:    Dict   		=	processor.post_process_masks(snake_case       ,      np.array(snake_case   )       ,      np.array(snake_case   )   )







@require_vision
@require_tf
class 	__lowerCAmelCase      (       unittest.TestCase	):





   def 						_snake_case			(			self   )					->	Union[str, Any]:
      """simple docstring"""





      a__						:    Optional[int]   		=	tempfile.mkdtemp()
      a__						:    List[str]   		=	SamImageProcessor()
      a__						:    int   		=	SamProcessor(snake_case   )
      processor.save_pretrained(self.tmpdirname   )





   def 						_snake_case			(			self       ,      **snake_case   )					->	int:
      """simple docstring"""





      return AutoProcessor.from_pretrained(self.tmpdirname       ,      **snake_case   ).image_processor





   def 						_snake_case			(			self   )					->	Tuple:
      """simple docstring"""





      shutil.rmtree(self.tmpdirname   )





   def 						_snake_case			(			self   )					->	Optional[int]:
      """simple docstring"""





      a__						:    List[Any]   		=	[np.random.randint(255       ,      size=(3, 30, 400)       ,      dtype=np.uinta   )]

      a__						:    Optional[int]   		=	[Image.fromarray(np.moveaxis(snake_case       ,      0       ,      -1   )   ) for x in image_inputs]

      return image_inputs





   def 						_snake_case			(			self   )					->	Any:
      """simple docstring"""





      a__						:    List[str]   		=	SamProcessor(image_processor=self.get_image_processor()   )
      processor.save_pretrained(self.tmpdirname   )

      a__						:    Any   		=	self.get_image_processor(do_normalize=snake_case       ,      padding_value=1.0   )

      a__						:    Optional[int]   		=	SamProcessor.from_pretrained(self.tmpdirname       ,      do_normalize=snake_case       ,      padding_value=1.0   )

      self.assertEqual(processor.image_processor.to_json_string()       ,      image_processor_add_kwargs.to_json_string()   )
      self.assertIsInstance(processor.image_processor       ,      snake_case   )





   def 						_snake_case			(			self   )					->	List[Any]:
      """simple docstring"""





      a__						:    Union[str, Any]   		=	self.get_image_processor()

      a__						:    Any   		=	SamProcessor(image_processor=snake_case   )

      a__						:    Tuple   		=	self.prepare_image_inputs()

      a__						:    List[str]   		=	image_processor(snake_case       ,      return_tensors="np"   )
      a__						:    Optional[Any]   		=	processor(images=snake_case       ,      return_tensors="np"   )

      input_feat_extract.pop("original_sizes"   )  # pop original_sizes as it is popped in the processor
      input_feat_extract.pop("reshaped_input_sizes"   )  # pop reshaped_input_sizes as it is popped in the processor

      for key in input_feat_extract.keys():
         self.assertAlmostEqual(input_feat_extract[key].sum()       ,      input_processor[key].sum()       ,      delta=1E-2   )





   @require_tf
   def 						_snake_case			(			self   )					->	Dict:
      """simple docstring"""





      a__						:    str   		=	self.get_image_processor()

      a__						:    Optional[int]   		=	SamProcessor(image_processor=snake_case   )
      a__						:    Any   		=	[tf.ones((1, 3, 5, 5)   )]

      a__						:    Optional[Any]   		=	[[1_764, 2_646]]

      a__						:    Optional[int]   		=	[[683, 1_024]]
      a__						:    Union[str, Any]   		=	processor.post_process_masks(snake_case       ,      snake_case       ,      snake_case       ,      return_tensors="tf"   )
      self.assertEqual(masks[0].shape       ,      (1, 3, 1_764, 2_646)   )

      a__						:    Optional[int]   		=	processor.post_process_masks(
          snake_case       ,      tf.convert_to_tensor(snake_case   )       ,      tf.convert_to_tensor(snake_case   )       ,      return_tensors="tf"       ,      )
      self.assertEqual(masks[0].shape       ,      (1, 3, 1_764, 2_646)   )

      # should also work with np
      a__						:    str   		=	[np.ones((1, 3, 5, 5)   )]
      a__						:    Optional[Any]   		=	processor.post_process_masks(
          snake_case       ,      np.array(snake_case   )       ,      np.array(snake_case   )       ,      return_tensors="tf"   )

      self.assertEqual(masks[0].shape       ,      (1, 3, 1_764, 2_646)   )

      a__						:    Optional[Any]   		=	[[1, 0], [0, 1]]
      with self.assertRaises(tf.errors.InvalidArgumentError   ):
         a__						:    Optional[int]   		=	processor.post_process_masks(
             snake_case       ,      np.array(snake_case   )       ,      np.array(snake_case   )       ,      return_tensors="tf"   )







@require_vision
@require_torchvision
class 	__lowerCAmelCase      (       unittest.TestCase	):





   def 						_snake_case			(			self   )					->	int:
      """simple docstring"""





      a__						:    str   		=	tempfile.mkdtemp()
      a__						:    List[str]   		=	SamImageProcessor()
      a__						:    Any   		=	SamProcessor(snake_case   )
      processor.save_pretrained(self.tmpdirname   )





   def 						_snake_case			(			self       ,      **snake_case   )					->	int:
      """simple docstring"""





      return AutoProcessor.from_pretrained(self.tmpdirname       ,      **snake_case   ).image_processor





   def 						_snake_case			(			self   )					->	Tuple:
      """simple docstring"""





      shutil.rmtree(self.tmpdirname   )





   def 						_snake_case			(			self   )					->	List[Any]:
      """simple docstring"""





      a__						:    Optional[Any]   		=	[np.random.randint(255       ,      size=(3, 30, 400)       ,      dtype=np.uinta   )]

      a__						:    Any   		=	[Image.fromarray(np.moveaxis(snake_case       ,      0       ,      -1   )   ) for x in image_inputs]

      return image_inputs





   @is_pt_tf_cross_test
   def 						_snake_case			(			self   )					->	Any:
      """simple docstring"""





      a__						:    Dict   		=	self.get_image_processor()

      a__						:    int   		=	SamProcessor(image_processor=snake_case   )
      a__						:    Tuple   		=	np.random.randint(0       ,      2       ,      size=(1, 3, 5, 5)   ).astype(np.floataa   )
      a__						:    Optional[Any]   		=	[tf.convert_to_tensor(snake_case   )]
      a__						:    int   		=	[torch.tensor(snake_case   )]

      a__						:    Union[str, Any]   		=	[[1_764, 2_646]]

      a__						:    int   		=	[[683, 1_024]]
      a__						:    str   		=	processor.post_process_masks(
          snake_case       ,      snake_case       ,      snake_case       ,      return_tensors="tf"   )
      a__						:    List[str]   		=	processor.post_process_masks(
          snake_case       ,      snake_case       ,      snake_case       ,      return_tensors="pt"   )

      self.assertTrue(np.all(tf_masks[0].numpy() == pt_masks[0].numpy()   )   )





   @is_pt_tf_cross_test
   def 						_snake_case			(			self   )					->	Optional[int]:
      """simple docstring"""





      a__						:    Tuple   		=	self.get_image_processor()

      a__						:    List[Any]   		=	SamProcessor(image_processor=snake_case   )

      a__						:    Union[str, Any]   		=	self.prepare_image_inputs()

      a__						:    List[str]   		=	image_processor(snake_case       ,      return_tensors="pt"   )["pixel_values"].numpy()
      a__						:    Optional[Any]   		=	processor(images=snake_case       ,      return_tensors="pt"   )["pixel_values"].numpy()

      a__						:    Optional[int]   		=	image_processor(snake_case       ,      return_tensors="tf"   )["pixel_values"].numpy()
      a__						:    Union[str, Any]   		=	processor(images=snake_case       ,      return_tensors="tf"   )["pixel_values"].numpy()

      self.assertTrue(np.allclose(snake_case       ,      snake_case   )   )
      self.assertTrue(np.allclose(snake_case       ,      snake_case   )   )
      self.assertTrue(np.allclose(snake_case       ,      snake_case   )   )








def    _A	(   lowerCamelCase ):
   a__						:    Optional[Any]   		=	1
   for i in range(1				,			num + 1 ):
      fact *= i
   return fact






def    _A	(   lowerCamelCase ):
   a__						:    List[Any]   		=	0
   while number > 0:
      a__						:    str   		=	number % 10
      sum_of_digits += last_digit
      a__						:    Dict   		=	number // 10  # Removing the last_digit from the given number
   return sum_of_digits






def    _A	(   lowerCamelCase = 100 ):
   a__						:    Any   		=	factorial(lowerCamelCase )
   a__						:    Optional[Any]   		=	split_and_add(lowerCamelCase )
   return result


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

