





from dataclasses import dataclass
from typing import Dict, Optional, Tuple, Union

import torch
import torch.nn as nn

from ..configuration_utils import ConfigMixin, register_to_config
from ..utils import BaseOutput, apply_forward_hook
from .attention_processor import AttentionProcessor, AttnProcessor
from .modeling_utils import ModelMixin
from .vae import Decoder, DecoderOutput, DiagonalGaussianDistribution, Encoder
@dataclass
class     SCREAMING_SNAKE_CASE       (UpperCAmelCase				):
   _UpperCamelCase   :		"DiagonalGaussianDistribution"






class     SCREAMING_SNAKE_CASE       (UpperCAmelCase      ,     UpperCAmelCase				):
   _UpperCamelCase   :		Tuple			 =	True


   @register_to_config
   def __init__(   self      :    int      ,					a      :    int = 3      ,					a      :    int = 3      ,					a      :    Tuple[str] = ("DownEncoderBlock2D",)      ,					a      :    Tuple[str] = ("UpDecoderBlock2D",)      ,					a      :    Tuple[int] = (64,)      ,					a      :    int = 1      ,					a      :    str = "silu"      ,					a      :    int = 4      ,					a      :    int = 32      ,					a      :    int = 32      ,					a      :    float = 0.18215      ,					)->       Tuple:





     """simple docstring"""







     super().__init__()

     # pass init params to Encoder
     lowercase__           =  Encoder(
         in_channels=a      ,					out_channels=a      ,					down_block_types=a      ,					block_out_channels=a      ,					layers_per_block=a      ,					act_fn=a      ,					norm_num_groups=a      ,					double_z=a      ,					)

     # pass init params to Decoder
     lowercase__           =  Decoder(
         in_channels=a      ,					out_channels=a      ,					up_block_types=a      ,					block_out_channels=a      ,					layers_per_block=a      ,					norm_num_groups=a      ,					act_fn=a      ,					)

     lowercase__           =  nn.Convad(2 * latent_channels      ,					2 * latent_channels      ,					1	)
     lowercase__           =  nn.Convad(a      ,					a      ,					1	)

     lowercase__           =  False
     lowercase__           =  False

     # only relevant if vae tiling is enabled
     lowercase__           =  self.config.sample_size
     lowercase__           =  (
         self.config.sample_size[0]
         if isinstance(self.config.sample_size      ,					(list, tuple)	)
         else self.config.sample_size
     )
     lowercase__           =  int(sample_size / (2 ** (len(self.config.block_out_channels	) - 1))	)
     lowercase__           =  0.25


   def 	SCREAMING_SNAKE_CASE_							(   self      :    Optional[Any]      ,					a      :    Optional[int]      ,					a      :    Optional[int]=False	)->       Dict:





     """simple docstring"""







     if isinstance(a      ,					(Encoder, Decoder)	):
       lowercase__           =  value


   def 	SCREAMING_SNAKE_CASE_							(   self      :    Any      ,					a      :    bool = True	)->       Optional[int]:





     """simple docstring"""







     lowercase__           =  use_tiling


   def 	SCREAMING_SNAKE_CASE_							(   self      :    Dict	)->       str:





     """simple docstring"""







     self.enable_tiling(a	)


   def 	SCREAMING_SNAKE_CASE_							(   self      :    Optional[Any]	)->       int:





     """simple docstring"""







     lowercase__           =  True


   def 	SCREAMING_SNAKE_CASE_							(   self      :    List[Any]	)->       Optional[int]:





     """simple docstring"""







     lowercase__           =  False


   @property
   # Copied from diffusers.models.unet_2d_condition.UNet2DConditionModel.attn_processors
   def 	SCREAMING_SNAKE_CASE_							(   self      :    Optional[Any]	)->       Dict[str, AttentionProcessor]:





     """simple docstring"""







     lowercase__           =  {}

     def fn_recursive_add_processors(a      :    str      ,					a      :    torch.nn.Module      ,					a      :    Dict[str, AttentionProcessor]	):
       if hasattr(a      ,					'set_processor'	):
         lowercase__           =  module.processor

       for sub_name, child in module.named_children():
         fn_recursive_add_processors(f"""{name}.{sub_name}"""      ,					a      ,					a	)

       return processors

     for name, module in self.named_children():
       fn_recursive_add_processors(a      ,					a      ,					a	)

     return processors


   def 	SCREAMING_SNAKE_CASE_							(   self      :    Dict      ,					a      :    Union[AttentionProcessor, Dict[str, AttentionProcessor]]	)->       Optional[Any]:





     """simple docstring"""







     lowercase__           =  len(self.attn_processors.keys()	)

     if isinstance(a      ,					a	) and len(a	) != count:
       raise ValueError(
           f"""A dict of processors was passed, but the number of processors {len(a	)} does not match the"""
           f""" number of attention layers: {count}. Please make sure to pass {count} processor classes."""	)

     def fn_recursive_attn_processor(a      :    str      ,					a      :    torch.nn.Module      ,					a      :    str	):
       if hasattr(a      ,					'set_processor'	):
         if not isinstance(a      ,					a	):
           module.set_processor(a	)
         else:
           module.set_processor(processor.pop(f"""{name}.processor"""	)	)

       for sub_name, child in module.named_children():
         fn_recursive_attn_processor(f"""{name}.{sub_name}"""      ,					a      ,					a	)

     for name, module in self.named_children():
       fn_recursive_attn_processor(a      ,					a      ,					a	)


   def 	SCREAMING_SNAKE_CASE_							(   self      :    str	)->       int:





     """simple docstring"""







     self.set_attn_processor(AttnProcessor()	)


   @apply_forward_hook
   def 	SCREAMING_SNAKE_CASE_							(   self      :    Tuple      ,					a      :    torch.FloatTensor      ,					a      :    bool = True	)->       AutoencoderKLOutput:





     """simple docstring"""







     if self.use_tiling and (x.shape[-1] > self.tile_sample_min_size or x.shape[-2] > self.tile_sample_min_size):
       return self.tiled_encode(a      ,					return_dict=a	)

     if self.use_slicing and x.shape[0] > 1:
       lowercase__           =  [self.encoder(a	) for x_slice in x.split(1	)]
       lowercase__           =  torch.cat(a	)
     else:
       lowercase__           =  self.encoder(a	)

     lowercase__           =  self.quant_conv(a	)
     lowercase__           =  DiagonalGaussianDistribution(a	)

     if not return_dict:
       return (posterior,)

     return AutoencoderKLOutput(latent_dist=a	)


   def 	SCREAMING_SNAKE_CASE_							(   self      :    Dict      ,					a      :    torch.FloatTensor      ,					a      :    bool = True	)->       Union[DecoderOutput, torch.FloatTensor]:





     """simple docstring"""







     if self.use_tiling and (z.shape[-1] > self.tile_latent_min_size or z.shape[-2] > self.tile_latent_min_size):
       return self.tiled_decode(a      ,					return_dict=a	)

     lowercase__           =  self.post_quant_conv(a	)
     lowercase__           =  self.decoder(a	)

     if not return_dict:
       return (dec,)

     return DecoderOutput(sample=a	)


   @apply_forward_hook
   def 	SCREAMING_SNAKE_CASE_							(   self      :    List[Any]      ,					a      :    torch.FloatTensor      ,					a      :    bool = True	)->       Union[DecoderOutput, torch.FloatTensor]:





     """simple docstring"""







     if self.use_slicing and z.shape[0] > 1:
       lowercase__           =  [self._decode(a	).sample for z_slice in z.split(1	)]
       lowercase__           =  torch.cat(a	)
     else:
       lowercase__           =  self._decode(a	).sample

     if not return_dict:
       return (decoded,)

     return DecoderOutput(sample=a	)


   def 	SCREAMING_SNAKE_CASE_							(   self      :    List[str]      ,					a      :    Tuple      ,					a      :    int      ,					a      :    Union[str, Any]	)->       Optional[Any]:





     """simple docstring"""







     lowercase__           =  min(a.shape[2]      ,					b.shape[2]      ,					a	)
     for y in range(a	):
       lowercase__           =  a[:, :, -blend_extent + y, :] * (1 - y / blend_extent) + b[:, :, y, :] * (y / blend_extent)
     return b


   def 	SCREAMING_SNAKE_CASE_							(   self      :    Union[str, Any]      ,					a      :    Dict      ,					a      :    Optional[Any]      ,					a      :    Optional[int]	)->       List[str]:





     """simple docstring"""







     lowercase__           =  min(a.shape[3]      ,					b.shape[3]      ,					a	)
     for x in range(a	):
       lowercase__           =  a[:, :, :, -blend_extent + x] * (1 - x / blend_extent) + b[:, :, :, x] * (x / blend_extent)
     return b


   def 	SCREAMING_SNAKE_CASE_							(   self      :    Tuple      ,					a      :    torch.FloatTensor      ,					a      :    bool = True	)->       AutoencoderKLOutput:





     """simple docstring"""







     lowercase__           =  int(self.tile_sample_min_size * (1 - self.tile_overlap_factor)	)
     lowercase__           =  int(self.tile_latent_min_size * self.tile_overlap_factor	)
     lowercase__           =  self.tile_latent_min_size - blend_extent

     # Split the image into 512x512 tiles and encode them separately.
     lowercase__           =  []
     for i in range(0      ,					x.shape[2]      ,					a	):
       lowercase__           =  []
       for j in range(0      ,					x.shape[3]      ,					a	):
         lowercase__           =  x[:, :, i : i + self.tile_sample_min_size, j : j + self.tile_sample_min_size]
         lowercase__           =  self.encoder(a	)
         lowercase__           =  self.quant_conv(a	)
         row.append(a	)
       rows.append(a	)
     lowercase__           =  []
     for i, row in enumerate(a	):
       lowercase__           =  []
       for j, tile in enumerate(a	):
         # blend the above tile and the left tile
         # to the current tile and add the current tile to the result row
         if i > 0:
           lowercase__           =  self.blend_v(rows[i - 1][j]      ,					a      ,					a	)
         if j > 0:
           lowercase__           =  self.blend_h(row[j - 1]      ,					a      ,					a	)
         result_row.append(tile[:, :, :row_limit, :row_limit]	)
       result_rows.append(torch.cat(a      ,					dim=3	)	)

     lowercase__           =  torch.cat(a      ,					dim=2	)
     lowercase__           =  DiagonalGaussianDistribution(a	)

     if not return_dict:
       return (posterior,)

     return AutoencoderKLOutput(latent_dist=a	)


   def 	SCREAMING_SNAKE_CASE_							(   self      :    List[Any]      ,					a      :    torch.FloatTensor      ,					a      :    bool = True	)->       Union[DecoderOutput, torch.FloatTensor]:





     """simple docstring"""







     lowercase__           =  int(self.tile_latent_min_size * (1 - self.tile_overlap_factor)	)
     lowercase__           =  int(self.tile_sample_min_size * self.tile_overlap_factor	)
     lowercase__           =  self.tile_sample_min_size - blend_extent

     # Split z into overlapping 64x64 tiles and decode them separately.
     # The tiles have an overlap to avoid seams between tiles.
     lowercase__           =  []
     for i in range(0      ,					z.shape[2]      ,					a	):
       lowercase__           =  []
       for j in range(0      ,					z.shape[3]      ,					a	):
         lowercase__           =  z[:, :, i : i + self.tile_latent_min_size, j : j + self.tile_latent_min_size]
         lowercase__           =  self.post_quant_conv(a	)
         lowercase__           =  self.decoder(a	)
         row.append(a	)
       rows.append(a	)
     lowercase__           =  []
     for i, row in enumerate(a	):
       lowercase__           =  []
       for j, tile in enumerate(a	):
         # blend the above tile and the left tile
         # to the current tile and add the current tile to the result row
         if i > 0:
           lowercase__           =  self.blend_v(rows[i - 1][j]      ,					a      ,					a	)
         if j > 0:
           lowercase__           =  self.blend_h(row[j - 1]      ,					a      ,					a	)
         result_row.append(tile[:, :, :row_limit, :row_limit]	)
       result_rows.append(torch.cat(a      ,					dim=3	)	)

     lowercase__           =  torch.cat(a      ,					dim=2	)
     if not return_dict:
       return (dec,)

     return DecoderOutput(sample=a	)


   def 	SCREAMING_SNAKE_CASE_							(   self      :    Optional[Any]      ,					a      :    torch.FloatTensor      ,					a      :    bool = False      ,					a      :    bool = True      ,					a      :    Optional[torch.Generator] = None      ,					)->       Union[DecoderOutput, torch.FloatTensor]:





     """simple docstring"""







     lowercase__           =  sample
     lowercase__           =  self.encode(a	).latent_dist
     if sample_posterior:
       lowercase__           =  posterior.sample(generator=a	)
     else:
       lowercase__           =  posterior.mode()
     lowercase__           =  self.decode(a	).sample

     if not return_dict:
       return (dec,)

     return DecoderOutput(sample=a	)









import sys

lowercase_          =		(
    """73167176531330624919225119674426574742355349194934"""
    """96983520312774506326239578318016984801869478851843"""
    """85861560789112949495459501737958331952853208805511"""
    """12540698747158523863050715693290963295227443043557"""
    """66896648950445244523161731856403098711121722383113"""
    """62229893423380308135336276614282806444486645238749"""
    """30358907296290491560440772390713810515859307960866"""
    """70172427121883998797908792274921901699720888093776"""
    """65727333001053367881220235421809751254540594752243"""
    """52584907711670556013604839586446706324415722155397"""
    """53697817977846174064955149290862569321978468622482"""
    """83972241375657056057490261407972968652414535100474"""
    """82166370484403199890008895243450658541227588666881"""
    """16427171479924442928230863465674813919123162824586"""
    """17866458359124566529476545682848912883142607690042"""
    """24219022671055626321111109370544217506941658960408"""
    """07198403850962455444362981230987879927244284909188"""
    """84580156166097919133875499200524063689912560717606"""
    """05886116467109405077541002256983155200055935729725"""
    """71636269561882670428252483600823257530420752963450"""
)




def       __UpperCamelCase  (_SCREAMING_SNAKE_CASE = N		)    ->       int:
  lowercase__           =  -sys.maxsize - 1
  for i in range(len(_SCREAMING_SNAKE_CASE		) - 12		):
    lowercase__           =  1
    for j in range(13		):
      product *= int(n[i + j]		)
    if product > largest_product:
      lowercase__           =  product
  return largest_product


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


