





class  _a  :






							"""simple docstring"""

							def __init__(   self					:  str     )						->Union[str, Any]:
													SCREAMING_SNAKE_CASE__  :					dict[int, list[int]] =       {}
													# indexmap keys are an index and it's values are the number at that index
													SCREAMING_SNAKE_CASE__  :					dict[int, int] =       {}

							def   A_	(   self					:  Tuple				,						a					:  list | str | range				,						a					:  int     )						->List[str]:






													if isinstance(UpperCAmelCase__				,						(range, str)     ):
																			SCREAMING_SNAKE_CASE__  :					Optional[int] =       list(UpperCAmelCase__     )
													elif not isinstance(UpperCAmelCase__				,						UpperCAmelCase__     ):
																			raise TypeError(
																			    "binary_search_delete() only accepts either a list, range or str"     )

													SCREAMING_SNAKE_CASE__  :					Optional[Any] =       0
													SCREAMING_SNAKE_CASE__  :					List[str] =       len(UpperCAmelCase__     ) - 1

													while low <= high:
																			SCREAMING_SNAKE_CASE__  :					Union[str, Any] =       (low + high) // 2
																			if array[mid] == item:
																									array.pop(UpperCAmelCase__     )
																									return array
																			elif array[mid] < item:
																									SCREAMING_SNAKE_CASE__  :					int =       mid + 1
																			else:
																									SCREAMING_SNAKE_CASE__  :					Tuple =       mid - 1
													raise ValueError(
													    "Either the item is not in the array or the array was unsorted"     )

							def   A_	(   self					:  int				,						a					:  list | str | range				,						a					:  int     )						->Dict:






													if isinstance(UpperCAmelCase__				,						(range, str)     ):
																			SCREAMING_SNAKE_CASE__  :					Union[str, Any] =       list(UpperCAmelCase__     )
													elif not isinstance(UpperCAmelCase__				,						UpperCAmelCase__     ):
																			raise TypeError(
																			    "binary_search_insert() only accepts either a list, range or str"     )

													SCREAMING_SNAKE_CASE__  :					Any =       0
													SCREAMING_SNAKE_CASE__  :					List[str] =       len(UpperCAmelCase__     ) - 1

													while low <= high:
																			SCREAMING_SNAKE_CASE__  :					Dict =       (low + high) // 2
																			if array[mid] == index:
																									# If the item already exists in the array,
																									# insert it after the existing item
																									array.insert(mid + 1				,						UpperCAmelCase__     )
																									return array
																			elif array[mid] < index:
																									SCREAMING_SNAKE_CASE__  :					Union[str, Any] =       mid + 1
																			else:
																									SCREAMING_SNAKE_CASE__  :					List[Any] =       mid - 1

																			 # If the item doesn't exist in the array, insert it at the appropriate position
													array.insert(UpperCAmelCase__				,						UpperCAmelCase__     )
													return array

							def   A_	(   self					:  Any				,						a					:  int				,						a					:  int     )						->Optional[Any]:






													if index in self.indexmap:
																			SCREAMING_SNAKE_CASE__  :					int =       self.indexmap[index]
																			if len(self.numbermap[n]     ) == 1:
																									del self.numbermap[n]
																			else:
																									SCREAMING_SNAKE_CASE__  :					List[str] =       self.binary_search_delete(self.numbermap[n]				,						UpperCAmelCase__     )

																			 # Set new index
													SCREAMING_SNAKE_CASE__  :					Dict =       number

													# Number not seen before or empty so insert number value
													if number not in self.numbermap:
																			SCREAMING_SNAKE_CASE__  :					Tuple =       [index]

													# Here we need to perform a binary search insertion in order to insert
													# The item in the correct place
													else:
																			SCREAMING_SNAKE_CASE__  :					Optional[Any] =       self.binary_search_insert(
																			    self.numbermap[number]				,						UpperCAmelCase__     )






							def   A_	(   self					:  int				,						a					:  int     )						->Any:
													return self.numbermap.get(UpperCAmelCase__				,						[-1]     )[0]


if __name__ == "__main__":
				import doctest

				doctest.testmod()







from datetime import date

import requests

a 			=							'https://api.carbonintensity.org.uk/intensity'
def    a__    (	):
   lowercase__    :						Union[str, Any]       =			requests.get(A       ).json()["""data"""][0]
   return last_half_hour["intensity"]["actual"]
def    a__    (	A		,					A       ):
   return requests.get(F'''{BASE_URL}/{start}/{end}'''       ).json()["data"]


if __name__ == "__main__":
 for entry in fetch_from_to(start=date(2020, 10, 1), end=date(2020, 10, 3)):
  print('from {from} to {to}: {intensity[actual]}'.format(**entry))
 print(F'{fetch_last_half_hour() = }')


