code: 
  
  
  
  
  
  '''simple docstring'''
  
  
  
  
  
  
  
  from __future__ import annotations
  
  from collections.abc import Iterable
  from dataclasses import dataclass
  from typing import Any
  
  
  
  
  
  class 					_UpperCAmelCase							:
  		a     :     Optional[Any]     						=("""_front""", """_back""", """_len""")
  
  
  
  
  
  		@dataclass
  		class 					_UpperCAmelCase							:
  				a     :     Any     						=None
  				a     :     Any     						=None
  				a     :     Any     						=None
  
  
  
  
  
  		class 					_UpperCAmelCase							:
  				a     :     List[Any]     						=("""_cur""",)
  				def __init__(						self,__SCREAMING_SNAKE_CASE    ):
  
  
  
  							'''simple docstring'''
  
  							__lowerCAmelCase      		=       cur
  				def __iter__(						self    ):
  
  
  
  							'''simple docstring'''
  
  							return self
  
  
  
  
  
  
  
  				def 						lowerCamelCase__    (						self    ):
  
  
  
  							'''simple docstring'''
  
  							if self._cur is None:
  										# finished iterating
  										raise StopIteration
  							__lowerCAmelCase      		=       self._cur.val
  							__lowerCAmelCase      		=       self._cur.next_node
  
  							return val
  
  
  
  
  
  		def __init__(						self,__SCREAMING_SNAKE_CASE = None    ):
  
  
  
  					'''simple docstring'''
  
  					__lowerCAmelCase      		=       None
  					__lowerCAmelCase      		=       None
  					__lowerCAmelCase      		=       0
  
  					if iterable is not None:
  								# append every value to the deque
  								for val in iterable:
  											self.append(_lowerCamelCase    )
  		def 						lowerCamelCase__    (						self,__SCREAMING_SNAKE_CASE    ):
  
  
  
  					'''simple docstring'''
  
  					__lowerCAmelCase      		=       self._Node(_lowerCamelCase,_lowerCamelCase,_lowerCamelCase    )
  					if self.is_empty():
  								# front = back
  								__lowerCAmelCase      		=       node
  								__lowerCAmelCase      		=       1
  					else:
  								# connect nodes
  								__lowerCAmelCase      		=       node
  								__lowerCAmelCase      		=       self._back
  								__lowerCAmelCase      		=       node  # assign new back to the new node
  
  								self._len += 1
  
  								# make sure there were no errors
  								assert not self.is_empty(), "Error on appending value."
  		def 						lowerCamelCase__    (						self,__SCREAMING_SNAKE_CASE    ):
  
  
  
  					'''simple docstring'''
  
  					__lowerCAmelCase      		=       self._Node(_lowerCamelCase,_lowerCamelCase,_lowerCamelCase    )
  					if self.is_empty():
  								# front = back
  								__lowerCAmelCase      		=       node
  								__lowerCAmelCase      		=       1
  					else:
  								# connect nodes
  								__lowerCAmelCase      		=       self._front
  								__lowerCAmelCase      		=       node
  								__lowerCAmelCase      		=       node  # assign new front to the new node
  
  								self._len += 1
  
  								# make sure there were no errors
  								assert not self.is_empty(), "Error on appending value."
  		def 						lowerCamelCase__    (						self,__SCREAMING_SNAKE_CASE    ):
  
  
  
  					'''simple docstring'''
  
  					for val in iterable:
  								self.append(_lowerCamelCase    )
  		def 						lowerCamelCase__    (						self,__SCREAMING_SNAKE_CASE    ):
  
  
  
  					'''simple docstring'''
  
  					for val in iterable:
  								self.appendleft(_lowerCamelCase    )
  		def 						lowerCamelCase__    (						self    ):
  
  
  
  					'''simple docstring'''
  
  					assert not self.is_empty(), "Deque is empty."
  
  					__lowerCAmelCase      		=       self._back
  					__lowerCAmelCase      		=       self._back.prev_node  # set new back
  					# drop the last node - python will deallocate memory automatically
  					__lowerCAmelCase      		=       None
  
  					self._len -= 1
  
  					return topop.val
  		def 						lowerCamelCase__    (						self    ):
  
  
  
  					'''simple docstring'''
  
  					assert not self.is_empty(), "Deque is empty."
  
  					__lowerCAmelCase      		=       self._front
  					__lowerCAmelCase      		=       self._front.next_node  # set new front and drop the first node
  					__lowerCAmelCase      		=       None
  
  					self._len -= 1
  
  					return topop.val
  		def 						lowerCamelCase__    (						self    ):
  
  
  
  					'''simple docstring'''
  
  					return self._front is None
  		def __len__(						self    ):
  
  
  
  					'''simple docstring'''
  
  					return self._len
  		def __eq__(						self,__SCREAMING_SNAKE_CASE    ):
  
  
  
  					'''simple docstring'''
  
  					if not isinstance(_lowerCamelCase,_lowerCamelCase    ):
  								return NotImplemented
  
  					__lowerCAmelCase      		=       self._front
  					__lowerCAmelCase      		=       other._front
  
  					# if the length of the dequeues are not the same, they are not equal
  					if len(self    ) != len(_lowerCamelCase    ):
  								return False
  
  					while me is not None and oth is not None:
  								# compare every value
  								if me.val != oth.val:
  											return False
  								__lowerCAmelCase      		=       me.next_node
  								__lowerCAmelCase      		=       oth.next_node
  
  					return True
  		def __iter__(						self    ):
  
  
  
  					'''simple docstring'''
  
  					return Deque._Iterator(self._front    )
  
  
  
  
  
  
  
  		def __repr__(						self    ):
  
  
  
  					'''simple docstring'''
  
  					__lowerCAmelCase      		=       []
  					__lowerCAmelCase      		=       self._front
  					while aux is not None:
  								# append the values in a list to display
  								values_list.append(aux.val    )
  								__lowerCAmelCase      		=       aux.next_node
  
  					return f'[{", ".join(repr(_lowerCamelCase    ) for val in values_list    )}]'
  
  
  if __name__ == "__main__":
  	import doctest
  
  	doctest.testmod()
  
  
style_context: 
  
  
  
  
  
  '''simple docstring'''
  
  
  
  
  
  
  
  from __future__ import annotations
  
  from collections.abc import Iterable, Iterator
  from typing import Any, Generic, TypeVar
  
  _a      :				Dict											=					TypeVar("""T""", bound=bool)
  
  
  
  
  
  class 					_UpperCAmelCase							(		Generic[T]     ):
  		def __init__(						self,__SCREAMING_SNAKE_CASE    ):
  
  
  
  					'''simple docstring'''
  
  					__lowerCAmelCase      		=       value
  					__lowerCAmelCase      		=       None
  					__lowerCAmelCase      		=       None
  		@property
  		def 						lowerCamelCase__    (						self    ):
  
  
  
  					'''simple docstring'''
  
  					return self._value
  
  
  
  
  
  
  
  		@staticmethod
  		def 						lowerCamelCase__    (						__SCREAMING_SNAKE_CASE,__SCREAMING_SNAKE_CASE    ):
  
  
  
  					'''simple docstring'''
  
  					if not roota:
  								return roota
  
  					if not roota:
  								return roota
  
  					if roota.value > roota.value:
  								__lowerCAmelCase		, __lowerCAmelCase      		=       roota, roota
  
  					__lowerCAmelCase      		=       roota
  					__lowerCAmelCase      		=       roota.right
  					__lowerCAmelCase      		=       roota.left
  					__lowerCAmelCase      		=       SkewNode.merge(__SCREAMING_SNAKE_CASE,__SCREAMING_SNAKE_CASE    )
  
  					return result
  
  
  
  
  
  class 					_UpperCAmelCase							(		Generic[T]     ):
  		def __init__(						self,__SCREAMING_SNAKE_CASE = ()    ):
  
  
  
  					'''simple docstring'''
  
  					__lowerCAmelCase      		=       None
  					if data:
  								for item in data:
  											self.insert(__SCREAMING_SNAKE_CASE    )
  		def __bool__(						self    ):
  
  
  
  					'''simple docstring'''
  
  					return self._root is not None
  		def __iter__(						self    ):
  
  
  
  					'''simple docstring'''
  
  					__lowerCAmelCase      		=       []
  					while self:
  								result.append(self.pop()    )
  
  					# Pushing items back to the heap not to clear it.
  					for item in result:
  								self.insert(__SCREAMING_SNAKE_CASE    )
  
  					return iter(__SCREAMING_SNAKE_CASE    )
  		def 						lowerCamelCase__    (						self,__SCREAMING_SNAKE_CASE    ):
  
  
  
  					'''simple docstring'''
  
  					__lowerCAmelCase      		=       SkewNode.merge(self._root,SkewNode(__SCREAMING_SNAKE_CASE    )    )
  		def 						lowerCamelCase__    (						self    ):
  
  
  
  					'''simple docstring'''
  
  					__lowerCAmelCase      		=       self.top()
  					__lowerCAmelCase      		=       (
  					    SkewNode.merge(self._root.left,self._root.right    ) if self._root else None
  					)
  
  					return result
  		def 						lowerCamelCase__    (						self    ):
  
  
  
  					'''simple docstring'''
  
  					if not self._root:
  								raise IndexError("""Can't get top element for the empty heap."""    )
  					return self._root.value
  
  
  
  
  
  
  
  		def 						lowerCamelCase__    (						self    ):
  
  
  
  					'''simple docstring'''
  
  					__lowerCAmelCase      		=       None
  
  
  if __name__ == "__main__":
  	import doctest
  
  	doctest.testmod()
  
  