

'''simple docstring'''

from __future__ import annotations

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

a       :      Union[str, Any]  	=			TypeVar("T")
a       :      Union[str, Any]  	=			TypeVar("U")







class   UpperCamelCase__   (       Generic[T, U]       ):


		"""simple docstring"""

		def __init__(			self   ,      snake_case   ,      snake_case      ):


							'''simple docstring'''

							UpperCAmelCase		:							Optional[int]        =       key
							UpperCAmelCase		:							str        =       val
							UpperCAmelCase		:							int        =       0
							UpperCAmelCase		:							DoubleLinkedListNode[T, U] | None        =       None
							UpperCAmelCase		:							DoubleLinkedListNode[T, U] | None        =       None







		def __repr__(			self      ):


							'''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   UpperCamelCase__   (       Generic[T, U]       ):


		"""simple docstring"""

		def __init__(			self      ):


							'''simple docstring'''

							UpperCAmelCase		:							DoubleLinkedListNode[T, U]        =       DoubleLinkedListNode(snake_case   ,      snake_case      )
							UpperCAmelCase		:							DoubleLinkedListNode[T, U]        =       DoubleLinkedListNode(snake_case   ,      snake_case      )
							UpperCAmelCase		:							List[Any]        =       self.rear, self.head







		def __repr__(			self      ):


							'''simple docstring'''

							UpperCAmelCase		:							Dict        =       ["DoubleLinkedList"]
							UpperCAmelCase		:							Any        =       self.head
							while node.next is not None:
												rep.append(str(snake_case      )      )
												UpperCAmelCase		:							Any        =       node.next
							rep.append(str(self.rear      )      )
							return ",\n    ".join(snake_case      )







		def 				A_	(			self   ,      snake_case      ):


							'''simple docstring'''

							UpperCAmelCase		:							Optional[Any]        =       self.rear.prev

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

							UpperCAmelCase		:							Union[str, Any]        =       node
							UpperCAmelCase		:							Optional[int]        =       previous
							UpperCAmelCase		:							Tuple        =       node
							UpperCAmelCase		:							int        =       self.rear
							node.freq += 1
							self._position_node(snake_case      )







		def 				A_	(			self   ,      snake_case      ):


							'''simple docstring'''

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

												UpperCAmelCase		:							int        =       previous_node.prev
												UpperCAmelCase		:							Any        =       node.prev
												UpperCAmelCase		:							str        =       previous_node
												UpperCAmelCase		:							Optional[int]        =       node







		def 				A_	(			self   ,      snake_case      ):


							'''simple docstring'''

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

							UpperCAmelCase		:							str        =       node.next
							UpperCAmelCase		:							Union[str, Any]        =       node.prev
							UpperCAmelCase		:							Union[str, Any]        =       None
							UpperCAmelCase		:							Union[str, Any]        =       None
							return node







class   UpperCamelCase__   (       Generic[T, U]       ):


		"""simple docstring"""

		SCREAMING_SNAKE_CASE__  :     Union[str, Any]       =							{}







		def __init__(			self   ,      snake_case      ):


							'''simple docstring'''

							UpperCAmelCase		:							DoubleLinkedList[T, U]        =       DoubleLinkedList()
							UpperCAmelCase		:							Optional[Any]        =       capacity
							UpperCAmelCase		:							Union[str, Any]        =       0
							UpperCAmelCase		:							Dict        =       0
							UpperCAmelCase		:							List[Any]        =       0
							UpperCAmelCase		:							dict[T, DoubleLinkedListNode[T, U]]        =       {}







		def __repr__(			self      ):


							'''simple docstring'''

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







		def __contains__(			self   ,      snake_case      ):


							'''simple docstring'''

							return key in self.cache







		def 				A_	(			self   ,      snake_case      ):


							'''simple docstring'''

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







		def 				A_	(			self   ,      snake_case   ,      snake_case      ):


							'''simple docstring'''

							if key not in self.cache:
												if self.num_keys >= self.capacity:
																	# delete first node when over capacity
																	UpperCAmelCase		:							Union[str, 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(snake_case      ) is not None
																	# first_node guaranteed to be in list

																	del self.cache[first_node.key]
																	self.num_keys -= 1
												UpperCAmelCase		:							Optional[int]        =       DoubleLinkedListNode(snake_case   ,      snake_case      )
												self.list.add(self.cache[key]      )
												self.num_keys += 1

							else:
												UpperCAmelCase		:							List[Any]        =       self.list.remove(self.cache[key]      )
												assert node is not None  # node guaranteed to be in list
												UpperCAmelCase		:							Optional[int]        =       value
												self.list.add(snake_case      )







		@classmethod
		def 				A_	(			cls   ,      snake_case = 1_2_8      ):


							'''simple docstring'''

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

																	UpperCAmelCase		:							List[Any]        =       cls.decorator_function_to_instance_map[func].get(args[0]      )
																	if result is None:
																						UpperCAmelCase		:							List[str]        =       func(*snake_case      )
																						cls.decorator_function_to_instance_map[func].put(args[0]   ,      snake_case      )
																	return result

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

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

												return cache_decorator_wrapper

							return cache_decorator_inner


if __name__ == "__main__":
				import doctest

				doctest.testmod()



'''simple docstring'''

from __future__ import annotations







class   UpperCamelCase__   :


		"""simple docstring"""

		def __init__(			self   ,      snake_case      ):


							'''simple docstring'''

							UpperCAmelCase		:							str        =       data
							UpperCAmelCase		:							Dict        =       None







class   UpperCamelCase__   :


		"""simple docstring"""

		def __init__(			self      ):


							'''simple docstring'''

							UpperCAmelCase		:							str        =       None







		def 				A_	(			self   ,      snake_case      ):


							'''simple docstring'''

							UpperCAmelCase		:							int        =       Node(snake_case      )
							UpperCAmelCase		:							Optional[int]        =       self.head
							UpperCAmelCase		:							Union[str, Any]        =       new_node
							return self.head.data







		def 				A_	(			self      ):


							'''simple docstring'''

							UpperCAmelCase		:							Dict        =       self.head
							UpperCAmelCase		:							str        =       self.head
							if self.head:
												while fast_pointer and fast_pointer.next:
																	UpperCAmelCase		:							List[str]        =       fast_pointer.next.next
																	UpperCAmelCase		:							Any        =       slow_pointer.next
												return slow_pointer.data
							else:
												print("No element found."      )
												return None


if __name__ == "__main__":
				a       :      List[str]  	=			LinkedList()
				for _ in range(int(input().strip())):
								a       :      str  	=			int(input().strip())
								link.push(data)
				print(link.middle_element())
