"""simple docstring"""






import os

_A   					=    {'I': 1, 'V': 5, 'X': 1_0, 'L': 5_0, 'C': 1_0_0, 'D': 5_0_0, 'M': 1_0_0_0}




def 						SCREAMING_SNAKE_CASE					(  __UpperCAmelCase       )							->   int:
				SCREAMING_SNAKE_CASE__		  =				0

				SCREAMING_SNAKE_CASE__		  =				0
				while index < len(__UpperCAmelCase       ) - 1:
								SCREAMING_SNAKE_CASE__		  =				SYMBOLS[numerals[index]]
								SCREAMING_SNAKE_CASE__		  =				SYMBOLS[numerals[index + 1]]
								if current_value < next_value:
												total_value -= current_value
								else:
												total_value += current_value
								index += 1
				total_value += SYMBOLS[numerals[index]]

				return total_value




def 						SCREAMING_SNAKE_CASE					(  __UpperCAmelCase       )							->   str:
				SCREAMING_SNAKE_CASE__		  =				""

				SCREAMING_SNAKE_CASE__		  =				num // 1_000
				numerals += m_count * "M"
				num %= 1_000

				SCREAMING_SNAKE_CASE__		  =				num // 100
				if c_count == 9:
								numerals += "CM"
								c_count -= 9
				elif c_count == 4:
								numerals += "CD"
								c_count -= 4
				if c_count >= 5:
								numerals += "D"
								c_count -= 5
				numerals += c_count * "C"
				num %= 100

				SCREAMING_SNAKE_CASE__		  =				num // 10
				if x_count == 9:
								numerals += "XC"
								x_count -= 9
				elif x_count == 4:
								numerals += "XL"
								x_count -= 4
				if x_count >= 5:
								numerals += "L"
								x_count -= 5
				numerals += x_count * "X"
				num %= 10

				if num == 9:
								numerals += "IX"
								num -= 9
				elif num == 4:
								numerals += "IV"
								num -= 4
				if num >= 5:
								numerals += "V"
								num -= 5
				numerals += num * "I"

				return numerals




def 						SCREAMING_SNAKE_CASE					(  __UpperCAmelCase = "/p089_roman.txt"       )							->   int:
				SCREAMING_SNAKE_CASE__		  =				0

				with open(os.path.dirname(__UpperCAmelCase       ) + roman_numerals_filename       ) as filea:
								SCREAMING_SNAKE_CASE__		  =				filea.readlines()

				for line in lines:
								SCREAMING_SNAKE_CASE__		  =				line.strip()
								SCREAMING_SNAKE_CASE__		  =				parse_roman_numerals(__UpperCAmelCase       )
								SCREAMING_SNAKE_CASE__		  =				generate_roman_numerals(__UpperCAmelCase       )
								savings += len(__UpperCAmelCase       ) - len(__UpperCAmelCase       )

				return savings


if __name__ == "__main__":
						print(F'{solution() = }')





"""simple docstring"""






def 						SCREAMING_SNAKE_CASE					(  __UpperCAmelCase       )							->   int:

				if not isinstance(__UpperCAmelCase  ,					__UpperCAmelCase       ):
								raise ValueError("multiplicative_persistence() only accepts integral values"       )
				if num < 0:
								raise ValueError("multiplicative_persistence() does not accept negative values"       )

				SCREAMING_SNAKE_CASE__		  =				0
				SCREAMING_SNAKE_CASE__		  =				str(__UpperCAmelCase       )

				while len(__UpperCAmelCase       ) != 1:
								SCREAMING_SNAKE_CASE__		  =				[int(__UpperCAmelCase       ) for i in num_string]

								SCREAMING_SNAKE_CASE__		  =				1
								for i in range(0  ,					len(__UpperCAmelCase       )       ):
												total *= numbers[i]

								SCREAMING_SNAKE_CASE__		  =				str(__UpperCAmelCase       )

								steps += 1
				return steps




def 						SCREAMING_SNAKE_CASE					(  __UpperCAmelCase       )							->   int:

				if not isinstance(__UpperCAmelCase  ,					__UpperCAmelCase       ):
								raise ValueError("additive_persistence() only accepts integral values"       )
				if num < 0:
								raise ValueError("additive_persistence() does not accept negative values"       )

				SCREAMING_SNAKE_CASE__		  =				0
				SCREAMING_SNAKE_CASE__		  =				str(__UpperCAmelCase       )

				while len(__UpperCAmelCase       ) != 1:
								SCREAMING_SNAKE_CASE__		  =				[int(__UpperCAmelCase       ) for i in num_string]

								SCREAMING_SNAKE_CASE__		  =				0
								for i in range(0  ,					len(__UpperCAmelCase       )       ):
												total += numbers[i]

								SCREAMING_SNAKE_CASE__		  =				str(__UpperCAmelCase       )

								steps += 1
				return steps


if __name__ == "__main__":
						import doctest

						doctest.testmod()




