

"""simple docstring"""


import heapq as hq
import math
from collections.abc import Iterator





class     snake_case	:

				def __init__(	self							:				Dict     ,  UpperCamelCase__							:				Dict)->   Tuple:



						'''simple docstring'''


						__lowerCAmelCase:       Optional[int]          =			str(id_)
						__lowerCAmelCase:       Tuple          =			None
						__lowerCAmelCase:       Dict          =			None
						__lowerCAmelCase:       Dict          =			[]
						__lowerCAmelCase:       int          =			{}  # {vertex:distance}

				def __lt__(	self							:				List[Any]     ,  UpperCamelCase__							:				int)->   Any:



						'''simple docstring'''


						return self.key < other.key

				def __repr__(	self							:				Tuple)->   List[str]:



						'''simple docstring'''


						return self.id

				def 							lowercase_     (	self							:				Dict     ,  UpperCamelCase__							:				Optional[Any])->   Any:



						'''simple docstring'''


						self.neighbors.append(_snake_case)




				def 							lowercase_     (	self							:				Tuple     ,  UpperCamelCase__							:				Any     ,  UpperCamelCase__							:				Tuple)->   List[str]:



						'''simple docstring'''


						__lowerCAmelCase:       Any          =			weight






def     a__    (    __SCREAMING_SNAKE_CASE					, __SCREAMING_SNAKE_CASE					, __SCREAMING_SNAKE_CASE					, __SCREAMING_SNAKE_CASE )	->	Union[str, Any]:
		# add the neighbors:
		graph[a - 1].add_neighbor(graph[b - 1] )
		graph[b - 1].add_neighbor(graph[a - 1] )
		# add the edges:
		graph[a - 1].add_edge(graph[b - 1]					, __lowerCamelCase )
		graph[b - 1].add_edge(graph[a - 1]					, __lowerCamelCase )






def     a__    (    __SCREAMING_SNAKE_CASE					, __SCREAMING_SNAKE_CASE )	->	list:
		__lowerCAmelCase:       List[Any]          =			[]
		for u in graph:
				__lowerCAmelCase:       str          =			math.inf
				__lowerCAmelCase:       Optional[Any]          =			None
		__lowerCAmelCase:       Union[str, Any]          =			0
		__lowerCAmelCase:       Tuple          =			graph[:]
		while q:
				__lowerCAmelCase:       int          =			min(__lowerCamelCase )
				q.remove(__lowerCamelCase )
				for v in u.neighbors:
						if (v in q) and (u.edges[v.id] < v.key):
								__lowerCAmelCase:       List[Any]          =			u
								__lowerCAmelCase:       Tuple          =			u.edges[v.id]
		for i in range(1					, len(__lowerCamelCase ) ):
				a.append((int(graph[i].id ) + 1, int(graph[i].pi.id ) + 1) )
		return a






def     a__    (    __SCREAMING_SNAKE_CASE					, __SCREAMING_SNAKE_CASE )	->	Iterator[tuple]:
		for u in graph:
				__lowerCAmelCase:       List[str]          =			math.inf
				__lowerCAmelCase:       Any          =			None
		__lowerCAmelCase:       Dict          =			0

		__lowerCAmelCase:       Any          =			list(__lowerCamelCase )
		hq.heapify(__lowerCamelCase )

		while h:
				__lowerCAmelCase:       List[str]          =			hq.heappop(__lowerCamelCase )
				for v in u.neighbors:
						if (v in h) and (u.edges[v.id] < v.key):
								__lowerCAmelCase:       str          =			u
								__lowerCAmelCase:       Optional[int]          =			u.edges[v.id]
								hq.heapify(__lowerCamelCase )

		for i in range(1					, len(__lowerCamelCase ) ):
				yield (int(graph[i].id ) + 1, int(graph[i].pi.id ) + 1)






def     a__    (    )	->	None:
		pass


if __name__ == "__main__":
			import doctest

			doctest.testmod()







"""simple docstring"""







import os



def      __UpperCAmelCase      (    )							->      int:
		with open(os.path.dirname(__lowerCamelCase	) + '''/p022_names.txt'''	) as file:
				lowercase__   :    List[Any]				=			str(file.readlines()[0]	)
				lowercase__   :    Dict				=			names.replace('''"'''						,     ''''''	).split(''','''	)

		names.sort()

		lowercase__   :    int				=			0
		lowercase__   :    Optional[Any]				=			0

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

				total_score += (i + 1) * name_score
				lowercase__   :    List[str]				=			0
		return total_score


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