import os
import tempfile
import unittest

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

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
      import torch

      from transformers import (
          DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
          DistilBertForMaskedLM,
          DistilBertForMultipleChoice,
          DistilBertForQuestionAnswering,
          DistilBertForSequenceClassification,
          DistilBertForTokenClassification,
          DistilBertModel,
      )





class 					A							(    UpperCAmelCase_					):


   def __init__(self					:						Dict	,  __UpperCAmelCase					:						List[Any]	,  __UpperCAmelCase					:						Union[str, Any]=1_3	,  __UpperCAmelCase					:						Optional[Any]=7	,  __UpperCAmelCase					:						Any=True	,  __UpperCAmelCase					:						Union[str, Any]=True	,  __UpperCAmelCase					:						int=False	,  __UpperCAmelCase					:						Any=True	,  __UpperCAmelCase					:						List[Any]=9_9	,  __UpperCAmelCase					:						Tuple=3_2	,  __UpperCAmelCase					:						Tuple=5	,  __UpperCAmelCase					:						Union[str, Any]=4	,  __UpperCAmelCase					:						List[str]=3_7	,  __UpperCAmelCase					:						List[str]="gelu"	,  __UpperCAmelCase					:						Dict=0.1	,  __UpperCAmelCase					:						List[Any]=0.1	,  __UpperCAmelCase					:						Tuple=5_1_2	,  __UpperCAmelCase					:						Any=1_6	,  __UpperCAmelCase					:						str=2	,  __UpperCAmelCase					:						Dict=0.02	,  __UpperCAmelCase					:						Union[str, Any]=3	,  __UpperCAmelCase					:						str=4	,  __UpperCAmelCase					:						Any=None	,  )						->    Any:
         """simple docstring"""



         UpperCAmelCase__								=  parent
         UpperCAmelCase__								=  batch_size
         UpperCAmelCase__								=  seq_length
         UpperCAmelCase__								=  is_training
         UpperCAmelCase__								=  use_input_mask
         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


   def       lowercase_				(self					:						List[Any]		)						->    List[Any]:
         """simple docstring"""



         UpperCAmelCase__								=  ids_tensor([self.batch_size, self.seq_length]	,  self.vocab_size		)

         UpperCAmelCase__								=  None
         if self.use_input_mask:
               UpperCAmelCase__								=  random_attention_mask([self.batch_size, self.seq_length]		)

         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__								=  self.get_config()

         return config, input_ids, input_mask, sequence_labels, token_labels, choice_labels


   def       lowercase_				(self					:						List[Any]		)						->    str:
         """simple docstring"""



         return DistilBertConfig(
             vocab_size=self.vocab_size	,  dim=self.hidden_size	,  n_layers=self.num_hidden_layers	,  n_heads=self.num_attention_heads	,  hidden_dim=self.intermediate_size	,  hidden_act=self.hidden_act	,  dropout=self.hidden_dropout_prob	,  attention_dropout=self.attention_probs_dropout_prob	,  max_position_embeddings=self.max_position_embeddings	,  initializer_range=self.initializer_range	,  )


   def       lowercase_				(self					:						int	,  __UpperCAmelCase					:						int	,  __UpperCAmelCase					:						Union[str, Any]	,  __UpperCAmelCase					:						List[str]	,  __UpperCAmelCase					:						Dict	,  __UpperCAmelCase					:						str	,  __UpperCAmelCase					:						Optional[int]		)						->    str:
         """simple docstring"""



         UpperCAmelCase__								=  DistilBertModel(config=__UpperCAmelCase		)
         model.to(__UpperCAmelCase		)
         model.eval()
         UpperCAmelCase__								=  model(__UpperCAmelCase	,  __UpperCAmelCase		)
         UpperCAmelCase__								=  model(__UpperCAmelCase		)
         self.parent.assertEqual(result.last_hidden_state.shape	,  (self.batch_size, self.seq_length, self.hidden_size)		)


   def       lowercase_				(self					:						Dict	,  __UpperCAmelCase					:						Tuple	,  __UpperCAmelCase					:						List[Any]	,  __UpperCAmelCase					:						List[str]	,  __UpperCAmelCase					:						Optional[int]	,  __UpperCAmelCase					:						Dict	,  __UpperCAmelCase					:						Tuple		)						->    List[Any]:
         """simple docstring"""



         UpperCAmelCase__								=  DistilBertForMaskedLM(config=__UpperCAmelCase		)
         model.to(__UpperCAmelCase		)
         model.eval()
         UpperCAmelCase__								=  model(__UpperCAmelCase	,  attention_mask=__UpperCAmelCase	,  labels=__UpperCAmelCase		)
         self.parent.assertEqual(result.logits.shape	,  (self.batch_size, self.seq_length, self.vocab_size)		)


   def       lowercase_				(self					:						Optional[int]	,  __UpperCAmelCase					:						List[str]	,  __UpperCAmelCase					:						Optional[Any]	,  __UpperCAmelCase					:						Optional[Any]	,  __UpperCAmelCase					:						Dict	,  __UpperCAmelCase					:						int	,  __UpperCAmelCase					:						str		)						->    Union[str, Any]:
         """simple docstring"""



         UpperCAmelCase__								=  DistilBertForQuestionAnswering(config=__UpperCAmelCase		)
         model.to(__UpperCAmelCase		)
         model.eval()
         UpperCAmelCase__								=  model(
             __UpperCAmelCase	,  attention_mask=__UpperCAmelCase	,  start_positions=__UpperCAmelCase	,  end_positions=__UpperCAmelCase		)
         self.parent.assertEqual(result.start_logits.shape	,  (self.batch_size, self.seq_length)		)
         self.parent.assertEqual(result.end_logits.shape	,  (self.batch_size, self.seq_length)		)


   def       lowercase_				(self					:						str	,  __UpperCAmelCase					:						Any	,  __UpperCAmelCase					:						Optional[Any]	,  __UpperCAmelCase					:						List[str]	,  __UpperCAmelCase					:						int	,  __UpperCAmelCase					:						List[str]	,  __UpperCAmelCase					:						List[Any]		)						->    Optional[Any]:
         """simple docstring"""



         UpperCAmelCase__								=  self.num_labels
         UpperCAmelCase__								=  DistilBertForSequenceClassification(__UpperCAmelCase		)
         model.to(__UpperCAmelCase		)
         model.eval()
         UpperCAmelCase__								=  model(__UpperCAmelCase	,  attention_mask=__UpperCAmelCase	,  labels=__UpperCAmelCase		)
         self.parent.assertEqual(result.logits.shape	,  (self.batch_size, self.num_labels)		)


   def       lowercase_				(self					:						Optional[int]	,  __UpperCAmelCase					:						Optional[Any]	,  __UpperCAmelCase					:						List[Any]	,  __UpperCAmelCase					:						int	,  __UpperCAmelCase					:						List[Any]	,  __UpperCAmelCase					:						Union[str, Any]	,  __UpperCAmelCase					:						Tuple		)						->    str:
         """simple docstring"""



         UpperCAmelCase__								=  self.num_labels
         UpperCAmelCase__								=  DistilBertForTokenClassification(config=__UpperCAmelCase		)
         model.to(__UpperCAmelCase		)
         model.eval()

         UpperCAmelCase__								=  model(__UpperCAmelCase	,  attention_mask=__UpperCAmelCase	,  labels=__UpperCAmelCase		)
         self.parent.assertEqual(result.logits.shape	,  (self.batch_size, self.seq_length, self.num_labels)		)


   def       lowercase_				(self					:						Optional[Any]	,  __UpperCAmelCase					:						int	,  __UpperCAmelCase					:						Any	,  __UpperCAmelCase					:						Optional[int]	,  __UpperCAmelCase					:						Tuple	,  __UpperCAmelCase					:						Dict	,  __UpperCAmelCase					:						int		)						->    Dict:
         """simple docstring"""



         UpperCAmelCase__								=  self.num_choices
         UpperCAmelCase__								=  DistilBertForMultipleChoice(config=__UpperCAmelCase		)
         model.to(__UpperCAmelCase		)
         model.eval()
         UpperCAmelCase__								=  input_ids.unsqueeze(1		).expand(-1	,  self.num_choices	,  -1		).contiguous()
         UpperCAmelCase__								=  input_mask.unsqueeze(1		).expand(-1	,  self.num_choices	,  -1		).contiguous()
         UpperCAmelCase__								=  model(
             __UpperCAmelCase	,  attention_mask=__UpperCAmelCase	,  labels=__UpperCAmelCase	,  )
         self.parent.assertEqual(result.logits.shape	,  (self.batch_size, self.num_choices)		)





   def       lowercase_				(self					:						List[Any]		)						->    int:
         """simple docstring"""



         UpperCAmelCase__								=  self.prepare_config_and_inputs()
         ((UpperCAmelCase__)		,				(UpperCAmelCase__)		,				(UpperCAmelCase__)		,				(UpperCAmelCase__)		,				(UpperCAmelCase__)		,				(UpperCAmelCase__))								=  config_and_inputs
         UpperCAmelCase__								=  {"input_ids": input_ids, "attention_mask": input_mask}
         return config, inputs_dict





@require_torch
class 					A							(    UpperCAmelCase_		,    UpperCAmelCase_		,    unittest.TestCase					):
   __UpperCAmelCase			:			Optional[int]              =      (
       (
           DistilBertModel,
           DistilBertForMaskedLM,
           DistilBertForMultipleChoice,
           DistilBertForQuestionAnswering,
           DistilBertForSequenceClassification,
           DistilBertForTokenClassification,
       )
       if is_torch_available()
       else None
   )
   __UpperCAmelCase			:			str              =      (
       {
           'feature-extraction': DistilBertModel,
           'fill-mask': DistilBertForMaskedLM,
           'question-answering': DistilBertForQuestionAnswering,
           'text-classification': DistilBertForSequenceClassification,
           'token-classification': DistilBertForTokenClassification,
           'zero-shot': DistilBertForSequenceClassification,
       }
       if is_torch_available()
       else {}
   )
   __UpperCAmelCase			:			int              =      True
   __UpperCAmelCase			:			Optional[Any]              =      True
   __UpperCAmelCase			:			Tuple              =      True
   __UpperCAmelCase			:			int              =      True


   def       lowercase_				(self					:						List[str]		)						->    List[str]:
         """simple docstring"""



         UpperCAmelCase__								=  DistilBertModelTester(self		)
         UpperCAmelCase__								=  ConfigTester(self	,  config_class=__UpperCAmelCase	,  dim=3_7		)


   def       lowercase_				(self					:						Tuple		)						->    Union[str, Any]:
         """simple docstring"""



         self.config_tester.run_common_tests()


   def       lowercase_				(self					:						Any		)						->    Tuple:
         """simple docstring"""



         UpperCAmelCase__								=  self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_distilbert_model(*__UpperCAmelCase		)


   def       lowercase_				(self					:						List[str]		)						->    Dict:
         """simple docstring"""



         UpperCAmelCase__								=  self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_distilbert_for_masked_lm(*__UpperCAmelCase		)


   def       lowercase_				(self					:						str		)						->    Tuple:
         """simple docstring"""



         UpperCAmelCase__								=  self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_distilbert_for_question_answering(*__UpperCAmelCase		)


   def       lowercase_				(self					:						Tuple		)						->    str:
         """simple docstring"""



         UpperCAmelCase__								=  self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_distilbert_for_sequence_classification(*__UpperCAmelCase		)


   def       lowercase_				(self					:						Tuple		)						->    Optional[Any]:
         """simple docstring"""



         UpperCAmelCase__								=  self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_distilbert_for_token_classification(*__UpperCAmelCase		)


   def       lowercase_				(self					:						int		)						->    Optional[int]:
         """simple docstring"""



         UpperCAmelCase__								=  self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_distilbert_for_multiple_choice(*__UpperCAmelCase		)


   @slow
   def       lowercase_				(self					:						Tuple		)						->    Optional[int]:
         """simple docstring"""



         for model_name in DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
               UpperCAmelCase__								=  DistilBertModel.from_pretrained(__UpperCAmelCase		)
               self.assertIsNotNone(__UpperCAmelCase		)





   @slow
   @require_torch_gpu
   def       lowercase_				(self					:						Optional[int]		)						->    Tuple:
         """simple docstring"""



         UpperCAmelCase__		,				UpperCAmelCase__								=  self.model_tester.prepare_config_and_inputs_for_common()
         for model_class in self.all_model_classes:
               # BertForMultipleChoice behaves incorrectly in JIT environments.
               if model_class == DistilBertForMultipleChoice:
                     return

               UpperCAmelCase__								=  True
               UpperCAmelCase__								=  model_class(config=__UpperCAmelCase		)

               UpperCAmelCase__								=  self._prepare_for_class(__UpperCAmelCase	,  __UpperCAmelCase		)
               UpperCAmelCase__								=  torch.jit.trace(
                   __UpperCAmelCase	,  (inputs_dict["input_ids"].to("cpu"		), inputs_dict["attention_mask"].to("cpu"		))		)

               with tempfile.TemporaryDirectory() as tmp:
                     torch.jit.save(__UpperCAmelCase	,  os.path.join(__UpperCAmelCase	,  "traced_model.pt"		)		)
                     UpperCAmelCase__								=  torch.jit.load(os.path.join(__UpperCAmelCase	,  "traced_model.pt"		)	,  map_location=__UpperCAmelCase		)
                     loaded(inputs_dict["input_ids"].to(__UpperCAmelCase		)	,  inputs_dict["attention_mask"].to(__UpperCAmelCase		)		)





@require_torch
class 					A							(    unittest.TestCase					):


   @slow
   def       lowercase_				(self					:						Dict		)						->    Union[str, Any]:
         """simple docstring"""



         UpperCAmelCase__								=  DistilBertModel.from_pretrained("distilbert-base-uncased"		)
         UpperCAmelCase__								=  torch.tensor([[0, 3_4_5, 2_3_2, 3_2_8, 7_4_0, 1_4_0, 1_6_9_5, 6_9, 6_0_7_8, 1_5_8_8, 2]]		)
         UpperCAmelCase__								=  torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]		)
         with torch.no_grad():
               UpperCAmelCase__								=  model(__UpperCAmelCase	,  attention_mask=__UpperCAmelCase		)[0]
         UpperCAmelCase__								=  torch.Size((1, 1_1, 7_6_8)		)
         self.assertEqual(output.shape	,  __UpperCAmelCase		)
         UpperCAmelCase__								=  torch.tensor(
             [[[-0.1639, 0.3299, 0.1648], [-0.1746, 0.3289, 0.1710], [-0.1884, 0.3357, 0.1810]]]		)

         self.assertTrue(torch.allclose(output[:, 1:4, 1:4]	,  __UpperCAmelCase	,  atol=1E-4		)		)




from __future__ import annotations




def        lowerCAmelCase_			(					__A							)					->    bool:







      '''simple docstring'''


      UpperCAmelCase__								=  str(__A							)
      return n == n[::-1]




def        lowerCAmelCase_			(					__A = 1_000_000							)					->    Optional[int]:







      '''simple docstring'''


      UpperCAmelCase__								=  0

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


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



