


"""simple docstring"""



class       __a	:







				def __init__(   self			,  UpperCAmelCase      ):

					'''simple docstring'''






					lowerCAmelCase_			       = data
					lowerCAmelCase_			       = None
					lowerCAmelCase_			       = None







				def __str__(   self      ):

					'''simple docstring'''






					return F"""{self.data}"""







class       __a	:







				def __init__(   self      ):

					'''simple docstring'''






					lowerCAmelCase_			       = None
					lowerCAmelCase_			       = None







				def __iter__(   self      ):

					'''simple docstring'''






					lowerCAmelCase_			       = self.head
					while node:
						yield node.data
						lowerCAmelCase_			       = node.next







				def __str__(   self      ):

					'''simple docstring'''






					return "->".join([str(__SCREAMING_SNAKE_CASE      ) for item in self]      )







				def __len__(   self      ):

					'''simple docstring'''






					return sum(1 for _ in self      )







				def     lowerCamelCase_    (   self			,  UpperCAmelCase      ):

					'''simple docstring'''






					self.insert_at_nth(0			,  __SCREAMING_SNAKE_CASE      )







				def     lowerCamelCase_    (   self			,  UpperCAmelCase      ):

					'''simple docstring'''






					self.insert_at_nth(len(self      )			,  __SCREAMING_SNAKE_CASE      )







				def     lowerCamelCase_    (   self			,  UpperCAmelCase			,  UpperCAmelCase      ):

					'''simple docstring'''






					lowerCAmelCase_			       = len(self      )

					if not 0 <= index <= length:
						raise IndexError('''list index out of range'''      )
					lowerCAmelCase_			       = Node(__SCREAMING_SNAKE_CASE      )
					if self.head is None:
						lowerCAmelCase_			       = lowerCAmelCase_			       = new_node
					elif index == 0:
						lowerCAmelCase_			       = new_node
						lowerCAmelCase_			       = self.head
						lowerCAmelCase_			       = new_node
					elif index == length:
						lowerCAmelCase_			       = new_node
						lowerCAmelCase_			       = self.tail
						lowerCAmelCase_			       = new_node
					else:
						lowerCAmelCase_			       = self.head
						for _ in range(0			,  __SCREAMING_SNAKE_CASE      ):
							lowerCAmelCase_			       = temp.next
						lowerCAmelCase_			       = new_node
						lowerCAmelCase_			       = temp.previous
						lowerCAmelCase_			       = temp
						lowerCAmelCase_			       = new_node







				def     lowerCamelCase_    (   self      ):

					'''simple docstring'''






					return self.delete_at_nth(0      )







				def     lowerCamelCase_    (   self      ):

					'''simple docstring'''






					return self.delete_at_nth(len(self      ) - 1      )







				def     lowerCamelCase_    (   self			,  UpperCAmelCase      ):

					'''simple docstring'''






					lowerCAmelCase_			       = len(self      )

					if not 0 <= index <= length - 1:
						raise IndexError('''list index out of range'''      )
					lowerCAmelCase_			       = self.head  # default first node
					if length == 1:
						lowerCAmelCase_			       = lowerCAmelCase_			       = None
					elif index == 0:
						lowerCAmelCase_			       = self.head.next
						lowerCAmelCase_			       = None
					elif index == length - 1:
						lowerCAmelCase_			       = self.tail
						lowerCAmelCase_			       = self.tail.previous
						lowerCAmelCase_			       = None
					else:
						lowerCAmelCase_			       = self.head
						for _ in range(0			,  __SCREAMING_SNAKE_CASE      ):
							lowerCAmelCase_			       = temp.next
						lowerCAmelCase_			       = temp
						lowerCAmelCase_			       = temp.previous
						lowerCAmelCase_			       = temp.next
					return delete_node.data







				def     lowerCamelCase_    (   self			,  UpperCAmelCase      ):

					'''simple docstring'''






					lowerCAmelCase_			       = self.head

					while current.data != data:  # Find the position to delete
						if current.next:
							lowerCAmelCase_			       = current.next
						else:  # We have reached the end an no value matches
							raise ValueError('''No data matching given value'''      )

					if current == self.head:
						self.delete_head()

					elif current == self.tail:
						self.delete_tail()

					else:  # Before: 1 <--> 2(current) <--> 3
						lowerCAmelCase_			       = current.next  # 1 --> 3
						lowerCAmelCase_			       = current.previous  # 1 <--> 3
					return data







				def     lowerCamelCase_    (   self      ):

					'''simple docstring'''






					return len(self      ) == 0




def     UpperCAmelCase    (					)	->   None:


	"""simple docstring"""




	lowerCAmelCase_			       = DoublyLinkedList()
	assert linked_list.is_empty() is True
	assert str(_lowercase  ) == ""

	try:
		linked_list.delete_head()
		raise AssertionError  # This should not happen.
	except IndexError:
		assert True  # This should happen.

	try:
		linked_list.delete_tail()
		raise AssertionError  # This should not happen.
	except IndexError:
		assert True  # This should happen.

	for i in range(1_0  ):
		assert len(_lowercase  ) == i
		linked_list.insert_at_nth(_lowercase ,      i + 1  )
	assert str(_lowercase  ) == "->".join(str(_lowercase  ) for i in range(1 ,      1_1  )  )

	linked_list.insert_at_head(0  )
	linked_list.insert_at_tail(1_1  )
	assert str(_lowercase  ) == "->".join(str(_lowercase  ) for i in range(0 ,      1_2  )  )

	assert linked_list.delete_head() == 0
	assert linked_list.delete_at_nth(9  ) == 1_0
	assert linked_list.delete_tail() == 1_1
	assert len(_lowercase  ) == 9
	assert str(_lowercase  ) == "->".join(str(_lowercase  ) for i in range(1 ,      1_0  )  )


if __name__ == "__main__":
			from doctest import testmod

			testmod()



"""simple docstring"""



def     UpperCAmelCase    (					_lowercase   :      list[int]  )	->   int:


	"""simple docstring"""




	lowerCAmelCase_			       = len(_lowercase  )
	if n in (0, 1):
		return 0
	return sum(query * (n - i - 1) for i, query in enumerate(sorted(_lowercase  )  )  )


if __name__ == "__main__":
		import doctest

		doctest.testmod()