

"""simple docstring"""



from heapq import heappop, heappush

import numpy as np





def  _snake_case     (    UpperCAmelCase_  :					Union[str, Any]					,   UpperCAmelCase_  :					Dict					,   UpperCAmelCase_  :					Any					,   UpperCAmelCase_  :					Dict					,   ):
     A__			,				A__										=  grid.shape
     A__										=  [-1, 1, 0, 0]
     A__										=  [0, 0, -1, 1]
     if allow_diagonal:
          dx += [-1, -1, 1, 1]
          dy += [-1, 1, -1, 1]

     A__			,				A__										=  [(0, source)], set()
     A__										=  np.full((rows, cols)					,   np.inf			)
     A__										=  0
     A__										=  np.empty((rows, cols)					,   dtype=_SCREAMING_SNAKE_CASE			)
     A__										=  None

     while queue:
          ((A__)			,				(A__))										=  heappop(_SCREAMING_SNAKE_CASE			)
          if (x, y) in visited:
               continue
          visited.add((x, y)			)

          if (x, y) == destination:
               A__										=  []
               while (x, y) != source:
                    path.append((x, y)			)
                    A__			,				A__										=  predecessors[x, y]
               path.append(_SCREAMING_SNAKE_CASE			)  # add the source manually
               path.reverse()
               return matrix[destination], path

          for i in range(len(_SCREAMING_SNAKE_CASE			)			):
               A__			,				A__										=  x + dx[i], y + dy[i]
               if 0 <= nx < rows and 0 <= ny < cols:
                    A__										=  grid[nx][ny]
                    if next_node == 1 and matrix[nx, ny] > dist + 1:
                         heappush(_SCREAMING_SNAKE_CASE					,   (dist + 1, (nx, ny))			)
                         A__										=  dist + 1
                         A__										=  (x, y)

     return np.inf, []


if __name__ == "__main__":
 import doctest

 doctest.testmod()








"""simple docstring"""



import math
import sys





def  _snake_case     (    UpperCAmelCase_  :					int			):
     if number != int(UpperCAmelCase_			):
          raise ValueError("""the value of input must be a natural number"""			)
     if number < 0:
          raise ValueError("""the value of input must not be a negative number"""			)
     if number == 0:
          return 1
     A__										=  [-1] * (number + 1)
     A__										=  0
     for i in range(1					,   number + 1			):
          A__										=  sys.maxsize
          A__										=  int(math.sqrt(UpperCAmelCase_			)			)
          for j in range(1					,   root + 1			):
               A__										=  1 + answers[i - (j**2)]
               A__										=  min(UpperCAmelCase_					,   UpperCAmelCase_			)
          A__										=  answer
     return answers[number]


if __name__ == "__main__":
 import doctest

 doctest.testmod()






