
from __future__ import annotations

from statistics import mean






def   lowerCamelCase__							(					a		,		a		,		a      )      ->   list[int]:
   _A:  Optional[int]					=       [0] * no_of_processes
   _A:  str					=       [0] * no_of_processes

   # Initialize remaining_time to waiting_time.

   for i in range(_SCREAMING_SNAKE_CASE      ):
      _A:  Any					=       burst_time[i]
   _A:  list[int]					=       []

   _A:  Optional[Any]					=       0
   _A:  Optional[int]					=       0

   # When processes are not completed,
   # A process whose arrival time has passed \
   # and has remaining execution time is put into the ready_process.
   # The shortest process in the ready_process, target_process is executed.

   while completed != no_of_processes:
      _A:  List[Any]					=       []
      _A:  int					=       -1

      for i in range(_SCREAMING_SNAKE_CASE      ):
         if (arrival_time[i] <= total_time) and (remaining_time[i] > 0):
            ready_process.append(_SCREAMING_SNAKE_CASE      )

      if len(_SCREAMING_SNAKE_CASE      ) > 0:
         _A:  int					=       ready_process[0]
         for i in ready_process:
            if remaining_time[i] < remaining_time[target_process]:
               _A:  Dict					=       i
         total_time += burst_time[target_process]
         completed += 1
         _A:  Tuple					=       0
         _A:  List[str]					=       (
             total_time - arrival_time[target_process] - burst_time[target_process]
         )
      else:
         total_time += 1

   return waiting_time






def   lowerCamelCase__							(					a		,		a		,		a      )      ->   list[int]:
   _A:  Optional[Any]					=       [0] * no_of_processes
   for i in range(_SCREAMING_SNAKE_CASE      ):
      _A:  str					=       burst_time[i] + waiting_time[i]
   return turn_around_time


if __name__ == "__main__":
   print('[TEST CASE 01]')

   UpperCAmelCase__		:     str     			=      4
   UpperCAmelCase__		:     Dict     			=      [2, 5, 3, 7]
   UpperCAmelCase__		:     str     			=      [0, 0, 0, 0]
   UpperCAmelCase__		:     Dict     			=      calculate_waitingtime(arrival_time, burst_time, no_of_processes)
   UpperCAmelCase__		:     Union[str, Any]     			=      calculate_turnaroundtime(
       burst_time, no_of_processes, waiting_time
   )

   # Printing the Result
   print('PID\tBurst Time\tArrival Time\tWaiting Time\tTurnaround Time')
   for i, process_id in enumerate(list(range(1, 5))):
      print(
          F"""{process_id}\t{burst_time[i]}\t\t\t{arrival_time[i]}\t\t\t\t"""
          F"""{waiting_time[i]}\t\t\t\t{turn_around_time[i]}"""
      )
   print(F"""\nAverage waiting time = {mean(waiting_time):.5f}""")
   print(F"""Average turnaround time = {mean(turn_around_time):.5f}""")










"""simple docstring"""





from __future__ import annotations

__A											=		tuple[int, int, int]
__A											=		tuple[str, str, str]


# used alphabet --------------------------
# from string.ascii_uppercase
__A											=		"""ABCDEFGHIJKLMNOPQRSTUVWXYZ"""

# -------------------------- default selection --------------------------
# rotors --------------------------
__A											=		"""EGZWVONAHDCLFQMSIPJBYUKXTR"""
__A											=		"""FOBHMDKEXQNRAULPGSJVTYICZW"""
__A											=		"""ZJXESIUQLHAVRMDOYGTNFWPBKC"""
# reflector --------------------------
__A											=		{
    """A""": """N""",
    """N""": """A""",
    """B""": """O""",
    """O""": """B""",
    """C""": """P""",
    """P""": """C""",
    """D""": """Q""",
    """Q""": """D""",
    """E""": """R""",
    """R""": """E""",
    """F""": """S""",
    """S""": """F""",
    """G""": """T""",
    """T""": """G""",
    """H""": """U""",
    """U""": """H""",
    """I""": """V""",
    """V""": """I""",
    """J""": """W""",
    """W""": """J""",
    """K""": """X""",
    """X""": """K""",
    """L""": """Y""",
    """Y""": """L""",
    """M""": """Z""",
    """Z""": """M""",
}

# -------------------------- extra rotors --------------------------
__A											=		"""RMDJXFUWGISLHVTCQNKYPBEZOA"""
__A											=		"""SGLCPQWZHKXAREONTFBVIYJUDM"""
__A											=		"""HVSICLTYKQUBXDWAJZOMFGPREN"""
__A											=		"""RZWQHFMVDBKICJLNTUXAGYPSOE"""
__A											=		"""LFKIJODBEGAMQPXVUHYSTCZRWN"""
__A											=		"""KOAEGVDHXPQZMLFTYWJNBRCIUS"""
def  __A   (_SCREAMING_SNAKE_CASE     ,   _SCREAMING_SNAKE_CASE     ,   _SCREAMING_SNAKE_CASE			)					->tuple[RotorPositionT, RotorSelectionT, dict[str, str]]:





  """simple docstring"""


  if (unique_rotsel := len(set(_SCREAMING_SNAKE_CASE			)			)) < 3:
    lowerCAmelCase__			:Union[str, Any]											=							F"Please use 3 unique rotors (not {unique_rotsel})"
    raise Exception(_SCREAMING_SNAKE_CASE			)

  # Checks if rotor positions are valid
  lowerCAmelCase__							,				lowerCAmelCase__							,				lowerCAmelCase__			:str											=							rotpos
  if not 0 < rotorposa <= len(_SCREAMING_SNAKE_CASE			):
    lowerCAmelCase__			:Tuple											=							F"First rotor position is not within range of 1..26 ({rotorposa}"
    raise ValueError(_SCREAMING_SNAKE_CASE			)
  if not 0 < rotorposa <= len(_SCREAMING_SNAKE_CASE			):
    lowerCAmelCase__			:Optional[Any]											=							F"Second rotor position is not within range of 1..26 ({rotorposa})"
    raise ValueError(_SCREAMING_SNAKE_CASE			)
  if not 0 < rotorposa <= len(_SCREAMING_SNAKE_CASE			):
    lowerCAmelCase__			:Union[str, Any]											=							F"Third rotor position is not within range of 1..26 ({rotorposa})"
    raise ValueError(_SCREAMING_SNAKE_CASE			)

  # Validates string and returns dict
  lowerCAmelCase__			:int											=							_plugboard(_SCREAMING_SNAKE_CASE			)

  return rotpos, rotsel, pbdict
def  __A   (_SCREAMING_SNAKE_CASE			)					->dict[str, str]:





  """simple docstring"""


  if not isinstance(_SCREAMING_SNAKE_CASE     ,   _SCREAMING_SNAKE_CASE			):
    lowerCAmelCase__			:str											=							F"Plugboard setting isn't type string ({type(_SCREAMING_SNAKE_CASE			)})"
    raise TypeError(_SCREAMING_SNAKE_CASE			)
  elif len(_SCREAMING_SNAKE_CASE			) % 2 != 0:
    lowerCAmelCase__			:str											=							F"Odd number of symbols ({len(_SCREAMING_SNAKE_CASE			)})"
    raise Exception(_SCREAMING_SNAKE_CASE			)
  elif pbstring == "":
    return {}

  pbstring.replace(' '     ,   ''			)

  # Checks if all characters are unique
  lowerCAmelCase__			:Any											=							set()
  for i in pbstring:
    if i not in abc:
      lowerCAmelCase__			:Any											=							F"'{i}' not in list of symbols"
      raise Exception(_SCREAMING_SNAKE_CASE			)
    elif i in tmppbl:
      lowerCAmelCase__			:Dict											=							F"Duplicate symbol ({i})"
      raise Exception(_SCREAMING_SNAKE_CASE			)
    else:
      tmppbl.add(_SCREAMING_SNAKE_CASE			)
  del tmppbl

  # Created the dictionary
  lowerCAmelCase__			:List[Any]											=							{}
  for j in range(0     ,   len(_SCREAMING_SNAKE_CASE			) - 1     ,   2			):
    lowerCAmelCase__			:Optional[int]											=							pbstring[j + 1]
    lowerCAmelCase__			:Union[str, Any]											=							pbstring[j]

  return pb
def  __A   (_SCREAMING_SNAKE_CASE     ,   _SCREAMING_SNAKE_CASE     ,   _SCREAMING_SNAKE_CASE = (rotora, rotora, rotora)     ,   _SCREAMING_SNAKE_CASE = ""     ,   )					->str:





  """simple docstring"""


  lowerCAmelCase__			:Tuple											=							text.upper()
  lowerCAmelCase__							,				lowerCAmelCase__							,				lowerCAmelCase__			:Tuple											=							_validator(
      _SCREAMING_SNAKE_CASE     ,   _SCREAMING_SNAKE_CASE     ,   plugb.upper()			)

  lowerCAmelCase__							,				lowerCAmelCase__							,				lowerCAmelCase__			:Tuple											=							rotor_position
  lowerCAmelCase__							,				lowerCAmelCase__							,				lowerCAmelCase__			:Union[str, Any]											=							rotor_selection
  rotorposa -= 1
  rotorposa -= 1
  rotorposa -= 1

  lowerCAmelCase__			:Dict											=							[]

  # encryption/decryption process --------------------------
  for symbol in text:
    if symbol in abc:
      # 1st plugboard --------------------------
      if symbol in plugboard:
        lowerCAmelCase__			:Dict											=							plugboard[symbol]

      # rotor ra --------------------------
      lowerCAmelCase__			:Optional[int]											=							abc.index(_SCREAMING_SNAKE_CASE			) + rotorposa
      lowerCAmelCase__			:str											=							rotora[index % len(_SCREAMING_SNAKE_CASE			)]

      # rotor rb --------------------------
      lowerCAmelCase__			:Optional[int]											=							abc.index(_SCREAMING_SNAKE_CASE			) + rotorposa
      lowerCAmelCase__			:int											=							rotora[index % len(_SCREAMING_SNAKE_CASE			)]

      # rotor rc --------------------------
      lowerCAmelCase__			:str											=							abc.index(_SCREAMING_SNAKE_CASE			) + rotorposa
      lowerCAmelCase__			:Optional[Any]											=							rotora[index % len(_SCREAMING_SNAKE_CASE			)]

      # reflector --------------------------
      # this is the reason you don't need another machine to decipher

      lowerCAmelCase__			:str											=							reflector[symbol]

      # 2nd rotors
      lowerCAmelCase__			:Tuple											=							abc[rotora.index(_SCREAMING_SNAKE_CASE			) - rotorposa]
      lowerCAmelCase__			:Optional[int]											=							abc[rotora.index(_SCREAMING_SNAKE_CASE			) - rotorposa]
      lowerCAmelCase__			:Any											=							abc[rotora.index(_SCREAMING_SNAKE_CASE			) - rotorposa]

      # 2nd plugboard
      if symbol in plugboard:
        lowerCAmelCase__			:Union[str, Any]											=							plugboard[symbol]

      # moves/resets rotor positions
      rotorposa += 1
      if rotorposa >= len(_SCREAMING_SNAKE_CASE			):
        lowerCAmelCase__			:str											=							0
        rotorposa += 1
      if rotorposa >= len(_SCREAMING_SNAKE_CASE			):
        lowerCAmelCase__			:List[Any]											=							0
        rotorposa += 1
      if rotorposa >= len(_SCREAMING_SNAKE_CASE			):
        lowerCAmelCase__			:Optional[Any]											=							0

        # else:
        #    pass
        #    Error could be also raised
        #    raise ValueError(
        #       'Invalid symbol('+repr(symbol)+')')
    result.append(_SCREAMING_SNAKE_CASE			)

  return "".join(_SCREAMING_SNAKE_CASE			)


if __name__ == "__main__":
  __A											=		"""This is my Python script that emulates the Enigma machine from WWII."""
  __A											=		(1, 1, 1)
  __A											=		"""pictures"""
  __A											=		(rotora, rotora, rotora)
  __A											=		enigma(message, rotor_pos, rotor_sel, pb)

  print("""Encrypted message:""", en)
  print("""Decrypted message:""", enigma(en, rotor_pos, rotor_sel, pb))
