


"""simple docstring"""






from __future__ import annotations

from random import random






class      A:

		"""simple docstring"""





		def __init__( self					,				SCREAMING_SNAKE_CASE__ = None   )      ->	Dict:

					"""simple docstring"""



					_UpperCamelCase					:int					     =	value
					_UpperCamelCase					:Tuple					     =	random()
					_UpperCamelCase					:Node | None					     =	None
					_UpperCamelCase					:Node | None					     =	None
		def __repr__( self   )      ->	str:

					"""simple docstring"""



					from pprint import pformat

					if self.left is None and self.right is None:
								return f"'{self.value}: {self.prior:.5}'"
					else:
								return pformat(
								    {f"{self.value}: {self.prior:.5}": (self.left, self.right)}					,				indent=1   )





		def __str__( self   )      ->	str:

					"""simple docstring"""



					_UpperCamelCase					:Dict					     =	str(self.value   ) + ''' '''
					_UpperCamelCase					:List[str]					     =	str(self.left or ''''''   )
					_UpperCamelCase					:List[str]					     =	str(self.right or ''''''   )
					return value + left + right





def 				A_       ( snake_case__       ,					snake_case__		)					->  tuple[Node | None, Node | None]:
			if root is None:  # None tree is split into 2 Nones
						return None, None
			elif root.value is None:
						return None, None
			else:
						if value < root.value:
									_UpperCamelCase     ,      _UpperCamelCase					:Dict					     =	split(root.left       ,					snake_case__		)
									return left, root
						else:
									_UpperCamelCase     ,      _UpperCamelCase					:Union[str, Any]					     =	split(root.right       ,					snake_case__		)
									return root, right





def 				A_       ( snake_case__       ,					snake_case__		)					->  Node | None:
			if (not left) or (not right):  # If one node is None, return the other
						return left or right
			elif left.prior < right.prior:
						_UpperCamelCase					:str					     =	merge(left.right       ,					snake_case__		)
						return left
			else:
						_UpperCamelCase					:List[Any]					     =	merge(snake_case__       ,					right.left		)
						return right





def 				A_       ( snake_case__       ,					snake_case__		)					->  Node | None:
			_UpperCamelCase					:Union[str, Any]					     =	Node(snake_case__		)
			_UpperCamelCase     ,      _UpperCamelCase					:List[str]					     =	split(snake_case__       ,					snake_case__		)
			return merge(merge(snake_case__       ,					snake_case__		)       ,					snake_case__		)





def 				A_       ( snake_case__       ,					snake_case__		)					->  Node | None:
			_UpperCamelCase     ,      _UpperCamelCase					:Optional[Any]					     =	split(snake_case__       ,					value - 1		)
			_UpperCamelCase     ,      _UpperCamelCase					:Tuple					     =	split(snake_case__       ,					snake_case__		)
			return merge(snake_case__       ,					snake_case__		)





def 				A_       ( snake_case__		)					->  None:
			if not root:  # None
						return
			else:
						inorder(root.left		)
						print(root.value       ,					end=''','''		)
						inorder(root.right		)





def 				A_       ( snake_case__       ,					snake_case__		)					->  Node | None:
			for arg in args.split():
						if arg[0] == "+":
									_UpperCamelCase					:Optional[Any]					     =	insert(snake_case__       ,					int(arg[1:]		)		)

						elif arg[0] == "-":
									_UpperCamelCase					:str					     =	erase(snake_case__       ,					int(arg[1:]		)		)

						else:
									print('''Unknown command'''		)

			return root





def 				A_       ( )					->  None:
			_UpperCamelCase					:Any					     =	None
			print(
			    '''enter numbers to create a tree, + value to add value into treap, '''
			    '''- value to erase all nodes with value. \'q\' to quit. '''		)

			_UpperCamelCase					:Optional[int]					     =	input()
			while args != "q":
						_UpperCamelCase					:Any					     =	interact_treap(snake_case__       ,					snake_case__		)
						print(snake_case__		)
						_UpperCamelCase					:Union[str, Any]					     =	input()

			print('''good by!'''		)


if __name__ == "__main__":
					import doctest

					doctest.testmod()
					main()





"""simple docstring"""






import os





def 				A_       ( )					->  Any:
			with open(os.path.dirname(snake_case__		) + '''/p022_names.txt'''		) as file:
						_UpperCamelCase					:Optional[Any]					     =	str(file.readlines()[0]		)
						_UpperCamelCase					:Dict					     =	names.replace('''"'''       ,					''''''		).split(''','''		)

			names.sort()

			_UpperCamelCase					:str					     =	0
			_UpperCamelCase					:Union[str, Any]					     =	0

			for i, name in enumerate(snake_case__		):
						for letter in name:
									name_score += ord(snake_case__		) - 64

						total_score += (i + 1) * name_score
						_UpperCamelCase					:List[Any]					     =	0
			return total_score


if __name__ == "__main__":
					print(solution())

