



'''simple docstring'''

import math

import torch
from torch import nn

from ..configuration_utils import ConfigMixin, register_to_config
from .attention_processor import Attention
from .embeddings import get_timestep_embedding
from .modeling_utils import ModelMixin

class __snake_case(				_lowerCAmelCase		,							_lowerCAmelCase ):


						'''simple docstring'''



						@register_to_config
						def __init__( self     ,	A_ = 128     ,	A_ = 256     ,	A_ = 2_0_0_0.0     ,	A_ = 768     ,	A_ = 12     ,	A_ = 12     ,	A_ = 64     ,	A_ = 2048     ,	A_ = 0.1     ,	)     ->     List[Any]:
							super().__init__()

							lowerCAmelCase   =     nn.Sequential(
							    nn.Linear(A_     ,	d_model * 4     ,	bias=A_				)     ,	nn.SiLU()     ,	nn.Linear(d_model * 4     ,	d_model * 4     ,	bias=A_				)     ,	nn.SiLU()     ,	)

							lowerCAmelCase   =     nn.Embedding(A_     ,	A_				)
							lowerCAmelCase   =     False

							lowerCAmelCase   =     nn.Linear(A_     ,	A_     ,	bias=A_				)

							lowerCAmelCase   =     nn.Dropout(p=A_				)

							lowerCAmelCase   =     nn.ModuleList()
							for lyr_num in range(A_				):
								# FiLM conditional T5 decoder
								lowerCAmelCase   =     DecoderLayer(d_model=A_     ,	d_kv=A_     ,	num_heads=A_     ,	d_ff=A_     ,	dropout_rate=A_				)
								self.decoders.append(A_				)

							lowerCAmelCase   =     TaLayerNorm(A_				)

							lowerCAmelCase   =     nn.Dropout(p=A_				)
							lowerCAmelCase   =     nn.Linear(A_     ,	A_     ,	bias=A_				)


						def     __snake_case   ( self     ,	A_     ,	A_				)     ->     Any:
							lowerCAmelCase   =     torch.mul(query_input.unsqueeze(-1				)     ,	key_input.unsqueeze(-2				)				)
							return mask.unsqueeze(-3				)




						def     __snake_case   ( self     ,	A_     ,	A_     ,	A_				)     ->     Optional[int]:
							lowerCAmelCase,       lowerCAmelCase,       lowerCAmelCase   =     decoder_input_tokens.shape
							assert decoder_noise_time.shape == (batch,)

							# decoder_noise_time is in [0, 1), so rescale to expected timing range.
							lowerCAmelCase   =     get_timestep_embedding(
							    decoder_noise_time * self.config.max_decoder_noise_time     ,	embedding_dim=self.config.d_model     ,	max_period=self.config.max_decoder_noise_time     ,	).to(dtype=self.dtype				)

							lowerCAmelCase   =     self.conditioning_emb(A_				).unsqueeze(1				)

							assert conditioning_emb.shape == (batch, 1, self.config.d_model * 4)

							lowerCAmelCase   =     decoder_input_tokens.shape[1]

							# If we want to use relative positions for audio context, we can just offset
							# this sequence by the length of encodings_and_masks.
							lowerCAmelCase   =     torch.broadcast_to(
							    torch.arange(A_     ,	device=decoder_input_tokens.device				)     ,	(batch, seq_length)     ,	)

							lowerCAmelCase   =     self.position_encoding(A_				)

							lowerCAmelCase   =     self.continuous_inputs_projection(A_				)
							inputs += position_encodings
							lowerCAmelCase   =     self.dropout(A_				)

							# decoder: No padding present.
							lowerCAmelCase   =     torch.ones(
							    decoder_input_tokens.shape[:2]     ,	device=decoder_input_tokens.device     ,	dtype=inputs.dtype				)

							# Translate encoding masks to encoder-decoder masks.
							lowerCAmelCase   =     [(x, self.encoder_decoder_mask(A_     ,	A_				)) for x, y in encodings_and_masks]

							# cross attend style: concat encodings
							lowerCAmelCase   =     torch.cat([x[0] for x in encodings_and_encdec_masks]     ,	dim=1				)
							lowerCAmelCase   =     torch.cat([x[1] for x in encodings_and_encdec_masks]     ,	dim=-1				)

							for lyr in self.decoders:
								lowerCAmelCase   =     lyr(
								    A_     ,	conditioning_emb=A_     ,	encoder_hidden_states=A_     ,	encoder_attention_mask=A_     ,	)[0]

							lowerCAmelCase   =     self.decoder_norm(A_				)
							lowerCAmelCase   =     self.post_dropout(A_				)

							lowerCAmelCase   =     self.spec_out(A_				)
							return spec_out







class __snake_case(				nn.Module ):


						'''simple docstring'''



						def __init__( self     ,	A_     ,	A_     ,	A_     ,	A_     ,	A_     ,	A_=1e-6				)     ->     Any:
							super().__init__()
							lowerCAmelCase   =     nn.ModuleList()

							# cond self attention: layer 0
							self.layer.append(
							    TaLayerSelfAttentionCond(d_model=A_     ,	d_kv=A_     ,	num_heads=A_     ,	dropout_rate=A_				)				)

							# cross attention: layer 1
							self.layer.append(
							    TaLayerCrossAttention(
							        d_model=A_     ,	d_kv=A_     ,	num_heads=A_     ,	dropout_rate=A_     ,	layer_norm_epsilon=A_     ,	)				)

							# Film Cond MLP + dropout: last layer
							self.layer.append(
							    TaLayerFFCond(d_model=A_     ,	d_ff=A_     ,	dropout_rate=A_     ,	layer_norm_epsilon=A_				)				)




						def     __snake_case   ( self     ,	A_     ,	A_=None     ,	A_=None     ,	A_=None     ,	A_=None     ,	A_=None     ,	)     ->     List[str]:
							lowerCAmelCase   =     self.layer[0](
							    A_     ,	conditioning_emb=A_     ,	attention_mask=A_     ,	)

							if encoder_hidden_states is not None:
								lowerCAmelCase   =     torch.where(encoder_attention_mask > 0     ,	0     ,	-1e10				).to(
								    encoder_hidden_states.dtype				)

								lowerCAmelCase   =     self.layer[1](
								    A_     ,	key_value_states=A_     ,	attention_mask=A_     ,	)

							# Apply Film Conditional Feed Forward layer
							lowerCAmelCase   =     self.layer[-1](A_     ,	A_				)

							return (hidden_states,)







class __snake_case(				nn.Module ):


						'''simple docstring'''



						def __init__( self     ,	A_     ,	A_     ,	A_     ,	A_				)     ->     Any:
							super().__init__()
							lowerCAmelCase   =     TaLayerNorm(A_				)
							lowerCAmelCase   =     TaFiLMLayer(in_features=d_model * 4     ,	out_features=A_				)
							lowerCAmelCase   =     Attention(query_dim=A_     ,	heads=A_     ,	dim_head=A_     ,	out_bias=A_     ,	scale_qk=A_				)
							lowerCAmelCase   =     nn.Dropout(A_				)




						def     __snake_case   ( self     ,	A_     ,	A_=None     ,	A_=None     ,	)     ->     List[str]:
							# pre_self_attention_layer_norm
							lowerCAmelCase   =     self.layer_norm(A_				)

							if conditioning_emb is not None:
								lowerCAmelCase   =     self.FiLMLayer(A_     ,	A_				)

							# Self-attention block
							lowerCAmelCase   =     self.attention(A_				)

							lowerCAmelCase   =     hidden_states + self.dropout(A_				)

							return hidden_states







class __snake_case(				nn.Module ):


						'''simple docstring'''



						def __init__( self     ,	A_     ,	A_     ,	A_     ,	A_     ,	A_				)     ->     Union[str, Any]:
							super().__init__()
							lowerCAmelCase   =     Attention(query_dim=A_     ,	heads=A_     ,	dim_head=A_     ,	out_bias=A_     ,	scale_qk=A_				)
							lowerCAmelCase   =     TaLayerNorm(A_     ,	eps=A_				)
							lowerCAmelCase   =     nn.Dropout(A_				)




						def     __snake_case   ( self     ,	A_     ,	A_=None     ,	A_=None     ,	)     ->     str:
							lowerCAmelCase   =     self.layer_norm(A_				)
							lowerCAmelCase   =     self.attention(
							    A_     ,	encoder_hidden_states=A_     ,	attention_mask=attention_mask.squeeze(1				)     ,	)
							lowerCAmelCase   =     hidden_states + self.dropout(A_				)
							return layer_output







class __snake_case(				nn.Module ):


						'''simple docstring'''



						def __init__( self     ,	A_     ,	A_     ,	A_     ,	A_				)     ->     Optional[Any]:
							super().__init__()
							lowerCAmelCase   =     TaDenseGatedActDense(d_model=A_     ,	d_ff=A_     ,	dropout_rate=A_				)
							lowerCAmelCase   =     TaFiLMLayer(in_features=d_model * 4     ,	out_features=A_				)
							lowerCAmelCase   =     TaLayerNorm(A_     ,	eps=A_				)
							lowerCAmelCase   =     nn.Dropout(A_				)




						def     __snake_case   ( self     ,	A_     ,	A_=None				)     ->     List[str]:
							lowerCAmelCase   =     self.layer_norm(A_				)
							if conditioning_emb is not None:
								lowerCAmelCase   =     self.film(A_     ,	A_				)

							lowerCAmelCase   =     self.DenseReluDense(A_				)
							lowerCAmelCase   =     hidden_states + self.dropout(A_				)
							return hidden_states







class __snake_case(				nn.Module ):


						'''simple docstring'''



						def __init__( self     ,	A_     ,	A_     ,	A_				)     ->     List[Any]:
							super().__init__()
							lowerCAmelCase   =     nn.Linear(A_     ,	A_     ,	bias=A_				)
							lowerCAmelCase   =     nn.Linear(A_     ,	A_     ,	bias=A_				)
							lowerCAmelCase   =     nn.Linear(A_     ,	A_     ,	bias=A_				)
							lowerCAmelCase   =     nn.Dropout(A_				)
							lowerCAmelCase   =     NewGELUActivation()




						def     __snake_case   ( self     ,	A_				)     ->     List[str]:
							lowerCAmelCase   =     self.act(self.wi_a(A_				)				)
							lowerCAmelCase   =     self.wi_a(A_				)
							lowerCAmelCase   =     hidden_gelu * hidden_linear
							lowerCAmelCase   =     self.dropout(A_				)

							lowerCAmelCase   =     self.wo(A_				)
							return hidden_states







class __snake_case(				nn.Module ):


						'''simple docstring'''



						def __init__( self     ,	A_     ,	A_=1e-6				)     ->     Optional[int]:
							super().__init__()
							lowerCAmelCase   =     nn.Parameter(torch.ones(A_				)				)
							lowerCAmelCase   =     eps




						def     __snake_case   ( self     ,	A_				)     ->     Union[str, Any]:
							# T5 uses a layer_norm which only scales and doesn't shift, which is also known as Root Mean
							# Square Layer Normalization https://arxiv.org/abs/1910.07467 thus variance is calculated
							# w/o mean and there is no bias. Additionally we want to make sure that the accumulation for
							# half-precision inputs is done in fp32

							lowerCAmelCase   =     hidden_states.to(torch.floataa				).pow(2				).mean(-1     ,	keepdim=A_				)
							lowerCAmelCase   =     hidden_states * torch.rsqrt(variance + self.variance_epsilon				)

							# convert into half-precision if necessary
							if self.weight.dtype in [torch.floataa, torch.bfloataa]:
								lowerCAmelCase   =     hidden_states.to(self.weight.dtype				)

							return self.weight * hidden_states







class __snake_case(				nn.Module ):


						'''simple docstring'''



						def     __snake_case   ( self     ,	A_				)     ->     torch.Tensor:
							return 0.5 * input * (1.0 + torch.tanh(math.sqrt(2.0 / math.pi				) * (input + 0.0_4_4_7_1_5 * torch.pow(A_     ,	3.0				))				))







class __snake_case(				nn.Module ):


						'''simple docstring'''



						def __init__( self     ,	A_     ,	A_				)     ->     Tuple:
							super().__init__()
							lowerCAmelCase   =     nn.Linear(A_     ,	out_features * 2     ,	bias=A_				)




						def     __snake_case   ( self     ,	A_     ,	A_				)     ->     Optional[int]:
							lowerCAmelCase   =     self.scale_bias(A_				)
							lowerCAmelCase,       lowerCAmelCase   =     torch.chunk(A_     ,	2     ,	-1				)
							lowerCAmelCase   =     x * (1 + scale) + shift
							return x




'''simple docstring'''

from __future__ import annotations






def 		_snake_case		( _SCREAMING_SNAKE_CASE					:						int | str							)      ->						bool:







	"""simple docstring"""
	lowerCAmelCase   =     str(_SCREAMING_SNAKE_CASE							)
	return n == n[::-1]






def 		_snake_case		( _SCREAMING_SNAKE_CASE					:						int = 1_000_000							)      ->						Dict:







	"""simple docstring"""
	lowerCAmelCase   =     0

	for i in range(1							,		_SCREAMING_SNAKE_CASE							):
		if is_palindrome(_SCREAMING_SNAKE_CASE							) and is_palindrome(bin(_SCREAMING_SNAKE_CASE							).split("""b"""							)[1]							):
			total += i
	return total


if __name__ == "__main__":
				print(solution(int(str(input().strip()))))