
class       _snake_case					:







			def __init__(				self						,   _a						,   _a=None						,   _a=None		):
				__magic_name__		:		Any	   =     data
				__magic_name__		:		List[str]	   =     previous
				__magic_name__		:		Union[str, Any]	   =     next_node







			def __str__(				self		):
				return f'''{self.data}'''







			def 			SCREAMING_SNAKE_CASE    (				self		):
				return self.data







			def 			SCREAMING_SNAKE_CASE    (				self		):
				return self.next







			def 			SCREAMING_SNAKE_CASE    (				self		):
				return self.previous







class       _snake_case					:







			def __init__(				self						,   _a		):
				__magic_name__		:		int	   =     head







			def __iter__(				self		):
				return self







			def 			SCREAMING_SNAKE_CASE    (				self		):
				if not self.current:
					raise StopIteration
				else:
					__magic_name__		:		Optional[Any]	   =     self.current.get_data()
					__magic_name__		:		int	   =     self.current.get_next()
					return value







class       _snake_case					:







			def __init__(				self		):
				__magic_name__		:		Union[str, Any]	   =     None  # First node in list
				__magic_name__		:		List[Any]	   =     None  # Last node in list







			def __str__(				self		):
				__magic_name__		:		int	   =     self.head
				__magic_name__		:		Optional[int]	   =     []
				while current is not None:
					nodes.append(current.get_data()		)
					__magic_name__		:		Dict	   =     current.get_next()
				return " ".join(str(_a		) for node in nodes		)







			def __contains__(				self						,   _a		):
				__magic_name__		:		Union[str, Any]	   =     self.head
				while current:
					if current.get_data() == value:
						return True
					__magic_name__		:		Union[str, Any]	   =     current.get_next()
				return False







			def __iter__(				self		):
				return LinkedListIterator(self.head		)







			def 			SCREAMING_SNAKE_CASE    (				self		):
				if self.head:
					return self.head.get_data()
				return None







			def 			SCREAMING_SNAKE_CASE    (				self		):
				if self.tail:
					return self.tail.get_data()
				return None







			def 			SCREAMING_SNAKE_CASE    (				self						,   _a		):
				if self.head is None:
					__magic_name__		:		Tuple	   =     node
					__magic_name__		:		List[Any]	   =     node
				else:
					self.insert_before_node(self.head						,   _a		)







			def 			SCREAMING_SNAKE_CASE    (				self						,   _a		):
				if self.head is None:
					self.set_head(_a		)
				else:
					self.insert_after_node(self.tail						,   _a		)







			def 			SCREAMING_SNAKE_CASE    (				self						,   _a		):
				__magic_name__		:		int	   =     Node(_a		)
				if self.head is None:
					self.set_head(_a		)
				else:
					self.set_tail(_a		)







			def 			SCREAMING_SNAKE_CASE    (				self						,   _a						,   _a		):
				__magic_name__		:		Dict	   =     node
				__magic_name__		:		Optional[Any]	   =     node.previous

				if node.get_previous() is None:
					__magic_name__		:		int	   =     node_to_insert
				else:
					__magic_name__		:		Tuple	   =     node_to_insert

				__magic_name__		:		str	   =     node_to_insert







			def 			SCREAMING_SNAKE_CASE    (				self						,   _a						,   _a		):
				__magic_name__		:		List[Any]	   =     node
				__magic_name__		:		Tuple	   =     node.next

				if node.get_next() is None:
					__magic_name__		:		Dict	   =     node_to_insert
				else:
					__magic_name__		:		Dict	   =     node_to_insert

				__magic_name__		:		Optional[Any]	   =     node_to_insert







			def 			SCREAMING_SNAKE_CASE    (				self						,   _a						,   _a		):
				__magic_name__		:		List[Any]	   =     1
				__magic_name__		:		Any	   =     Node(_a		)
				__magic_name__		:		int	   =     self.head
				while node:
					if current_position == position:
						self.insert_before_node(_a						,   _a		)
						return
					current_position += 1
					__magic_name__		:		Tuple	   =     node.next
				self.insert_after_node(self.tail						,   _a		)







			def 			SCREAMING_SNAKE_CASE    (				self						,   _a		):
				__magic_name__		:		Any	   =     self.head
				while node:
					if node.get_data() == item:
						return node
					__magic_name__		:		Tuple	   =     node.get_next()
				raise Exception("Node not found"		)







			def 			SCREAMING_SNAKE_CASE    (				self						,   _a		):
				if (node := self.get_node(_a		)) is not None:
					if node == self.head:
						__magic_name__		:		Optional[int]	   =     self.head.get_next()

					if node == self.tail:
						__magic_name__		:		Optional[Any]	   =     self.tail.get_previous()

					self.remove_node_pointers(_a		)







			@staticmethod
			def 			SCREAMING_SNAKE_CASE    (				_a		):
				if node.get_next():
					__magic_name__		:		Any	   =     node.previous

				if node.get_previous():
					__magic_name__		:		Optional[int]	   =     node.next

				__magic_name__		:		str	   =     None
				__magic_name__		:		int	   =     None







			def 			SCREAMING_SNAKE_CASE    (				self		):
				return self.head is None







def   lowerCAmelCase_						(					)				->		Dict:







	'''simple docstring'''










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()




