


'''simple docstring'''





from math import gcd






def 	UpperCAmelCase__(							_SCREAMING_SNAKE_CASE				:   int = 1_2000   ):






			"""simple docstring"""




			__A=  0
			for d in range(max_d + 1   ):
						for n in range(d // 3 + 1,(d + 1) // 2   ):
									if gcd(_SCREAMING_SNAKE_CASE,_SCREAMING_SNAKE_CASE   ) == 1:
												fractions_number += 1
			return fractions_number


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







'''simple docstring'''





import collections
import inspect
import unittest

from transformers import SwinConfig
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_backbone_common import BackboneTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
					import torch
					from torch import nn

					from transformers import SwinBackbone, SwinForImageClassification, SwinForMaskedImageModeling, SwinModel
					from transformers.models.swin.modeling_swin import SWIN_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
					from PIL import Image

					from transformers import AutoImageProcessor
class 	a__				:





			'''simple docstring'''

			def __init__(     self       : Union[str, Any] ,						lowerCAmelCase_       : int ,						lowerCAmelCase_       : List[str]=13 ,						lowerCAmelCase_       : Dict=32 ,						lowerCAmelCase_       : Optional[Any]=2 ,						lowerCAmelCase_       : Optional[int]=3 ,						lowerCAmelCase_       : Optional[Any]=16 ,						lowerCAmelCase_       : int=[1, 2, 1] ,						lowerCAmelCase_       : List[str]=[2, 2, 4] ,						lowerCAmelCase_       : Tuple=2 ,						lowerCAmelCase_       : List[str]=2.0 ,						lowerCAmelCase_       : List[Any]=True ,						lowerCAmelCase_       : str=0.0 ,						lowerCAmelCase_       : str=0.0 ,						lowerCAmelCase_       : str=0.1 ,						lowerCAmelCase_       : Optional[int]="gelu" ,						lowerCAmelCase_       : Union[str, Any]=False ,						lowerCAmelCase_       : Union[str, Any]=True ,						lowerCAmelCase_       : List[Any]=0.02 ,						lowerCAmelCase_       : Union[str, Any]=1E-5 ,						lowerCAmelCase_       : Optional[Any]=True ,						lowerCAmelCase_       : str=None ,						lowerCAmelCase_       : List[str]=True ,						lowerCAmelCase_       : Tuple=10 ,						lowerCAmelCase_       : Any=8 ,						lowerCAmelCase_       : int=["stage1", "stage2"] ,						lowerCAmelCase_       : Optional[int]=[1, 2] ,						)			->		Union[str, Any]:
						__A=  parent
						__A=  batch_size
						__A=  image_size
						__A=  patch_size
						__A=  num_channels
						__A=  embed_dim
						__A=  depths
						__A=  num_heads
						__A=  window_size
						__A=  mlp_ratio
						__A=  qkv_bias
						__A=  hidden_dropout_prob
						__A=  attention_probs_dropout_prob
						__A=  drop_path_rate
						__A=  hidden_act
						__A=  use_absolute_embeddings
						__A=  patch_norm
						__A=  layer_norm_eps
						__A=  initializer_range
						__A=  is_training
						__A=  scope
						__A=  use_labels
						__A=  type_sequence_label_size
						__A=  encoder_stride
						__A=  out_features
						__A=  out_indices
			def 				lowerCAmelCase    (     self       : Optional[int]  )			->		Optional[int]:
						__A=  floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]  )

						__A=  None
						if self.use_labels:
									__A=  ids_tensor([self.batch_size] ,						self.type_sequence_label_size  )

						__A=  self.get_config()

						return config, pixel_values, labels
			def 				lowerCAmelCase    (     self       : List[Any]  )			->		Optional[int]:
						return SwinConfig(
						    image_size=self.image_size ,						patch_size=self.patch_size ,						num_channels=self.num_channels ,						embed_dim=self.embed_dim ,						depths=self.depths ,						num_heads=self.num_heads ,						window_size=self.window_size ,						mlp_ratio=self.mlp_ratio ,						qkv_bias=self.qkv_bias ,						hidden_dropout_prob=self.hidden_dropout_prob ,						attention_probs_dropout_prob=self.attention_probs_dropout_prob ,						drop_path_rate=self.drop_path_rate ,						hidden_act=self.hidden_act ,						use_absolute_embeddings=self.use_absolute_embeddings ,						path_norm=self.patch_norm ,						layer_norm_eps=self.layer_norm_eps ,						initializer_range=self.initializer_range ,						encoder_stride=self.encoder_stride ,						out_features=self.out_features ,						out_indices=self.out_indices ,						)
			def 				lowerCAmelCase    (     self       : List[Any] ,						lowerCAmelCase_       : List[str] ,						lowerCAmelCase_       : int ,						lowerCAmelCase_       : List[Any]  )			->		str:
						__A=  SwinModel(config=lowerCAmelCase_  )
						model.to(lowerCAmelCase_  )
						model.eval()
						__A=  model(lowerCAmelCase_  )

						__A=  ((config.image_size // config.patch_size) ** 2) // (4 ** (len(config.depths  ) - 1))
						__A=  int(config.embed_dim * 2 ** (len(config.depths  ) - 1)  )

						self.parent.assertEqual(result.last_hidden_state.shape ,						(self.batch_size, expected_seq_len, expected_dim)  )
			def 				lowerCAmelCase    (     self       : str ,						lowerCAmelCase_       : Optional[Any] ,						lowerCAmelCase_       : List[Any] ,						lowerCAmelCase_       : List[Any]  )			->		Optional[int]:
						__A=  SwinBackbone(config=lowerCAmelCase_  )
						model.to(lowerCAmelCase_  )
						model.eval()
						__A=  model(lowerCAmelCase_  )

						# verify hidden states
						self.parent.assertEqual(len(result.feature_maps  ) ,						len(config.out_features  )  )
						self.parent.assertListEqual(list(result.feature_maps[0].shape  ) ,						[self.batch_size, model.channels[0], 16, 16]  )

						# verify channels
						self.parent.assertEqual(len(model.channels  ) ,						len(config.out_features  )  )

						# verify backbone works with out_features=None
						__A=  None
						__A=  SwinBackbone(config=lowerCAmelCase_  )
						model.to(lowerCAmelCase_  )
						model.eval()
						__A=  model(lowerCAmelCase_  )

						# verify feature maps
						self.parent.assertEqual(len(result.feature_maps  ) ,						1  )
						self.parent.assertListEqual(list(result.feature_maps[0].shape  ) ,						[self.batch_size, model.channels[-1], 4, 4]  )

						# verify channels
						self.parent.assertEqual(len(model.channels  ) ,						1  )
			def 				lowerCAmelCase    (     self       : Any ,						lowerCAmelCase_       : List[Any] ,						lowerCAmelCase_       : List[str] ,						lowerCAmelCase_       : Dict  )			->		Optional[int]:
						__A=  SwinForMaskedImageModeling(config=lowerCAmelCase_  )
						model.to(lowerCAmelCase_  )
						model.eval()
						__A=  model(lowerCAmelCase_  )
						self.parent.assertEqual(
						    result.logits.shape ,						(self.batch_size, self.num_channels, self.image_size, self.image_size)  )

						# test greyscale images
						__A=  1
						__A=  SwinForMaskedImageModeling(lowerCAmelCase_  )
						model.to(lowerCAmelCase_  )
						model.eval()

						__A=  floats_tensor([self.batch_size, 1, self.image_size, self.image_size]  )
						__A=  model(lowerCAmelCase_  )
						self.parent.assertEqual(result.logits.shape ,						(self.batch_size, 1, self.image_size, self.image_size)  )
			def 				lowerCAmelCase    (     self       : Union[str, Any] ,						lowerCAmelCase_       : List[str] ,						lowerCAmelCase_       : int ,						lowerCAmelCase_       : Dict  )			->		str:
						__A=  self.type_sequence_label_size
						__A=  SwinForImageClassification(lowerCAmelCase_  )
						model.to(lowerCAmelCase_  )
						model.eval()
						__A=  model(lowerCAmelCase_ ,						labels=lowerCAmelCase_  )
						self.parent.assertEqual(result.logits.shape ,						(self.batch_size, self.type_sequence_label_size)  )

						# test greyscale images
						__A=  1
						__A=  SwinForImageClassification(lowerCAmelCase_  )
						model.to(lowerCAmelCase_  )
						model.eval()

						__A=  floats_tensor([self.batch_size, 1, self.image_size, self.image_size]  )
						__A=  model(lowerCAmelCase_  )
						self.parent.assertEqual(result.logits.shape ,						(self.batch_size, self.type_sequence_label_size)  )

			def 				lowerCAmelCase    (     self       : List[Any]  )			->		Any:
						__A=  self.prepare_config_and_inputs()
						(
						    (
						    __A
						),  (
						    __A
						),  (
						    __A
						),  
						)=  config_and_inputs
						__A=  {'pixel_values': pixel_values}
						return config, inputs_dict


@require_torch
class 	a__				(				a_			,     a_			,     unittest.TestCase      ):





			'''simple docstring'''

			A	:							Optional[int]							= (
			    (
			        SwinModel,
			        SwinBackbone,
			        SwinForImageClassification,
			        SwinForMaskedImageModeling,
			    )
			    if is_torch_available()
			    else ()
			)
			A	:							Tuple							= (
			    {'''feature-extraction''': SwinModel, '''image-classification''': SwinForImageClassification}
			    if is_torch_available()
			    else {}
			)
			A	:							str							= True

			A	:							int							= False
			A	:							str							= False
			A	:							Any							= False
			def 				lowerCAmelCase    (     self       : List[str]  )			->		str:
						__A=  SwinModelTester(self  )
						__A=  ConfigTester(self ,						config_class=lowerCAmelCase_ ,						embed_dim=37  )
			def 				lowerCAmelCase    (     self       : Union[str, Any]  )			->		Optional[Any]:
						self.create_and_test_config_common_properties()
						self.config_tester.create_and_test_config_to_json_string()
						self.config_tester.create_and_test_config_to_json_file()
						self.config_tester.create_and_test_config_from_and_save_pretrained()
						self.config_tester.create_and_test_config_with_num_labels()
						self.config_tester.check_config_can_be_init_without_params()
						self.config_tester.check_config_arguments_init()
			def 				lowerCAmelCase    (     self       : str  )			->		List[str]:
						return
			def 				lowerCAmelCase    (     self       : str  )			->		Optional[int]:
						__A=  self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_model(*lowerCAmelCase_  )
			@unittest.skip(reason='Got `CUDA error: misaligned address` with PyTorch 2.0.0.'  )
			def 				lowerCAmelCase    (     self       : List[str]  )			->		Dict:
						pass
			def 				lowerCAmelCase    (     self       : Any  )			->		Optional[int]:
						super().test_training_gradient_checkpointing()
			def 				lowerCAmelCase    (     self       : Tuple  )			->		int:
						__A=  self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_backbone(*lowerCAmelCase_  )
			def 				lowerCAmelCase    (     self       : List[Any]  )			->		int:
						__A=  self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_masked_image_modeling(*lowerCAmelCase_  )
			def 				lowerCAmelCase    (     self       : List[str]  )			->		int:
						__A=  self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_image_classification(*lowerCAmelCase_  )
			@unittest.skip(reason='Swin does not use inputs_embeds'  )
			def 				lowerCAmelCase    (     self       : List[str]  )			->		Tuple:
						pass
			@unittest.skip(reason='Swin Transformer does not use feedforward chunking'  )
			def 				lowerCAmelCase    (     self       : str  )			->		str:
						pass
			def 				lowerCAmelCase    (     self       : Optional[int]  )			->		Tuple:
						__A,  __A=  self.model_tester.prepare_config_and_inputs_for_common()

						for model_class in self.all_model_classes:
									__A=  model_class(lowerCAmelCase_  )
									self.assertIsInstance(model.get_input_embeddings() ,						(nn.Module)  )
									__A=  model.get_output_embeddings()
									self.assertTrue(x is None or isinstance(lowerCAmelCase_ ,						nn.Linear  )  )
			def 				lowerCAmelCase    (     self       : Any  )			->		Any:
						__A,  __A=  self.model_tester.prepare_config_and_inputs_for_common()

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

									__A=  ['pixel_values']
									self.assertListEqual(arg_names[:1] ,						lowerCAmelCase_  )
			def 				lowerCAmelCase    (     self       : Any  )			->		Union[str, Any]:
						__A,  __A=  self.model_tester.prepare_config_and_inputs_for_common()
						__A=  True

						for model_class in self.all_model_classes:
									__A=  True
									__A=  False
									__A=  True
									__A=  model_class(lowerCAmelCase_  )
									model.to(lowerCAmelCase_  )
									model.eval()
									with torch.no_grad():
												__A=  model(**self._prepare_for_class(lowerCAmelCase_ ,						lowerCAmelCase_  )  )
									__A=  outputs.attentions
									__A=  len(self.model_tester.depths  )
									self.assertEqual(len(lowerCAmelCase_  ) ,						lowerCAmelCase_  )

									# check that output_attentions also work using config
									del inputs_dict["output_attentions"]
									__A=  True
									__A=  config.window_size**2
									__A=  model_class(lowerCAmelCase_  )
									model.to(lowerCAmelCase_  )
									model.eval()
									with torch.no_grad():
												__A=  model(**self._prepare_for_class(lowerCAmelCase_ ,						lowerCAmelCase_  )  )
									__A=  outputs.attentions
									self.assertEqual(len(lowerCAmelCase_  ) ,						lowerCAmelCase_  )

									self.assertListEqual(
									    list(attentions[0].shape[-3:]  ) ,						[self.model_tester.num_heads[0], window_size_squared, window_size_squared] ,						)
									__A=  len(lowerCAmelCase_  )

									# Check attention is always last and order is fine
									__A=  True
									__A=  True
									__A=  model_class(lowerCAmelCase_  )
									model.to(lowerCAmelCase_  )
									model.eval()
									with torch.no_grad():
												__A=  model(**self._prepare_for_class(lowerCAmelCase_ ,						lowerCAmelCase_  )  )

									# also another +1 for reshaped_hidden_states
									__A=  1 if model_class.__name__ == 'SwinBackbone' else 2
									self.assertEqual(out_len + added_hidden_states ,						len(lowerCAmelCase_  )  )

									__A=  outputs.attentions

									self.assertEqual(len(lowerCAmelCase_  ) ,						lowerCAmelCase_  )

									self.assertListEqual(
									    list(self_attentions[0].shape[-3:]  ) ,						[self.model_tester.num_heads[0], window_size_squared, window_size_squared] ,						)
			def 				lowerCAmelCase    (     self       : str ,						lowerCAmelCase_       : List[str] ,						lowerCAmelCase_       : List[str] ,						lowerCAmelCase_       : List[Any] ,						lowerCAmelCase_       : int  )			->		Dict:
						__A=  model_class(lowerCAmelCase_  )
						model.to(lowerCAmelCase_  )
						model.eval()

						with torch.no_grad():
									__A=  model(**self._prepare_for_class(lowerCAmelCase_ ,						lowerCAmelCase_  )  )

						__A=  outputs.hidden_states

						__A=  getattr(
						    self.model_tester ,						'expected_num_hidden_layers' ,						len(self.model_tester.depths  ) + 1  )
						self.assertEqual(len(lowerCAmelCase_  ) ,						lowerCAmelCase_  )

						# Swin has a different seq_length
						__A=  (
						    config.patch_size
						    if isinstance(config.patch_size ,						collections.abc.Iterable  )
						    else (config.patch_size, config.patch_size)
						)

						__A=  (image_size[1] // patch_size[1]) * (image_size[0] // patch_size[0])

						self.assertListEqual(
						    list(hidden_states[0].shape[-2:]  ) ,						[num_patches, self.model_tester.embed_dim] ,						)

						if not model_class.__name__ == "SwinBackbone":
									__A=  outputs.reshaped_hidden_states
									self.assertEqual(len(lowerCAmelCase_  ) ,						lowerCAmelCase_  )

									__A,  __A,  __A,  __A=  reshaped_hidden_states[0].shape
									__A=  (
									    reshaped_hidden_states[0].view(lowerCAmelCase_ ,						lowerCAmelCase_ ,						height * width  ).permute(0 ,						2 ,						1  )
									)
									self.assertListEqual(
									    list(reshaped_hidden_states.shape[-2:]  ) ,						[num_patches, self.model_tester.embed_dim] ,						)
			def 				lowerCAmelCase    (     self       : Optional[Any]  )			->		str:
						__A,  __A=  self.model_tester.prepare_config_and_inputs_for_common()

						__A=  (
						    self.model_tester.image_size
						    if isinstance(self.model_tester.image_size ,						collections.abc.Iterable  )
						    else (self.model_tester.image_size, self.model_tester.image_size)
						)

						for model_class in self.all_model_classes:
									__A=  True
									self.check_hidden_states_output(lowerCAmelCase_ ,						lowerCAmelCase_ ,						lowerCAmelCase_ ,						lowerCAmelCase_  )

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

									self.check_hidden_states_output(lowerCAmelCase_ ,						lowerCAmelCase_ ,						lowerCAmelCase_ ,						lowerCAmelCase_  )
			def 				lowerCAmelCase    (     self       : str  )			->		str:
						__A,  __A=  self.model_tester.prepare_config_and_inputs_for_common()
						__A=  3

						__A=  (
						    self.model_tester.image_size
						    if isinstance(self.model_tester.image_size ,						collections.abc.Iterable  )
						    else (self.model_tester.image_size, self.model_tester.image_size)
						)
						__A=  (
						    config.patch_size
						    if isinstance(config.patch_size ,						collections.abc.Iterable  )
						    else (config.patch_size, config.patch_size)
						)

						__A=  image_size[0] + patch_size[0] - (image_size[0] % patch_size[0])
						__A=  image_size[1] + patch_size[1] - (image_size[1] % patch_size[1])

						for model_class in self.all_model_classes:
									__A=  True
									self.check_hidden_states_output(lowerCAmelCase_ ,						lowerCAmelCase_ ,						lowerCAmelCase_ ,						(padded_height, padded_width)  )

									# check that output_hidden_states also work using config
									del inputs_dict["output_hidden_states"]
									__A=  True
									self.check_hidden_states_output(lowerCAmelCase_ ,						lowerCAmelCase_ ,						lowerCAmelCase_ ,						(padded_height, padded_width)  )
			@slow
			def 				lowerCAmelCase    (     self       : Any  )			->		Any:
						for model_name in SWIN_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
									__A=  SwinModel.from_pretrained(lowerCAmelCase_  )
									self.assertIsNotNone(lowerCAmelCase_  )

			def 				lowerCAmelCase    (     self       : Union[str, Any]  )			->		Union[str, Any]:
						__A,  __A=  self.model_tester.prepare_config_and_inputs_for_common()

						__A=  _config_zero_init(lowerCAmelCase_  )
						for model_class in self.all_model_classes:
									__A=  model_class(config=lowerCAmelCase_  )
									for name, param in model.named_parameters():
												if "embeddings" not in name and param.requires_grad:
															self.assertIn(
															    ((param.data.mean() * 1E9).round() / 1E9).item() ,						[0.0, 1.0] ,						msg=F"""Parameter {name} of model {model_class} seems not properly initialized""" ,						)


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





			'''simple docstring'''

			@cached_property
			def 				lowerCAmelCase    (     self       : int  )			->		Dict:
						return (
						    AutoImageProcessor.from_pretrained('microsoft/swin-tiny-patch4-window7-224'  )
						    if is_vision_available()
						    else None
						)

			@slow
			def 				lowerCAmelCase    (     self       : str  )			->		Any:
						__A=  SwinForImageClassification.from_pretrained('microsoft/swin-tiny-patch4-window7-224'  ).to(lowerCAmelCase_  )
						__A=  self.default_image_processor

						__A=  Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'  )
						__A=  image_processor(images=lowerCAmelCase_ ,						return_tensors='pt'  ).to(lowerCAmelCase_  )

						# forward pass
						with torch.no_grad():
									__A=  model(**lowerCAmelCase_  )

						# verify the logits
						__A=  torch.Size((1, 1_000)  )
						self.assertEqual(outputs.logits.shape ,						lowerCAmelCase_  )
						__A=  torch.tensor([-0.09_48, -0.64_54, -0.09_21]  ).to(lowerCAmelCase_  )
						self.assertTrue(torch.allclose(outputs.logits[0, :3] ,						lowerCAmelCase_ ,						atol=1E-4  )  )


@require_torch
class 	a__				(				unittest.TestCase			,     a_      ):





			'''simple docstring'''

			A	:							List[str]							= (SwinBackbone,) if is_torch_available() else ()
			A	:							List[Any]							= SwinConfig
			def 				lowerCAmelCase    (     self       : Tuple  )			->		Dict:
						__A=  SwinModelTester(self  )



