
'''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):
					_lowerCAmelCase			     =	42
					_lowerCAmelCase			     =	42
					_lowerCAmelCase			     =	0.0
					_lowerCAmelCase			     =	1
					_lowerCAmelCase			     =	1
					_lowerCAmelCase			     =	True
					_lowerCAmelCase			     =	False
					_lowerCAmelCase			     =	False
					_lowerCAmelCase			     =	False
					_lowerCAmelCase			     =	jnp.floataa
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									lowerCamelCase					:			Tuple									= []
									lowerCamelCase					:			Dict									= []

									for i in range(self.num_layers      ):
													lowerCamelCase					:			Dict									= self.in_channels if i == 0 else self.out_channels

													lowerCamelCase					:			Tuple									= FlaxResnetBlockaD(
													    in_channels=__A,    out_channels=self.out_channels,    dropout_prob=self.dropout,    dtype=self.dtype,    )
													resnets.append(__A      )

													lowerCamelCase					:			Optional[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      )

									lowerCamelCase					:			str									= resnets
									lowerCamelCase					:			List[str]									= attentions

									if self.add_downsample:
													lowerCamelCase					:			Any									= FlaxDownsampleaD(self.out_channels,    dtype=self.dtype      )




					def __call__(     self,    A,    A,    A,    A=True      ):

									"""simple docstring"""


									lowerCamelCase					:			Tuple									= ()

									for resnet, attn in zip(self.resnets,    self.attentions      ):
													lowerCamelCase					:			Dict									= resnet(__A,    __A,    deterministic=__A      )
													lowerCamelCase					:			str									= attn(__A,    __A,    deterministic=__A      )
													output_states += (hidden_states,)

									if self.add_downsample:
													lowerCamelCase					:			int									= self.downsamplers_a(__A      )
													output_states += (hidden_states,)

									return hidden_states, output_states





class     __snake_case		(   nn.Module):
					_lowerCAmelCase			     =	42
					_lowerCAmelCase			     =	42
					_lowerCAmelCase			     =	0.0
					_lowerCAmelCase			     =	1
					_lowerCAmelCase			     =	True
					_lowerCAmelCase			     =	jnp.floataa
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									lowerCamelCase					:			int									= []

									for i in range(self.num_layers      ):
													lowerCamelCase					:			int									= self.in_channels if i == 0 else self.out_channels

													lowerCamelCase					:			Tuple									= FlaxResnetBlockaD(
													    in_channels=__A,    out_channels=self.out_channels,    dropout_prob=self.dropout,    dtype=self.dtype,    )
													resnets.append(__A      )
									lowerCamelCase					:			Dict									= resnets

									if self.add_downsample:
													lowerCamelCase					:			str									= FlaxDownsampleaD(self.out_channels,    dtype=self.dtype      )




					def __call__(     self,    A,    A,    A=True      ):

									"""simple docstring"""


									lowerCamelCase					:			Union[str, Any]									= ()

									for resnet in self.resnets:
													lowerCamelCase					:			Optional[Any]									= resnet(__A,    __A,    deterministic=__A      )
													output_states += (hidden_states,)

									if self.add_downsample:
													lowerCamelCase					:			int									= self.downsamplers_a(__A      )
													output_states += (hidden_states,)

									return hidden_states, output_states





class     __snake_case		(   nn.Module):
					_lowerCAmelCase			     =	42
					_lowerCAmelCase			     =	42
					_lowerCAmelCase			     =	42
					_lowerCAmelCase			     =	0.0
					_lowerCAmelCase			     =	1
					_lowerCAmelCase			     =	1
					_lowerCAmelCase			     =	True
					_lowerCAmelCase			     =	False
					_lowerCAmelCase			     =	False
					_lowerCAmelCase			     =	False
					_lowerCAmelCase			     =	jnp.floataa
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									lowerCamelCase					:			Optional[Any]									= []
									lowerCamelCase					:			int									= []

									for i in range(self.num_layers      ):
													lowerCamelCase					:			str									= self.in_channels if (i == self.num_layers - 1) else self.out_channels
													lowerCamelCase					:			Any									= self.prev_output_channel if i == 0 else self.out_channels

													lowerCamelCase					:			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      )

													lowerCamelCase					:			List[str]									= 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      )

									lowerCamelCase					:			Dict									= resnets
									lowerCamelCase					:			Tuple									= attentions

									if self.add_upsample:
													lowerCamelCase					:			Union[str, Any]									= FlaxUpsampleaD(self.out_channels,    dtype=self.dtype      )




					def __call__(     self,    A,    A,    A,    A,    A=True      ):

									"""simple docstring"""


									for resnet, attn in zip(self.resnets,    self.attentions      ):
													# pop res hidden states
													lowerCamelCase					:			Tuple									= res_hidden_states_tuple[-1]
													lowerCamelCase					:			Tuple									= res_hidden_states_tuple[:-1]
													lowerCamelCase					:			Optional[int]									= jnp.concatenate((hidden_states, res_hidden_states),    axis=-1      )

													lowerCamelCase					:			Any									= resnet(__A,    __A,    deterministic=__A      )
													lowerCamelCase					:			str									= attn(__A,    __A,    deterministic=__A      )

									if self.add_upsample:
													lowerCamelCase					:			List[str]									= self.upsamplers_a(__A      )

									return hidden_states





class     __snake_case		(   nn.Module):
					_lowerCAmelCase			     =	42
					_lowerCAmelCase			     =	42
					_lowerCAmelCase			     =	42
					_lowerCAmelCase			     =	0.0
					_lowerCAmelCase			     =	1
					_lowerCAmelCase			     =	True
					_lowerCAmelCase			     =	jnp.floataa
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									lowerCamelCase					:			Any									= []

									for i in range(self.num_layers      ):
													lowerCamelCase					:			Dict									= self.in_channels if (i == self.num_layers - 1) else self.out_channels
													lowerCamelCase					:			List[str]									= self.prev_output_channel if i == 0 else self.out_channels

													lowerCamelCase					:			Tuple									= FlaxResnetBlockaD(
													    in_channels=resnet_in_channels + res_skip_channels,    out_channels=self.out_channels,    dropout_prob=self.dropout,    dtype=self.dtype,    )
													resnets.append(__A      )

									lowerCamelCase					:			Optional[Any]									= resnets

									if self.add_upsample:
													lowerCamelCase					:			List[str]									= FlaxUpsampleaD(self.out_channels,    dtype=self.dtype      )




					def __call__(     self,    A,    A,    A,    A=True      ):

									"""simple docstring"""


									for resnet in self.resnets:
													# pop res hidden states
													lowerCamelCase					:			List[str]									= res_hidden_states_tuple[-1]
													lowerCamelCase					:			List[Any]									= res_hidden_states_tuple[:-1]
													lowerCamelCase					:			Dict									= jnp.concatenate((hidden_states, res_hidden_states),    axis=-1      )

													lowerCamelCase					:			List[Any]									= resnet(__A,    __A,    deterministic=__A      )

									if self.add_upsample:
													lowerCamelCase					:			int									= self.upsamplers_a(__A      )

									return hidden_states





class     __snake_case		(   nn.Module):
					_lowerCAmelCase			     =	42
					_lowerCAmelCase			     =	0.0
					_lowerCAmelCase			     =	1
					_lowerCAmelCase			     =	1
					_lowerCAmelCase			     =	False
					_lowerCAmelCase			     =	False
					_lowerCAmelCase			     =	jnp.floataa
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									lowerCamelCase					:			str									= [
									    FlaxResnetBlockaD(
									        in_channels=self.in_channels,    out_channels=self.in_channels,    dropout_prob=self.dropout,    dtype=self.dtype,    )
									]

									lowerCamelCase					:			Optional[int]									= []

									for _ in range(self.num_layers      ):
													lowerCamelCase					:			List[Any]									= 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      )

													lowerCamelCase					:			Tuple									= FlaxResnetBlockaD(
													    in_channels=self.in_channels,    out_channels=self.in_channels,    dropout_prob=self.dropout,    dtype=self.dtype,    )
													resnets.append(__A      )

									lowerCamelCase					:			int									= resnets
									lowerCamelCase					:			Union[str, Any]									= attentions




					def __call__(     self,    A,    A,    A,    A=True      ):

									"""simple docstring"""


									lowerCamelCase					:			int									= self.resnets[0](__A,    __A      )
									for attn, resnet in zip(self.attentions,    self.resnets[1:]      ):
													lowerCamelCase					:			Optional[Any]									= attn(__A,    __A,    deterministic=__A      )
													lowerCamelCase					:			Dict									= resnet(__A,    __A,    deterministic=__A      )

									return hidden_states


'''simple docstring'''






from __future__ import annotations





def    UpperCAmelCase							(  UpperCAmelCase__							:							int):
				lowerCamelCase					:			List[Any]									= str(UpperCAmelCase__)
				return len(UpperCAmelCase__) == 9 and set(UpperCAmelCase__) == set('123456789')





def    UpperCAmelCase							(  ):
				for base_num in range(99_99       ,							49_99       ,							-1):
								lowerCamelCase					:			Tuple									= 10_00_02 * base_num
								if is_9_pandigital(UpperCAmelCase__):
												return candidate

				for base_num in range(3_33       ,							99       ,							-1):
								lowerCamelCase					:			List[Any]									= 1_00_20_03 * base_num
								if is_9_pandigital(UpperCAmelCase__):
												return candidate

				return None


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