

def 					__lowerCamelCase	( UpperCamelCase__      ):







							'''simple docstring'''






							assert (
							    isinstance(UpperCamelCase__   ,							UpperCamelCase__      ) and number_of_steps > 0
							), F'''number_of_steps needs to be positive integer, your input {number_of_steps}'''
							if number_of_steps == 1:
														return 1
							snake_case_				,    snake_case_							=    1, 1
							for _ in range(number_of_steps - 1      ):
														snake_case_				,    snake_case_							=    current + previous, current
							return current


if __name__ == "__main__":
					import doctest

					doctest.testmod()







def 					__lowerCamelCase	( ):







							'''simple docstring'''






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


_UpperCAmelCase		:   Union[str, Any]										=       generate_large_matrix()
_UpperCAmelCase		:   Tuple										=       (
    [[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 					__lowerCamelCase	( UpperCamelCase__      ):







							'''simple docstring'''






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





def 					__lowerCamelCase	( UpperCamelCase__      ):







							'''simple docstring'''






							snake_case_							=    0
							snake_case_							=    len(UpperCamelCase__      ) - 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_							=    (left + right) // 2
														snake_case_							=    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_							=    mid + 1
														else:
																					snake_case_							=    mid - 1
    # No negative numbers so return the last index of the array + 1 which is the length.
							return len(UpperCamelCase__      )





def 					__lowerCamelCase	( UpperCamelCase__      ):







							'''simple docstring'''






							snake_case_							=    0
							snake_case_							=    len(grid[0]      )

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





def 					__lowerCamelCase	( UpperCamelCase__      ):







							'''simple docstring'''






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





def 					__lowerCamelCase	( UpperCamelCase__      ):







							'''simple docstring'''






							snake_case_							=    0
							for row in grid:
														for i, number in enumerate(UpperCamelCase__      ):
																					if number < 0:
																												total += len(UpperCamelCase__      ) - i
																												break
							return total





def 					__lowerCamelCase	( ):







							'''simple docstring'''






							from timeit import timeit

							print('Running benchmarks'      )
							snake_case_							=    (
							    '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_							=    timeit(F'''{func}(grid=grid)'''   ,							setup=UpperCamelCase__   ,							number=500      )
														print(F'''{func}() took {time:0.4f} seconds'''      )


if __name__ == "__main__":
					import doctest

					doctest.testmod()
					benchmark()




