



'''simple docstring'''

from __future__ import annotations

from collections.abc import Callable
from typing import Generic, TypeVar

UpperCAmelCase     		=   TypeVar('T')
UpperCAmelCase     		=   TypeVar('U')

class __snake_case(				Generic[T, U] ):


	'''simple docstring'''



	def __init__( self     ,	A_     ,	A_				)     ->     Dict:
		lowerCAmelCase   =     key
		lowerCAmelCase   =     val
		lowerCAmelCase   =     None
		lowerCAmelCase   =     None




	def __repr__( self				)     ->     str:
		return (
		    f'Node: key: {self.key}, val: {self.val}, '
		    f'has next: {bool(self.next				)}, has prev: {bool(self.prev				)}'
		)







class __snake_case(				Generic[T, U] ):


	'''simple docstring'''



	def __init__( self				)     ->     None:
		lowerCAmelCase   =     DoubleLinkedListNode(A_     ,	A_				)
		lowerCAmelCase   =     DoubleLinkedListNode(A_     ,	A_				)
		lowerCAmelCase,       lowerCAmelCase   =     self.rear, self.head


	def __repr__( self				)     ->     str:
		lowerCAmelCase   =     ["""DoubleLinkedList"""]
		lowerCAmelCase   =     self.head
		while node.next is not None:
			rep.append(str(A_				)				)
			lowerCAmelCase   =     node.next
		rep.append(str(self.rear				)				)
		return ",\n    ".join(A_				)


	def     __snake_case   ( self     ,	A_				)     ->     None:
		lowerCAmelCase   =     self.rear.prev

		# All nodes other than self.head are guaranteed to have non-None previous
		assert previous is not None

		lowerCAmelCase   =     node
		lowerCAmelCase   =     previous
		lowerCAmelCase   =     node
		lowerCAmelCase   =     self.rear




	def     __snake_case   ( self     ,	A_				)     ->     DoubleLinkedListNode[T, U] | None:

		if node.prev is None or node.next is None:
			return None

		lowerCAmelCase   =     node.next
		lowerCAmelCase   =     node.prev
		lowerCAmelCase   =     None
		lowerCAmelCase   =     None
		return node







class __snake_case(				Generic[T, U] ):


	'''simple docstring'''



	UpperCAmelCase							:   dict[Callable[[T], U], LRUCache[T, U]]									=		{}


	def __init__( self     ,	A_				)     ->     str:
		lowerCAmelCase   =     DoubleLinkedList()
		lowerCAmelCase   =     capacity
		lowerCAmelCase   =     0
		lowerCAmelCase   =     0
		lowerCAmelCase   =     0
		lowerCAmelCase   =     {}


	def __repr__( self				)     ->     str:
		return (
		    f'CacheInfo(hits={self.hits}, misses={self.miss}, '
		    f'capacity={self.capacity}, current size={self.num_keys})'
		)


	def __contains__( self     ,	A_				)     ->     bool:
		return key in self.cache


	def     __snake_case   ( self     ,	A_				)     ->     U | None:
		# Note: pythonic interface would throw KeyError rather than return None

		if key in self.cache:
			self.hits += 1
			lowerCAmelCase   =     self.cache[key]
			lowerCAmelCase   =     self.list.remove(self.cache[key]				)
			assert node == value_node

			# node is guaranteed not None because it is in self.cache
			assert node is not None
			self.list.add(A_				)
			return node.val
		self.miss += 1
		return None


	def     __snake_case   ( self     ,	A_     ,	A_				)     ->     None:

		if key not in self.cache:
			if self.num_keys >= self.capacity:
				# delete first node (oldest) when over capacity
				lowerCAmelCase   =     self.list.head.next

				# guaranteed to have a non-None first node when num_keys > 0
				# explain to type checker via assertions
				assert first_node is not None
				assert first_node.key is not None
				assert (
				    self.list.remove(A_				) is not None
				)  # node guaranteed to be in list assert node.key is not None

				del self.cache[first_node.key]
				self.num_keys -= 1
			lowerCAmelCase   =     DoubleLinkedListNode(A_     ,	A_				)
			self.list.add(self.cache[key]				)
			self.num_keys += 1

		else:
			# bump node to the end of the list, update value
			lowerCAmelCase   =     self.list.remove(self.cache[key]				)
			assert node is not None  # node guaranteed to be in list
			lowerCAmelCase   =     value
			self.list.add(A_				)




	@classmethod
	def     __snake_case   ( cls     ,	A_ = 128				)     ->     Callable[[Callable[[T], U]], Callable[..., U]]:

		def cache_decorator_inner(A_				) -> Callable[..., U]:
			def cache_decorator_wrapper(*A_				) -> U:
				if func not in cls.decorator_function_to_instance_map:
					lowerCAmelCase   =     LRUCache(A_				)

				lowerCAmelCase   =     cls.decorator_function_to_instance_map[func].get(args[0]				)
				if result is None:
					lowerCAmelCase   =     func(*A_				)
					cls.decorator_function_to_instance_map[func].put(args[0]     ,	A_				)
				return result

			def cache_info() -> LRUCache[T, U]:
				return cls.decorator_function_to_instance_map[func]

			setattr(A_     ,	"""cache_info"""     ,	A_				)  # noqa: B010

			return cache_decorator_wrapper

		return cache_decorator_inner


if __name__ == "__main__":
				import doctest

				doctest.testmod()




'''simple docstring'''

from __future__ import annotations






def 		_snake_case		( _SCREAMING_SNAKE_CASE					:						int | str							)      ->						bool:







	"""simple docstring"""
	lowerCAmelCase   =     str(_SCREAMING_SNAKE_CASE							)
	return n == n[::-1]






def 		_snake_case		( _SCREAMING_SNAKE_CASE					:						int = 1_000_000							)      ->						Dict:







	"""simple docstring"""
	lowerCAmelCase   =     0

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


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