



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





 """simple docstring"""



 lowerCamelCase_        =      4_2
 lowerCamelCase_        =      4_2
 lowerCamelCase_        =      0.0
 lowerCamelCase_        =      1
 lowerCamelCase_        =      1
 lowerCamelCase_        =      True
 lowerCamelCase_        =      False
 lowerCamelCase_        =      False
 lowerCamelCase_        =      False
 lowerCamelCase_        =      jnp.floataa
 def lowercase_		(    self       )						->				Any:




   """simple docstring"""







   _A							     =     []
   _A							     =     []

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

     _A							     =     FlaxResnetBlockaD(
         in_channels=A_						,     out_channels=self.out_channels						,     dropout_prob=self.dropout						,     dtype=self.dtype						,     )
     resnets.append(A_       )

     _A							     =     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_       )

   _A							     =     resnets
   _A							     =     attentions

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



 def __call__(    self						,     a						,     a						,     a						,     a=True       )						->				Optional[Any]:




   """simple docstring"""







   _A							     =     ()

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

   if self.add_downsample:
     _A							     =     self.downsamplers_a(A_       )
     output_states += (hidden_states,)

   return hidden_states, output_states







class 		_snake_case   (      nn.Module					):





 """simple docstring"""



 lowerCamelCase_        =      4_2
 lowerCamelCase_        =      4_2
 lowerCamelCase_        =      0.0
 lowerCamelCase_        =      1
 lowerCamelCase_        =      True
 lowerCamelCase_        =      jnp.floataa
 def lowercase_		(    self       )						->				Tuple:




   """simple docstring"""







   _A							     =     []

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

     _A							     =     FlaxResnetBlockaD(
         in_channels=A_						,     out_channels=self.out_channels						,     dropout_prob=self.dropout						,     dtype=self.dtype						,     )
     resnets.append(A_       )
   _A							     =     resnets

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



 def __call__(    self						,     a						,     a						,     a=True       )						->				int:




   """simple docstring"""







   _A							     =     ()

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

   if self.add_downsample:
     _A							     =     self.downsamplers_a(A_       )
     output_states += (hidden_states,)

   return hidden_states, output_states







class 		_snake_case   (      nn.Module					):





 """simple docstring"""



 lowerCamelCase_        =      4_2
 lowerCamelCase_        =      4_2
 lowerCamelCase_        =      4_2
 lowerCamelCase_        =      0.0
 lowerCamelCase_        =      1
 lowerCamelCase_        =      1
 lowerCamelCase_        =      True
 lowerCamelCase_        =      False
 lowerCamelCase_        =      False
 lowerCamelCase_        =      False
 lowerCamelCase_        =      jnp.floataa
 def lowercase_		(    self       )						->				Dict:




   """simple docstring"""







   _A							     =     []
   _A							     =     []

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

     _A							     =     FlaxResnetBlockaD(
         in_channels=resnet_in_channels + res_skip_channels						,     out_channels=self.out_channels						,     dropout_prob=self.dropout						,     dtype=self.dtype						,     )
     resnets.append(A_       )

     _A							     =     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_       )

   _A							     =     resnets
   _A							     =     attentions

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



 def __call__(    self						,     a						,     a						,     a						,     a						,     a=True       )						->				Dict:




   """simple docstring"""







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

     _A							     =     resnet(A_						,     A_						,     deterministic=A_       )
     _A							     =     attn(A_						,     A_						,     deterministic=A_       )

   if self.add_upsample:
     _A							     =     self.upsamplers_a(A_       )

   return hidden_states







class 		_snake_case   (      nn.Module					):





 """simple docstring"""



 lowerCamelCase_        =      4_2
 lowerCamelCase_        =      4_2
 lowerCamelCase_        =      4_2
 lowerCamelCase_        =      0.0
 lowerCamelCase_        =      1
 lowerCamelCase_        =      True
 lowerCamelCase_        =      jnp.floataa
 def lowercase_		(    self       )						->				List[Any]:




   """simple docstring"""







   _A							     =     []

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

     _A							     =     FlaxResnetBlockaD(
         in_channels=resnet_in_channels + res_skip_channels						,     out_channels=self.out_channels						,     dropout_prob=self.dropout						,     dtype=self.dtype						,     )
     resnets.append(A_       )

   _A							     =     resnets

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



 def __call__(    self						,     a						,     a						,     a						,     a=True       )						->				Tuple:




   """simple docstring"""







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

     _A							     =     resnet(A_						,     A_						,     deterministic=A_       )

   if self.add_upsample:
     _A							     =     self.upsamplers_a(A_       )

   return hidden_states







class 		_snake_case   (      nn.Module					):





 """simple docstring"""



 lowerCamelCase_        =      4_2
 lowerCamelCase_        =      0.0
 lowerCamelCase_        =      1
 lowerCamelCase_        =      1
 lowerCamelCase_        =      False
 lowerCamelCase_        =      False
 lowerCamelCase_        =      jnp.floataa
 def lowercase_		(    self       )						->				Union[str, Any]:




   """simple docstring"""







   _A							     =     [
       FlaxResnetBlockaD(
           in_channels=self.in_channels						,     out_channels=self.in_channels						,     dropout_prob=self.dropout						,     dtype=self.dtype						,     )
   ]

   _A							     =     []

   for _ in range(self.num_layers       ):
     _A							     =     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_       )

     _A							     =     FlaxResnetBlockaD(
         in_channels=self.in_channels						,     out_channels=self.in_channels						,     dropout_prob=self.dropout						,     dtype=self.dtype						,     )
     resnets.append(A_       )

   _A							     =     resnets
   _A							     =     attentions



 def __call__(    self						,     a						,     a						,     a						,     a=True       )						->				Optional[Any]:




   """simple docstring"""







   _A							     =     self.resnets[0](A_						,     A_       )
   for attn, resnet in zip(self.attentions						,     self.resnets[1:]       ):
     _A							     =     attn(A_						,     A_						,     deterministic=A_       )
     _A							     =     resnet(A_						,     A_						,     deterministic=A_       )

   return hidden_states






from math import factorial






def 				_UpperCAmelCase			(    A = 20     ):




   '''simple docstring'''

   UpperCAmelCase__						=2 * n  # middle entry of odd rows starting at row 3 is the solution for n = 1,
   # 2, 3,...
   UpperCAmelCase__						=n // 2

   return int(factorial(A     ) / (factorial(A     ) * factorial(n - k     ))     )


if __name__ == "__main__":
    import sys

    if len(sys.argv) == 1:
        print(solution(20))
    else:
        try:
            UpperCamelCase_												=	int(sys.argv[1])
            print(solution(n))
        except ValueError:
            print('Invalid entry - please enter a number.')



