






'''simple docstring'''




def 					__lowercase						(			__lowercase = 100       )       ->						int:

      '''simple docstring'''


      _A			     =	n * (n + 1) * (2 * n + 1) / 6
      _A			     =	(n * (n + 1) / 2) ** 2
      return int(square_of_sum - sum_of_squares       )


if __name__ == "__main__":
    print(F"""{solution() = }""")







import inspect
import unittest

from transformers import MobileNetVaConfig
from transformers.testing_utils import require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
			import torch

			from transformers import MobileNetVaForImageClassification, MobileNetVaForSemanticSegmentation, MobileNetVaModel
			from transformers.models.mobilenet_va.modeling_mobilenet_va import MOBILENET_V2_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
			from PIL import Image

			from transformers import MobileNetVaImageProcessor




class    SCREAMING_SNAKE_CASE__     (	UpperCAmelCase					):





	'''simple docstring'''



	def  A							(  self	:    List[str]	):


				'''simple docstring'''


				_snake_case		=			self.config_class(**self.inputs_dict	)
				self.parent.assertTrue(hasattr(lowercase			,  'tf_padding'	)	)
				self.parent.assertTrue(hasattr(lowercase			,  'depth_multiplier'	)	)




class    SCREAMING_SNAKE_CASE__     :





	'''simple docstring'''



	def __init__(  self	:    Dict			,  lowercase	:    List[str]			,  lowercase	:    Dict=13			,  lowercase	:    Optional[int]=3			,  lowercase	:    Any=32			,  lowercase	:    Any=0.25			,  lowercase	:    Union[str, Any]=8			,  lowercase	:    List[Any]=8			,  lowercase	:    List[Any]=6			,  lowercase	:    Dict=32			,  lowercase	:    Dict=True			,  lowercase	:    Optional[Any]=True			,  lowercase	:    Tuple=True			,  lowercase	:    Tuple="relu6"			,  lowercase	:    List[Any]=1_280			,  lowercase	:    Optional[Any]=0.1			,  lowercase	:    int=0.02			,  lowercase	:    Optional[Any]=True			,  lowercase	:    List[str]=True			,  lowercase	:    List[str]=10			,  lowercase	:    Optional[Any]=None			,  ):


				'''simple docstring'''


				_snake_case		=			parent
				_snake_case		=			batch_size
				_snake_case		=			num_channels
				_snake_case		=			image_size
				_snake_case		=			depth_multiplier
				_snake_case		=			depth_divisible_by
				_snake_case		=			min_depth
				_snake_case		=			expand_ratio
				_snake_case		=			tf_padding
				_snake_case		=			output_stride
				_snake_case		=			first_layer_is_expansion
				_snake_case		=			finegrained_output
				_snake_case		=			hidden_act
				_snake_case		=			last_hidden_size if finegrained_output else int(last_hidden_size * depth_multiplier	)
				_snake_case		=			classifier_dropout_prob
				_snake_case		=			use_labels
				_snake_case		=			is_training
				_snake_case		=			num_labels
				_snake_case		=			initializer_range
				_snake_case		=			scope



	def  A							(  self	:    Union[str, Any]	):


				'''simple docstring'''


				_snake_case		=			floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]	)

				_snake_case		=			None
				_snake_case		=			None
				if self.use_labels:
							_snake_case		=			ids_tensor([self.batch_size]			,  self.num_labels	)
							_snake_case		=			ids_tensor([self.batch_size, self.image_size, self.image_size]			,  self.num_labels	)

				_snake_case		=			self.get_config()

				return config, pixel_values, labels, pixel_labels



	def  A							(  self	:    str	):


				'''simple docstring'''


				return MobileNetVaConfig(
				    num_channels=self.num_channels			,  image_size=self.image_size			,  depth_multiplier=self.depth_multiplier			,  depth_divisible_by=self.depth_divisible_by			,  min_depth=self.min_depth			,  expand_ratio=self.expand_ratio			,  output_stride=self.output_stride			,  first_layer_is_expansion=self.first_layer_is_expansion			,  finegrained_output=self.finegrained_output			,  hidden_act=self.hidden_act			,  tf_padding=self.tf_padding			,  classifier_dropout_prob=self.classifier_dropout_prob			,  initializer_range=self.initializer_range			,  )



	def  A							(  self	:    Optional[Any]			,  lowercase	:    str			,  lowercase	:    List[str]			,  lowercase	:    str			,  lowercase	:    Dict	):


				'''simple docstring'''


				_snake_case		=			MobileNetVaModel(config=lowercase	)
				model.to(lowercase	)
				model.eval()
				_snake_case		=			model(lowercase	)
				self.parent.assertEqual(
				    result.last_hidden_state.shape			,  (
				        self.batch_size,
				        self.last_hidden_size,
				        self.image_size // self.output_stride,
				        self.image_size // self.output_stride,
				    )			,  )
				self.parent.assertEqual(
				    result.pooler_output.shape			,  (self.batch_size, self.last_hidden_size)			,  )



	def  A							(  self	:    List[Any]			,  lowercase	:    Optional[int]			,  lowercase	:    Optional[int]			,  lowercase	:    Optional[Any]			,  lowercase	:    List[Any]	):


				'''simple docstring'''


				_snake_case		=			self.num_labels
				_snake_case		=			MobileNetVaForImageClassification(lowercase	)
				model.to(lowercase	)
				model.eval()
				_snake_case		=			model(lowercase			,  labels=lowercase	)
				self.parent.assertEqual(result.logits.shape			,  (self.batch_size, self.num_labels)	)



	def  A							(  self	:    Any			,  lowercase	:    int			,  lowercase	:    Dict			,  lowercase	:    int			,  lowercase	:    List[Any]	):


				'''simple docstring'''


				_snake_case		=			self.num_labels
				_snake_case		=			MobileNetVaForSemanticSegmentation(lowercase	)
				model.to(lowercase	)
				model.eval()
				_snake_case		=			model(lowercase	)
				self.parent.assertEqual(
				    result.logits.shape			,  (
				        self.batch_size,
				        self.num_labels,
				        self.image_size // self.output_stride,
				        self.image_size // self.output_stride,
				    )			,  )
				_snake_case		=			model(lowercase			,  labels=lowercase	)
				self.parent.assertEqual(
				    result.logits.shape			,  (
				        self.batch_size,
				        self.num_labels,
				        self.image_size // self.output_stride,
				        self.image_size // self.output_stride,
				    )			,  )





	def  A							(  self	:    str	):


				'''simple docstring'''


				_snake_case		=			self.prepare_config_and_inputs()
				_snake_case	,					_snake_case	,					_snake_case	,					_snake_case		=			config_and_inputs
				_snake_case		=			{'pixel_values': pixel_values}
				return config, inputs_dict




@require_torch
class    SCREAMING_SNAKE_CASE__     (	UpperCAmelCase							,UpperCAmelCase							,unittest.TestCase					):





	'''simple docstring'''



	_UpperCAmelCase       :		str       =					(
	    (MobileNetVaModel, MobileNetVaForImageClassification, MobileNetVaForSemanticSegmentation)
	    if is_torch_available()
	    else ()
	)
	_UpperCAmelCase       :		str       =					(
	    {
	        "feature-extraction": MobileNetVaModel,
	        "image-classification": MobileNetVaForImageClassification,
	        "image-segmentation": MobileNetVaForSemanticSegmentation,
	    }
	    if is_torch_available()
	    else {}
	)

	_UpperCAmelCase       :		Optional[int]       =					False
	_UpperCAmelCase       :		Dict       =					False
	_UpperCAmelCase       :		Dict       =					False
	_UpperCAmelCase       :		Union[str, Any]       =					False



	def  A							(  self	:    Any	):


				'''simple docstring'''


				_snake_case		=			MobileNetVaModelTester(self	)
				_snake_case		=			MobileNetVaConfigTester(self			,  config_class=lowercase			,  has_text_modality=lowercase	)



	def  A							(  self	:    Any	):


				'''simple docstring'''


				self.config_tester.run_common_tests()



	@unittest.skip(reason='MobileNetV2 does not use inputs_embeds'	)
	def  A							(  self	:    List[str]	):


				'''simple docstring'''


				pass



	@unittest.skip(reason='MobileNetV2 does not support input and output embeddings'	)
	def  A							(  self	:    int	):


				'''simple docstring'''


				pass



	@unittest.skip(reason='MobileNetV2 does not output attentions'	)
	def  A							(  self	:    Any	):


				'''simple docstring'''


				pass



	def  A							(  self	:    Optional[int]	):


				'''simple docstring'''


				_snake_case	,					_snake_case		=			self.model_tester.prepare_config_and_inputs_for_common()

				for model_class in self.all_model_classes:
							_snake_case		=			model_class(lowercase	)
							_snake_case		=			inspect.signature(model.forward	)
							# signature.parameters is an OrderedDict => so arg_names order is deterministic
							_snake_case		=			[*signature.parameters.keys()]

							_snake_case		=			['pixel_values']
							self.assertListEqual(arg_names[:1]			,  lowercase	)



	def  A							(  self	:    List[str]	):


				'''simple docstring'''


				_snake_case		=			self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_model(*lowercase	)



	def  A							(  self	:    List[Any]	):


				'''simple docstring'''


				def check_hidden_states_output(lowercase	:    List[Any]			,  lowercase	:    Union[str, Any]			,  lowercase	:    str	):
							_snake_case		=			model_class(lowercase	)
							model.to(lowercase	)
							model.eval()

							with torch.no_grad():
										_snake_case		=			model(**self._prepare_for_class(lowercase			,  lowercase	)	)

							_snake_case		=			outputs.hidden_states

							_snake_case		=			16
							self.assertEqual(len(lowercase	)			,  lowercase	)

				_snake_case	,					_snake_case		=			self.model_tester.prepare_config_and_inputs_for_common()

				for model_class in self.all_model_classes:
							_snake_case		=			True
							check_hidden_states_output(lowercase			,  lowercase			,  lowercase	)

							# check that output_hidden_states also work using config
							del inputs_dict["output_hidden_states"]
							_snake_case		=			True

							check_hidden_states_output(lowercase			,  lowercase			,  lowercase	)



	def  A							(  self	:    Tuple	):


				'''simple docstring'''


				_snake_case		=			self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_image_classification(*lowercase	)



	def  A							(  self	:    Dict	):


				'''simple docstring'''


				_snake_case		=			self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_semantic_segmentation(*lowercase	)





	@slow
	def  A							(  self	:    List[Any]	):


				'''simple docstring'''


				for model_name in MOBILENET_V2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
							_snake_case		=			MobileNetVaModel.from_pretrained(lowercase	)
							self.assertIsNotNone(lowercase	)






def        a_		(       ) ->  Union[str, Any]:
			_snake_case		=			Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png' )
			return image




@require_torch
@require_vision
class    SCREAMING_SNAKE_CASE__     (	unittest.TestCase					):





	'''simple docstring'''



	@cached_property
	def  A							(  self	:    Optional[Any]	):


				'''simple docstring'''


				return (
				    MobileNetVaImageProcessor.from_pretrained('google/mobilenet_v2_1.0_224'	) if is_vision_available() else None
				)



	@slow
	def  A							(  self	:    List[Any]	):


				'''simple docstring'''


				_snake_case		=			MobileNetVaForImageClassification.from_pretrained('google/mobilenet_v2_1.0_224'	).to(lowercase	)

				_snake_case		=			self.default_image_processor
				_snake_case		=			prepare_img()
				_snake_case		=			image_processor(images=lowercase			,  return_tensors='pt'	).to(lowercase	)

				# forward pass
				with torch.no_grad():
							_snake_case		=			model(**lowercase	)

				# verify the logits
				_snake_case		=			torch.Size((1, 1_001)	)
				self.assertEqual(outputs.logits.shape			,  lowercase	)

				_snake_case		=			torch.tensor([0.2445, -1.1993, 0.1905]	).to(lowercase	)

				self.assertTrue(torch.allclose(outputs.logits[0, :3]			,  lowercase			,  atol=1E-4	)	)





	@slow
	def  A							(  self	:    Dict	):


				'''simple docstring'''


				_snake_case		=			MobileNetVaForSemanticSegmentation.from_pretrained('google/deeplabv3_mobilenet_v2_1.0_513'	)
				_snake_case		=			model.to(lowercase	)

				_snake_case		=			MobileNetVaImageProcessor.from_pretrained('google/deeplabv3_mobilenet_v2_1.0_513'	)

				_snake_case		=			prepare_img()
				_snake_case		=			image_processor(images=lowercase			,  return_tensors='pt'	).to(lowercase	)

				# forward pass
				with torch.no_grad():
							_snake_case		=			model(**lowercase	)
				_snake_case		=			outputs.logits

				# verify the logits
				_snake_case		=			torch.Size((1, 21, 65, 65)	)
				self.assertEqual(logits.shape			,  lowercase	)

				_snake_case		=			torch.tensor(
				    [
				        [[17.5790, 17.7581, 18.3355], [18.3257, 18.4230, 18.8973], [18.6169, 18.8650, 19.2187]],
				        [[-2.1595, -2.0977, -2.3741], [-2.4226, -2.3028, -2.6835], [-2.7819, -2.5991, -2.7706]],
				        [[4.2058, 4.8317, 4.7638], [4.4136, 5.0361, 4.9383], [4.5028, 4.9644, 4.8734]],
				    ]			,  device=lowercase			,  )

				self.assertTrue(torch.allclose(logits[0, :3, :3, :3]			,  lowercase			,  atol=1E-4	)	)