



'''simple docstring'''

def 						__UpperCamelCase				(							) ->			list[list[int]]:
	return [list(range(1000 - i,				-1000 - i,				-1					)					) for i in range(1000					)]


_A				:    List[Any]     						=generate_large_matrix()
_A				:    Optional[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 						__UpperCamelCase				(							_lowercase					) ->			None:
	assert all(row == sorted(_lowercase,				reverse=_lowercase					) for row in grid					)
	assert all(list(_lowercase					) == sorted(_lowercase,				reverse=_lowercase					) for col in zip(*_lowercase					)					)







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







def 						__UpperCamelCase				(							_lowercase					) ->			int:
	_lowercase					:       Any       =		0
	_lowercase					:       str       =		len(grid[0]					)

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







def 						__UpperCamelCase				(							_lowercase					) ->			int:
	return len([number for row in grid for number in row if number < 0]					)







def 						__UpperCamelCase				(							_lowercase					) ->			int:
	_lowercase					:       List[Any]       =		0
	for row in grid:
		for i, number in enumerate(_lowercase					):
			if number < 0:
				total += len(_lowercase					) - i
				break
	return total







def 						__UpperCamelCase				(							) ->			None:
	from timeit import timeit

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


if __name__ == "__main__":
		import doctest

		doctest.testmod()
		benchmark()





'''simple docstring'''

from __future__ import annotations

import requests







def 						__UpperCamelCase				(							_lowercase					) ->			dict:
	_lowercase					:       Optional[int]       =		f'''https://hacker-news.firebaseio.com/v0/item/{story_id}.json?print=pretty'''
	return requests.get(_lowercase					).json()







def 						__UpperCamelCase				(							_lowercase = 10					) ->			list[dict]:
	_lowercase					:       Union[str, Any]       =		'https://hacker-news.firebaseio.com/v0/topstories.json?print=pretty'
	_lowercase					:       Optional[Any]       =		requests.get(_lowercase					).json()[:max_stories]
	return [get_hackernews_story(_lowercase					) for story_id in story_ids]







def 						__UpperCamelCase				(							_lowercase = 10					) ->			str:
	_lowercase					:       Tuple       =		hackernews_top_stories(_lowercase					)
	return "\n".join('* [{title}]({url})'.format(**_lowercase					) for story in stories					)


if __name__ == "__main__":
		print(hackernews_top_stories_as_markdown())
