

'''simple docstring'''




import unittest

from transformers import is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

from ...generation.test_utils import GenerationTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
  import torch

  from transformers import (
      OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST,
      OpenAIGPTConfig,
      OpenAIGPTDoubleHeadsModel,
      OpenAIGPTForSequenceClassification,
      OpenAIGPTLMHeadModel,
      OpenAIGPTModel,
  )



class 							lowercase_						:

  '''simple docstring'''





  def __init__(  self ,			a_ ,			a_=1_3 ,			a_=7 ,			a_=True ,			a_=True ,			a_=True ,			a_=9_9 ,			a_=3_2 ,			a_=5 ,			a_=4 ,			a_=3_7 ,			a_="gelu" ,			a_=0.1 ,			a_=0.1 ,			a_=5_1_2 ,			a_=1_6 ,			a_=2 ,			a_=0.02 ,			a_=3 ,			a_=4 ,			a_=None ,			)				->					Tuple:


    """simple docstring"""
    UpperCAmelCase    				=						parent
    UpperCAmelCase    				=						batch_size
    UpperCAmelCase    				=						seq_length
    UpperCAmelCase    				=						is_training
    UpperCAmelCase    				=						use_token_type_ids
    UpperCAmelCase    				=						use_labels
    UpperCAmelCase    				=						vocab_size
    UpperCAmelCase    				=						hidden_size
    UpperCAmelCase    				=						num_hidden_layers
    UpperCAmelCase    				=						num_attention_heads
    UpperCAmelCase    				=						intermediate_size
    UpperCAmelCase    				=						hidden_act
    UpperCAmelCase    				=						hidden_dropout_prob
    UpperCAmelCase    				=						attention_probs_dropout_prob
    UpperCAmelCase    				=						max_position_embeddings
    UpperCAmelCase    				=						type_vocab_size
    UpperCAmelCase    				=						type_sequence_label_size
    UpperCAmelCase    				=						initializer_range
    UpperCAmelCase    				=						num_labels
    UpperCAmelCase    				=						num_choices
    UpperCAmelCase    				=						scope
    UpperCAmelCase    				=						self.vocab_size - 1
  def     snake_case_      (  self  )				->					int:


    """simple docstring"""
    UpperCAmelCase    				=						ids_tensor([self.batch_size, self.seq_length] ,			self.vocab_size  )

    UpperCAmelCase    				=						None
    if self.use_token_type_ids:
      UpperCAmelCase    				=						ids_tensor([self.batch_size, self.seq_length] ,			self.type_vocab_size  )

    UpperCAmelCase    				=						None
    UpperCAmelCase    				=						None
    UpperCAmelCase    				=						None
    if self.use_labels:
      UpperCAmelCase    				=						ids_tensor([self.batch_size] ,			self.type_sequence_label_size  )
      UpperCAmelCase    				=						ids_tensor([self.batch_size, self.seq_length] ,			self.num_labels  )
      UpperCAmelCase    				=						ids_tensor([self.batch_size] ,			self.num_choices  )

    UpperCAmelCase    				=						OpenAIGPTConfig(
        vocab_size=self.vocab_size ,			n_embd=self.hidden_size ,			n_layer=self.num_hidden_layers ,			n_head=self.num_attention_heads ,			n_positions=self.max_position_embeddings ,			pad_token_id=self.pad_token_id ,			)

    UpperCAmelCase    				=						ids_tensor([self.num_hidden_layers, self.num_attention_heads] ,			2  )

    return (
        config,
        input_ids,
        head_mask,
        token_type_ids,
        sequence_labels,
        token_labels,
        choice_labels,
    )
  def     snake_case_      (  self ,			a_ ,			a_ ,			a_ ,			a_ ,			*a_  )				->					List[Any]:


    """simple docstring"""
    UpperCAmelCase    				=						OpenAIGPTModel(config=a_  )
    model.to(a_  )
    model.eval()

    UpperCAmelCase    				=						model(a_ ,			token_type_ids=a_ ,			head_mask=a_  )
    UpperCAmelCase    				=						model(a_ ,			token_type_ids=a_  )
    UpperCAmelCase    				=						model(a_  )

    self.parent.assertEqual(result.last_hidden_state.shape ,			(self.batch_size, self.seq_length, self.hidden_size)  )
  def     snake_case_      (  self ,			a_ ,			a_ ,			a_ ,			a_ ,			*a_  )				->					List[Any]:


    """simple docstring"""
    UpperCAmelCase    				=						OpenAIGPTLMHeadModel(a_  )
    model.to(a_  )
    model.eval()

    UpperCAmelCase    				=						model(a_ ,			token_type_ids=a_ ,			labels=a_  )
    self.parent.assertEqual(result.loss.shape ,			()  )
    self.parent.assertEqual(result.logits.shape ,			(self.batch_size, self.seq_length, self.vocab_size)  )
  def     snake_case_      (  self ,			a_ ,			a_ ,			a_ ,			a_ ,			*a_  )				->					Any:


    """simple docstring"""
    UpperCAmelCase    				=						OpenAIGPTDoubleHeadsModel(a_  )
    model.to(a_  )
    model.eval()

    UpperCAmelCase    				=						model(a_ ,			token_type_ids=a_ ,			labels=a_  )
    self.parent.assertEqual(result.loss.shape ,			()  )
    self.parent.assertEqual(result.logits.shape ,			(self.batch_size, self.seq_length, self.vocab_size)  )
  def     snake_case_      (  self ,			a_ ,			a_ ,			a_ ,			a_ ,			*a_  )				->					Optional[Any]:


    """simple docstring"""
    UpperCAmelCase    				=						self.num_labels
    UpperCAmelCase    				=						OpenAIGPTForSequenceClassification(a_  )
    model.to(a_  )
    model.eval()

    UpperCAmelCase    				=						ids_tensor([self.batch_size] ,			self.type_sequence_label_size  )
    UpperCAmelCase    				=						model(a_ ,			token_type_ids=a_ ,			labels=a_  )
    self.parent.assertEqual(result.logits.shape ,			(self.batch_size, self.num_labels)  )





  def     snake_case_      (  self  )				->					Tuple:


    """simple docstring"""
    UpperCAmelCase    				=						self.prepare_config_and_inputs()
    (
        (
        UpperCAmelCase
    )				,   (
        UpperCAmelCase
    )				,   (
        UpperCAmelCase
    )				,   (
        UpperCAmelCase
    )				,   (
        UpperCAmelCase
    )				,   (
        UpperCAmelCase
    )				,   (
        UpperCAmelCase
    )				,   
    )    				=						config_and_inputs
    UpperCAmelCase    				=						{
        'input_ids': input_ids,
        'token_type_ids': token_type_ids,
        'head_mask': head_mask,
    }

    return config, inputs_dict




@require_torch
class 							lowercase_						(		a			,							a			,							a			,							unittest.TestCase			):

  '''simple docstring'''





  __lowerCAmelCase       :			Union[str, Any]     	= (
      (OpenAIGPTModel, OpenAIGPTLMHeadModel, OpenAIGPTDoubleHeadsModel, OpenAIGPTForSequenceClassification)
      if is_torch_available()
      else ()
  )
  __lowerCAmelCase       :			Tuple     	= (
      (OpenAIGPTLMHeadModel,) if is_torch_available() else ()
  )  # TODO (PVP): Add Double HeadsModel when generate() function is changed accordingly
  __lowerCAmelCase       :			str     	= (
      {
          "feature-extraction": OpenAIGPTModel,
          "text-classification": OpenAIGPTForSequenceClassification,
          "text-generation": OpenAIGPTLMHeadModel,
          "zero-shot": OpenAIGPTForSequenceClassification,
      }
      if is_torch_available()
      else {}
  )
  def     snake_case_      (  self ,			a_ ,			a_ ,			a_ ,			a_ ,			a_  )				->					int:


    """simple docstring"""
    if pipeline_test_casse_name == "ZeroShotClassificationPipelineTests":
      # Get `tokenizer does not have a padding token` error for both fast/slow tokenizers.
      # `OpenAIGPTConfig` was never used in pipeline tests, either because of a missing checkpoint or because a
      # tiny config could not be created.
      return True

    return False
  def     snake_case_      (  self ,			a_ ,			a_ ,			a_=False  )				->					List[Any]:


    """simple docstring"""
    UpperCAmelCase    				=						super()._prepare_for_class(a_ ,			a_ ,			return_labels=a_  )

    if return_labels:
      if model_class.__name__ == "OpenAIGPTDoubleHeadsModel":
        UpperCAmelCase    				=						torch.zeros(
            (self.model_tester.batch_size, self.model_tester.num_choices, self.model_tester.seq_length) ,			dtype=torch.long ,			device=a_ ,			)
        UpperCAmelCase    				=						inputs_dict['labels']
        UpperCAmelCase    				=						inputs_dict['labels']
        UpperCAmelCase    				=						torch.zeros(
            (self.model_tester.batch_size, self.model_tester.num_choices) ,			dtype=torch.long ,			device=a_ ,			)
        UpperCAmelCase    				=						torch.zeros(
            self.model_tester.batch_size ,			dtype=torch.long ,			device=a_  )
    return inputs_dict
  def     snake_case_      (  self  )				->					Dict:


    """simple docstring"""
    UpperCAmelCase    				=						OpenAIGPTModelTester(self  )
    UpperCAmelCase    				=						ConfigTester(self ,			config_class=a_ ,			n_embd=3_7  )
  def     snake_case_      (  self  )				->					Optional[Any]:


    """simple docstring"""
    self.config_tester.run_common_tests()
  def     snake_case_      (  self  )				->					Any:


    """simple docstring"""
    UpperCAmelCase    				=						self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_openai_gpt_model(*a_  )
  def     snake_case_      (  self  )				->					Optional[Any]:


    """simple docstring"""
    UpperCAmelCase    				=						self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_lm_head_model(*a_  )
  def     snake_case_      (  self  )				->					Dict:


    """simple docstring"""
    UpperCAmelCase    				=						self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_double_lm_head_model(*a_  )
  def     snake_case_      (  self  )				->					str:


    """simple docstring"""
    UpperCAmelCase    				=						self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_openai_gpt_for_sequence_classification(*a_  )





  @slow
  def     snake_case_      (  self  )				->					Optional[Any]:


    """simple docstring"""
    for model_name in OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
      UpperCAmelCase    				=						OpenAIGPTModel.from_pretrained(a_  )
      self.assertIsNotNone(a_  )




@require_torch
class 							lowercase_						(		unittest.TestCase			):

  '''simple docstring'''





  @slow
  def     snake_case_      (  self  )				->					Optional[Any]:


    """simple docstring"""
    UpperCAmelCase    				=						OpenAIGPTLMHeadModel.from_pretrained('openai-gpt'  )
    model.to(a_  )
    UpperCAmelCase    				=						torch.tensor([[4_8_1, 4_7_3_5, 5_4_4]] ,			dtype=torch.long ,			device=a_  )  # the president is
    UpperCAmelCase    				=						[
        4_8_1,
        4_7_3_5,
        5_4_4,
        2_4_6,
        9_6_3,
        8_7_0,
        7_6_2,
        2_3_9,
        2_4_4,
        4_0_4_7_7,
        2_4_4,
        2_4_9,
        7_1_9,
        8_8_1,
        4_8_7,
        5_4_4,
        2_4_0,
        2_4_4,
        6_0_3,
        4_8_1,
    ]  # the president is a very good man. " \n " i\'m sure he is, " said the

    UpperCAmelCase    				=						model.generate(a_ ,			do_sample=a_  )
    self.assertListEqual(output_ids[0].tolist() ,			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()))))


