
'''simple docstring'''
from collections.abc import Generator
from math import sin

def 						UpperCamelCase_     (	__SCREAMING_SNAKE_CASE       ):
				"""simple docstring"""






				if len(__UpperCAmelCase       ) != 3_2:
								raise ValueError("Input must be of length 32"       )

				snake_case_ :    List[Any]     			=						b""
				for i in [3, 2, 1, 0]:
								little_endian += string_aa[8 * i : 8 * i + 8]
				return little_endian

def 						UpperCamelCase_     (	__SCREAMING_SNAKE_CASE       ):
				"""simple docstring"""






				if i < 0:
								raise ValueError("Input must be non-negative"       )

				snake_case_ :    Any     			=						format(__UpperCAmelCase,		"08x"       )[-8:]
				snake_case_ :    List[str]     			=						b""
				for i in [3, 2, 1, 0]:
								little_endian_hex += hex_rep[2 * i : 2 * i + 2].encode("utf-8"       )
				return little_endian_hex

def 						UpperCamelCase_     (	__SCREAMING_SNAKE_CASE       ):
				"""simple docstring"""






				snake_case_ :    int     			=						b""
				for char in message:
								bit_string += format(__UpperCAmelCase,		"08b"       ).encode("utf-8"       )
				snake_case_ :    Optional[int]     			=						format(len(__UpperCAmelCase       ),		"064b"       ).encode("utf-8"       )

				# Pad bit_string to a multiple of 512 chars
				bit_string += b"1"
				while len(__UpperCAmelCase       ) % 5_1_2 != 4_4_8:
								bit_string += b"0"
				bit_string += to_little_endian(start_len[3_2:]       ) + to_little_endian(start_len[:3_2]       )

				return bit_string

def 						UpperCamelCase_     (	__SCREAMING_SNAKE_CASE       ):
				"""simple docstring"""






				if len(__UpperCAmelCase       ) % 5_1_2 != 0:
								raise ValueError("Input must have length that's a multiple of 512"       )

				for pos in range(0,		len(__UpperCAmelCase       ),		5_1_2       ):
								snake_case_ :    Union[str, Any]     			=						bit_string[pos : pos + 5_1_2]
								snake_case_ :    Dict     			=						[]
								for i in range(0,		5_1_2,		3_2       ):
												block_words.append(int(to_little_endian(block[i : i + 3_2]       ),		2       )       )
								yield block_words

def 						UpperCamelCase_     (	__SCREAMING_SNAKE_CASE       ):
				"""simple docstring"""






				if i < 0:
								raise ValueError("Input must be non-negative"       )

				snake_case_ :    List[Any]     			=						format(__UpperCAmelCase,		"032b"       )
				snake_case_ :    int     			=						""
				for c in i_str:
								new_str += "1" if c == "0" else "0"
				return int(__UpperCAmelCase,		2       )

def 						UpperCamelCase_     (	__SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE       ):
				"""simple docstring"""






				return (a + b) % 2**3_2

def 						UpperCamelCase_     (	__SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE       ):
				"""simple docstring"""






				if i < 0:
								raise ValueError("Input must be non-negative"       )
				if shift < 0:
								raise ValueError("Shift must be non-negative"       )
				return ((i << shift) ^ (i >> (3_2 - shift))) % 2**3_2

def 						UpperCamelCase_     (	__SCREAMING_SNAKE_CASE       ):
				"""simple docstring"""






				snake_case_ :    Dict     			=						preprocess(__UpperCAmelCase       )

				snake_case_ :    Union[str, Any]     			=						[int(2**3_2 * abs(sin(i + 1       )       )       ) for i in range(6_4       )]

				# Starting states
				snake_case_ :    Dict     			=						0x67_452_301
				snake_case_ :    Union[str, Any]     			=						0xef_cda_b89
				snake_case_ :    Any     			=						0x98_bad_cfe
				snake_case_ :    Optional[Any]     			=						0x10_325_476

				snake_case_ :    Tuple     			=						[
				    7,
				    1_2,
				    1_7,
				    2_2,
				    7,
				    1_2,
				    1_7,
				    2_2,
				    7,
				    1_2,
				    1_7,
				    2_2,
				    7,
				    1_2,
				    1_7,
				    2_2,
				    5,
				    9,
				    1_4,
				    2_0,
				    5,
				    9,
				    1_4,
				    2_0,
				    5,
				    9,
				    1_4,
				    2_0,
				    5,
				    9,
				    1_4,
				    2_0,
				    4,
				    1_1,
				    1_6,
				    2_3,
				    4,
				    1_1,
				    1_6,
				    2_3,
				    4,
				    1_1,
				    1_6,
				    2_3,
				    4,
				    1_1,
				    1_6,
				    2_3,
				    6,
				    1_0,
				    1_5,
				    2_1,
				    6,
				    1_0,
				    1_5,
				    2_1,
				    6,
				    1_0,
				    1_5,
				    2_1,
				    6,
				    1_0,
				    1_5,
				    2_1,
				]

				# Process bit string in chunks, each with 16 32-char words
				for block_words in get_block_words(__UpperCAmelCase       ):
								snake_case_ :    List[Any]     			=						aa
								snake_case_ :    List[Any]     			=						ba
								snake_case_ :    List[str]     			=						ca
								snake_case_ :    int     			=						da

								# Hash current chunk
								for i in range(6_4       ):
												if i <= 1_5:
																# f = (b & c) | (not_32(b) & d)     # Alternate definition for f
																snake_case_ :    List[Any]     			=						d ^ (b & (c ^ d))
																snake_case_ :    Any     			=						i
												elif i <= 3_1:
																# f = (d & b) | (not_32(d) & c)     # Alternate definition for f
																snake_case_ :    List[str]     			=						c ^ (d & (b ^ c))
																snake_case_ :    Optional[int]     			=						(5 * i + 1) % 1_6
												elif i <= 4_7:
																snake_case_ :    List[Any]     			=						b ^ c ^ d
																snake_case_ :    Union[str, Any]     			=						(3 * i + 5) % 1_6
												else:
																snake_case_ :    Optional[int]     			=						c ^ (b | not_aa(__UpperCAmelCase       ))
																snake_case_ :    int     			=						(7 * i) % 1_6
												snake_case_ :    List[Any]     			=						(f + a + added_consts[i] + block_words[g]) % 2**3_2
												snake_case_ :    int     			=						d
												snake_case_ :    Union[str, Any]     			=						c
												snake_case_ :    Dict     			=						b
												snake_case_ :    Optional[int]     			=						sum_aa(__UpperCAmelCase,		left_rotate_aa(__UpperCAmelCase,		shift_amounts[i]       )       )

								# Add hashed chunk to running total
								snake_case_ :    Optional[int]     			=						sum_aa(__UpperCAmelCase,		__UpperCAmelCase       )
								snake_case_ :    Tuple     			=						sum_aa(__UpperCAmelCase,		__UpperCAmelCase       )
								snake_case_ :    Tuple     			=						sum_aa(__UpperCAmelCase,		__UpperCAmelCase       )
								snake_case_ :    List[Any]     			=						sum_aa(__UpperCAmelCase,		__UpperCAmelCase       )

				snake_case_ :    List[Any]     			=						reformat_hex(__UpperCAmelCase       ) + reformat_hex(__UpperCAmelCase       ) + reformat_hex(__UpperCAmelCase       ) + reformat_hex(__UpperCAmelCase       )
				return digest


if __name__ == "__main__":
		import doctest

		doctest.testmod()






'''simple docstring'''
from __future__ import annotations

from statistics import mean

def 						UpperCamelCase_     (	__SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE       ):
    """simple docstring"""






    snake_case_ :    Any     			=						[0] * no_of_processes
    snake_case_ :    Optional[int]     			=						[0] * no_of_processes

    # Initialize remaining_time to waiting_time.

    for i in range(__SCREAMING_SNAKE_CASE       ):
        snake_case_ :    str     			=						burst_time[i]
    snake_case_ :    list[int]     			=						[]

    snake_case_ :    Tuple     			=						0
    snake_case_ :    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:
        snake_case_ :    Any     			=						[]
        snake_case_ :    Dict     			=						-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:
            snake_case_ :    Dict     			=						ready_process[0]
            for i in ready_process:
                if remaining_time[i] < remaining_time[target_process]:
                    snake_case_ :    Optional[int]     			=						i
            total_time += burst_time[target_process]
            completed += 1
            snake_case_ :    Tuple     			=						0
            snake_case_ :    int     			=						(
                total_time - arrival_time[target_process] - burst_time[target_process]
            )
        else:
            total_time += 1

    return waiting_time

def 						UpperCamelCase_     (	__SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE       ):
    """simple docstring"""






    snake_case_ :    Optional[int]     			=						[0] * no_of_processes
    for i in range(__SCREAMING_SNAKE_CASE       ):
        snake_case_ :    Dict     			=						burst_time[i] + waiting_time[i]
    return turn_around_time


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

  a_											=						4
  a_											=						[2, 5, 3, 7]
  a_											=						[0, 0, 0, 0]
  a_											=						calculate_waitingtime(arrival_time, burst_time, no_of_processes)
  a_											=						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}""")




