
import math





class   __UpperCamelCase				:






     """simple docstring"""







     def __init__(							self    :    Dict      ,		_A    :    int      ,		_A    :    int      ,		_A    :    int      ,		_A    :    Optional[Any]				):







       """simple docstring"""




       __SCREAMING_SNAKE_CASE     :					Dict			=						x
       __SCREAMING_SNAKE_CASE     :					Tuple			=						y
       __SCREAMING_SNAKE_CASE     :					List[Any]			=						step_size
       __SCREAMING_SNAKE_CASE     :					int			=						function_to_optimize



     def 				UpperCAmelCase__    (							self    :    Any				):







       """simple docstring"""




       return self.function(self.x      ,		self.y				)



     def 				UpperCAmelCase__    (							self    :    int				):







       """simple docstring"""




       __SCREAMING_SNAKE_CASE     :					Union[str, Any]			=						self.step_size
       return [
           SearchProblem(_A      ,		_A      ,		_A      ,		self.function				)
           for x, y in (
               (self.x - step_size, self.y - step_size),
               (self.x - step_size, self.y),
               (self.x - step_size, self.y + step_size),
               (self.x, self.y - step_size),
               (self.x, self.y + step_size),
               (self.x + step_size, self.y - step_size),
               (self.x + step_size, self.y),
               (self.x + step_size, self.y + step_size),
           )
       ]



     def __hash__(							self    :    Union[str, Any]				):







       """simple docstring"""




       return hash(str(self				)				)



     def __eq__(							self    :    Tuple      ,		_A    :    int				):







       """simple docstring"""




       if isinstance(_A      ,		_A				):
         return hash(str(self				)				) == hash(str(_A				)				)
       return False




     def __str__(							self    :    Optional[Any]				):







       """simple docstring"""




       return F'''x: {self.x} y: {self.y}'''






def     a__			(    snake_case   ,	snake_case = True   ,	snake_case = math.inf   ,	snake_case = -math.inf   ,	snake_case = math.inf   ,	snake_case = -math.inf   ,	snake_case = False   ,	snake_case = 10_000   ,	):





  """simple docstring"""
  __SCREAMING_SNAKE_CASE     :					Optional[int]			=						search_prob
  __SCREAMING_SNAKE_CASE     :					Union[str, Any]			=						[]  # list to store the current score at each iteration
  __SCREAMING_SNAKE_CASE     :					Optional[Any]			=						0
  __SCREAMING_SNAKE_CASE     :					Any			=						False
  __SCREAMING_SNAKE_CASE     :					Optional[int]			=						set()
  while not solution_found and iterations < max_iter:
    visited.add(snake_case    )
    iterations += 1
    __SCREAMING_SNAKE_CASE     :					Tuple			=						current_state.score()
    scores.append(snake_case    )
    __SCREAMING_SNAKE_CASE     :					str			=						current_state.get_neighbors()
    __SCREAMING_SNAKE_CASE     :					str			=						-math.inf
    __SCREAMING_SNAKE_CASE     :					Tuple			=						math.inf
    __SCREAMING_SNAKE_CASE     :					List[str]			=						None  # to hold the next best neighbor
    for neighbor in neighbors:
      if neighbor in visited:
        continue  # do not want to visit the same state again
      if (
          neighbor.x > max_x
          or neighbor.x < min_x
          or neighbor.y > max_y
          or neighbor.y < min_y
      ):
        continue  # neighbor outside our bounds
      __SCREAMING_SNAKE_CASE     :					str			=						neighbor.score() - current_score
      if find_max:  # finding max
        # going to direction with greatest ascent
        if change > max_change and change > 0:
          __SCREAMING_SNAKE_CASE     :					Any			=						change
          __SCREAMING_SNAKE_CASE     :					Any			=						neighbor
      else:  # finding min
        # to direction with greatest descent
        if change < min_change and change < 0:
          __SCREAMING_SNAKE_CASE     :					Optional[Any]			=						change
          __SCREAMING_SNAKE_CASE     :					Optional[Any]			=						neighbor
    if next_state is not None:
      # we found at least one neighbor which improved the current state
      __SCREAMING_SNAKE_CASE     :					Dict			=						next_state
    else:
      # since we have no neighbor that improves the solution we stop the search
      __SCREAMING_SNAKE_CASE     :					Union[str, Any]			=						True

  if visualization:
    from matplotlib import pyplot as plt

    plt.plot(range(snake_case    )   ,	snake_case    )
    plt.xlabel('''Iterations'''    )
    plt.ylabel('''Function values'''    )
    plt.show()

  return current_state


if __name__ == "__main__":
   import doctest

   doctest.testmod()


   def     a__			(    snake_case   ,	snake_case    ):





     """simple docstring"""
     return (x**2) + (y**2)

   # starting the problem with initial coordinates (3, 4)
   lowercase_											=	SearchProblem(x=3, y=4, step_size=1, function_to_optimize=test_fa)
   lowercase_											=	hill_climbing(prob, find_max=False)
   print(
       """The minimum score for f(x, y) = x^2 + y^2 found via hill climbing: """
       f'''{local_min.score()}'''
   )

   # starting the problem with initial coordinates (12, 47)
   lowercase_											=	SearchProblem(x=12, y=47, step_size=1, function_to_optimize=test_fa)
   lowercase_											=	hill_climbing(
       prob, find_max=False, max_x=100, min_x=5, max_y=50, min_y=-5, visualization=True
   )
   print(
       """The minimum score for f(x, y) = x^2 + y^2 with the domain 100 > x > 5 """
       f'''and 50 > y > - 5 found via hill climbing: {local_min.score()}'''
   )


   def     a__			(    snake_case   ,	snake_case    ):





     """simple docstring"""
     return (3 * x**2) - (6 * y)

   lowercase_											=	SearchProblem(x=3, y=4, step_size=1, function_to_optimize=test_fa)
   lowercase_											=	hill_climbing(prob, find_max=True)


   print(
       """The maximum score for f(x, y) = x^2 + y^2 found via hill climbing: """
       f'''{local_min.score()}'''
   )


from collections import defaultdict


def     a__			(    snake_case    ):





  """simple docstring"""
  __SCREAMING_SNAKE_CASE     :					defaultdict[str, int]			=						defaultdict(snake_case    )
  # Creating a dictionary containing count of each word
  for word in sentence.split():
    occurrence[word] += 1
  return occurrence


if __name__ == "__main__":
   for word, count in word_occurrence("""INPUT STRING""").items():
      print(f'''{word}: {count}''')
