'''simple docstring'''

from typing import Optional, Tuple, Union

import flax
import flax.linen as nn
import jax
import jax.numpy as jnp
from flax.core.frozen_dict import FrozenDict

from ..configuration_utils import ConfigMixin, flax_register_to_config
from ..utils import BaseOutput
from .embeddings_flax import FlaxTimestepEmbedding, FlaxTimesteps
from .modeling_flax_utils import FlaxModelMixin
from .unet_ad_blocks_flax import (
    FlaxCrossAttnDownBlockaD,
    FlaxCrossAttnUpBlockaD,
    FlaxDownBlockaD,
    FlaxUNetMidBlockaDCrossAttn,
    FlaxUpBlockaD,
)



@flax.struct.dataclass
class 			UpperCAmelCase  (						a__					):





       '''simple docstring'''



       SCREAMING_SNAKE_CASE							=    42



@flax_register_to_config
class 			UpperCAmelCase  (						nn.Module    ,						a__    ,						a__					):





       '''simple docstring'''



       SCREAMING_SNAKE_CASE							=    3_2
       SCREAMING_SNAKE_CASE							=    4
       SCREAMING_SNAKE_CASE							=    4
       SCREAMING_SNAKE_CASE							=    (
           "CrossAttnDownBlock2D",
           "CrossAttnDownBlock2D",
           "CrossAttnDownBlock2D",
           "DownBlock2D",
       )
       SCREAMING_SNAKE_CASE							=    ("UpBlock2D", "CrossAttnUpBlock2D", "CrossAttnUpBlock2D", "CrossAttnUpBlock2D")
       SCREAMING_SNAKE_CASE							=    False
       SCREAMING_SNAKE_CASE							=    (3_2_0, 6_4_0, 1_2_8_0, 1_2_8_0)
       SCREAMING_SNAKE_CASE							=    2
       SCREAMING_SNAKE_CASE							=    8
       SCREAMING_SNAKE_CASE							=    None
       SCREAMING_SNAKE_CASE							=    1_2_8_0
       SCREAMING_SNAKE_CASE							=    0.0
       SCREAMING_SNAKE_CASE							=    False
       SCREAMING_SNAKE_CASE							=    jnp.floataa
       SCREAMING_SNAKE_CASE							=    True
       SCREAMING_SNAKE_CASE							=    0
       SCREAMING_SNAKE_CASE							=    False

       def _lowerCAmelCase(						self	,   __lowerCAmelCase )  ->  FrozenDict:
        # init input tensors
        lowercase__				:    Any  =					(1, self.in_channels, self.sample_size, self.sample_size)
        lowercase__				:    Optional[int]  =					jnp.zeros(__lowerCAmelCase	,   dtype=jnp.floataa )
        lowercase__				:    Optional[Any]  =					jnp.ones((1,)	,   dtype=jnp.intaa )
        lowercase__				:    Any  =					jnp.zeros((1, 1, self.cross_attention_dim)	,   dtype=jnp.floataa )

        lowercase__ ,							lowercase__				:    List[str]  =					jax.random.split(__lowerCAmelCase )
        lowercase__				:    int  =					{'''params''': params_rng, '''dropout''': dropout_rng}

        return self.init(__lowerCAmelCase	,   __lowerCAmelCase	,   __lowerCAmelCase	,   __lowerCAmelCase )["params"]

       def _lowerCAmelCase(						self )  ->  Tuple:
        lowercase__				:    Optional[int]  =					self.block_out_channels
        lowercase__				:    Optional[int]  =					block_out_channels[0] * 4

        if self.num_attention_heads is not None:
         raise ValueError(
             '''At the moment it is not possible to define the number of attention heads via `num_attention_heads` because of a naming issue as described in https://github.com/huggingface/diffusers/issues/2011#issuecomment-1547958131. Passing `num_attention_heads` will only be supported in diffusers v0.19.''' )

        # If `num_attention_heads` is not defined (which is the case for most models)
        # it will default to `attention_head_dim`. This looks weird upon first reading it and it is.
        # The reason for this behavior is to correct for incorrectly named variables that were introduced
        # when this library was created. The incorrect naming was only discovered much later in https://github.com/huggingface/diffusers/issues/2011#issuecomment-1547958131
        # Changing `attention_head_dim` to `num_attention_heads` for 40,000+ configurations is too backwards breaking
        # which is why we correct for the naming here.
        lowercase__				:    Optional[Any]  =					self.num_attention_heads or self.attention_head_dim

        # input
        lowercase__				:    Tuple  =					nn.Conv(
            block_out_channels[0]	,   kernel_size=(3, 3)	,   strides=(1, 1)	,   padding=((1, 1), (1, 1))	,   dtype=self.dtype	,   )

        # time
        lowercase__				:    Union[str, Any]  =					FlaxTimesteps(
            block_out_channels[0]	,   flip_sin_to_cos=self.flip_sin_to_cos	,   freq_shift=self.config.freq_shift )
        lowercase__				:    Tuple  =					FlaxTimestepEmbedding(__lowerCAmelCase	,   dtype=self.dtype )

        lowercase__				:    str  =					self.only_cross_attention
        if isinstance(__lowerCAmelCase	,   __lowerCAmelCase ):
         lowercase__				:    Optional[Any]  =					(only_cross_attention,) * len(self.down_block_types )

        if isinstance(__lowerCAmelCase	,   __lowerCAmelCase ):
         lowercase__				:    Any  =					(num_attention_heads,) * len(self.down_block_types )

        # down
        lowercase__				:    str  =					[]
        lowercase__				:    Optional[Any]  =					block_out_channels[0]
        for i, down_block_type in enumerate(self.down_block_types ):
         lowercase__				:    str  =					output_channel
         lowercase__				:    Any  =					block_out_channels[i]
         lowercase__				:    List[Any]  =					i == len(__lowerCAmelCase ) - 1

         if down_block_type == "CrossAttnDownBlock2D":
          lowercase__				:    List[Any]  =					FlaxCrossAttnDownBlockaD(
              in_channels=__lowerCAmelCase	,   out_channels=__lowerCAmelCase	,   dropout=self.dropout	,   num_layers=self.layers_per_block	,   num_attention_heads=num_attention_heads[i]	,   add_downsample=not is_final_block	,   use_linear_projection=self.use_linear_projection	,   only_cross_attention=only_cross_attention[i]	,   use_memory_efficient_attention=self.use_memory_efficient_attention	,   dtype=self.dtype	,   )
         else:
          lowercase__				:    Union[str, Any]  =					FlaxDownBlockaD(
              in_channels=__lowerCAmelCase	,   out_channels=__lowerCAmelCase	,   dropout=self.dropout	,   num_layers=self.layers_per_block	,   add_downsample=not is_final_block	,   dtype=self.dtype	,   )

         down_blocks.append(__lowerCAmelCase )
        lowercase__				:    List[str]  =					down_blocks

        # mid
        lowercase__				:    str  =					FlaxUNetMidBlockaDCrossAttn(
            in_channels=block_out_channels[-1]	,   dropout=self.dropout	,   num_attention_heads=num_attention_heads[-1]	,   use_linear_projection=self.use_linear_projection	,   use_memory_efficient_attention=self.use_memory_efficient_attention	,   dtype=self.dtype	,   )

        # up
        lowercase__				:    Optional[int]  =					[]
        lowercase__				:    Optional[int]  =					list(reversed(__lowerCAmelCase ) )
        lowercase__				:    Tuple  =					list(reversed(__lowerCAmelCase ) )
        lowercase__				:    int  =					list(reversed(__lowerCAmelCase ) )
        lowercase__				:    Optional[Any]  =					reversed_block_out_channels[0]
        for i, up_block_type in enumerate(self.up_block_types ):
         lowercase__				:    str  =					output_channel
         lowercase__				:    Tuple  =					reversed_block_out_channels[i]
         lowercase__				:    Optional[int]  =					reversed_block_out_channels[min(i + 1	,   len(__lowerCAmelCase ) - 1 )]

         lowercase__				:    List[Any]  =					i == len(__lowerCAmelCase ) - 1

         if up_block_type == "CrossAttnUpBlock2D":
          lowercase__				:    Optional[int]  =					FlaxCrossAttnUpBlockaD(
              in_channels=__lowerCAmelCase	,   out_channels=__lowerCAmelCase	,   prev_output_channel=__lowerCAmelCase	,   num_layers=self.layers_per_block + 1	,   num_attention_heads=reversed_num_attention_heads[i]	,   add_upsample=not is_final_block	,   dropout=self.dropout	,   use_linear_projection=self.use_linear_projection	,   only_cross_attention=only_cross_attention[i]	,   use_memory_efficient_attention=self.use_memory_efficient_attention	,   dtype=self.dtype	,   )
         else:
          lowercase__				:    Optional[Any]  =					FlaxUpBlockaD(
              in_channels=__lowerCAmelCase	,   out_channels=__lowerCAmelCase	,   prev_output_channel=__lowerCAmelCase	,   num_layers=self.layers_per_block + 1	,   add_upsample=not is_final_block	,   dropout=self.dropout	,   dtype=self.dtype	,   )

         up_blocks.append(__lowerCAmelCase )
         lowercase__				:    Union[str, Any]  =					output_channel
        lowercase__				:    List[Any]  =					up_blocks

        # out
        lowercase__				:    Optional[int]  =					nn.GroupNorm(num_groups=32	,   epsilon=1E-5 )
        lowercase__				:    Tuple  =					nn.Conv(
            self.out_channels	,   kernel_size=(3, 3)	,   strides=(1, 1)	,   padding=((1, 1), (1, 1))	,   dtype=self.dtype	,   )


       def __call__(						self	,   __lowerCAmelCase	,   __lowerCAmelCase	,   __lowerCAmelCase	,   __lowerCAmelCase=None	,   __lowerCAmelCase=None	,   __lowerCAmelCase = True	,   __lowerCAmelCase = False	,   )  ->  Union[FlaxUNetaDConditionOutput, Tuple]:
        # 1. time
        if not isinstance(__lowerCAmelCase	,   jnp.ndarray ):
         lowercase__				:    int  =					jnp.array([timesteps]	,   dtype=jnp.intaa )
        elif isinstance(__lowerCAmelCase	,   jnp.ndarray ) and len(timesteps.shape ) == 0:
         lowercase__				:    Optional[int]  =					timesteps.astype(dtype=jnp.floataa )
         lowercase__				:    Union[str, Any]  =					jnp.expand_dims(__lowerCAmelCase	,   0 )

        lowercase__				:    Any  =					self.time_proj(__lowerCAmelCase )
        lowercase__				:    Union[str, Any]  =					self.time_embedding(__lowerCAmelCase )

        # 2. pre-process
        lowercase__				:    Union[str, Any]  =					jnp.transpose(__lowerCAmelCase	,   (0, 2, 3, 1) )
        lowercase__				:    Union[str, Any]  =					self.conv_in(__lowerCAmelCase )

        # 3. down
        lowercase__				:    List[str]  =					(sample,)
        for down_block in self.down_blocks:
         if isinstance(__lowerCAmelCase	,   __lowerCAmelCase ):
          lowercase__ ,							lowercase__				:    Union[str, Any]  =					down_block(__lowerCAmelCase	,   __lowerCAmelCase	,   __lowerCAmelCase	,   deterministic=not train )
         else:
          lowercase__ ,							lowercase__				:    List[str]  =					down_block(__lowerCAmelCase	,   __lowerCAmelCase	,   deterministic=not train )
         down_block_res_samples += res_samples

        if down_block_additional_residuals is not None:
         lowercase__				:    int  =					()

         for down_block_res_sample, down_block_additional_residual in zip(
             __lowerCAmelCase	,   __lowerCAmelCase ):
          down_block_res_sample += down_block_additional_residual
          new_down_block_res_samples += (down_block_res_sample,)

         lowercase__				:    Tuple  =					new_down_block_res_samples

        # 4. mid
        lowercase__				:    str  =					self.mid_block(__lowerCAmelCase	,   __lowerCAmelCase	,   __lowerCAmelCase	,   deterministic=not train )

        if mid_block_additional_residual is not None:
         sample += mid_block_additional_residual

        # 5. up
        for up_block in self.up_blocks:
         lowercase__				:    Any  =					down_block_res_samples[-(self.layers_per_block + 1) :]
         lowercase__				:    List[str]  =					down_block_res_samples[: -(self.layers_per_block + 1)]
         if isinstance(__lowerCAmelCase	,   __lowerCAmelCase ):
          lowercase__				:    List[Any]  =					up_block(
              __lowerCAmelCase	,   temb=__lowerCAmelCase	,   encoder_hidden_states=__lowerCAmelCase	,   res_hidden_states_tuple=__lowerCAmelCase	,   deterministic=not train	,   )
         else:
          lowercase__				:    str  =					up_block(__lowerCAmelCase	,   temb=__lowerCAmelCase	,   res_hidden_states_tuple=__lowerCAmelCase	,   deterministic=not train )

        # 6. post-process
        lowercase__				:    List[Any]  =					self.conv_norm_out(__lowerCAmelCase )
        lowercase__				:    str  =					nn.silu(__lowerCAmelCase )
        lowercase__				:    Optional[int]  =					self.conv_out(__lowerCAmelCase )
        lowercase__				:    Optional[Any]  =					jnp.transpose(__lowerCAmelCase	,   (0, 3, 1, 2) )

        if not return_dict:
         return (sample,)

        return FlaxUNetaDConditionOutput(sample=__lowerCAmelCase )


'''simple docstring'''

def 			__UpperCamelCase       (   UpperCAmelCase     ):
 lowercase__ ,							lowercase__				:    Optional[int]  =					[], []
 while len(UpperCAmelCase     ) > 1:
  lowercase__ ,							lowercase__				:    List[str]  =					min(UpperCAmelCase     ), max(UpperCAmelCase     )
  start.append(UpperCAmelCase     )
  end.append(UpperCAmelCase     )
  collection.remove(UpperCAmelCase     )
  collection.remove(UpperCAmelCase     )
 end.reverse()
 return start + collection + end


if __name__ == "__main__":
  __a: Optional[int]          =   input("""Enter numbers separated by a comma:\n""").strip()
  __a: Tuple          =   [int(item) for item in user_input.split(""",""")]
  print(*merge_sort(unsorted), sep=""",""")

