import numpy as np
from PIL import Image



def 			__SCREAMING_SNAKE_CASE						(      __UpperCamelCase					: np.ndarray				,  __UpperCamelCase					: int				,  __UpperCamelCase					: int			)							->      np.ndarray:







  """simple docstring"""





  SCREAMING_SNAKE_CASE__    							=   np.array(__UpperCamelCase			)
  if arr.shape[0] != arr.shape[1]:
    raise ValueError("""The input array is not a square matrix"""			)
  SCREAMING_SNAKE_CASE__    							=   0
  SCREAMING_SNAKE_CASE__    							=   0
  SCREAMING_SNAKE_CASE__    							=   0
  SCREAMING_SNAKE_CASE__    							=   0

  # compute the shape of the output matrix
  SCREAMING_SNAKE_CASE__    							=   (arr.shape[0] - size) // stride + 1
  # initialize the output matrix with zeros of shape maxpool_shape
  SCREAMING_SNAKE_CASE__    							=   np.zeros((maxpool_shape, maxpool_shape)			)

  while i < arr.shape[0]:
    if i + size > arr.shape[0]:
      # if the end of the matrix is reached, break
      break
    while j < arr.shape[1]:
      # if the end of the matrix is reached, break
      if j + size > arr.shape[1]:
        break
      # compute the maximum of the pooling matrix
      SCREAMING_SNAKE_CASE__    							=   np.max(arr[i : i + size, j : j + size]			)
      # shift the pooling matrix by stride of column pixels
      j += stride
      mat_j += 1

    # shift the pooling matrix by stride of row pixels
    i += stride
    mat_i += 1

    # reset the column index to 0
    SCREAMING_SNAKE_CASE__    							=   0
    SCREAMING_SNAKE_CASE__    							=   0

  return updated_arr



def 			__SCREAMING_SNAKE_CASE						(      __UpperCamelCase					: np.ndarray				,  __UpperCamelCase					: int				,  __UpperCamelCase					: int			)							->      np.ndarray:







  """simple docstring"""





  SCREAMING_SNAKE_CASE__    							=   np.array(__UpperCamelCase			)
  if arr.shape[0] != arr.shape[1]:
    raise ValueError("""The input array is not a square matrix"""			)
  SCREAMING_SNAKE_CASE__    							=   0
  SCREAMING_SNAKE_CASE__    							=   0
  SCREAMING_SNAKE_CASE__    							=   0
  SCREAMING_SNAKE_CASE__    							=   0

  # compute the shape of the output matrix
  SCREAMING_SNAKE_CASE__    							=   (arr.shape[0] - size) // stride + 1
  # initialize the output matrix with zeros of shape avgpool_shape
  SCREAMING_SNAKE_CASE__    							=   np.zeros((avgpool_shape, avgpool_shape)			)

  while i < arr.shape[0]:
    # if the end of the matrix is reached, break
    if i + size > arr.shape[0]:
      break
    while j < arr.shape[1]:
      # if the end of the matrix is reached, break
      if j + size > arr.shape[1]:
        break
      # compute the average of the pooling matrix
      SCREAMING_SNAKE_CASE__    							=   int(np.average(arr[i : i + size, j : j + size]			)			)
      # shift the pooling matrix by stride of column pixels
      j += stride
      mat_j += 1

    # shift the pooling matrix by stride of row pixels
    i += stride
    mat_i += 1
    # reset the column index to 0
    SCREAMING_SNAKE_CASE__    							=   0
    SCREAMING_SNAKE_CASE__    							=   0

  return updated_arr


# Main Function
if __name__ == "__main__":
   from doctest import testmod

   testmod(name='''avgpooling''', verbose=True)

   # Loading the image
   __lowerCamelCase    :				List[str]							     =	Image.open('''path_to_image''')

   # Converting the image to numpy array and maxpooling, displaying the result
   # Ensure that the image is a square matrix

   Image.fromarray(maxpooling(np.array(image), size=3, stride=2)).show()

   # Converting the image to numpy array and averagepooling, displaying the result
   # Ensure that the image is a square matrix

   Image.fromarray(avgpooling(np.array(image), size=3, stride=2)).show()

import os

__lowerCamelCase    :				Union[str, Any]							     =	{'''I''': 1, '''V''': 5, '''X''': 10, '''L''': 50, '''C''': 100, '''D''': 500, '''M''': 1000}



def 			__SCREAMING_SNAKE_CASE						(      __UpperCamelCase					: str			)							->      int:







  """simple docstring"""





  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					: int			)							->      str:







  """simple docstring"""





  SCREAMING_SNAKE_CASE__    							=   """"""

  SCREAMING_SNAKE_CASE__    							=   num // 10_00
  numerals += m_count * "M"
  num %= 10_00

  SCREAMING_SNAKE_CASE__    							=   num // 1_00
  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 %= 1_00

  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					: str = "/p089_roman.txt"			)							->      int:







  """simple docstring"""





  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() = }""")
