



def 			lowerCAmelCase__	(					):





				'''simple docstring'''

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


__snake_case       :	List[str]            =generate_large_matrix()
__snake_case       :	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 			lowerCAmelCase__	(					lowerCamelCase_	:	Optional[Any]):





				'''simple docstring'''

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






def 			lowerCAmelCase__	(					lowerCamelCase_	:	Union[str, Any]):





				'''simple docstring'''

				lowerCAmelCase__  :       List[Any]				=  0
				lowerCAmelCase__  :       List[str]				=  len(lowerCamelCase_) - 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:
								lowerCAmelCase__  :       int				=  (left + right) // 2
								lowerCAmelCase__  :       int				=  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:
												lowerCAmelCase__  :       Union[str, Any]				=  mid + 1
								else:
												lowerCAmelCase__  :       int				=  mid - 1
    # No negative numbers so return the last index of the array + 1 which is the length.
				return len(lowerCamelCase_)






def 			lowerCAmelCase__	(					lowerCamelCase_	:	Tuple):





				'''simple docstring'''

				lowerCAmelCase__  :       Dict				=  0
				lowerCAmelCase__  :       Tuple				=  len(grid[0])

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






def 			lowerCAmelCase__	(					lowerCamelCase_	:	List[Any]):





				'''simple docstring'''

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






def 			lowerCAmelCase__	(					lowerCamelCase_	:	Tuple):





				'''simple docstring'''

				lowerCAmelCase__  :       List[str]				=  0
				for row in grid:
								for i, number in enumerate(lowerCamelCase_):
												if number < 0:
																total += len(lowerCamelCase_) - i
																break
				return total






def 			lowerCAmelCase__	(					):





				'''simple docstring'''

				from timeit import timeit

				print('''Running benchmarks''')
				lowerCAmelCase__  :       Optional[int]				=  (
				    '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
				):
								lowerCAmelCase__  :       Any				=  timeit(f"""{func}(grid=grid)""" ,setup=lowerCamelCase_ ,number=500)
								print(f"""{func}() took {time:0.4f} seconds""")


if __name__ == "__main__":
							import doctest

							doctest.testmod()
							benchmark()






def 			lowerCAmelCase__	(					lowerCamelCase_	:	int):





				'''simple docstring'''

				if length <= 0 or not isinstance(lowerCamelCase_ ,lowerCamelCase_):
								raise ValueError('''Length must be a positive integer.''')
				return [n * (2 * n - 1) for n in range(lowerCamelCase_)]


if __name__ == "__main__":
							print(hexagonal_numbers(length=5))
							print(hexagonal_numbers(length=1_0))

