
"""simple docstring"""







lowercase_         =       "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"




def       A_      (       lowercase   )  ->				bytes:


     """simple docstring"""







     if not isinstance(lowercase    ,			lowercase   ):
          UpperCAmelCase_    :     Optional[int]            =	f'''a bytes-like object is required, not \'{data.__class__.__name__}\''''
          raise TypeError(lowercase   )

     UpperCAmelCase_    :     List[str]            =	"""""".join(bin(lowercase   )[2:].zfill(8   ) for byte in data   )

     UpperCAmelCase_    :     str            =	len(lowercase   ) % 6 != 0

     if padding_needed:
          # The padding that will be added later
          UpperCAmelCase_    :     Any            =	b"""=""" * ((6 - len(lowercase   ) % 6) // 2)

          # Append binary_stream with arbitrary binary digits (0's by default) to make its
          # length a multiple of 6.
          binary_stream += "0" * (6 - len(lowercase   ) % 6)
     else:
          UpperCAmelCase_    :     Dict            =	b""""""

     # Encode every 6 binary digits to their corresponding Base64 character
     return (
         "".join(
             B64_CHARSET[int(binary_stream[index : index + 6]    ,			2   )]
             for index in range(0    ,			len(lowercase   )    ,			6   )   ).encode()
         + padding
     )




def       A_      (       lowercase   )  ->				bytes:


     """simple docstring"""







     if not isinstance(lowercase    ,			lowercase   ) and not isinstance(lowercase    ,			lowercase   ):
          UpperCAmelCase_    :     Any            =	(
              """argument should be a bytes-like object or ASCII string, """
              f'''not \'{encoded_data.__class__.__name__}\''''
          )
          raise TypeError(lowercase   )

     # In case encoded_data is a bytes-like object, make sure it contains only
     # ASCII characters so we convert it to a string object
     if isinstance(lowercase    ,			lowercase   ):
          try:
               UpperCAmelCase_    :     Dict            =	encoded_data.decode("""utf-8"""   )
          except UnicodeDecodeError:
               raise ValueError("""base64 encoded data should only contain ASCII characters"""   )

     UpperCAmelCase_    :     int            =	encoded_data.count("""="""   )

     # Check if the encoded string contains non base64 characters
     if padding:
          assert all(
              char in B64_CHARSET for char in encoded_data[:-padding]   ), "Invalid base64 character(s) found."
     else:
          assert all(
              char in B64_CHARSET for char in encoded_data   ), "Invalid base64 character(s) found."

     # Check the padding
     assert len(lowercase   ) % 4 == 0 and padding < 3, "Incorrect padding"

     if padding:
          # Remove padding if there is one
          UpperCAmelCase_    :     Optional[Any]            =	encoded_data[:-padding]

          UpperCAmelCase_    :     Optional[Any]            =	"""""".join(
              bin(B64_CHARSET.index(lowercase   )   )[2:].zfill(6   ) for char in encoded_data   )[: -padding * 2]
     else:
          UpperCAmelCase_    :     List[Any]            =	"""""".join(
              bin(B64_CHARSET.index(lowercase   )   )[2:].zfill(6   ) for char in encoded_data   )

     UpperCAmelCase_    :     List[Any]            =	[
         int(binary_stream[index : index + 8]    ,			2   )
         for index in range(0    ,			len(lowercase   )    ,			8   )
     ]

     return bytes(lowercase   )


if __name__ == "__main__":
       import doctest

       doctest.testmod()



"""simple docstring"""







class 		UpperCAmelCase_						:
 """simple docstring"""




 def __init__(			self							:			Optional[Any]  , a_							:			int			)->       str:



      """simple docstring"""

      UpperCAmelCase_    :     Any            =	n
      UpperCAmelCase_    :     str            =	[None] * self.n
      UpperCAmelCase_    :     List[Any]            =	0  # index of the first element
      UpperCAmelCase_    :     List[Any]            =	0
      UpperCAmelCase_    :     Dict            =	0




 def __len__(			self							:			Union[str, Any]			)->       int:



      """simple docstring"""

      return self.size




 def 	a   (			self							:			Dict			)->       bool:



      """simple docstring"""

      return self.size == 0




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



      """simple docstring"""

      return False if self.is_empty() else self.array[self.front]




 def 	a   (			self							:			Dict  , a_							:			int			)->       Optional[int]:



      """simple docstring"""

      if self.size >= self.n:
           raise Exception("""QUEUE IS FULL"""			)

      UpperCAmelCase_    :     List[str]            =	data
      UpperCAmelCase_    :     Optional[int]            =	(self.rear + 1) % self.n
      self.size += 1
      return self






 def 	a   (			self							:			Union[str, Any]			)->       List[Any]:



      """simple docstring"""

      if self.size == 0:
           raise Exception("""UNDERFLOW"""			)

      UpperCAmelCase_    :     Tuple            =	self.array[self.front]
      UpperCAmelCase_    :     List[str]            =	None
      UpperCAmelCase_    :     Dict            =	(self.front + 1) % self.n
      self.size -= 1
      return temp

