

'''simple docstring'''




import re
from typing import Callable, List, Optional, Union

import tensorflow as tf


try:
  from tensorflow.keras.optimizers.legacy import Adam
except ImportError:
  from tensorflow.keras.optimizers import Adam



class 							lowercase_						(		tf.keras.optimizers.schedules.LearningRateSchedule			):

  '''simple docstring'''





  def __init__(  self ,			a_ ,			a_ ,			a_ ,			a_ = 1.0 ,			a_ = None ,			)				->					Tuple:


    """simple docstring"""
    super().__init__()
    UpperCAmelCase    				=						initial_learning_rate
    UpperCAmelCase    				=						warmup_steps
    UpperCAmelCase    				=						power
    UpperCAmelCase    				=						decay_schedule_fn
    UpperCAmelCase    				=						name
  def __call__(  self ,			a_  )				->					Union[str, Any]:


    """simple docstring"""
    with tf.name_scope(self.name or 'WarmUp'  ) as name:
      # Implements polynomial warmup. i.e., if global_step < warmup_steps, the
      # learning rate will be `global_step/num_warmup_steps * init_lr`.
      UpperCAmelCase    				=						tf.cast(a_ ,			tf.floataa  )
      UpperCAmelCase    				=						tf.cast(self.warmup_steps ,			tf.floataa  )
      UpperCAmelCase    				=						global_step_float / warmup_steps_float
      UpperCAmelCase    				=						self.initial_learning_rate * tf.math.pow(a_ ,			self.power  )
      return tf.cond(
          global_step_float < warmup_steps_float ,			lambda: warmup_learning_rate ,			lambda: self.decay_schedule_fn(step - self.warmup_steps  ) ,			name=a_ ,			)





  def     snake_case_      (  self  )				->					Optional[int]:


    """simple docstring"""
    return {
        "initial_learning_rate": self.initial_learning_rate,
        "decay_schedule_fn": self.decay_schedule_fn,
        "warmup_steps": self.warmup_steps,
        "power": self.power,
        "name": self.name,
    }




def    lowerCamelCase__		(    SCREAMING_SNAKE_CASE   : float							, SCREAMING_SNAKE_CASE   : int							, SCREAMING_SNAKE_CASE   : int							, SCREAMING_SNAKE_CASE   : float = 0.0							, SCREAMING_SNAKE_CASE   : float = 0.9							, SCREAMING_SNAKE_CASE   : float = 0.999							, SCREAMING_SNAKE_CASE   : float = 1E-8							, SCREAMING_SNAKE_CASE   : Optional[float] = None							, SCREAMING_SNAKE_CASE   : Optional[float] = None							, SCREAMING_SNAKE_CASE   : float = 0.0							, SCREAMING_SNAKE_CASE   : float = 1.0							, SCREAMING_SNAKE_CASE   : Optional[List[str]] = None							, ):
  UpperCAmelCase    				=						tf.keras.optimizers.schedules.PolynomialDecay(
      initial_learning_rate=SCREAMING_SNAKE_CASE							, decay_steps=num_train_steps - num_warmup_steps							, end_learning_rate=init_lr * min_lr_ratio							, power=SCREAMING_SNAKE_CASE							, )
  if num_warmup_steps:
    UpperCAmelCase    				=						WarmUp(
        initial_learning_rate=SCREAMING_SNAKE_CASE							, decay_schedule_fn=SCREAMING_SNAKE_CASE							, warmup_steps=SCREAMING_SNAKE_CASE							, )
  if weight_decay_rate > 0.0:
    UpperCAmelCase    				=						AdamWeightDecay(
        learning_rate=SCREAMING_SNAKE_CASE							, weight_decay_rate=SCREAMING_SNAKE_CASE							, beta_a=SCREAMING_SNAKE_CASE							, beta_a=SCREAMING_SNAKE_CASE							, epsilon=SCREAMING_SNAKE_CASE							, clipnorm=SCREAMING_SNAKE_CASE							, global_clipnorm=SCREAMING_SNAKE_CASE							, exclude_from_weight_decay=['LayerNorm', 'layer_norm', 'bias']							, include_in_weight_decay=SCREAMING_SNAKE_CASE							, )
  else:
    UpperCAmelCase    				=						tf.keras.optimizers.Adam(
        learning_rate=SCREAMING_SNAKE_CASE							, beta_a=SCREAMING_SNAKE_CASE							, beta_a=SCREAMING_SNAKE_CASE							, epsilon=SCREAMING_SNAKE_CASE							, clipnorm=SCREAMING_SNAKE_CASE							, global_clipnorm=SCREAMING_SNAKE_CASE							, )
  # We return the optimizer and the LR scheduler in order to better track the
  # evolution of the LR independently of the optimizer.
  return optimizer, lr_schedule



class 							lowercase_						(		a			):

  '''simple docstring'''





  def __init__(  self ,			a_ = 0.001 ,			a_ = 0.9 ,			a_ = 0.999 ,			a_ = 1E-7 ,			a_ = False ,			a_ = 0.0 ,			a_ = None ,			a_ = None ,			a_ = "AdamWeightDecay" ,			**a_ ,			)				->					int:


    """simple docstring"""
    super().__init__(a_ ,			a_ ,			a_ ,			a_ ,			a_ ,			a_ ,			**a_  )
    UpperCAmelCase    				=						weight_decay_rate
    UpperCAmelCase    				=						include_in_weight_decay
    UpperCAmelCase    				=						exclude_from_weight_decay
  @classmethod
  def     snake_case_      (  cls ,			a_  )				->					Union[str, Any]:


    """simple docstring"""
    UpperCAmelCase    				=						{'WarmUp': WarmUp}
    return super(a_ ,			cls  ).from_config(a_ ,			custom_objects=a_  )
  def     snake_case_      (  self ,			a_ ,			a_ ,			a_  )				->					Dict:


    """simple docstring"""
    super(a_ ,			self  )._prepare_local(a_ ,			a_ ,			a_  )
    UpperCAmelCase    				=						tf.constant(
        self.weight_decay_rate ,			name='adam_weight_decay_rate'  )
  def     snake_case_      (  self ,			a_ ,			a_ ,			a_  )				->					Tuple:


    """simple docstring"""
    UpperCAmelCase    				=						self._do_use_weight_decay(var.name  )
    if do_decay:
      return var.assign_sub(
          learning_rate * var * apply_state[(var.device, var.dtype.base_dtype)]['weight_decay_rate'] ,			use_locking=self._use_locking ,			)
    return tf.no_op()
  def     snake_case_      (  self ,			a_ ,			a_=None ,			**a_  )				->					Tuple:


    """simple docstring"""
    UpperCAmelCase				,   UpperCAmelCase    				=						list(zip(*a_  )  )
    return super(a_ ,			self  ).apply_gradients(zip(a_ ,			a_  ) ,			name=a_ ,			**a_  )
  def     snake_case_      (  self ,			a_ ,			a_ ,			a_  )				->					Tuple:


    """simple docstring"""
    if apply_state is None:
      return self._decayed_lr_t[var_dtype], {}

    UpperCAmelCase    				=						apply_state or {}
    UpperCAmelCase    				=						apply_state.get((var_device, var_dtype)  )
    if coefficients is None:
      UpperCAmelCase    				=						self._fallback_apply_state(a_ ,			a_  )
      UpperCAmelCase    				=						coefficients

    return coefficients["lr_t"], {"apply_state": apply_state}
  def     snake_case_      (  self ,			a_ ,			a_ ,			a_=None  )				->					Tuple:


    """simple docstring"""
    UpperCAmelCase				,   UpperCAmelCase    				=						self._get_lr(var.device ,			var.dtype.base_dtype ,			a_  )
    UpperCAmelCase    				=						self._decay_weights_op(a_ ,			a_ ,			a_  )
    with tf.control_dependencies([decay]  ):
      return super(a_ ,			self  )._resource_apply_dense(a_ ,			a_ ,			**a_  )
  def     snake_case_      (  self ,			a_ ,			a_ ,			a_ ,			a_=None  )				->					Any:


    """simple docstring"""
    UpperCAmelCase				,   UpperCAmelCase    				=						self._get_lr(var.device ,			var.dtype.base_dtype ,			a_  )
    UpperCAmelCase    				=						self._decay_weights_op(a_ ,			a_ ,			a_  )
    with tf.control_dependencies([decay]  ):
      return super(a_ ,			self  )._resource_apply_sparse(a_ ,			a_ ,			a_ ,			**a_  )
  def     snake_case_      (  self  )				->					int:


    """simple docstring"""
    UpperCAmelCase    				=						super().get_config()
    config.update({'weight_decay_rate': self.weight_decay_rate}  )
    return config





  def     snake_case_      (  self ,			a_  )				->					Any:


    """simple docstring"""
    if self.weight_decay_rate == 0:
      return False

    if self._include_in_weight_decay:
      for r in self._include_in_weight_decay:
        if re.search(a_ ,			a_  ) is not None:
          return True

    if self._exclude_from_weight_decay:
      for r in self._exclude_from_weight_decay:
        if re.search(a_ ,			a_  ) is not None:
          return False
    return True




class 							lowercase_						(		a			):

  '''simple docstring'''





  def __init__(  self  )				->					List[str]:


    """simple docstring"""
    UpperCAmelCase    				=						[]
    UpperCAmelCase    				=						None
  @property
  def     snake_case_      (  self  )				->					Any:


    """simple docstring"""
    if self._accum_steps is None:
      UpperCAmelCase    				=						tf.Variable(
          tf.constant(0 ,			dtype=tf.intaa  ) ,			trainable=a_ ,			synchronization=tf.VariableSynchronization.ON_READ ,			aggregation=tf.VariableAggregation.ONLY_FIRST_REPLICA ,			)

    return self._accum_steps.value()
  @property
  def     snake_case_      (  self  )				->					Any:


    """simple docstring"""
    if not self._gradients:
      raise ValueError('The accumulator should be called first to initialize the gradients'  )
    return [gradient.value() if gradient is not None else gradient for gradient in self._gradients]
  def __call__(  self ,			a_  )				->					Union[str, Any]:


    """simple docstring"""
    if not self._gradients:
      UpperCAmelCase    				=						self.step  # Create the step variable.
      self._gradients.extend(
          [
              tf.Variable(
                  tf.zeros_like(a_  ) ,			trainable=a_ ,			synchronization=tf.VariableSynchronization.ON_READ ,			aggregation=tf.VariableAggregation.ONLY_FIRST_REPLICA ,			)
              if gradient is not None
              else gradient
              for gradient in gradients
          ]  )
    if len(a_  ) != len(self._gradients  ):
      raise ValueError(F'''Expected {len(self._gradients  )} gradients, but got {len(a_  )}'''  )

    for accum_gradient, gradient in zip(self._gradients ,			a_  ):
      if accum_gradient is not None and gradient is not None:
        accum_gradient.assign_add(a_  )

    self._accum_steps.assign_add(1  )





  def     snake_case_      (  self  )				->					int:


    """simple docstring"""
    if not self._gradients:
      return
    self._accum_steps.assign(0  )
    for gradient in self._gradients:
      if gradient is not None:
        gradient.assign(tf.zeros_like(a_  )  )





'''simple docstring'''




from __future__ import annotations


def    lowerCamelCase__		(    SCREAMING_SNAKE_CASE   : int | str    ):
  UpperCAmelCase    				=						str(SCREAMING_SNAKE_CASE    )
  return n == n[::-1]


def    lowerCamelCase__		(    SCREAMING_SNAKE_CASE   : int = 100_0000    ):
  UpperCAmelCase    				=						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()))))


