





"""simple docstring"""





from typing import Callable, Dict, Optional, Tuple

import torch
from torch import nn
from torch.distributions import (
    AffineTransform,
    Distribution,
    Independent,
    NegativeBinomial,
    Normal,
    StudentT,
    TransformedDistribution,
)






class    _lowerCAmelCase  (	a			):
       """simple docstring"""




       def __init__(       self       ,					__UpperCAmelCase       ,					__UpperCAmelCase=None       ,					__UpperCAmelCase=None       ,					__UpperCAmelCase=0 ):



         '''simple docstring'''

         lowerCAmelCase__     :List[Any]											=				1.0 if scale is None else scale
         lowerCAmelCase__     :List[Any]											=				0.0 if loc is None else loc

         super().__init__(__UpperCAmelCase       ,					[AffineTransform(loc=self.loc       ,					scale=self.scale       ,					event_dim=__UpperCAmelCase )] )






       @property
       def 	snake_case		(       self ):



         '''simple docstring'''

         return self.base_dist.mean * self.scale + self.loc






       @property
       def 	snake_case		(       self ):



         '''simple docstring'''

         return self.base_dist.variance * self.scale**2






       @property
       def 	snake_case		(       self ):



         '''simple docstring'''

         return self.variance.sqrt()






class    _lowerCAmelCase  (	nn.Module			):
       """simple docstring"""




       def __init__(       self       ,					__UpperCAmelCase       ,					__UpperCAmelCase       ,					__UpperCAmelCase       ,					**__UpperCAmelCase ):



         '''simple docstring'''

         super().__init__(**__UpperCAmelCase )
         lowerCAmelCase__     :List[Any]											=				args_dim
         lowerCAmelCase__     :int											=				nn.ModuleList([nn.Linear(__UpperCAmelCase       ,					__UpperCAmelCase ) for dim in args_dim.values()] )
         lowerCAmelCase__     :Optional[int]											=				domain_map






       def 	snake_case		(       self       ,					__UpperCAmelCase ):



         '''simple docstring'''

         lowerCAmelCase__     :Any											=				[proj(__UpperCAmelCase ) for proj in self.proj]

         return self.domain_map(*__UpperCAmelCase )






class    _lowerCAmelCase  (	nn.Module			):
       """simple docstring"""




       def __init__(       self       ,					__UpperCAmelCase ):



         '''simple docstring'''

         super().__init__()
         lowerCAmelCase__     :Optional[Any]											=				function






       def 	snake_case		(       self       ,					__UpperCAmelCase       ,					*__UpperCAmelCase ):



         '''simple docstring'''

         return self.function(__UpperCAmelCase       ,					*__UpperCAmelCase )






class    _lowerCAmelCase  :
       """simple docstring"""




       __magic_name__	:type
       __magic_name__	:int
       __magic_name__	:Dict[str, int]






       def __init__(       self       ,					__UpperCAmelCase = 1 ):



         '''simple docstring'''

         lowerCAmelCase__     :Optional[int]											=				dim
         lowerCAmelCase__     :Optional[int]											=				{k: dim * self.args_dim[k] for k in self.args_dim}






       def 	snake_case		(       self       ,					__UpperCAmelCase ):



         '''simple docstring'''

         if self.dim == 1:
           return self.distribution_class(*__UpperCAmelCase )
         else:
           return Independent(self.distribution_class(*__UpperCAmelCase )       ,					1 )






       def 	snake_case		(       self       ,					__UpperCAmelCase       ,					__UpperCAmelCase = None       ,					__UpperCAmelCase = None       ,					):



         '''simple docstring'''

         lowerCAmelCase__     :Optional[Any]											=				self._base_distribution(__UpperCAmelCase )
         if loc is None and scale is None:
           return distr
         else:
           return AffineTransformed(__UpperCAmelCase       ,					loc=__UpperCAmelCase       ,					scale=__UpperCAmelCase       ,					event_dim=self.event_dim )






       @property
       def 	snake_case		(       self ):



         '''simple docstring'''

         return () if self.dim == 1 else (self.dim,)






       @property
       def 	snake_case		(       self ):



         '''simple docstring'''

         return len(self.event_shape )






       @property
       def 	snake_case		(       self ):



         '''simple docstring'''

         return 0.0






       def 	snake_case		(       self       ,					__UpperCAmelCase ):



         '''simple docstring'''

         return ParameterProjection(
             in_features=__UpperCAmelCase       ,					args_dim=self.args_dim       ,					domain_map=LambdaLayer(self.domain_map )       ,					)






       def 	snake_case		(       self       ,					*__UpperCAmelCase ):



         '''simple docstring'''

         raise NotImplementedError()






       @staticmethod
       def 	snake_case		(       __UpperCAmelCase ):



         '''simple docstring'''

         return (x + torch.sqrt(torch.square(__UpperCAmelCase ) + 4.0 )) / 2.0






class    _lowerCAmelCase  (	a			):
       """simple docstring"""




       __magic_name__	:Dict[str, int]						    =   {"df": 1, "loc": 1, "scale": 1}
       __magic_name__	:type						    =   StudentT






       @classmethod
       def 	snake_case		(       cls       ,					__UpperCAmelCase       ,					__UpperCAmelCase       ,					__UpperCAmelCase ):



         '''simple docstring'''

         lowerCAmelCase__     :str											=				cls.squareplus(__UpperCAmelCase ).clamp_min(torch.finfo(scale.dtype ).eps )
         lowerCAmelCase__     :Dict											=				2.0 + cls.squareplus(__UpperCAmelCase )
         return df.squeeze(-1 ), loc.squeeze(-1 ), scale.squeeze(-1 )






class    _lowerCAmelCase  (	a			):
       """simple docstring"""




       __magic_name__	:Dict[str, int]						    =   {"loc": 1, "scale": 1}
       __magic_name__	:type						    =   Normal






       @classmethod
       def 	snake_case		(       cls       ,					__UpperCAmelCase       ,					__UpperCAmelCase ):



         '''simple docstring'''

         lowerCAmelCase__     :Union[str, Any]											=				cls.squareplus(__UpperCAmelCase ).clamp_min(torch.finfo(scale.dtype ).eps )
         return loc.squeeze(-1 ), scale.squeeze(-1 )






class    _lowerCAmelCase  (	a			):
       """simple docstring"""




       __magic_name__	:Dict[str, int]						    =   {"total_count": 1, "logits": 1}
       __magic_name__	:type						    =   NegativeBinomial






       @classmethod
       def 	snake_case		(       cls       ,					__UpperCAmelCase       ,					__UpperCAmelCase ):



         '''simple docstring'''

         lowerCAmelCase__     :List[Any]											=				cls.squareplus(__UpperCAmelCase )
         return total_count.squeeze(-1 ), logits.squeeze(-1 )






       def 	snake_case		(       self       ,					__UpperCAmelCase ):



         '''simple docstring'''

         lowerCAmelCase__				,							lowerCAmelCase__     :Optional[Any]											=				distr_args
         if self.dim == 1:
           return self.distribution_class(total_count=__UpperCAmelCase       ,					logits=__UpperCAmelCase )
         else:
           return Independent(self.distribution_class(total_count=__UpperCAmelCase       ,					logits=__UpperCAmelCase )       ,					1 )






       def 	snake_case		(       self       ,					__UpperCAmelCase       ,					__UpperCAmelCase = None       ,					__UpperCAmelCase = None ):



         '''simple docstring'''

         lowerCAmelCase__				,							lowerCAmelCase__     :str											=				distr_args

         if scale is not None:
           # See scaling property of Gamma.
           logits += scale.log()

         return self._base_distribution((total_count, logits) )





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()))))






