





'''simple docstring'''
def     a   (    __a = 10**9     )						->			int:



					'''simple docstring'''






					UpperCamelCase__     :Union[str, Any]							      =				1
					UpperCamelCase__     :List[Any]							      =				2

					UpperCamelCase__     :Tuple							      =				0
					UpperCamelCase__     :int							      =				0
					UpperCamelCase__     :Optional[Any]							      =				0
					while perimeter <= max_perimeter:
										perimeters_sum += perimeter

										prev_value += 2 * value
										value += prev_value

										UpperCamelCase__     :List[Any]							      =				2 * value + 2 if i % 2 == 0 else 2 * value - 2
										i += 1

					return perimeters_sum


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



'''simple docstring'''
import contextlib
import copy
import random
from typing import Any, Dict, Iterable, Optional, Union

import numpy as np
import torch

from .utils import deprecate, is_transformers_available


if is_transformers_available():
		import transformers


def     a   (    __a     )						->			Optional[int]:



					'''simple docstring'''






					random.seed(__a     )
					np.random.seed(__a     )
					torch.manual_seed(__a     )
					torch.cuda.manual_seed_all(__a     )
					# ^^ safe to call this function even if cuda is not available







class      lowercase			:

		"""simple docstring"""

		def __init__(	self					,     UpperCamelCase_					,     UpperCamelCase_ = 0.9999					,     UpperCamelCase_ = 0.0					,     UpperCamelCase_ = 0					,     UpperCamelCase_ = False					,     UpperCamelCase_ = 1.0					,     UpperCamelCase_ = 2 / 3					,     UpperCamelCase_ = None					,     UpperCamelCase_ = None					,     **UpperCamelCase_					,     ):

							'''simple docstring'''


							if isinstance(UpperCamelCase_					,     torch.nn.Module							):
												UpperCamelCase__     :Optional[Any]							      =				(
												    '''Passing a `torch.nn.Module` to `ExponentialMovingAverage` is deprecated. '''
												    '''Please pass the parameters of the module instead.'''
												)
												deprecate(
												    '''passing a `torch.nn.Module` to `ExponentialMovingAverage`'''					,     '''1.0.0'''					,     UpperCamelCase_					,     standard_warn=UpperCamelCase_					,     )
												UpperCamelCase__     :Optional[int]							      =				parameters.parameters()

												# set use_ema_warmup to True if a torch.nn.Module is passed for backwards compatibility
												UpperCamelCase__     :str							      =				True

							if kwargs.get('''max_value'''					,     UpperCamelCase_							) is not None:
												UpperCamelCase__     :List[str]							      =				'''The `max_value` argument is deprecated. Please use `decay` instead.'''
												deprecate('''max_value'''					,     '''1.0.0'''					,     UpperCamelCase_					,     standard_warn=UpperCamelCase_							)
												UpperCamelCase__     :int							      =				kwargs['''max_value''']

							if kwargs.get('''min_value'''					,     UpperCamelCase_							) is not None:
												UpperCamelCase__     :Union[str, Any]							      =				'''The `min_value` argument is deprecated. Please use `min_decay` instead.'''
												deprecate('''min_value'''					,     '''1.0.0'''					,     UpperCamelCase_					,     standard_warn=UpperCamelCase_							)
												UpperCamelCase__     :Any							      =				kwargs['''min_value''']

							UpperCamelCase__     :Optional[int]							      =				list(UpperCamelCase_							)
							UpperCamelCase__     :Tuple							      =				[p.clone().detach() for p in parameters]

							if kwargs.get('''device'''					,     UpperCamelCase_							) is not None:
												UpperCamelCase__     :str							      =				'''The `device` argument is deprecated. Please use `to` instead.'''
												deprecate('''device'''					,     '''1.0.0'''					,     UpperCamelCase_					,     standard_warn=UpperCamelCase_							)
												self.to(device=kwargs['''device''']							)

							UpperCamelCase__     :Union[str, Any]							      =				None

							UpperCamelCase__     :List[Any]							      =				decay
							UpperCamelCase__     :List[str]							      =				min_decay
							UpperCamelCase__     :Optional[int]							      =				update_after_step
							UpperCamelCase__     :int							      =				use_ema_warmup
							UpperCamelCase__     :Any							      =				inv_gamma
							UpperCamelCase__     :Union[str, Any]							      =				power
							UpperCamelCase__     :Union[str, Any]							      =				0
							UpperCamelCase__     :Dict							      =				None  # set in `step()`

							UpperCamelCase__     :List[Any]							      =				model_cls
							UpperCamelCase__     :Optional[Any]							      =				model_config




		@classmethod
		def 					lowerCAmelCase__       (	cls					,     UpperCamelCase_					,     UpperCamelCase_							):

							'''simple docstring'''


							UpperCamelCase__      ,       UpperCamelCase__     :Tuple							      =				model_cls.load_config(UpperCamelCase_					,     return_unused_kwargs=UpperCamelCase_							)
							UpperCamelCase__     :List[str]							      =				model_cls.from_pretrained(UpperCamelCase_							)

							UpperCamelCase__     :str							      =				cls(model.parameters()					,     model_cls=UpperCamelCase_					,     model_config=model.config							)

							ema_model.load_state_dict(UpperCamelCase_							)
							return ema_model




		def 					lowerCAmelCase__       (	self					,     UpperCamelCase_							):

							'''simple docstring'''


							if self.model_cls is None:
												raise ValueError('''`save_pretrained` can only be used if `model_cls` was defined at __init__.'''							)

							if self.model_config is None:
												raise ValueError('''`save_pretrained` can only be used if `model_config` was defined at __init__.'''							)

							UpperCamelCase__     :Optional[Any]							      =				self.model_cls.from_config(self.model_config							)
							UpperCamelCase__     :Optional[int]							      =				self.state_dict()
							state_dict.pop('''shadow_params'''					,     UpperCamelCase_							)

							model.register_to_config(**UpperCamelCase_							)
							self.copy_to(model.parameters()							)
							model.save_pretrained(UpperCamelCase_							)




		def 					lowerCAmelCase__       (	self					,     UpperCamelCase_							):

							'''simple docstring'''


							UpperCamelCase__     :str							      =				max(0					,     optimization_step - self.update_after_step - 1							)

							if step <= 0:
												return 0.0

							if self.use_ema_warmup:
												UpperCamelCase__     :Dict							      =				1 - (1 + step / self.inv_gamma) ** -self.power
							else:
												UpperCamelCase__     :int							      =				(1 + step) / (10 + step)

							UpperCamelCase__     :Any							      =				min(UpperCamelCase_					,     self.decay							)
							# make sure decay is not smaller than min_decay
							UpperCamelCase__     :Dict							      =				max(UpperCamelCase_					,     self.min_decay							)
							return cur_decay_value




		@torch.no_grad()
		def 					lowerCAmelCase__       (	self					,     UpperCamelCase_							):

							'''simple docstring'''


							if isinstance(UpperCamelCase_					,     torch.nn.Module							):
												UpperCamelCase__     :Optional[Any]							      =				(
												    '''Passing a `torch.nn.Module` to `ExponentialMovingAverage.step` is deprecated. '''
												    '''Please pass the parameters of the module instead.'''
												)
												deprecate(
												    '''passing a `torch.nn.Module` to `ExponentialMovingAverage.step`'''					,     '''1.0.0'''					,     UpperCamelCase_					,     standard_warn=UpperCamelCase_					,     )
												UpperCamelCase__     :str							      =				parameters.parameters()

							UpperCamelCase__     :Dict							      =				list(UpperCamelCase_							)

							self.optimization_step += 1

							# Compute the decay factor for the exponential moving average.
							UpperCamelCase__     :Any							      =				self.get_decay(self.optimization_step							)
							UpperCamelCase__     :Tuple							      =				decay
							UpperCamelCase__     :List[Any]							      =				1 - decay

							UpperCamelCase__     :Optional[Any]							      =				contextlib.nullcontext
							if is_transformers_available() and transformers.deepspeed.is_deepspeed_zeroa_enabled():
												import deepspeed

							for s_param, param in zip(self.shadow_params					,     UpperCamelCase_							):
												if is_transformers_available() and transformers.deepspeed.is_deepspeed_zeroa_enabled():
																	UpperCamelCase__     :Dict							      =				deepspeed.zero.GatheredParameters(UpperCamelCase_					,     modifier_rank=UpperCamelCase_							)

												with context_manager():
																	if param.requires_grad:
																						s_param.sub_(one_minus_decay * (s_param - param)							)
																	else:
																						s_param.copy_(UpperCamelCase_							)




		def 					lowerCAmelCase__       (	self					,     UpperCamelCase_							):

							'''simple docstring'''


							UpperCamelCase__     :Tuple							      =				list(UpperCamelCase_							)
							for s_param, param in zip(self.shadow_params					,     UpperCamelCase_							):
												param.data.copy_(s_param.to(param.device							).data							)




		def 					lowerCAmelCase__       (	self					,     UpperCamelCase_=None					,     UpperCamelCase_=None							):

							'''simple docstring'''


							UpperCamelCase__     :Tuple							      =				[
							    p.to(device=UpperCamelCase_					,     dtype=UpperCamelCase_							) if p.is_floating_point() else p.to(device=UpperCamelCase_							)
							    for p in self.shadow_params
							]




		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							return {
							    "decay": self.decay,
							    "min_decay": self.min_decay,
							    "optimization_step": self.optimization_step,
							    "update_after_step": self.update_after_step,
							    "use_ema_warmup": self.use_ema_warmup,
							    "inv_gamma": self.inv_gamma,
							    "power": self.power,
							    "shadow_params": self.shadow_params,
							}




		def 					lowerCAmelCase__       (	self					,     UpperCamelCase_							):

							'''simple docstring'''


							UpperCamelCase__     :List[str]							      =				[param.detach().cpu().clone() for param in parameters]




		def 					lowerCAmelCase__       (	self					,     UpperCamelCase_							):

							'''simple docstring'''


							if self.temp_stored_params is None:
												raise RuntimeError('''This ExponentialMovingAverage has no `store()`ed weights ''' '''to `restore()`'''							)
							for c_param, param in zip(self.temp_stored_params					,     UpperCamelCase_							):
												param.data.copy_(c_param.data							)

							# Better memory-wise.
							UpperCamelCase__     :Optional[Any]							      =				None




		def 					lowerCAmelCase__       (	self					,     UpperCamelCase_							):

							'''simple docstring'''


							UpperCamelCase__     :int							      =				copy.deepcopy(UpperCamelCase_							)

							UpperCamelCase__     :Dict							      =				state_dict.get('''decay'''					,     self.decay							)
							if self.decay < 0.0 or self.decay > 1.0:
												raise ValueError('''Decay must be between 0 and 1'''							)

							UpperCamelCase__     :Union[str, Any]							      =				state_dict.get('''min_decay'''					,     self.min_decay							)
							if not isinstance(self.min_decay					,     UpperCamelCase_							):
												raise ValueError('''Invalid min_decay'''							)

							UpperCamelCase__     :Union[str, Any]							      =				state_dict.get('''optimization_step'''					,     self.optimization_step							)
							if not isinstance(self.optimization_step					,     UpperCamelCase_							):
												raise ValueError('''Invalid optimization_step'''							)

							UpperCamelCase__     :List[Any]							      =				state_dict.get('''update_after_step'''					,     self.update_after_step							)
							if not isinstance(self.update_after_step					,     UpperCamelCase_							):
												raise ValueError('''Invalid update_after_step'''							)

							UpperCamelCase__     :List[str]							      =				state_dict.get('''use_ema_warmup'''					,     self.use_ema_warmup							)
							if not isinstance(self.use_ema_warmup					,     UpperCamelCase_							):
												raise ValueError('''Invalid use_ema_warmup'''							)

							UpperCamelCase__     :Optional[int]							      =				state_dict.get('''inv_gamma'''					,     self.inv_gamma							)
							if not isinstance(self.inv_gamma					,     (float, int)							):
												raise ValueError('''Invalid inv_gamma'''							)

							UpperCamelCase__     :str							      =				state_dict.get('''power'''					,     self.power							)
							if not isinstance(self.power					,     (float, int)							):
												raise ValueError('''Invalid power'''							)

							UpperCamelCase__     :Tuple							      =				state_dict.get('''shadow_params'''					,     UpperCamelCase_							)
							if shadow_params is not None:
												UpperCamelCase__     :Dict							      =				shadow_params
												if not isinstance(self.shadow_params					,     UpperCamelCase_							):
																	raise ValueError('''shadow_params must be a list'''							)
												if not all(isinstance(UpperCamelCase_					,     torch.Tensor							) for p in self.shadow_params							):
																	raise ValueError('''shadow_params must all be Tensors'''							)