






'''simple docstring'''





import flax.linen as nn
import jax.numpy as jnp

from .attention_flax import FlaxTransformeraDModel
from .resnet_flax import FlaxDownsampleaD, FlaxResnetBlockaD, FlaxUpsampleaD


class  snake_case__      (					nn.Module):
					a_        =					42
					a_        =					42
					a_        =					0.0
					a_        =					1
					a_        =					1
					a_        =					True
					a_        =					False
					a_        =					False
					a_        =					False
					a_        =					jnp.floataa




					def 		A      (  self  :		int      )    ->							Optional[int]:
								UpperCAmelCase_      :       Optional[int]          =       []
								UpperCAmelCase_      :       int          =       []

								for i in range(self.num_layers      ):
											UpperCAmelCase_      :       List[Any]          =       self.in_channels if i == 0 else self.out_channels

											UpperCAmelCase_      :       str          =       FlaxResnetBlockaD(
											    in_channels=_A				, out_channels=self.out_channels				, dropout_prob=self.dropout				, dtype=self.dtype				, )
											resnets.append(_A      )

											UpperCAmelCase_      :       Tuple          =       FlaxTransformeraDModel(
											    in_channels=self.out_channels				, n_heads=self.num_attention_heads				, d_head=self.out_channels // self.num_attention_heads				, depth=1				, use_linear_projection=self.use_linear_projection				, only_cross_attention=self.only_cross_attention				, use_memory_efficient_attention=self.use_memory_efficient_attention				, dtype=self.dtype				, )
											attentions.append(_A      )

								UpperCAmelCase_      :       List[Any]          =       resnets
								UpperCAmelCase_      :       List[Any]          =       attentions

								if self.add_downsample:
											UpperCAmelCase_      :       Tuple          =       FlaxDownsampleaD(self.out_channels				, dtype=self.dtype      )





					def __call__(  self  :		Any				, _A  :		Optional[int]				, _A  :		int				, _A  :		Union[str, Any]				, _A  :		int=True      )    ->							int:
								UpperCAmelCase_      :       str          =       ()

								for resnet, attn in zip(self.resnets				, self.attentions      ):
											UpperCAmelCase_      :       int          =       resnet(_A				, _A				, deterministic=_A      )
											UpperCAmelCase_      :       int          =       attn(_A				, _A				, deterministic=_A      )
											output_states += (hidden_states,)

								if self.add_downsample:
											UpperCAmelCase_      :       List[str]          =       self.downsamplers_a(_A      )
											output_states += (hidden_states,)

								return hidden_states, output_states






class  snake_case__      (					nn.Module):
					a_        =					42
					a_        =					42
					a_        =					0.0
					a_        =					1
					a_        =					True
					a_        =					jnp.floataa




					def 		A      (  self  :		Any      )    ->							str:
								UpperCAmelCase_      :       Union[str, Any]          =       []

								for i in range(self.num_layers      ):
											UpperCAmelCase_      :       Union[str, Any]          =       self.in_channels if i == 0 else self.out_channels

											UpperCAmelCase_      :       Any          =       FlaxResnetBlockaD(
											    in_channels=_A				, out_channels=self.out_channels				, dropout_prob=self.dropout				, dtype=self.dtype				, )
											resnets.append(_A      )
								UpperCAmelCase_      :       int          =       resnets

								if self.add_downsample:
											UpperCAmelCase_      :       List[Any]          =       FlaxDownsampleaD(self.out_channels				, dtype=self.dtype      )





					def __call__(  self  :		List[str]				, _A  :		Optional[int]				, _A  :		Any				, _A  :		Dict=True      )    ->							Optional[int]:
								UpperCAmelCase_      :       Tuple          =       ()

								for resnet in self.resnets:
											UpperCAmelCase_      :       Dict          =       resnet(_A				, _A				, deterministic=_A      )
											output_states += (hidden_states,)

								if self.add_downsample:
											UpperCAmelCase_      :       List[str]          =       self.downsamplers_a(_A      )
											output_states += (hidden_states,)

								return hidden_states, output_states






class  snake_case__      (					nn.Module):
					a_        =					42
					a_        =					42
					a_        =					42
					a_        =					0.0
					a_        =					1
					a_        =					1
					a_        =					True
					a_        =					False
					a_        =					False
					a_        =					False
					a_        =					jnp.floataa




					def 		A      (  self  :		List[str]      )    ->							int:
								UpperCAmelCase_      :       int          =       []
								UpperCAmelCase_      :       Any          =       []

								for i in range(self.num_layers      ):
											UpperCAmelCase_      :       Union[str, Any]          =       self.in_channels if (i == self.num_layers - 1) else self.out_channels
											UpperCAmelCase_      :       List[str]          =       self.prev_output_channel if i == 0 else self.out_channels

											UpperCAmelCase_      :       Optional[int]          =       FlaxResnetBlockaD(
											    in_channels=resnet_in_channels + res_skip_channels				, out_channels=self.out_channels				, dropout_prob=self.dropout				, dtype=self.dtype				, )
											resnets.append(_A      )

											UpperCAmelCase_      :       List[Any]          =       FlaxTransformeraDModel(
											    in_channels=self.out_channels				, n_heads=self.num_attention_heads				, d_head=self.out_channels // self.num_attention_heads				, depth=1				, use_linear_projection=self.use_linear_projection				, only_cross_attention=self.only_cross_attention				, use_memory_efficient_attention=self.use_memory_efficient_attention				, dtype=self.dtype				, )
											attentions.append(_A      )

								UpperCAmelCase_      :       Optional[int]          =       resnets
								UpperCAmelCase_      :       Tuple          =       attentions

								if self.add_upsample:
											UpperCAmelCase_      :       Optional[Any]          =       FlaxUpsampleaD(self.out_channels				, dtype=self.dtype      )





					def __call__(  self  :		Dict				, _A  :		List[str]				, _A  :		str				, _A  :		List[str]				, _A  :		List[str]				, _A  :		List[str]=True      )    ->							Union[str, Any]:
								for resnet, attn in zip(self.resnets				, self.attentions      ):
											# pop res hidden states
											UpperCAmelCase_      :       Tuple          =       res_hidden_states_tuple[-1]
											UpperCAmelCase_      :       int          =       res_hidden_states_tuple[:-1]
											UpperCAmelCase_      :       Optional[Any]          =       jnp.concatenate((hidden_states, res_hidden_states)				, axis=-1      )

											UpperCAmelCase_      :       Optional[int]          =       resnet(_A				, _A				, deterministic=_A      )
											UpperCAmelCase_      :       List[Any]          =       attn(_A				, _A				, deterministic=_A      )

								if self.add_upsample:
											UpperCAmelCase_      :       Optional[Any]          =       self.upsamplers_a(_A      )

								return hidden_states






class  snake_case__      (					nn.Module):
					a_        =					42
					a_        =					42
					a_        =					42
					a_        =					0.0
					a_        =					1
					a_        =					True
					a_        =					jnp.floataa




					def 		A      (  self  :		Any      )    ->							Union[str, Any]:
								UpperCAmelCase_      :       Any          =       []

								for i in range(self.num_layers      ):
											UpperCAmelCase_      :       int          =       self.in_channels if (i == self.num_layers - 1) else self.out_channels
											UpperCAmelCase_      :       Optional[Any]          =       self.prev_output_channel if i == 0 else self.out_channels

											UpperCAmelCase_      :       Union[str, Any]          =       FlaxResnetBlockaD(
											    in_channels=resnet_in_channels + res_skip_channels				, out_channels=self.out_channels				, dropout_prob=self.dropout				, dtype=self.dtype				, )
											resnets.append(_A      )

								UpperCAmelCase_      :       Union[str, Any]          =       resnets

								if self.add_upsample:
											UpperCAmelCase_      :       str          =       FlaxUpsampleaD(self.out_channels				, dtype=self.dtype      )





					def __call__(  self  :		int				, _A  :		Optional[Any]				, _A  :		Dict				, _A  :		Dict				, _A  :		Optional[int]=True      )    ->							Dict:
								for resnet in self.resnets:
											# pop res hidden states
											UpperCAmelCase_      :       int          =       res_hidden_states_tuple[-1]
											UpperCAmelCase_      :       Any          =       res_hidden_states_tuple[:-1]
											UpperCAmelCase_      :       str          =       jnp.concatenate((hidden_states, res_hidden_states)				, axis=-1      )

											UpperCAmelCase_      :       Optional[int]          =       resnet(_A				, _A				, deterministic=_A      )

								if self.add_upsample:
											UpperCAmelCase_      :       Optional[int]          =       self.upsamplers_a(_A      )

								return hidden_states






class  snake_case__      (					nn.Module):
					a_        =					42
					a_        =					0.0
					a_        =					1
					a_        =					1
					a_        =					False
					a_        =					False
					a_        =					jnp.floataa




					def 		A      (  self  :		int      )    ->							Union[str, Any]:
								# there is always at least one resnet
								UpperCAmelCase_      :       Optional[Any]          =       [
								    FlaxResnetBlockaD(
								        in_channels=self.in_channels				, out_channels=self.in_channels				, dropout_prob=self.dropout				, dtype=self.dtype				, )
								]

								UpperCAmelCase_      :       Union[str, Any]          =       []

								for _ in range(self.num_layers      ):
											UpperCAmelCase_      :       Dict          =       FlaxTransformeraDModel(
											    in_channels=self.in_channels				, n_heads=self.num_attention_heads				, d_head=self.in_channels // self.num_attention_heads				, depth=1				, use_linear_projection=self.use_linear_projection				, use_memory_efficient_attention=self.use_memory_efficient_attention				, dtype=self.dtype				, )
											attentions.append(_A      )

											UpperCAmelCase_      :       Union[str, Any]          =       FlaxResnetBlockaD(
											    in_channels=self.in_channels				, out_channels=self.in_channels				, dropout_prob=self.dropout				, dtype=self.dtype				, )
											resnets.append(_A      )

								UpperCAmelCase_      :       List[Any]          =       resnets
								UpperCAmelCase_      :       List[Any]          =       attentions





					def __call__(  self  :		int				, _A  :		List[str]				, _A  :		Union[str, Any]				, _A  :		str				, _A  :		int=True      )    ->							Any:
								UpperCAmelCase_      :       int          =       self.resnets[0](_A				, _A      )
								for attn, resnet in zip(self.attentions				, self.resnets[1:]      ):
											UpperCAmelCase_      :       str          =       attn(_A				, _A				, deterministic=_A      )
											UpperCAmelCase_      :       Any          =       resnet(_A				, _A				, deterministic=_A      )

								return hidden_states










'''simple docstring'''





_UpperCamelCase						:						List[str]  =					[sum(int(c, 10) ** 2 for c in i.__str__()) for i in range(100_000)]
def __UpperCAmelCase   (					A					:			int		)    ->   int:
			UpperCAmelCase_      :       str          =       0
			while number:
						# Increased Speed Slightly by checking every 5 digits together.
						sum_of_digits_squared += DIGITS_SQUARED[number % 1_0_0_0_0_0]
						number //= 1_0_0_0_0_0

			return sum_of_digits_squared


# There are 2 Chains made,
# One ends with 89 with the chain member 58 being the one which when declared first,
# there will be the least number of iterations for all the members to be checked.

# The other one ends with 1 and has only one element 1.

# So 58 and 1 are chosen to be declared at the starting.

# Changed dictionary to an array to quicken the solution
_UpperCamelCase						:						list[bool | None]  =					[None] * 10_000_000
_UpperCamelCase						:						List[str]  =					True
_UpperCamelCase						:						Tuple  =					False
def __UpperCAmelCase   (					A					:			int		)    ->   bool:

			if CHAINS[number - 1] is not None:
						return CHAINS[number - 1]  # type: ignore

			UpperCAmelCase_      :       Dict          =       chain(next_number(A		)		)
			UpperCAmelCase_      :       int          =       number_chain

			while number < 1_0_0_0_0_0_0_0:
						UpperCAmelCase_      :       Optional[Any]          =       number_chain
						number *= 1_0

			return number_chain
def __UpperCAmelCase   (					A					:			int = 1_0_0_0_0_0_0_0		)    ->   int:
			for i in range(1			,       A		):
						if CHAINS[i] is None:
									chain(i + 1		)

			return CHAINS[:number].count(A		)


if __name__ == "__main__":
						import doctest

						doctest.testmod()
						print(f'''{solution() = }''')


