

from timeit import timeit

snake_case_			  = {
    '''MALAYALAM''': True,
    '''String''': False,
    '''rotor''': True,
    '''level''': True,
    '''A''': True,
    '''BB''': True,
    '''ABC''': False,
    '''amanaplanacanalpanama''': True,  # "a man a plan a canal panama"
}
# Ensure our test data is valid
assert all((key == key[::-1]) is value for key, value in test_data.items())

def 	snake_case__			(    SCREAMING_SNAKE_CASE_		:    str			):



     '''simple docstring'''





     lowercase__    :   int      =       0
     lowercase__    :   Optional[int]      =       len(SCREAMING_SNAKE_CASE_			) - 1
     while start_i < end_i:
          if s[start_i] == s[end_i]:
               start_i += 1
               end_i -= 1
          else:
               return False
     return True

def 	snake_case__			(    SCREAMING_SNAKE_CASE_		:    str			):



     '''simple docstring'''





     lowercase__    :   Any      =       len(SCREAMING_SNAKE_CASE_			) // 2
     lowercase__    :   int      =       len(SCREAMING_SNAKE_CASE_			)

     # We need to traverse till half of the length of string
     # as we can get access of the i'th last element from
     # i'th index.
     # eg: [0,1,2,3,4,5] => 4th index can be accessed
     # with the help of 1st index (i==n-i-1)
     # where n is length of string
     return all(s[i] == s[n - i - 1] for i in range(SCREAMING_SNAKE_CASE_			)			)

def 	snake_case__			(    SCREAMING_SNAKE_CASE_		:    str			):



     '''simple docstring'''





     if len(SCREAMING_SNAKE_CASE_			) <= 2:
          return True
     if s[0] == s[len(SCREAMING_SNAKE_CASE_			) - 1]:
          return is_palindrome_recursive(s[1:-1]			)
     else:
          return False

def 	snake_case__			(    SCREAMING_SNAKE_CASE_		:    str			):



     '''simple docstring'''





     return s == s[::-1]

def 	snake_case__			(    SCREAMING_SNAKE_CASE_		:    str			):



     '''simple docstring'''





     lowercase__    :   str      =       f"""all({name}(key) is value for key, value in test_data.items())"""
     lowercase__    :   str      =       f"""from __main__ import test_data, {name}"""
     lowercase__    :   List[Any]      =       500_000
     lowercase__    :   Optional[int]      =       timeit(stmt=SCREAMING_SNAKE_CASE_	,     setup=SCREAMING_SNAKE_CASE_	,     number=SCREAMING_SNAKE_CASE_			)
     print(f"""{name:<35} finished {number:,} runs in {result:.5f} seconds"""			)


if __name__ == "__main__":
       for key, value in test_data.items():
              assert is_palindrome(key) is is_palindrome_recursive(key)
              assert is_palindrome(key) is is_palindrome_slice(key)
              print(F'''{key:21} {value}''')
       print('''a man a plan a canal panama''')

       # finished 500,000 runs in 0.46793 seconds
       benchmark_function('''is_palindrome_slice''')
       # finished 500,000 runs in 0.85234 seconds
       benchmark_function('''is_palindrome''')
       # finished 500,000 runs in 1.32028 seconds
       benchmark_function('''is_palindrome_recursive''')
       # finished 500,000 runs in 2.08679 seconds
       benchmark_function('''is_palindrome_traversal''')




from __future__ import annotations

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

snake_case_			  = TypeVar('''T''')
snake_case_			  = TypeVar('''U''')


class       SCREAMING_SNAKE_CASE__					(Generic[T, U]     ):





    def __init__(      self						,   a						,   a):
         lowercase__    :   List[Any]      =       key
         lowercase__    :   List[Any]      =       val
         lowercase__    :   DoubleLinkedListNode[T, U] | None      =       None
         lowercase__    :   DoubleLinkedListNode[T, U] | None      =       None





    def __repr__(      self):
         return (
             f"""Node: key: {self.key}, val: {self.val}, """
             f"""has next: {bool(self.next)}, has prev: {bool(self.prev)}"""
         )



class       SCREAMING_SNAKE_CASE__					(Generic[T, U]     ):





    def __init__(      self):
         lowercase__    :   DoubleLinkedListNode[T, U]      =       DoubleLinkedListNode(a						,   a)
         lowercase__    :   DoubleLinkedListNode[T, U]      =       DoubleLinkedListNode(a						,   a)
         lowercase__      , lowercase__    :   Union[str, Any]      =       self.rear, self.head





    def __repr__(      self):
         lowercase__    :   Any      =       ['DoubleLinkedList']
         lowercase__    :   List[str]      =       self.head
         while node.next is not None:
              rep.append(str(a))
              lowercase__    :   Tuple      =       node.next
         rep.append(str(self.rear))
         return ",\n    ".join(a)





    def       snake_case_				(      self						,   a):
         lowercase__    :   Optional[Any]      =       self.rear.prev

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

         lowercase__    :   Dict      =       node
         lowercase__    :   int      =       previous
         lowercase__    :   Union[str, Any]      =       node
         lowercase__    :   Optional[int]      =       self.rear





    def       snake_case_				(      self						,   a):

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

         lowercase__    :   Union[str, Any]      =       node.next
         lowercase__    :   Tuple      =       node.prev
         lowercase__    :   Union[str, Any]      =       None
         lowercase__    :   List[Any]      =       None
         return node



class       SCREAMING_SNAKE_CASE__					(Generic[T, U]     ):
    __lowerCamelCase						:       dict[Callable[[T], U], LRUCache[T, U]]														=     {}





    def __init__(      self						,   a):
         lowercase__    :   DoubleLinkedList[T, U]      =       DoubleLinkedList()
         lowercase__    :   Optional[Any]      =       capacity
         lowercase__    :   Union[str, Any]      =       0
         lowercase__    :   Tuple      =       0
         lowercase__    :   int      =       0
         lowercase__    :   dict[T, DoubleLinkedListNode[T, U]]      =       {}





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





    def __contains__(      self						,   a):
         return key in self.cache





    def       snake_case_				(      self						,   a):
         # Note: pythonic interface would throw KeyError rather than return None

         if key in self.cache:
              self.hits += 1
              lowercase__    :   DoubleLinkedListNode[T, U]      =       self.cache[key]
              lowercase__    :   str      =       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):

         if key not in self.cache:
              if self.num_keys >= self.capacity:
                   # delete first node (oldest) when over capacity
                   lowercase__    :   Optional[int]      =       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
              lowercase__    :   Optional[Any]      =       DoubleLinkedListNode(a						,   a)
              self.list.add(self.cache[key])
              self.num_keys += 1

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





    @classmethod
    def       snake_case_				(      cls						,   a = 128):

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

                   lowercase__    :   str      =       cls.decorator_function_to_instance_map[func].get(args[0])
                   if result is None:
                        lowercase__    :   str      =       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()

