



import json
import os
import re
import unittest

from transformers import CodeGenTokenizer, CodeGenTokenizerFast
from transformers.models.codegen.tokenization_codegen import VOCAB_FILES_NAMES
from transformers.testing_utils import require_tokenizers, slow

from ...test_tokenization_common import TokenizerTesterMixin







@require_tokenizers
class 				_a				(   _lowerCAmelCase ,		unittest.TestCase					):
			A      		=	CodeGenTokenizer
			A      		=	CodeGenTokenizerFast
			A      		=	True
			A      		=	{'''add_prefix_space''': True}
			A      		=	False

			def      __snake_case       (self					)       ->   Tuple:
						super().setUp()

						# Adapted from Sennrich et al. 2015 and https://github.com/rsennrich/subword-nmt
						UpperCAmelCase_:		Any							      =     [
						    """l""",
						    """o""",
						    """w""",
						    """e""",
						    """r""",
						    """s""",
						    """t""",
						    """i""",
						    """d""",
						    """n""",
						    """\u0120""",
						    """\u0120l""",
						    """\u0120n""",
						    """\u0120lo""",
						    """\u0120low""",
						    """er""",
						    """\u0120lowest""",
						    """\u0120newer""",
						    """\u0120wider""",
						    """<unk>""",
						    """<|endoftext|>""",
						]
						UpperCAmelCase_:		str							      =     dict(zip(SCREAMING_SNAKE_CASE_,   range(len(SCREAMING_SNAKE_CASE_					)					)					)					)
						UpperCAmelCase_:		str							      =     ["""#version: 0.2""", """\u0120 l""", """\u0120l o""", """\u0120lo w""", """e r""", """"""]
						UpperCAmelCase_:		Dict							      =     {"""unk_token""": """<unk>"""}

						UpperCAmelCase_:		int							      =     os.path.join(self.tmpdirname,   VOCAB_FILES_NAMES["""vocab_file"""]					)
						UpperCAmelCase_:		Any							      =     os.path.join(self.tmpdirname,   VOCAB_FILES_NAMES["""merges_file"""]					)
						with open(self.vocab_file,   """w""",   encoding="""utf-8"""					) as fp:
									fp.write(json.dumps(SCREAMING_SNAKE_CASE_					) + """\n"""					)
						with open(self.merges_file,   """w""",   encoding="""utf-8"""					) as fp:
									fp.write("""\n""".join(SCREAMING_SNAKE_CASE_					)					)

			def      __snake_case       (self,   **SCREAMING_SNAKE_CASE_					)       ->   List[Any]:
						kwargs.update(self.special_tokens_map					)
						return CodeGenTokenizer.from_pretrained(self.tmpdirname,   **SCREAMING_SNAKE_CASE_					)

			def      __snake_case       (self,   **SCREAMING_SNAKE_CASE_					)       ->   Union[str, Any]:
						kwargs.update(self.special_tokens_map					)
						return CodeGenTokenizerFast.from_pretrained(self.tmpdirname,   **SCREAMING_SNAKE_CASE_					)

			def      __snake_case       (self,   SCREAMING_SNAKE_CASE_					)       ->   List[str]:
						UpperCAmelCase_:		Dict							      =     """lower newer"""
						UpperCAmelCase_:		int							      =     """lower newer"""
						return input_text, output_text

			def      __snake_case       (self					)       ->   List[str]:
						UpperCAmelCase_:		Optional[Any]							      =     CodeGenTokenizer(self.vocab_file,   self.merges_file,   **self.special_tokens_map					)
						UpperCAmelCase_:		int							      =     """lower newer"""
						UpperCAmelCase_:		int							      =     ["""\u0120low""", """er""", """\u0120""", """n""", """e""", """w""", """er"""]
						UpperCAmelCase_:		Union[str, Any]							      =     tokenizer.tokenize(SCREAMING_SNAKE_CASE_,   add_prefix_space=SCREAMING_SNAKE_CASE_					)
						self.assertListEqual(SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_					)

						UpperCAmelCase_:		List[str]							      =     tokens + [tokenizer.unk_token]
						UpperCAmelCase_:		str							      =     [14, 15, 10, 9, 3, 2, 15, 19]
						self.assertListEqual(tokenizer.convert_tokens_to_ids(SCREAMING_SNAKE_CASE_					),   SCREAMING_SNAKE_CASE_					)

			def      __snake_case       (self					)       ->   Dict:
						if not self.test_rust_tokenizer:
									return

						UpperCAmelCase_:		Dict							      =     self.get_tokenizer()
						UpperCAmelCase_:		Union[str, Any]							      =     self.get_rust_tokenizer(add_prefix_space=SCREAMING_SNAKE_CASE_					)

						UpperCAmelCase_:		Optional[Any]							      =     """lower newer"""

						# Testing tokenization
						UpperCAmelCase_:		List[Any]							      =     tokenizer.tokenize(SCREAMING_SNAKE_CASE_,   add_prefix_space=SCREAMING_SNAKE_CASE_					)
						UpperCAmelCase_:		List[str]							      =     rust_tokenizer.tokenize(SCREAMING_SNAKE_CASE_					)
						self.assertListEqual(SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_					)

						# Testing conversion to ids without special tokens
						UpperCAmelCase_:		List[Any]							      =     tokenizer.encode(SCREAMING_SNAKE_CASE_,   add_special_tokens=SCREAMING_SNAKE_CASE_,   add_prefix_space=SCREAMING_SNAKE_CASE_					)
						UpperCAmelCase_:		int							      =     rust_tokenizer.encode(SCREAMING_SNAKE_CASE_,   add_special_tokens=SCREAMING_SNAKE_CASE_					)
						self.assertListEqual(SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_					)

						# Testing conversion to ids with special tokens
						UpperCAmelCase_:		Union[str, Any]							      =     self.get_rust_tokenizer(add_prefix_space=SCREAMING_SNAKE_CASE_					)
						UpperCAmelCase_:		List[Any]							      =     tokenizer.encode(SCREAMING_SNAKE_CASE_,   add_prefix_space=SCREAMING_SNAKE_CASE_					)
						UpperCAmelCase_:		str							      =     rust_tokenizer.encode(SCREAMING_SNAKE_CASE_					)
						self.assertListEqual(SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_					)

						# Testing the unknown token
						UpperCAmelCase_:		Dict							      =     tokens + [rust_tokenizer.unk_token]
						UpperCAmelCase_:		List[str]							      =     [14, 15, 10, 9, 3, 2, 15, 19]
						self.assertListEqual(rust_tokenizer.convert_tokens_to_ids(SCREAMING_SNAKE_CASE_					),   SCREAMING_SNAKE_CASE_					)

			def      __snake_case       (self,   *SCREAMING_SNAKE_CASE_,   **SCREAMING_SNAKE_CASE_					)       ->   Any:
						# It's very difficult to mix/test pretokenization with byte-level
						# And get both CodeGen and Roberta to work at the same time (mostly an issue of adding a space before the string)
						pass

			def      __snake_case       (self,   SCREAMING_SNAKE_CASE_=15					)       ->   Union[str, Any]:
						for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
									with self.subTest(f'{tokenizer.__class__.__name__} ({pretrained_name})'					):
												UpperCAmelCase_:		Any							      =     self.rust_tokenizer_class.from_pretrained(SCREAMING_SNAKE_CASE_,   **SCREAMING_SNAKE_CASE_					)

												# Simple input
												UpperCAmelCase_:		List[Any]							      =     """This is a simple input"""
												UpperCAmelCase_:		Tuple							      =     ["""This is a simple input 1""", """This is a simple input 2"""]
												UpperCAmelCase_:		Any							      =     ("""This is a simple input""", """This is a pair""")
												UpperCAmelCase_:		str							      =     [
												    ("""This is a simple input 1""", """This is a simple input 2"""),
												    ("""This is a simple pair 1""", """This is a simple pair 2"""),
												]

												# Simple input tests
												self.assertRaises(SCREAMING_SNAKE_CASE_,   tokenizer_r.encode,   SCREAMING_SNAKE_CASE_,   max_length=SCREAMING_SNAKE_CASE_,   padding="""max_length"""					)

												# Simple input
												self.assertRaises(SCREAMING_SNAKE_CASE_,   tokenizer_r.encode_plus,   SCREAMING_SNAKE_CASE_,   max_length=SCREAMING_SNAKE_CASE_,   padding="""max_length"""					)

												# Simple input
												self.assertRaises(
												    SCREAMING_SNAKE_CASE_,   tokenizer_r.batch_encode_plus,   SCREAMING_SNAKE_CASE_,   max_length=SCREAMING_SNAKE_CASE_,   padding="""max_length""",   )

												# Pair input
												self.assertRaises(SCREAMING_SNAKE_CASE_,   tokenizer_r.encode,   SCREAMING_SNAKE_CASE_,   max_length=SCREAMING_SNAKE_CASE_,   padding="""max_length"""					)

												# Pair input
												self.assertRaises(SCREAMING_SNAKE_CASE_,   tokenizer_r.encode_plus,   SCREAMING_SNAKE_CASE_,   max_length=SCREAMING_SNAKE_CASE_,   padding="""max_length"""					)

												# Pair input
												self.assertRaises(
												    SCREAMING_SNAKE_CASE_,   tokenizer_r.batch_encode_plus,   SCREAMING_SNAKE_CASE_,   max_length=SCREAMING_SNAKE_CASE_,   padding="""max_length""",   )

			def      __snake_case       (self					)       ->   int:
						UpperCAmelCase_:		int							      =     CodeGenTokenizer.from_pretrained(self.tmpdirname,   pad_token="""<pad>"""					)

						# Simple input
						UpperCAmelCase_:		Any							      =     """This is a simple input"""
						UpperCAmelCase_:		Tuple							      =     ["""This is a simple input looooooooong""", """This is a simple input"""]
						UpperCAmelCase_:		str							      =     ("""This is a simple input""", """This is a pair""")
						UpperCAmelCase_:		Optional[int]							      =     [
						    ("""This is a simple input loooooong""", """This is a simple input"""),
						    ("""This is a simple pair loooooong""", """This is a simple pair"""),
						]

						UpperCAmelCase_:		Dict							      =     tokenizer.pad_token_id

						UpperCAmelCase_:		Any							      =     tokenizer(SCREAMING_SNAKE_CASE_,   padding="""max_length""",   max_length=30,   return_tensors="""np"""					)
						UpperCAmelCase_:		List[str]							      =     tokenizer(SCREAMING_SNAKE_CASE_,   padding=SCREAMING_SNAKE_CASE_,   truncate=SCREAMING_SNAKE_CASE_,   return_tensors="""np"""					)
						UpperCAmelCase_:		Optional[Any]							      =     tokenizer(*SCREAMING_SNAKE_CASE_,   padding="""max_length""",   max_length=60,   return_tensors="""np"""					)
						UpperCAmelCase_:		List[str]							      =     tokenizer(SCREAMING_SNAKE_CASE_,   padding=SCREAMING_SNAKE_CASE_,   truncate=SCREAMING_SNAKE_CASE_,   return_tensors="""np"""					)

						# s
						# test single string max_length padding
						self.assertEqual(out_s["""input_ids"""].shape[-1],   30					)
						self.assertTrue(pad_token_id in out_s["""input_ids"""]					)
						self.assertTrue(0 in out_s["""attention_mask"""]					)

						# s2
						# test automatic padding
						self.assertEqual(out_sa["""input_ids"""].shape[-1],   33					)
						# long slice doesn't have padding
						self.assertFalse(pad_token_id in out_sa["""input_ids"""][0]					)
						self.assertFalse(0 in out_sa["""attention_mask"""][0]					)
						# short slice does have padding
						self.assertTrue(pad_token_id in out_sa["""input_ids"""][1]					)
						self.assertTrue(0 in out_sa["""attention_mask"""][1]					)

						# p
						# test single pair max_length padding
						self.assertEqual(out_p["""input_ids"""].shape[-1],   60					)
						self.assertTrue(pad_token_id in out_p["""input_ids"""]					)
						self.assertTrue(0 in out_p["""attention_mask"""]					)

						# p2
						# test automatic padding pair
						self.assertEqual(out_pa["""input_ids"""].shape[-1],   52					)
						# long slice pair doesn't have padding
						self.assertFalse(pad_token_id in out_pa["""input_ids"""][0]					)
						self.assertFalse(0 in out_pa["""attention_mask"""][0]					)
						# short slice pair does have padding
						self.assertTrue(pad_token_id in out_pa["""input_ids"""][1]					)
						self.assertTrue(0 in out_pa["""attention_mask"""][1]					)

			def      __snake_case       (self					)       ->   int:
						UpperCAmelCase_:		str							      =     """$$$"""
						UpperCAmelCase_:		str							      =     CodeGenTokenizer.from_pretrained(self.tmpdirname,   bos_token=SCREAMING_SNAKE_CASE_,   add_bos_token=SCREAMING_SNAKE_CASE_					)

						UpperCAmelCase_:		Optional[Any]							      =     """This is a simple input"""
						UpperCAmelCase_:		Optional[Any]							      =     ["""This is a simple input 1""", """This is a simple input 2"""]

						UpperCAmelCase_:		Union[str, Any]							      =     tokenizer.bos_token_id

						UpperCAmelCase_:		Union[str, Any]							      =     tokenizer(SCREAMING_SNAKE_CASE_					)
						UpperCAmelCase_:		List[str]							      =     tokenizer(SCREAMING_SNAKE_CASE_					)

						self.assertEqual(out_s.input_ids[0],   SCREAMING_SNAKE_CASE_					)
						self.assertTrue(all(o[0] == bos_token_id for o in out_sa.input_ids					)					)

						UpperCAmelCase_:		Union[str, Any]							      =     tokenizer.decode(out_s.input_ids					)
						UpperCAmelCase_:		Optional[int]							      =     tokenizer.batch_decode(out_sa.input_ids					)

						self.assertEqual(decode_s.split()[0],   SCREAMING_SNAKE_CASE_					)
						self.assertTrue(all(d.split()[0] == bos_token for d in decode_sa					)					)

			@slow
			def      __snake_case       (self					)       ->   Optional[Any]:
						UpperCAmelCase_:		Tuple							      =     CodeGenTokenizer.from_pretrained("""Salesforce/codegen-350M-mono"""					)

						UpperCAmelCase_:		int							      =     """\nif len_a > len_b:\n    result = a\nelse:\n    result = b\n\n\n\n#"""
						UpperCAmelCase_:		str							      =     """\nif len_a > len_b:      result = a\nelse:      result = b"""

						UpperCAmelCase_:		Union[str, Any]							      =     tokenizer.encode(SCREAMING_SNAKE_CASE_					)
						UpperCAmelCase_:		int							      =     ["""^#""", re.escape("""<|endoftext|>"""					), """^'''""", """^\"\"\"""", """\n\n\n"""]
						UpperCAmelCase_:		Optional[Any]							      =     tokenizer.decode(SCREAMING_SNAKE_CASE_,   truncate_before_pattern=SCREAMING_SNAKE_CASE_					)
						self.assertEqual(SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_					)

			def      __snake_case       (self					)       ->   str:
						pass











from __future__ import annotations







def  lowerCAmelCase_	(lowerCAmelCase__:		int | str  ):





			"""simple docstring"""


			UpperCAmelCase_:		Optional[int]							      =     str(lowerCAmelCase__  )
			return n == n[::-1]







def  lowerCAmelCase_	(lowerCAmelCase__:		int = 1_0_0_0_0_0_0  ):





			"""simple docstring"""


			UpperCAmelCase_:		int							      =     0

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


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






