"""simple docstring"""
from __future__ import annotations

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

lowercase__   			=      TypeVar('T')
lowercase__   			=      TypeVar('U')




class   __snake_case			(	Generic[T, U]							):



      def __init__(		self       ,     lowercase       ,     lowercase)      ->     Union[str, Any]:





        '''simple docstring'''





        a__:	Dict     				=      key
        a__:	int     				=      val
        a__:	int     				=      0
        a__:	DoubleLinkedListNode[T, U] | None     				=      None
        a__:	DoubleLinkedListNode[T, U] | None     				=      None



      def __repr__(		self)      ->     str:





        '''simple docstring'''





        return "Node: key: {}, val: {}, freq: {}, has next: {}, has prev: {}".format(
            self.key       ,     self.val       ,     self.freq       ,     self.next is not None       ,     self.prev is not None)







class   __snake_case			(	Generic[T, U]							):



      def __init__(		self)      ->     None:





        '''simple docstring'''





        a__:	DoubleLinkedListNode[T, U]     				=      DoubleLinkedListNode(lowercase       ,     lowercase)
        a__:	DoubleLinkedListNode[T, U]     				=      DoubleLinkedListNode(lowercase       ,     lowercase)
        a__				,       a__:	str     				=      self.rear, self.head



      def __repr__(		self)      ->     str:





        '''simple docstring'''





        a__:	Optional[Any]     				=      ['DoubleLinkedList']
        a__:	List[Any]     				=      self.head
        while node.next is not None:
          rep.append(str(lowercase))
          a__:	Optional[int]     				=      node.next
        rep.append(str(self.rear))
        return ",\n    ".join(lowercase)



      def     lowerCamelCase_  (		self       ,     lowercase)      ->     None:





        '''simple docstring'''





        a__:	Optional[int]     				=      self.rear.prev

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

        a__:	List[str]     				=      node
        a__:	Dict     				=      previous
        a__:	str     				=      node
        a__:	Optional[int]     				=      self.rear
        node.freq += 1
        self._position_node(lowercase)



      def     lowerCamelCase_  (		self       ,     lowercase)      ->     None:





        '''simple docstring'''





        while node.prev is not None and node.prev.freq > node.freq:
          # swap node with previous node
          a__:	Dict     				=      node.prev

          a__:	Optional[int]     				=      previous_node.prev
          a__:	Dict     				=      node.prev
          a__:	Optional[int]     				=      previous_node
          a__:	Optional[int]     				=      node



      def     lowerCamelCase_  (		self       ,     lowercase)      ->     DoubleLinkedListNode[T, U] | None:





        '''simple docstring'''





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

        a__:	int     				=      node.next
        a__:	Tuple     				=      node.prev
        a__:	Dict     				=      None
        a__:	List[str]     				=      None
        return node







class   __snake_case			(	Generic[T, U]							):
      a__								=						{}



      def __init__(		self       ,     lowercase)      ->     int:





        '''simple docstring'''





        a__:	DoubleLinkedList[T, U]     				=      DoubleLinkedList()
        a__:	Any     				=      capacity
        a__:	Optional[Any]     				=      0
        a__:	Optional[int]     				=      0
        a__:	Tuple     				=      0
        a__:	dict[T, DoubleLinkedListNode[T, U]]     				=      {}



      def __repr__(		self)      ->     str:





        '''simple docstring'''





        return (
            f'CacheInfo(hits={self.hits}, misses={self.miss}, '
            f'capacity={self.capacity}, current_size={self.num_keys})'
        )



      def __contains__(		self       ,     lowercase)      ->     bool:





        '''simple docstring'''





        return key in self.cache



      def     lowerCamelCase_  (		self       ,     lowercase)      ->     U | None:





        '''simple docstring'''





        if key in self.cache:
          self.hits += 1
          a__:	DoubleLinkedListNode[T, U]     				=      self.cache[key]
          a__:	Union[str, Any]     				=      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(lowercase)
          return node.val
        self.miss += 1
        return None



      def     lowerCamelCase_  (		self       ,     lowercase       ,     lowercase)      ->     None:





        '''simple docstring'''





        if key not in self.cache:
          if self.num_keys >= self.capacity:
            # delete first node when over capacity
            a__:	Optional[Any]     				=      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(lowercase) is not None
            # first_node guaranteed to be in list

            del self.cache[first_node.key]
            self.num_keys -= 1
          a__:	Optional[Any]     				=      DoubleLinkedListNode(lowercase       ,     lowercase)
          self.list.add(self.cache[key])
          self.num_keys += 1

        else:
          a__:	Union[str, Any]     				=      self.list.remove(self.cache[key])
          assert node is not None  # node guaranteed to be in list
          a__:	int     				=      value
          self.list.add(lowercase)



      @classmethod
      def     lowerCamelCase_  (		cls       ,     lowercase = 1_28)      ->     Callable[[Callable[[T], U]], Callable[..., U]]:





        '''simple docstring'''





        def cache_decorator_inner(lowercase) -> Callable[..., U]:
          def cache_decorator_wrapper(*lowercase) -> U:
            if func not in cls.decorator_function_to_instance_map:
              a__:	int     				=      LFUCache(lowercase)

            a__:	Any     				=      cls.decorator_function_to_instance_map[func].get(args[0])
            if result is None:
              a__:	int     				=      func(*lowercase)
              cls.decorator_function_to_instance_map[func].put(args[0]       ,     lowercase)
            return result

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

          setattr(lowercase       ,     'cache_info'       ,     lowercase)  # noqa: B010

          return cache_decorator_wrapper

        return cache_decorator_inner


if __name__ == "__main__":
 import doctest

 doctest.testmod()







'''simple docstring'''




from __future__ import annotations



def  __lowerCamelCase    (   _lowercase						) ->     int | None:
							for r in range(1      ,							_lowercase						):
														UpperCAmelCase	:						Dict					=						[]
														for x in range(n - 1						):
																					UpperCAmelCase	:						List[str]					=						pow(_lowercase      ,							_lowercase      ,							_lowercase						)
																					if val in li:
																												break
																					li.append(_lowercase						)
														else:
																					return r
							return None


if __name__ == "__main__":
							a  :     Dict       =       int(input("""Enter a prime number q: """))
							a  :     Union[str, Any]       =       find_primitive(q)
							if a is None:
														print(F'''Cannot find the primitive for the value: {a!r}''')
							else:
														a  :     str       =       int(input("""Enter private key of A: """))
														a  :     str       =       pow(a, a_private, q)
														a  :     List[Any]       =       int(input("""Enter private key of B: """))
														a  :     str       =       pow(a, b_private, q)

														a  :     Union[str, Any]       =       pow(b_public, a_private, q)
														a  :     List[Any]       =       pow(a_public, b_private, q)

														print("""The key value generated by A is: """, a_secret)
														print("""The key value generated by B is: """, b_secret)

