






from __future__ import annotations

import unittest

from transformers import XGLMConfig, XGLMTokenizer, is_tf_available
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
   import tensorflow as tf

   from transformers.models.xglm.modeling_tf_xglm import (
       TF_XGLM_PRETRAINED_MODEL_ARCHIVE_LIST,
       TFXGLMForCausalLM,
       TFXGLMModel,
   )


@require_tf
class  SCREAMING_SNAKE_CASE			:
     '''simple docstring'''


     UpperCamelCase_							:		Union[str, Any]			=	XGLMConfig
     UpperCamelCase_							:		Optional[int]			=	{}
     UpperCamelCase_							:		Union[str, Any]			=	'''gelu'''


     def __init__(				self       :	List[str]					, UpperCAmelCase_       :	Dict					, UpperCAmelCase_       :	int=14					, UpperCAmelCase_       :	int=7					, UpperCAmelCase_       :	Dict=True					, UpperCAmelCase_       :	Any=True					, UpperCAmelCase_       :	str=True					, UpperCAmelCase_       :	Tuple=99					, UpperCAmelCase_       :	Any=32					, UpperCAmelCase_       :	Optional[int]=2					, UpperCAmelCase_       :	str=4					, UpperCAmelCase_       :	List[Any]=37					, UpperCAmelCase_       :	Dict="gelu"					, UpperCAmelCase_       :	Tuple=0.1					, UpperCAmelCase_       :	List[Any]=0.1					, UpperCAmelCase_       :	Tuple=512					, UpperCAmelCase_       :	Dict=0.02					, ):
       SCREAMING_SNAKE_CASE       :      str							=    parent
       SCREAMING_SNAKE_CASE       :      List[str]							=    batch_size
       SCREAMING_SNAKE_CASE       :      Tuple							=    seq_length
       SCREAMING_SNAKE_CASE       :      List[str]							=    is_training
       SCREAMING_SNAKE_CASE       :      Tuple							=    use_input_mask
       SCREAMING_SNAKE_CASE       :      List[str]							=    use_labels
       SCREAMING_SNAKE_CASE       :      Union[str, Any]							=    vocab_size
       SCREAMING_SNAKE_CASE       :      Tuple							=    d_model
       SCREAMING_SNAKE_CASE       :      Any							=    num_hidden_layers
       SCREAMING_SNAKE_CASE       :      Union[str, Any]							=    num_attention_heads
       SCREAMING_SNAKE_CASE       :      Optional[Any]							=    ffn_dim
       SCREAMING_SNAKE_CASE       :      List[str]							=    activation_function
       SCREAMING_SNAKE_CASE       :      Dict							=    activation_dropout
       SCREAMING_SNAKE_CASE       :      Optional[Any]							=    attention_dropout
       SCREAMING_SNAKE_CASE       :      str							=    max_position_embeddings
       SCREAMING_SNAKE_CASE       :      Any							=    initializer_range
       SCREAMING_SNAKE_CASE       :      int							=    None
       SCREAMING_SNAKE_CASE       :      Union[str, Any]							=    0
       SCREAMING_SNAKE_CASE       :      Union[str, Any]							=    2
       SCREAMING_SNAKE_CASE       :      Optional[Any]							=    1


     def 				_A       (				self       :	Union[str, Any]      ):
       return XGLMConfig.from_pretrained("facebook/xglm-564M"      )


     def 				_A       (				self       :	Dict      ):
       SCREAMING_SNAKE_CASE       :      int							=    tf.clip_by_value(
           ids_tensor([self.batch_size, self.seq_length]					, self.vocab_size      )					, clip_value_min=0					, clip_value_max=3      )

       SCREAMING_SNAKE_CASE       :      List[str]							=    None
       if self.use_input_mask:
         SCREAMING_SNAKE_CASE       :      Optional[Any]							=    random_attention_mask([self.batch_size, self.seq_length]      )

       SCREAMING_SNAKE_CASE       :      List[Any]							=    self.get_config()

       SCREAMING_SNAKE_CASE       :      int							=    floats_tensor([self.num_hidden_layers, self.num_attention_heads]					, 2      )

       return (
           config,
           input_ids,
           input_mask,
           head_mask,
       )


     def 				_A       (				self       :	Optional[Any]      ):
       return XGLMConfig(
           vocab_size=self.vocab_size					, d_model=self.hidden_size					, num_layers=self.num_hidden_layers					, attention_heads=self.num_attention_heads					, ffn_dim=self.ffn_dim					, activation_function=self.activation_function					, activation_dropout=self.activation_dropout					, attention_dropout=self.attention_dropout					, max_position_embeddings=self.max_position_embeddings					, initializer_range=self.initializer_range					, use_cache=UpperCAmelCase_					, bos_token_id=self.bos_token_id					, eos_token_id=self.eos_token_id					, pad_token_id=self.pad_token_id					, return_dict=UpperCAmelCase_					, )






     def 				_A       (				self       :	Dict      ):
       SCREAMING_SNAKE_CASE       :      Dict							=    self.prepare_config_and_inputs()

       (
           (
           SCREAMING_SNAKE_CASE
       )						,  (
           SCREAMING_SNAKE_CASE
       )						,  (
           SCREAMING_SNAKE_CASE
       )						,  (
           SCREAMING_SNAKE_CASE
       )						,  
       )       :      List[Any]							=    config_and_inputs

       SCREAMING_SNAKE_CASE       :      int							=    {
           "input_ids": input_ids,
           "head_mask": head_mask,
       }

       return config, inputs_dict





@require_tf
class  SCREAMING_SNAKE_CASE			(			lowerCAmelCase      ,		lowerCAmelCase      ,		unittest.TestCase					):
     '''simple docstring'''


     UpperCamelCase_							:		List[Any]			=	(TFXGLMModel, TFXGLMForCausalLM) if is_tf_available() else ()
     UpperCamelCase_							:		List[str]			=	(TFXGLMForCausalLM,) if is_tf_available() else ()
     UpperCamelCase_							:		Optional[int]			=	(
         {'''feature-extraction''': TFXGLMModel, '''text-generation''': TFXGLMForCausalLM} if is_tf_available() else {}
     )
     UpperCamelCase_							:		Dict			=	False
     UpperCamelCase_							:		List[Any]			=	False
     UpperCamelCase_							:		int			=	False


     def 				_A       (				self       :	Any      ):
       SCREAMING_SNAKE_CASE       :      Optional[int]							=    TFXGLMModelTester(self      )
       SCREAMING_SNAKE_CASE       :      Optional[Any]							=    ConfigTester(self					, config_class=UpperCAmelCase_					, n_embd=37      )


     def 				_A       (				self       :	Union[str, Any]      ):
       self.config_tester.run_common_tests()


     @slow
     def 				_A       (				self       :	List[Any]      ):
       for model_name in TF_XGLM_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
         SCREAMING_SNAKE_CASE       :      Optional[Any]							=    TFXGLMModel.from_pretrained(UpperCAmelCase_      )
         self.assertIsNotNone(UpperCAmelCase_      )






     @unittest.skip(reason="Currently, model embeddings are going to undergo a major refactor."      )
     def 				_A       (				self       :	Optional[Any]      ):
       super().test_resize_token_embeddings()





@require_tf
class  SCREAMING_SNAKE_CASE			(			unittest.TestCase					):
     '''simple docstring'''


     @slow
     def 				_A       (				self       :	List[str]					, UpperCAmelCase_       :	Optional[Any]=True      ):
       SCREAMING_SNAKE_CASE       :      str							=    TFXGLMForCausalLM.from_pretrained("facebook/xglm-564M"      )
       SCREAMING_SNAKE_CASE       :      Union[str, Any]							=    tf.convert_to_tensor([[2, 268, 9865]]					, dtype=tf.intaa      )  # The dog
       # </s> The dog is a very friendly dog. He is very affectionate and loves to play with other
       # fmt: off
       SCREAMING_SNAKE_CASE       :      Tuple							=    [2, 268, 9865, 67, 11, 1988, 5_7252, 9865, 5, 984, 67, 1988, 21_3838, 1658, 53, 7_0446, 33, 6657, 278, 1581]
       # fmt: on
       SCREAMING_SNAKE_CASE       :      List[Any]							=    model.generate(UpperCAmelCase_					, do_sample=UpperCAmelCase_					, num_beams=1      )
       if verify_outputs:
         self.assertListEqual(output_ids[0].numpy().tolist()					, UpperCAmelCase_      )


     @slow
     def 				_A       (				self       :	List[str]      ):
       SCREAMING_SNAKE_CASE       :      List[str]							=    XGLMTokenizer.from_pretrained("facebook/xglm-564M"      )
       SCREAMING_SNAKE_CASE       :      List[Any]							=    TFXGLMForCausalLM.from_pretrained("facebook/xglm-564M"      )

       tf.random.set_seed(0      )
       SCREAMING_SNAKE_CASE       :      List[Any]							=    tokenizer("Today is a nice day and"					, return_tensors="tf"      )
       SCREAMING_SNAKE_CASE       :      Optional[int]							=    tokenized.input_ids
       # forces the generation to happen on CPU, to avoid GPU-related quirks (and assure same output regardless of the available devices)
       with tf.device(":/CPU:0"      ):
         SCREAMING_SNAKE_CASE       :      Optional[int]							=    model.generate(UpperCAmelCase_					, do_sample=UpperCAmelCase_					, seed=[7, 0]      )
       SCREAMING_SNAKE_CASE       :      Optional[Any]							=    tokenizer.decode(output_ids[0]					, skip_special_tokens=UpperCAmelCase_      )

       SCREAMING_SNAKE_CASE       :      int							=    (
           "Today is a nice day and warm evening here over Southern Alberta!! Today when they closed schools due"
       )
       self.assertEqual(UpperCAmelCase_					, UpperCAmelCase_      )






     @slow
     def 				_A       (				self       :	Tuple      ):
       SCREAMING_SNAKE_CASE       :      Dict							=    TFXGLMForCausalLM.from_pretrained("facebook/xglm-564M"      )
       SCREAMING_SNAKE_CASE       :      Dict							=    XGLMTokenizer.from_pretrained("facebook/xglm-564M"      )

       SCREAMING_SNAKE_CASE       :      Union[str, Any]							=    "left"

       # use different length sentences to test batching
       SCREAMING_SNAKE_CASE       :      Optional[Any]							=    [
           "This is an extremelly long sentence that only exists to test the ability of the model to cope with "
           "left-padding, such as in batched generation. The output for the sequence below should be the same "
           "regardless of whether left padding is applied or not. When",
           "Hello, my dog is a little",
       ]

       SCREAMING_SNAKE_CASE       :      List[Any]							=    tokenizer(UpperCAmelCase_					, return_tensors="tf"					, padding=UpperCAmelCase_      )
       SCREAMING_SNAKE_CASE       :      List[Any]							=    inputs["input_ids"]

       SCREAMING_SNAKE_CASE       :      str							=    model.generate(input_ids=UpperCAmelCase_					, attention_mask=inputs["attention_mask"]					, max_new_tokens=12      )

       SCREAMING_SNAKE_CASE       :      List[str]							=    tokenizer(sentences[0]					, return_tensors="tf"      ).input_ids
       SCREAMING_SNAKE_CASE       :      Optional[int]							=    model.generate(input_ids=UpperCAmelCase_					, max_new_tokens=12      )

       SCREAMING_SNAKE_CASE       :      Tuple							=    tokenizer(sentences[1]					, return_tensors="tf"      ).input_ids
       SCREAMING_SNAKE_CASE       :      List[str]							=    model.generate(input_ids=UpperCAmelCase_					, max_new_tokens=12      )

       SCREAMING_SNAKE_CASE       :      Tuple							=    tokenizer.batch_decode(UpperCAmelCase_					, skip_special_tokens=UpperCAmelCase_      )
       SCREAMING_SNAKE_CASE       :      Optional[Any]							=    tokenizer.decode(output_non_padded[0]					, skip_special_tokens=UpperCAmelCase_      )
       SCREAMING_SNAKE_CASE       :      Union[str, Any]							=    tokenizer.decode(output_padded[0]					, skip_special_tokens=UpperCAmelCase_      )

       SCREAMING_SNAKE_CASE       :      Tuple							=    [
           "This is an extremelly long sentence that only exists to test the ability of the model to cope with "
           "left-padding, such as in batched generation. The output for the sequence below should be the same "
           "regardless of whether left padding is applied or not. When left padding is applied, the sequence will be "
           "a single",
           "Hello, my dog is a little bit of a shy one, but he is very friendly",
       ]
       self.assertListEqual(UpperCAmelCase_					, UpperCAmelCase_      )
       self.assertListEqual(UpperCAmelCase_					, [non_padded_sentence, padded_sentence]      )














from __future__ import annotations


def   lowerCamelCase__			(     lowercase				):

  """simple docstring"""






  SCREAMING_SNAKE_CASE       :      Optional[Any]							=    str(lowercase				)
  return n == n[::-1]


def   lowerCamelCase__			(     lowercase = 1000000				):

  """simple docstring"""






  SCREAMING_SNAKE_CASE       :      int							=    0

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


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






