
"""simple docstring"""





import os

_a		       =							{'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1_000}







def 	__a     (		__lowerCamelCase  ):
   UpperCAmelCase_					:					Union[str, Any]			     =    0

   UpperCAmelCase_					:					List[str]			     =    0
   while index < len(__lowerCamelCase  ) - 1:
      UpperCAmelCase_					:					Tuple			     =    SYMBOLS[numerals[index]]
      UpperCAmelCase_					:					List[str]			     =    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 	__a     (		__lowerCamelCase  ):
   UpperCAmelCase_					:					List[str]			     =    ""

   UpperCAmelCase_					:					Any			     =    num // 1000
   numerals += m_count * "M"
   num %= 1000

   UpperCAmelCase_					:					Any			     =    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

   UpperCAmelCase_					:					str			     =    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 	__a     (		__lowerCamelCase = "/p089_roman.txt"  ):
   UpperCAmelCase_					:					int			     =    0

   with open(os.path.dirname(__lowerCamelCase  ) + roman_numerals_filename  ) as filea:
      UpperCAmelCase_					:					Optional[Any]			     =    filea.readlines()

   for line in lines:
      UpperCAmelCase_					:					Tuple			     =    line.strip()
      UpperCAmelCase_					:					Optional[Any]			     =    parse_roman_numerals(__lowerCamelCase  )
      UpperCAmelCase_					:					Tuple			     =    generate_roman_numerals(__lowerCamelCase  )
      savings += len(__lowerCamelCase  ) - len(__lowerCamelCase  )

   return savings


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










from __future__ import annotations




def      lowercase__      (     __snake_case    :							tuple[int, int]     ,       __snake_case    :							int  ):


					'''simple docstring'''


					UpperCAmelCase_       ,  UpperCAmelCase_    :      Tuple            =						position
					UpperCAmelCase_    :      str            =						[
					    (y + 1, x + 2),
					    (y - 1, x + 2),
					    (y + 1, x - 2),
					    (y - 1, x - 2),
					    (y + 2, x + 1),
					    (y + 2, x - 1),
					    (y - 2, x + 1),
					    (y - 2, x - 1),
					]
					UpperCAmelCase_    :      Optional[Any]            =						[]

					for position in positions:
										UpperCAmelCase_       ,  UpperCAmelCase_    :      Tuple            =						position
										if 0 <= y_test < n and 0 <= x_test < n:
															permissible_positions.append(__snake_case  )

					return permissible_positions




def      lowercase__      (     __snake_case    :							list[list[int]]  ):


					'''simple docstring'''


					return not any(elem == 0 for row in board for elem in row  )




def      lowercase__      (     __snake_case    :							list[list[int]]     ,       __snake_case    :							tuple[int, int]     ,       __snake_case    :							int  ):


					'''simple docstring'''


					if is_complete(__snake_case  ):
										return True

					for position in get_valid_pos(__snake_case     ,       len(__snake_case  )  ):
										UpperCAmelCase_       ,  UpperCAmelCase_    :      Any            =						position

										if board[y][x] == 0:
															UpperCAmelCase_    :      Optional[Any]            =						curr + 1
															if open_knight_tour_helper(__snake_case     ,       __snake_case     ,       curr + 1  ):
																				return True
															UpperCAmelCase_    :      List[Any]            =						0

					return False




def      lowercase__      (     __snake_case    :							int  ):


					'''simple docstring'''


					UpperCAmelCase_    :      str            =						[[0 for i in range(__snake_case  )] for j in range(__snake_case  )]

					for i in range(__snake_case  ):
										for j in range(__snake_case  ):
															UpperCAmelCase_    :      Optional[Any]            =						1
															if open_knight_tour_helper(__snake_case     ,       (i, j)     ,       1  ):
																				return board
															UpperCAmelCase_    :      List[Any]            =						0

					UpperCAmelCase_    :      List[str]            =						F"Open Kight Tour cannot be performed on a board of size {n}"
					raise ValueError(__snake_case  )


if __name__ == "__main__":
		import doctest

		doctest.testmod()






