






from abc import ABC, abstractmethod
from typing import List, Optional


class  SCREAMING_SNAKE_CASE			(			lowerCAmelCase					):
     '''simple docstring'''


     def __init__(				self       :	List[Any]      ):
       # test for the above condition
       self.test()


     def 				_A       (				self       :	Any      ):
       SCREAMING_SNAKE_CASE       :      Optional[int]							=    0
       SCREAMING_SNAKE_CASE       :      Optional[int]							=    False
       while not completed:
         if counter == 1:
           self.reset()
         SCREAMING_SNAKE_CASE       :      List[Any]							=    self.advance()
         if not self.does_advance(UpperCAmelCase_      ):
           raise Exception(
               "Custom Constraint is not defined correctly. self.does_advance(self.advance()) must be true."      )

         SCREAMING_SNAKE_CASE						,  SCREAMING_SNAKE_CASE						,  SCREAMING_SNAKE_CASE       :      Dict							=    self.update(UpperCAmelCase_      )
         counter += 1

         if counter > 1_0000:
           raise Exception("update() does not fulfill the constraint."      )

       if self.remaining() != 0:
         raise Exception("Custom Constraint is not defined correctly."      )


     @abstractmethod
     def 				_A       (				self       :	Optional[int]      ):
       raise NotImplementedError(
           f'''{self.__class__} is an abstract class. Only classes inheriting this class can be called.'''      )


     @abstractmethod
     def 				_A       (				self       :	Optional[int]					, UpperCAmelCase_       :	int      ):
       raise NotImplementedError(
           f'''{self.__class__} is an abstract class. Only classes inheriting this class can be called.'''      )


     @abstractmethod
     def 				_A       (				self       :	List[Any]					, UpperCAmelCase_       :	int      ):
       raise NotImplementedError(
           f'''{self.__class__} is an abstract class. Only classes inheriting this class can be called.'''      )


     @abstractmethod
     def 				_A       (				self       :	Tuple      ):
       raise NotImplementedError(
           f'''{self.__class__} is an abstract class. Only classes inheriting this class can be called.'''      )


     @abstractmethod
     def 				_A       (				self       :	List[Any]      ):
       raise NotImplementedError(
           f'''{self.__class__} is an abstract class. Only classes inheriting this class can be called.'''      )






     @abstractmethod
     def 				_A       (				self       :	Tuple					, UpperCAmelCase_       :	List[Any]=False      ):
       raise NotImplementedError(
           f'''{self.__class__} is an abstract class. Only classes inheriting this class can be called.'''      )





class  SCREAMING_SNAKE_CASE			(			lowerCAmelCase					):
     '''simple docstring'''


     def __init__(				self       :	Union[str, Any]					, UpperCAmelCase_       :	List[int]      ):
       super(UpperCAmelCase_					, self      ).__init__()

       if not isinstance(UpperCAmelCase_					, UpperCAmelCase_      ) or len(UpperCAmelCase_      ) == 0:
         raise ValueError(f'''`token_ids` has to be a non-empty list, but is {token_ids}.'''      )
       if any((not isinstance(UpperCAmelCase_					, UpperCAmelCase_      ) or token_id < 0) for token_id in token_ids      ):
         raise ValueError(f'''Each list in `token_ids` has to be a list of positive integers, but is {token_ids}.'''      )

       SCREAMING_SNAKE_CASE       :      Union[str, Any]							=    token_ids

       SCREAMING_SNAKE_CASE       :      Any							=    len(self.token_ids      )
       SCREAMING_SNAKE_CASE       :      str							=    -1  # the index of the currently fulfilled step
       SCREAMING_SNAKE_CASE       :      Union[str, Any]							=    False


     def 				_A       (				self       :	List[Any]      ):
       if self.completed:
         return None
       return self.token_ids[self.fulfilled_idx + 1]


     def 				_A       (				self       :	str					, UpperCAmelCase_       :	int      ):
       if not isinstance(UpperCAmelCase_					, UpperCAmelCase_      ):
         raise ValueError(f'''`token_id` has to be an `int`, but is {token_id} of type {type(UpperCAmelCase_      )}'''      )

       if self.completed:
         return False

       return token_id == self.token_ids[self.fulfilled_idx + 1]


     def 				_A       (				self       :	Optional[Any]					, UpperCAmelCase_       :	int      ):
       if not isinstance(UpperCAmelCase_					, UpperCAmelCase_      ):
         raise ValueError(f'''`token_id` has to be an `int`, but is {token_id} of type {type(UpperCAmelCase_      )}'''      )

       SCREAMING_SNAKE_CASE       :      int							=    False
       SCREAMING_SNAKE_CASE       :      Any							=    False
       SCREAMING_SNAKE_CASE       :      List[Any]							=    False

       if self.does_advance(UpperCAmelCase_      ):
         self.fulfilled_idx += 1
         SCREAMING_SNAKE_CASE       :      int							=    True
         if self.fulfilled_idx == (self.seqlen - 1):
           SCREAMING_SNAKE_CASE       :      Optional[Any]							=    True
         SCREAMING_SNAKE_CASE       :      Tuple							=    completed
       else:
         # failed to make progress.
         SCREAMING_SNAKE_CASE       :      Tuple							=    True
         self.reset()
       return stepped, completed, reset


     def 				_A       (				self       :	List[str]      ):
       SCREAMING_SNAKE_CASE       :      Optional[Any]							=    False
       SCREAMING_SNAKE_CASE       :      str							=    0


     def 				_A       (				self       :	Optional[Any]      ):
       return self.seqlen - (self.fulfilled_idx + 1)






     def 				_A       (				self       :	Optional[Any]					, UpperCAmelCase_       :	List[str]=False      ):
       SCREAMING_SNAKE_CASE       :      str							=    PhrasalConstraint(self.token_ids      )

       if stateful:
         SCREAMING_SNAKE_CASE       :      List[str]							=    self.seqlen
         SCREAMING_SNAKE_CASE       :      Any							=    self.fulfilled_idx
         SCREAMING_SNAKE_CASE       :      Any							=    self.completed

       return new_constraint





class  SCREAMING_SNAKE_CASE			:
     '''simple docstring'''


     def __init__(				self       :	List[str]					, UpperCAmelCase_       :	List[List[int]]					, UpperCAmelCase_       :	Any=True      ):
       SCREAMING_SNAKE_CASE       :      Dict							=    max([len(UpperCAmelCase_      ) for one in nested_token_ids]      )

       SCREAMING_SNAKE_CASE       :      List[Any]							=    {}
       for token_ids in nested_token_ids:
         SCREAMING_SNAKE_CASE       :      Dict							=    root
         for tidx, token_id in enumerate(UpperCAmelCase_      ):
           if token_id not in level:
             SCREAMING_SNAKE_CASE       :      int							=    {}

           SCREAMING_SNAKE_CASE       :      str							=    level[token_id]

       if no_subsets and self.has_subsets(UpperCAmelCase_					, UpperCAmelCase_      ):
         raise ValueError(
             "Each list in `nested_token_ids` can't be a complete subset of another list, but is"
             f''' {nested_token_ids}.'''      )

       SCREAMING_SNAKE_CASE       :      List[Any]							=    root


     def 				_A       (				self       :	int					, UpperCAmelCase_       :	List[str]      ):
       SCREAMING_SNAKE_CASE       :      Optional[int]							=    self.trie

       for current_token in current_seq:
         SCREAMING_SNAKE_CASE       :      Any							=    start[current_token]

       SCREAMING_SNAKE_CASE       :      List[str]							=    list(start.keys()      )

       return next_tokens


     def 				_A       (				self       :	str					, UpperCAmelCase_       :	Tuple      ):
       SCREAMING_SNAKE_CASE       :      Optional[int]							=    self.next_tokens(UpperCAmelCase_      )

       return len(UpperCAmelCase_      ) == 0


     def 				_A       (				self       :	Optional[Any]					, UpperCAmelCase_       :	Tuple      ):
       SCREAMING_SNAKE_CASE       :      Tuple							=    list(root.values()      )
       if len(UpperCAmelCase_      ) == 0:
         return 1
       else:
         return sum([self.count_leaves(UpperCAmelCase_      ) for nn in next_nodes]      )






     def 				_A       (				self       :	Any					, UpperCAmelCase_       :	Optional[Any]					, UpperCAmelCase_       :	Any      ):
       SCREAMING_SNAKE_CASE       :      int							=    self.count_leaves(UpperCAmelCase_      )
       return len(UpperCAmelCase_      ) != leaf_count





class  SCREAMING_SNAKE_CASE			(			lowerCAmelCase					):
     '''simple docstring'''


     def __init__(				self       :	Optional[Any]					, UpperCAmelCase_       :	List[List[int]]      ):
       super(UpperCAmelCase_					, self      ).__init__()

       if not isinstance(UpperCAmelCase_					, UpperCAmelCase_      ) or len(UpperCAmelCase_      ) == 0:
         raise ValueError(f'''`nested_token_ids` has to be a non-empty list, but is {nested_token_ids}.'''      )
       if any(not isinstance(UpperCAmelCase_					, UpperCAmelCase_      ) for token_ids in nested_token_ids      ):
         raise ValueError(f'''`nested_token_ids` has to be a list of lists, but is {nested_token_ids}.'''      )
       if any(
           any((not isinstance(UpperCAmelCase_					, UpperCAmelCase_      ) or token_id < 0) for token_id in token_ids      )
           for token_ids in nested_token_ids      ):
         raise ValueError(
             f'''Each list in `nested_token_ids` has to be a list of positive integers, but is {nested_token_ids}.'''      )

       SCREAMING_SNAKE_CASE       :      Optional[int]							=    DisjunctiveTrie(UpperCAmelCase_      )
       SCREAMING_SNAKE_CASE       :      Optional[Any]							=    nested_token_ids

       SCREAMING_SNAKE_CASE       :      Optional[int]							=    self.trie.max_height
       SCREAMING_SNAKE_CASE       :      Union[str, Any]							=    []
       SCREAMING_SNAKE_CASE       :      Tuple							=    False


     def 				_A       (				self       :	Dict      ):
       SCREAMING_SNAKE_CASE       :      List[str]							=    self.trie.next_tokens(self.current_seq      )

       if len(UpperCAmelCase_      ) == 0:
         return None
       else:
         return token_list


     def 				_A       (				self       :	Dict					, UpperCAmelCase_       :	int      ):
       if not isinstance(UpperCAmelCase_					, UpperCAmelCase_      ):
         raise ValueError(f'''`token_id` is supposed to be type `int`, but is {token_id} of type {type(UpperCAmelCase_      )}'''      )

       SCREAMING_SNAKE_CASE       :      int							=    self.trie.next_tokens(self.current_seq      )

       return token_id in next_tokens


     def 				_A       (				self       :	Tuple					, UpperCAmelCase_       :	int      ):
       if not isinstance(UpperCAmelCase_					, UpperCAmelCase_      ):
         raise ValueError(f'''`token_id` is supposed to be type `int`, but is {token_id} of type {type(UpperCAmelCase_      )}'''      )

       SCREAMING_SNAKE_CASE       :      Optional[int]							=    False
       SCREAMING_SNAKE_CASE       :      Dict							=    False
       SCREAMING_SNAKE_CASE       :      Optional[int]							=    False

       if self.does_advance(UpperCAmelCase_      ):
         self.current_seq.append(UpperCAmelCase_      )
         SCREAMING_SNAKE_CASE       :      Union[str, Any]							=    True
       else:
         SCREAMING_SNAKE_CASE       :      Any							=    True
         self.reset()

       SCREAMING_SNAKE_CASE       :      Tuple							=    self.trie.reached_leaf(self.current_seq      )
       SCREAMING_SNAKE_CASE       :      Any							=    completed

       return stepped, completed, reset


     def 				_A       (				self       :	List[Any]      ):
       SCREAMING_SNAKE_CASE       :      Tuple							=    False
       SCREAMING_SNAKE_CASE       :      Any							=    []


     def 				_A       (				self       :	str      ):
       if self.completed:
         # since this can be completed without reaching max height
         return 0
       else:
         return self.seqlen - len(self.current_seq      )






     def 				_A       (				self       :	List[str]					, UpperCAmelCase_       :	int=False      ):
       SCREAMING_SNAKE_CASE       :      Optional[Any]							=    DisjunctiveConstraint(self.token_ids      )

       if stateful:
         SCREAMING_SNAKE_CASE       :      Dict							=    self.seqlen
         SCREAMING_SNAKE_CASE       :      Dict							=    self.current_seq
         SCREAMING_SNAKE_CASE       :      Optional[Any]							=    self.completed

       return new_constraint





class  SCREAMING_SNAKE_CASE			:
     '''simple docstring'''


     def __init__(				self       :	List[Any]					, UpperCAmelCase_       :	List[Constraint]      ):
       SCREAMING_SNAKE_CASE       :      str							=    constraints

       # max # of steps required to fulfill a given constraint
       SCREAMING_SNAKE_CASE       :      Dict							=    max([c.seqlen for c in constraints]      )
       SCREAMING_SNAKE_CASE       :      Optional[int]							=    len(UpperCAmelCase_      )
       SCREAMING_SNAKE_CASE       :      List[str]							=    False

       self.init_state()


     def 				_A       (				self       :	Optional[Any]      ):
       SCREAMING_SNAKE_CASE       :      Any							=    []
       SCREAMING_SNAKE_CASE       :      Union[str, Any]							=    None
       SCREAMING_SNAKE_CASE       :      int							=    [constraint.copy(stateful=UpperCAmelCase_      ) for constraint in self.constraints]


     def 				_A       (				self       :	List[str]      ):
       SCREAMING_SNAKE_CASE       :      Dict							=    0
       if self.inprogress_constraint:
         # extra points for having a constraint mid-fulfilled
         add += self.max_seqlen - self.inprogress_constraint.remaining()

       return (len(self.complete_constraints      ) * self.max_seqlen) + add


     def 				_A       (				self       :	List[Any]      ):
       SCREAMING_SNAKE_CASE       :      Any							=    []
       if self.inprogress_constraint is None:
         for constraint in self.pending_constraints:  # "pending" == "unfulfilled yet"
           SCREAMING_SNAKE_CASE       :      Dict							=    constraint.advance()
           if isinstance(UpperCAmelCase_					, UpperCAmelCase_      ):
             token_list.append(UpperCAmelCase_      )
           elif isinstance(UpperCAmelCase_					, UpperCAmelCase_      ):
             token_list.extend(UpperCAmelCase_      )
       else:
         SCREAMING_SNAKE_CASE       :      List[Any]							=    self.inprogress_constraint.advance()
         if isinstance(UpperCAmelCase_					, UpperCAmelCase_      ):
           token_list.append(UpperCAmelCase_      )
         elif isinstance(UpperCAmelCase_					, UpperCAmelCase_      ):
           token_list.extend(UpperCAmelCase_      )

       if len(UpperCAmelCase_      ) == 0:
         return None
       else:
         return token_list


     def 				_A       (				self       :	Union[str, Any]					, UpperCAmelCase_       :	Optional[List[int]]      ):
       self.init_state()

       if token_ids is not None:
         for token in token_ids:
           # completes or steps **one** constraint
           SCREAMING_SNAKE_CASE						,  SCREAMING_SNAKE_CASE       :      List[Any]							=    self.add(UpperCAmelCase_      )

           # the entire list of constraints are fulfilled
           if self.completed:
             break


     def 				_A       (				self       :	Optional[Any]					, UpperCAmelCase_       :	int      ):
       if not isinstance(UpperCAmelCase_					, UpperCAmelCase_      ):
         raise ValueError(f'''`token_id` should be an `int`, but is `{token_id}`.'''      )

       SCREAMING_SNAKE_CASE						,  SCREAMING_SNAKE_CASE       :      Any							=    False, False

       if self.completed:
         SCREAMING_SNAKE_CASE       :      Union[str, Any]							=    True
         SCREAMING_SNAKE_CASE       :      int							=    False
         return complete, stepped

       if self.inprogress_constraint is not None:
         # In the middle of fulfilling a constraint. If the `token_id` *does* makes an incremental progress to current
         # job, simply update the state

         SCREAMING_SNAKE_CASE						,  SCREAMING_SNAKE_CASE						,  SCREAMING_SNAKE_CASE       :      Dict							=    self.inprogress_constraint.update(UpperCAmelCase_      )
         if reset:
           # 1. If the next token breaks the progress, then we must restart.
           #     e.g. constraint = "I love pies" and sequence so far is "I love" but `token_id` == "books".

           #     But that doesn't mean we self.init_state(), since we only reset the state for this particular
           #     constraint, not the full list of constraints.

           self.pending_constraints.append(self.inprogress_constraint.copy(stateful=UpperCAmelCase_      )      )
           SCREAMING_SNAKE_CASE       :      str							=    None

         if complete:
           # 2. If the next token completes the constraint, move it to completed list, set
           #     inprogress to None. If there are no pending constraints either, then this full list of constraints
           #     is complete.

           self.complete_constraints.append(self.inprogress_constraint      )
           SCREAMING_SNAKE_CASE       :      List[Any]							=    None

           if len(self.pending_constraints      ) == 0:
             # we're done!
             SCREAMING_SNAKE_CASE       :      Any							=    True

       else:
         # Not in the middle of fulfilling a constraint. So does this `token_id` helps us step towards any of our list
         # of constraints?

         for cidx, pending_constraint in enumerate(self.pending_constraints      ):
           if pending_constraint.does_advance(UpperCAmelCase_      ):
             SCREAMING_SNAKE_CASE						,  SCREAMING_SNAKE_CASE						,  SCREAMING_SNAKE_CASE       :      Optional[Any]							=    pending_constraint.update(UpperCAmelCase_      )

             if not stepped:
               raise Exception(
                   "`constraint.update(token_id)` is not yielding incremental progress, "
                   "even though `constraint.does_advance(token_id)` is true."      )

             if complete:
               self.complete_constraints.append(UpperCAmelCase_      )
               SCREAMING_SNAKE_CASE       :      Any							=    None

             if not complete and stepped:
               SCREAMING_SNAKE_CASE       :      List[str]							=    pending_constraint

             if complete or stepped:
               # If we made any progress at all, then it's at least not a "pending constraint".

               SCREAMING_SNAKE_CASE       :      List[Any]							=    (
                   self.pending_constraints[:cidx] + self.pending_constraints[cidx + 1 :]
               )

               if len(self.pending_constraints      ) == 0 and self.inprogress_constraint is None:
                 # If there's no longer any pending after this and no inprogress either, then we must be
                 # complete.

                 SCREAMING_SNAKE_CASE       :      Dict							=    True

               break  # prevent accidentally stepping through multiple constraints with just one token.

       return complete, stepped






     def 				_A       (				self       :	Union[str, Any]					, UpperCAmelCase_       :	List[Any]=True      ):
       SCREAMING_SNAKE_CASE       :      List[str]							=    ConstraintListState(self.constraints      )  # we actually never though self.constraints objects
       # throughout this process. So it's at initialization state.

       if stateful:
         SCREAMING_SNAKE_CASE       :      str							=    [
             constraint.copy(stateful=UpperCAmelCase_      ) for constraint in self.complete_constraints
         ]
         if self.inprogress_constraint is not None:
           SCREAMING_SNAKE_CASE       :      List[str]							=    self.inprogress_constraint.copy(stateful=UpperCAmelCase_      )
         SCREAMING_SNAKE_CASE       :      Union[str, Any]							=    [constraint.copy() for constraint in self.pending_constraints]

       return new_state














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






