from statistics import mean

import numpy as np






def 					snake_case    (			snake_case__     :List[Any]  ,      snake_case__     :Union[str, Any]  ,      snake_case__     :int  ,      snake_case__     :List[Any])		->  int:
       _A	  =    0
       # Number of processes finished
       _A	  =    0
       # Displays the finished process.
       # If it is 0, the performance is completed if it is 1, before the performance.
       _A	  =    [0] * no_of_process
       # List to include calculation results
       _A	  =    [0] * no_of_process

       # Sort by arrival time.
       _A	  =    [burst_time[i] for i in np.argsort(_snake_case)]
       _A	  =    [process_name[i] for i in np.argsort(_snake_case)]
       arrival_time.sort()

       while no_of_process > finished_process_count:
              _A	  =    0
              while finished_process[i] == 1:
                     i += 1
              if current_time < arrival_time[i]:
                     _A	  =    arrival_time[i]

              _A	  =    0
              # Index showing the location of the process being performed
              _A	  =    0
              # Saves the current response ratio.
              _A	  =    0
              for i in range(0  ,      _snake_case):
                     if finished_process[i] == 0 and arrival_time[i] <= current_time:
                            _A	  =    (burst_time[i] + (current_time - arrival_time[i])) / burst_time[
                                i
                            ]
                     if response_ratio < temp:
                            _A	  =    temp
                            _A	  =    i

        # Calculate the turn around time
              _A	  =    current_time + burst_time[loc] - arrival_time[loc]
              current_time += burst_time[loc]
              # Indicates that the process has been performed.
              _A	  =    1
              # Increase finished_process_count by 1
              finished_process_count += 1

       return turn_around_time






def 					snake_case    (			snake_case__     :Optional[int]  ,      snake_case__     :List[str]  ,      snake_case__     :Tuple  ,      snake_case__     :Union[str, Any])		->  Optional[int]:
       _A	  =    [0] * no_of_process
       for i in range(0  ,      _snake_case):
              _A	  =    turn_around_time[i] - burst_time[i]
       return waiting_time


if __name__ == "__main__":
    _SCREAMING_SNAKE_CASE     				=		5
    _SCREAMING_SNAKE_CASE     				=		['A', 'B', 'C', 'D', 'E']
    _SCREAMING_SNAKE_CASE     				=		[1, 2, 3, 4, 5]
    _SCREAMING_SNAKE_CASE     				=		[1, 2, 3, 4, 5]

    _SCREAMING_SNAKE_CASE     				=		calculate_turn_around_time(
        process_name, arrival_time, burst_time, no_of_process
    )
    _SCREAMING_SNAKE_CASE     				=		calculate_waiting_time(
        process_name, turn_around_time, burst_time, no_of_process
    )

    print('Process name \tArrival time \tBurst time \tTurn around time \tWaiting time')
    for i in range(0, no_of_process):
        print(
            F'''{process_name[i]}\t\t{arrival_time[i]}\t\t{burst_time[i]}\t\t'''
            F'''{turn_around_time[i]}\t\t\t{waiting_time[i]}'''
        )

    print(F'''average waiting time : {mean(waiting_time):.5f}''')
    print(F'''average turn around time : {mean(turn_around_time):.5f}''')






"""simple docstring"""



def 					lowerCamelCase   (     _snake_case    ,_snake_case ):
    UpperCAmelCase__	:      Optional[int]     							=					''
    for i in table:
        res += inp[i - 1]
    return res
def 					lowerCamelCase   (     _snake_case ):
    return data[1:] + data[0]
def 					lowerCamelCase   (     _snake_case    ,_snake_case ):
    UpperCAmelCase__	:      str     							=					''
    for i in range(len(_snake_case ) ):
        if a[i] == b[i]:
            res += "0"
        else:
            res += "1"
    return res
def 					lowerCamelCase   (     _snake_case    ,_snake_case ):
    UpperCAmelCase__	:      str     							=					int('0b' + data[0] + data[-1]    ,2 )
    UpperCAmelCase__	:      Optional[Any]     							=					int('0b' + data[1:3]    ,2 )
    return bin(s[row][col] )[2:]
def 					lowerCamelCase   (     _snake_case    ,_snake_case    ,_snake_case    ,_snake_case    ,_snake_case ):
    UpperCAmelCase__	:      Any     							=					message[:4]
    UpperCAmelCase__	:      Optional[Any]     							=					message[4:]
    UpperCAmelCase__	:      Dict     							=					apply_table(_snake_case    ,_snake_case )
    UpperCAmelCase__	:      Optional[Any]     							=					xor(_snake_case    ,_snake_case )
    UpperCAmelCase__	:      Dict     							=					apply_sbox(_snake_case    ,temp[:4] )  # noqa: E741
    UpperCAmelCase__	:      Tuple     							=					apply_sbox(_snake_case    ,temp[4:] )
    UpperCAmelCase__	:      List[str]     							=					'0' * (2 - len(_snake_case )) + l  # noqa: E741
    UpperCAmelCase__	:      Optional[Any]     							=					'0' * (2 - len(_snake_case )) + r
    UpperCAmelCase__	:      Optional[int]     							=					apply_table(l + r    ,_snake_case )
    UpperCAmelCase__	:      Any     							=					xor(_snake_case    ,_snake_case )
    return temp + right


if __name__ == "__main__":
    UpperCamelCase__          =	input('Enter 10 bit key: ')
    UpperCamelCase__          =	input('Enter 8 bit message: ')

    UpperCamelCase__          =	[6, 3, 7, 4, 8, 5, 10, 9]
    UpperCamelCase__          =	[3, 5, 2, 7, 4, 10, 1, 9, 8, 6]
    UpperCamelCase__          =	[2, 4, 3, 1]
    UpperCamelCase__          =	[2, 6, 3, 1, 4, 8, 5, 7]
    UpperCamelCase__          =	[4, 1, 3, 5, 7, 2, 8, 6]
    UpperCamelCase__          =	[4, 1, 2, 3, 2, 3, 4, 1]
    UpperCamelCase__          =	[[1, 0, 3, 2], [3, 2, 1, 0], [0, 2, 1, 3], [3, 1, 3, 2]]
    UpperCamelCase__          =	[[0, 1, 2, 3], [2, 0, 1, 3], [3, 0, 1, 0], [2, 1, 0, 3]]

    # key generation
    UpperCamelCase__          =	apply_table(key, paa_table)
    UpperCamelCase__          =	temp[:5]
    UpperCamelCase__          =	temp[5:]
    UpperCamelCase__          =	left_shift(left)
    UpperCamelCase__          =	left_shift(right)
    UpperCamelCase__          =	apply_table(left + right, pa_table)
    UpperCamelCase__          =	left_shift(left)
    UpperCamelCase__          =	left_shift(right)
    UpperCamelCase__          =	left_shift(left)
    UpperCamelCase__          =	left_shift(right)
    UpperCamelCase__          =	apply_table(left + right, pa_table)

    # encryption
    UpperCamelCase__          =	apply_table(message, IP)
    UpperCamelCase__          =	function(expansion, sa, sa, keya, temp)
    UpperCamelCase__          =	temp[4:] + temp[:4]
    UpperCamelCase__          =	function(expansion, sa, sa, keya, temp)
    UpperCamelCase__          =	apply_table(temp, IP_inv)
    print('Cipher text is:', CT)

    # decryption
    UpperCamelCase__          =	apply_table(CT, IP)
    UpperCamelCase__          =	function(expansion, sa, sa, keya, temp)
    UpperCamelCase__          =	temp[4:] + temp[:4]
    UpperCamelCase__          =	function(expansion, sa, sa, keya, temp)
    UpperCamelCase__          =	apply_table(temp, IP_inv)
    print('Plain text after decypting is:', PT)

