

'''simple docstring'''


def 						_a							(					):

		"""simple docstring"""

		return [list(range(10_00 - i ,				-10_00 - i ,				-1  )  ) for i in range(10_00  )]


lowerCAmelCase__    :							str					    =    generate_large_matrix()
lowerCAmelCase__    :							int					    =    (
    [[4, 3, 2, -1], [3, 2, 1, -1], [1, 1, -1, -2], [-1, -1, -2, -3]],
    [[3, 2], [1, 0]],
    [[7, 7, 6]],
    [[7, 7, 6], [-1, -2, -3]],
    grid,
)




def 						_a							(					__lowerCAmelCase		:   list[list[int]]  ):

		"""simple docstring"""

		assert all(row == sorted(__snake_case ,				reverse=__snake_case  ) for row in grid  )
		assert all(list(__snake_case  ) == sorted(__snake_case ,				reverse=__snake_case  ) for col in zip(*__snake_case  )  )




def 						_a							(					__lowerCAmelCase		:   list[int]  ):

		"""simple docstring"""

		snake_case__    :							List[str]							    =	0
		snake_case__    :							List[str]							    =	len(__snake_case  ) - 1

		# Edge cases such as no values or all numbers are negative.
		if not array or array[0] < 0:
				return 0

		while right + 1 > left:
				snake_case__    :							List[str]							    =	(left + right) // 2
				snake_case__    :							Dict							    =	array[mid]

				# Num must be negative and the index must be greater than or equal to 0.
				if num < 0 and array[mid - 1] >= 0:
						return mid

				if num >= 0:
						snake_case__    :							Optional[Any]							    =	mid + 1
				else:
						snake_case__    :							Optional[int]							    =	mid - 1
    # No negative numbers so return the last index of the array + 1 which is the length.
		return len(__snake_case  )




def 						_a							(					__lowerCAmelCase		:   list[list[int]]  ):

		"""simple docstring"""

		snake_case__    :							Optional[Any]							    =	0
		snake_case__    :							List[Any]							    =	len(grid[0]  )

		for i in range(len(__snake_case  )  ):
				snake_case__    :							Tuple							    =	find_negative_index(grid[i][:bound]  )
				total += bound
		return (len(__snake_case  ) * len(grid[0]  )) - total




def 						_a							(					__lowerCAmelCase		:   list[list[int]]  ):

		"""simple docstring"""

		return len([number for row in grid for number in row if number < 0]  )




def 						_a							(					__lowerCAmelCase		:   list[list[int]]  ):

		"""simple docstring"""

		snake_case__    :							Union[str, Any]							    =	0
		for row in grid:
				for i, number in enumerate(__snake_case  ):
						if number < 0:
								total += len(__snake_case  ) - i
								break
		return total




def 						_a							(					):

		"""simple docstring"""

		from timeit import timeit

		print('''Running benchmarks'''  )
		snake_case__    :							Optional[Any]							    =	(
		    '''from __main__ import count_negatives_binary_search, '''
		    '''count_negatives_brute_force, count_negatives_brute_force_with_break, grid'''
		)
		for func in (
		    "count_negatives_binary_search",  # took 0.7727 seconds
		    "count_negatives_brute_force_with_break",  # took 4.6505 seconds
		    "count_negatives_brute_force",  # took 12.8160 seconds
		):
				snake_case__    :							Any							    =	timeit(F"""{func}(grid=grid)""" ,				setup=__snake_case ,				number=5_00  )
				print(F"""{func}() took {time:0.4f} seconds"""  )


if __name__ == "__main__":
					import doctest

					doctest.testmod()
					benchmark()




'''simple docstring'''

import colorsys

from PIL import Image  # type: ignore



def snake_case_      (					__snake_case  :							float	,   __snake_case  :							float	,   __snake_case  :							int)			->					float:
   lowerCAmelCase_			=      x
   lowerCAmelCase_			=      y
   for step in range(__snake_case):  # noqa: B007
      lowerCAmelCase_			=      a * a - b * b + x
      lowerCAmelCase_			=      2 * a * b + y
      lowerCAmelCase_			=      a_new

      # divergence happens for all complex number with an absolute value
      # greater than 4
      if a * a + b * b > 4:
         break
   return step / (max_step - 1)



def snake_case_      (					__snake_case  :							float)			->					tuple:
   if distance == 1:
      return (0, 0, 0)
   else:
      return (255, 255, 255)



def snake_case_      (					__snake_case  :							float)			->					tuple:
   if distance == 1:
      return (0, 0, 0)
   else:
      return tuple(round(i * 255) for i in colorsys.hsv_to_rgb(__snake_case	,   1	,   1))



def snake_case_      (					__snake_case  :							int = 800	,   __snake_case  :							int = 600	,   __snake_case  :							float = -0.6	,   __snake_case  :							float = 0	,   __snake_case  :							float = 3.2	,   __snake_case  :							int = 50	,   __snake_case  :							bool = True	,   )			->					Image.Image:
   lowerCAmelCase_			=      Image.new('''RGB'''	,   (image_width, image_height))
   lowerCAmelCase_			=      img.load()

   # loop through the image-coordinates
   for image_x in range(__snake_case):
      for image_y in range(__snake_case):
         # determine the figure-coordinates based on the image-coordinates
         lowerCAmelCase_			=      figure_width / image_width * image_height
         lowerCAmelCase_			=      figure_center_x + (image_x / image_width - 0.5) * figure_width
         lowerCAmelCase_			=      figure_center_y + (image_y / image_height - 0.5) * figure_height

         lowerCAmelCase_			=      get_distance(__snake_case	,   __snake_case	,   __snake_case)

         # color the corresponding pixel based on the selected coloring-function
         if use_distance_color_coding:
            lowerCAmelCase_			=      get_color_coded_rgb(__snake_case)
         else:
            lowerCAmelCase_			=      get_black_and_white_rgb(__snake_case)

   return img


if __name__ == "__main__":
 import doctest

 doctest.testmod()

 # colored version, full figure
 A_     :						List[str]    							=get_image()

 # uncomment for colored version, different section, zoomed in
 # img = get_image(figure_center_x = -0.6, figure_center_y = -0.4,
 # figure_width = 0.8)

 # uncomment for black and white version, full figure
 # img = get_image(use_distance_color_coding = False)

 # uncomment to save the image
 # img.save("mandelbrot.png")

 img.show()





