





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

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



class       A__     ( nn.Module    ):
      _UpperCAmelCase			:int
      _UpperCAmelCase			:int
      _UpperCAmelCase			:float							=     0.0
      _UpperCAmelCase			:int							=     1
      _UpperCAmelCase			:int							=     1
      _UpperCAmelCase			:bool							=     True
      _UpperCAmelCase			:bool							=     False
      _UpperCAmelCase			:bool							=     False
      _UpperCAmelCase			:bool							=     False
      _UpperCAmelCase			:jnp.dtype							=     jnp.floataa





      def  __UpperCamelCase(				self     ):
       '''simple docstring'''




       UpperCamelCase			:      str 			=     []
       UpperCamelCase			:      List[str] 			=     []

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

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

        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(lowerCAmelCase_     )

       UpperCamelCase			:      str 			=     resnets
       UpperCamelCase			:      Optional[Any] 			=     attentions

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





      def __call__(				self ,							A_ ,							A_ ,							A_ ,							A_=True     ):
       '''simple docstring'''




       UpperCamelCase			:      Tuple 			=     ()

       for resnet, attn in zip(self.resnets ,							self.attentions     ):
        UpperCamelCase			:      Optional[Any] 			=     resnet(lowerCAmelCase_ ,							lowerCAmelCase_ ,							deterministic=lowerCAmelCase_     )
        UpperCamelCase			:      Dict 			=     attn(lowerCAmelCase_ ,							lowerCAmelCase_ ,							deterministic=lowerCAmelCase_     )
        output_states += (hidden_states,)

       if self.add_downsample:
        UpperCamelCase			:      Tuple 			=     self.downsamplers_a(lowerCAmelCase_     )
        output_states += (hidden_states,)

       return hidden_states, output_states



class       A__     ( nn.Module    ):
      _UpperCAmelCase			:int
      _UpperCAmelCase			:int
      _UpperCAmelCase			:float							=     0.0
      _UpperCAmelCase			:int							=     1
      _UpperCAmelCase			:bool							=     True
      _UpperCAmelCase			:jnp.dtype							=     jnp.floataa





      def  __UpperCamelCase(				self     ):
       '''simple docstring'''




       UpperCamelCase			:      int 			=     []

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

        UpperCamelCase			:      List[Any] 			=     FlaxResnetBlockaD(
            in_channels=lowerCAmelCase_ ,							out_channels=self.out_channels ,							dropout_prob=self.dropout ,							dtype=self.dtype ,							)
        resnets.append(lowerCAmelCase_     )
       UpperCamelCase			:      List[str] 			=     resnets

       if self.add_downsample:
        UpperCamelCase			:      Optional[Any] 			=     FlaxDownsampleaD(self.out_channels ,							dtype=self.dtype     )





      def __call__(				self ,							A_ ,							A_ ,							A_=True     ):
       '''simple docstring'''




       UpperCamelCase			:      Optional[int] 			=     ()

       for resnet in self.resnets:
        UpperCamelCase			:      Optional[int] 			=     resnet(lowerCAmelCase_ ,							lowerCAmelCase_ ,							deterministic=lowerCAmelCase_     )
        output_states += (hidden_states,)

       if self.add_downsample:
        UpperCamelCase			:      Optional[Any] 			=     self.downsamplers_a(lowerCAmelCase_     )
        output_states += (hidden_states,)

       return hidden_states, output_states



class       A__     ( nn.Module    ):
      _UpperCAmelCase			:int
      _UpperCAmelCase			:int
      _UpperCAmelCase			:int
      _UpperCAmelCase			:float							=     0.0
      _UpperCAmelCase			:int							=     1
      _UpperCAmelCase			:int							=     1
      _UpperCAmelCase			:bool							=     True
      _UpperCAmelCase			:bool							=     False
      _UpperCAmelCase			:bool							=     False
      _UpperCAmelCase			:bool							=     False
      _UpperCAmelCase			:jnp.dtype							=     jnp.floataa





      def  __UpperCamelCase(				self     ):
       '''simple docstring'''




       UpperCamelCase			:      Any 			=     []
       UpperCamelCase			:      Any 			=     []

       for i in range(self.num_layers     ):
        UpperCamelCase			:      Optional[int] 			=     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			:      int 			=     FlaxResnetBlockaD(
            in_channels=resnet_in_channels + res_skip_channels ,							out_channels=self.out_channels ,							dropout_prob=self.dropout ,							dtype=self.dtype ,							)
        resnets.append(lowerCAmelCase_     )

        UpperCamelCase			:      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(lowerCAmelCase_     )

       UpperCamelCase			:      Optional[Any] 			=     resnets
       UpperCamelCase			:      int 			=     attentions

       if self.add_upsample:
        UpperCamelCase			:      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
        UpperCamelCase			:      int 			=     res_hidden_states_tuple[-1]
        UpperCamelCase			:      str 			=     res_hidden_states_tuple[:-1]
        UpperCamelCase			:      Any 			=     jnp.concatenate((hidden_states, res_hidden_states) ,							axis=-1     )

        UpperCamelCase			:      int 			=     resnet(lowerCAmelCase_ ,							lowerCAmelCase_ ,							deterministic=lowerCAmelCase_     )
        UpperCamelCase			:      Optional[Any] 			=     attn(lowerCAmelCase_ ,							lowerCAmelCase_ ,							deterministic=lowerCAmelCase_     )

       if self.add_upsample:
        UpperCamelCase			:      str 			=     self.upsamplers_a(lowerCAmelCase_     )

       return hidden_states



class       A__     ( nn.Module    ):
      _UpperCAmelCase			:int
      _UpperCAmelCase			:int
      _UpperCAmelCase			:int
      _UpperCAmelCase			:float							=     0.0
      _UpperCAmelCase			:int							=     1
      _UpperCAmelCase			:bool							=     True
      _UpperCAmelCase			:jnp.dtype							=     jnp.floataa





      def  __UpperCamelCase(				self     ):
       '''simple docstring'''




       UpperCamelCase			:      Optional[int] 			=     []

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

        UpperCamelCase			:      Dict 			=     FlaxResnetBlockaD(
            in_channels=resnet_in_channels + res_skip_channels ,							out_channels=self.out_channels ,							dropout_prob=self.dropout ,							dtype=self.dtype ,							)
        resnets.append(lowerCAmelCase_     )

       UpperCamelCase			:      Tuple 			=     resnets

       if self.add_upsample:
        UpperCamelCase			:      Optional[Any] 			=     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
        UpperCamelCase			:      Dict 			=     res_hidden_states_tuple[-1]
        UpperCamelCase			:      Optional[int] 			=     res_hidden_states_tuple[:-1]
        UpperCamelCase			:      List[Any] 			=     jnp.concatenate((hidden_states, res_hidden_states) ,							axis=-1     )

        UpperCamelCase			:      Optional[int] 			=     resnet(lowerCAmelCase_ ,							lowerCAmelCase_ ,							deterministic=lowerCAmelCase_     )

       if self.add_upsample:
        UpperCamelCase			:      Dict 			=     self.upsamplers_a(lowerCAmelCase_     )

       return hidden_states



class       A__     ( nn.Module    ):
      _UpperCAmelCase			:int
      _UpperCAmelCase			:float							=     0.0
      _UpperCAmelCase			:int							=     1
      _UpperCAmelCase			:int							=     1
      _UpperCAmelCase			:bool							=     False
      _UpperCAmelCase			:bool							=     False
      _UpperCAmelCase			:jnp.dtype							=     jnp.floataa





      def  __UpperCamelCase(				self     ):
       '''simple docstring'''




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

       UpperCamelCase			:      Optional[Any] 			=     []

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

        UpperCamelCase			:      List[str] 			=     FlaxResnetBlockaD(
            in_channels=self.in_channels ,							out_channels=self.in_channels ,							dropout_prob=self.dropout ,							dtype=self.dtype ,							)
        resnets.append(lowerCAmelCase_     )

       UpperCamelCase			:      Tuple 			=     resnets
       UpperCamelCase			:      List[Any] 			=     attentions





      def __call__(				self ,							A_ ,							A_ ,							A_ ,							A_=True     ):
       '''simple docstring'''




       UpperCamelCase			:      List[Any] 			=     self.resnets[0](lowerCAmelCase_ ,							lowerCAmelCase_     )
       for attn, resnet in zip(self.attentions ,							self.resnets[1:]     ):
        UpperCamelCase			:      int 			=     attn(lowerCAmelCase_ ,							lowerCAmelCase_ ,							deterministic=lowerCAmelCase_     )
        UpperCamelCase			:      Optional[int] 			=     resnet(lowerCAmelCase_ ,							lowerCAmelCase_ ,							deterministic=lowerCAmelCase_     )

       return hidden_states







from __future__ import annotations



def 	A_       (  _lowerCAmelCase  )		->				list[int]:
 UpperCamelCase			:      Optional[Any] 			=     [True] * limit
 UpperCamelCase			:      Optional[Any] 			=     False
 UpperCamelCase			:      List[str] 			=     False
 UpperCamelCase			:      Tuple 			=     True

 for i in range(3							,     int(limit**0.5 + 1  )							,     2  ):
  UpperCamelCase			:      Optional[Any] 			=     i * 2
  while index < limit:
   UpperCamelCase			:      int 			=     False
   UpperCamelCase			:      Optional[int] 			=     index + i

 UpperCamelCase			:      Any 			=     [2]

 for i in range(3							,     _lowerCAmelCase							,     2  ):
  if is_prime[i]:
   primes.append(_lowerCAmelCase  )

 return primes



def 	A_       (  _lowerCAmelCase = 100_0000  )		->				int:
 UpperCamelCase			:      Union[str, Any] 			=     prime_sieve(_lowerCAmelCase  )
 UpperCamelCase			:      List[str] 			=     0
 UpperCamelCase			:      Union[str, Any] 			=     0

 for i in range(len(_lowerCAmelCase  )  ):
  for j in range(i + length							,     len(_lowerCAmelCase  )  ):
   UpperCamelCase			:      Dict 			=     sum(primes[i:j]  )
   if sol >= ceiling:
    break

   if sol in primes:
    UpperCamelCase			:      int 			=     j - i
    UpperCamelCase			:      Dict 			=     sol

 return largest


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