


"""simple docstring"""






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      A(  lowerCamelCase__		):

		"""simple docstring"""





		A    =							42






class      A(  lowerCamelCase__				,							lowerCamelCase__		):

		"""simple docstring"""





		A    =							True
		@register_to_config
		def __init__( self					,				SCREAMING_SNAKE_CASE__ = 3					,				SCREAMING_SNAKE_CASE__ = 3					,				SCREAMING_SNAKE_CASE__ = ("DownEncoderBlock2D",)					,				SCREAMING_SNAKE_CASE__ = ("UpDecoderBlock2D",)					,				SCREAMING_SNAKE_CASE__ = (64,)					,				SCREAMING_SNAKE_CASE__ = 1					,				SCREAMING_SNAKE_CASE__ = "silu"					,				SCREAMING_SNAKE_CASE__ = 4					,				SCREAMING_SNAKE_CASE__ = 32					,				SCREAMING_SNAKE_CASE__ = 32					,				SCREAMING_SNAKE_CASE__ = 0.1_8_2_1_5					,				)      ->	Optional[Any]:

					"""simple docstring"""



					super().__init__()

					# pass init params to Encoder
					_UpperCamelCase					:List[str]					     =	Encoder(
					    in_channels=SCREAMING_SNAKE_CASE__					,				out_channels=SCREAMING_SNAKE_CASE__					,				down_block_types=SCREAMING_SNAKE_CASE__					,				block_out_channels=SCREAMING_SNAKE_CASE__					,				layers_per_block=SCREAMING_SNAKE_CASE__					,				act_fn=SCREAMING_SNAKE_CASE__					,				norm_num_groups=SCREAMING_SNAKE_CASE__					,				double_z=SCREAMING_SNAKE_CASE__					,				)

					# pass init params to Decoder
					_UpperCamelCase					:int					     =	Decoder(
					    in_channels=SCREAMING_SNAKE_CASE__					,				out_channels=SCREAMING_SNAKE_CASE__					,				up_block_types=SCREAMING_SNAKE_CASE__					,				block_out_channels=SCREAMING_SNAKE_CASE__					,				layers_per_block=SCREAMING_SNAKE_CASE__					,				norm_num_groups=SCREAMING_SNAKE_CASE__					,				act_fn=SCREAMING_SNAKE_CASE__					,				)

					_UpperCamelCase					:Any					     =	nn.Convad(2 * latent_channels					,				2 * latent_channels					,				1   )
					_UpperCamelCase					:Union[str, Any]					     =	nn.Convad(SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__					,				1   )

					_UpperCamelCase					:List[Any]					     =	False
					_UpperCamelCase					:List[str]					     =	False

					# only relevant if vae tiling is enabled
					_UpperCamelCase					:Any					     =	self.config.sample_size
					_UpperCamelCase					:Optional[Any]					     =	(
					    self.config.sample_size[0]
					    if isinstance(self.config.sample_size					,				(list, tuple)   )
					    else self.config.sample_size
					)
					_UpperCamelCase					:Optional[Any]					     =	int(sample_size / (2 ** (len(self.config.block_out_channels   ) - 1))   )
					_UpperCamelCase					:Tuple					     =	0.2_5
		def   _UpperCamelCase( self					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__=False   )      ->	Optional[Any]:

					"""simple docstring"""



					if isinstance(SCREAMING_SNAKE_CASE__					,				(Encoder, Decoder)   ):
								_UpperCamelCase					:Optional[Any]					     =	value
		def   _UpperCamelCase( self					,				SCREAMING_SNAKE_CASE__ = True   )      ->	int:

					"""simple docstring"""



					_UpperCamelCase					:int					     =	use_tiling
		def   _UpperCamelCase( self   )      ->	Any:

					"""simple docstring"""



					self.enable_tiling(SCREAMING_SNAKE_CASE__   )
		def   _UpperCamelCase( self   )      ->	Any:

					"""simple docstring"""



					_UpperCamelCase					:Optional[int]					     =	True
		def   _UpperCamelCase( self   )      ->	List[Any]:

					"""simple docstring"""



					_UpperCamelCase					:Tuple					     =	False
		@property
		# Copied from diffusers.models.unet_2d_condition.UNet2DConditionModel.attn_processors
		def   _UpperCamelCase( self   )      ->	Dict[str, AttentionProcessor]:

					"""simple docstring"""



					_UpperCamelCase					:str					     =	{}

					def fn_recursive_add_processors(SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__   ):
								if hasattr(SCREAMING_SNAKE_CASE__					,				'''set_processor'''   ):
											_UpperCamelCase					:Any					     =	module.processor

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

								return processors

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

					return processors
		def   _UpperCamelCase( self					,				SCREAMING_SNAKE_CASE__   )      ->	Union[str, Any]:

					"""simple docstring"""



					_UpperCamelCase					:List[Any]					     =	len(self.attn_processors.keys()   )

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

					def fn_recursive_attn_processor(SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__   ):
								if hasattr(SCREAMING_SNAKE_CASE__					,				'''set_processor'''   ):
											if not isinstance(SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__   ):
														module.set_processor(SCREAMING_SNAKE_CASE__   )
											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}"					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__   )

					for name, module in self.named_children():
								fn_recursive_attn_processor(SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__   )
		def   _UpperCamelCase( self   )      ->	Dict:

					"""simple docstring"""



					self.set_attn_processor(AttnProcessor()   )
		@apply_forward_hook
		def   _UpperCamelCase( self					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__ = 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(SCREAMING_SNAKE_CASE__					,				return_dict=SCREAMING_SNAKE_CASE__   )

					if self.use_slicing and x.shape[0] > 1:
								_UpperCamelCase					:int					     =	[self.encoder(SCREAMING_SNAKE_CASE__   ) for x_slice in x.split(1   )]
								_UpperCamelCase					:Tuple					     =	torch.cat(SCREAMING_SNAKE_CASE__   )
					else:
								_UpperCamelCase					:Optional[int]					     =	self.encoder(SCREAMING_SNAKE_CASE__   )

					_UpperCamelCase					:List[str]					     =	self.quant_conv(SCREAMING_SNAKE_CASE__   )
					_UpperCamelCase					:List[str]					     =	DiagonalGaussianDistribution(SCREAMING_SNAKE_CASE__   )

					if not return_dict:
								return (posterior,)

					return AutoencoderKLOutput(latent_dist=SCREAMING_SNAKE_CASE__   )
		def   _UpperCamelCase( self					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__ = 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(SCREAMING_SNAKE_CASE__					,				return_dict=SCREAMING_SNAKE_CASE__   )

					_UpperCamelCase					:List[str]					     =	self.post_quant_conv(SCREAMING_SNAKE_CASE__   )
					_UpperCamelCase					:int					     =	self.decoder(SCREAMING_SNAKE_CASE__   )

					if not return_dict:
								return (dec,)

					return DecoderOutput(sample=SCREAMING_SNAKE_CASE__   )
		@apply_forward_hook
		def   _UpperCamelCase( self					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__ = True   )      ->	Union[DecoderOutput, torch.FloatTensor]:

					"""simple docstring"""



					if self.use_slicing and z.shape[0] > 1:
								_UpperCamelCase					:Dict					     =	[self._decode(SCREAMING_SNAKE_CASE__   ).sample for z_slice in z.split(1   )]
								_UpperCamelCase					:Any					     =	torch.cat(SCREAMING_SNAKE_CASE__   )
					else:
								_UpperCamelCase					:Optional[int]					     =	self._decode(SCREAMING_SNAKE_CASE__   ).sample

					if not return_dict:
								return (decoded,)

					return DecoderOutput(sample=SCREAMING_SNAKE_CASE__   )
		def   _UpperCamelCase( self					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__   )      ->	Union[str, Any]:

					"""simple docstring"""



					_UpperCamelCase					:Tuple					     =	min(a.shape[2]					,				b.shape[2]					,				SCREAMING_SNAKE_CASE__   )
					for y in range(SCREAMING_SNAKE_CASE__   ):
								_UpperCamelCase					:int					     =	a[:, :, -blend_extent + y, :] * (1 - y / blend_extent) + b[:, :, y, :] * (y / blend_extent)
					return b
		def   _UpperCamelCase( self					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__   )      ->	List[str]:

					"""simple docstring"""



					_UpperCamelCase					:Dict					     =	min(a.shape[3]					,				b.shape[3]					,				SCREAMING_SNAKE_CASE__   )
					for x in range(SCREAMING_SNAKE_CASE__   ):
								_UpperCamelCase					:Tuple					     =	a[:, :, :, -blend_extent + x] * (1 - x / blend_extent) + b[:, :, :, x] * (x / blend_extent)
					return b
		def   _UpperCamelCase( self					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__ = True   )      ->	AutoencoderKLOutput:

					"""simple docstring"""



					_UpperCamelCase					:Optional[Any]					     =	int(self.tile_sample_min_size * (1 - self.tile_overlap_factor)   )
					_UpperCamelCase					:int					     =	int(self.tile_latent_min_size * self.tile_overlap_factor   )
					_UpperCamelCase					:int					     =	self.tile_latent_min_size - blend_extent

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

					_UpperCamelCase					:Any					     =	torch.cat(SCREAMING_SNAKE_CASE__					,				dim=2   )
					_UpperCamelCase					:Union[str, Any]					     =	DiagonalGaussianDistribution(SCREAMING_SNAKE_CASE__   )

					if not return_dict:
								return (posterior,)

					return AutoencoderKLOutput(latent_dist=SCREAMING_SNAKE_CASE__   )
		def   _UpperCamelCase( self					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__ = True   )      ->	Union[DecoderOutput, torch.FloatTensor]:

					"""simple docstring"""



					_UpperCamelCase					:Union[str, Any]					     =	int(self.tile_latent_min_size * (1 - self.tile_overlap_factor)   )
					_UpperCamelCase					:Tuple					     =	int(self.tile_sample_min_size * self.tile_overlap_factor   )
					_UpperCamelCase					:List[str]					     =	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.
					_UpperCamelCase					:Optional[int]					     =	[]
					for i in range(0					,				z.shape[2]					,				SCREAMING_SNAKE_CASE__   ):
								_UpperCamelCase					:List[str]					     =	[]
								for j in range(0					,				z.shape[3]					,				SCREAMING_SNAKE_CASE__   ):
											_UpperCamelCase					:List[str]					     =	z[:, :, i : i + self.tile_latent_min_size, j : j + self.tile_latent_min_size]
											_UpperCamelCase					:Tuple					     =	self.post_quant_conv(SCREAMING_SNAKE_CASE__   )
											_UpperCamelCase					:List[str]					     =	self.decoder(SCREAMING_SNAKE_CASE__   )
											row.append(SCREAMING_SNAKE_CASE__   )
								rows.append(SCREAMING_SNAKE_CASE__   )
					_UpperCamelCase					:Optional[Any]					     =	[]
					for i, row in enumerate(SCREAMING_SNAKE_CASE__   ):
								_UpperCamelCase					:Union[str, Any]					     =	[]
								for j, tile in enumerate(SCREAMING_SNAKE_CASE__   ):
											# blend the above tile and the left tile
											# to the current tile and add the current tile to the result row
											if i > 0:
														_UpperCamelCase					:Dict					     =	self.blend_v(rows[i - 1][j]					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__   )
											if j > 0:
														_UpperCamelCase					:Any					     =	self.blend_h(row[j - 1]					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__   )
											result_row.append(tile[:, :, :row_limit, :row_limit]   )
								result_rows.append(torch.cat(SCREAMING_SNAKE_CASE__					,				dim=3   )   )

					_UpperCamelCase					:Union[str, Any]					     =	torch.cat(SCREAMING_SNAKE_CASE__					,				dim=2   )
					if not return_dict:
								return (dec,)

					return DecoderOutput(sample=SCREAMING_SNAKE_CASE__   )





		def   _UpperCamelCase( self					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__ = False					,				SCREAMING_SNAKE_CASE__ = True					,				SCREAMING_SNAKE_CASE__ = None					,				)      ->	Union[DecoderOutput, torch.FloatTensor]:

					"""simple docstring"""



					_UpperCamelCase					:int					     =	sample
					_UpperCamelCase					:Any					     =	self.encode(SCREAMING_SNAKE_CASE__   ).latent_dist
					if sample_posterior:
								_UpperCamelCase					:Optional[int]					     =	posterior.sample(generator=SCREAMING_SNAKE_CASE__   )
					else:
								_UpperCamelCase					:Tuple					     =	posterior.mode()
					_UpperCamelCase					:Tuple					     =	self.decode(SCREAMING_SNAKE_CASE__   ).sample

					if not return_dict:
								return (dec,)

					return DecoderOutput(sample=SCREAMING_SNAKE_CASE__   )





"""simple docstring"""






import os





def 				A_       ( )					->  Any:
			with open(os.path.dirname(snake_case__		) + '''/p022_names.txt'''		) as file:
						_UpperCamelCase					:Optional[Any]					     =	str(file.readlines()[0]		)
						_UpperCamelCase					:Dict					     =	names.replace('''"'''       ,					''''''		).split(''','''		)

			names.sort()

			_UpperCamelCase					:str					     =	0
			_UpperCamelCase					:Union[str, Any]					     =	0

			for i, name in enumerate(snake_case__		):
						for letter in name:
									name_score += ord(snake_case__		) - 64

						total_score += (i + 1) * name_score
						_UpperCamelCase					:List[Any]					     =	0
			return total_score


if __name__ == "__main__":
					print(solution())

