



"""simple docstring"""




import numpy as np
def 					A_			(		snake_case_     :       Tuple						,snake_case_     :       Optional[int]="utf-8"						,snake_case_     :       Tuple="surrogatepass"    ):







    '''simple docstring'''
    UpperCamelCase				:   str          =							bin(int.from_bytes(text.encode(snake_case_						,snake_case_    )						,"""big"""    )    )[2:]
    return bits.zfill(8 * ((len(snake_case_    ) + 7) // 8)    )
def 					A_			(		snake_case_     :       Optional[Any]						,snake_case_     :       str="utf-8"						,snake_case_     :       Optional[int]="surrogatepass"    ):







    '''simple docstring'''
    UpperCamelCase				:   List[str]          =							int(snake_case_						,2    )
    return n.to_bytes((n.bit_length() + 7) // 8						,"""big"""    ).decode(snake_case_						,snake_case_    ) or "\0"
def 					A_			(		snake_case_     :       List[Any]						,snake_case_     :       Tuple    ):







    '''simple docstring'''







    if size_par + len(snake_case_    ) <= 2**size_par - (len(snake_case_    ) - 1):
        raise ValueError("""size of parity don\'t match with size of data"""    )

    UpperCamelCase				:   List[Any]          =							[]
    UpperCamelCase				:   List[Any]          =							[]
    UpperCamelCase				:   List[str]          =							[bin(snake_case_    )[2:] for x in range(1						,size_par + len(snake_case_    ) + 1    )]

    # sorted information data for the size of the output data
    UpperCamelCase				:   Optional[Any]          =							[]
    # data position template + parity
    UpperCamelCase				:   int          =							[]
    # parity bit counter
    UpperCamelCase				:   List[Any]          =							0
    # counter position of data bits
    UpperCamelCase				:   Union[str, Any]          =							0

    for x in range(1						,size_par + len(snake_case_    ) + 1    ):
        # Performs a template of bit positions - who should be given,
        # and who should be parity
        if qtd_bp < size_par:
            if (np.log(snake_case_    ) / np.log(2    )).is_integer():
                data_out_gab.append("""P"""    )
                UpperCamelCase				:   Dict          =							qtd_bp + 1
            else:
                data_out_gab.append("""D"""    )
        else:
            data_out_gab.append("""D"""    )

        # Sorts the data to the new output size
        if data_out_gab[-1] == "D":
            data_ord.append(data[cont_data]    )
            cont_data += 1
        else:
            data_ord.append(snake_case_    )

    # Calculates parity
    UpperCamelCase				:   Optional[Any]          =							0  # parity bit counter
    for bp in range(1						,size_par + 1    ):
        # Bit counter one for a given parity
        UpperCamelCase				:   List[str]          =							0
        # counter to control the loop reading
        UpperCamelCase				:   Any          =							0
        for x in data_ord:
            if x is not None:
                try:
                    UpperCamelCase				:   Dict          =							(bin_pos[cont_loop])[-1 * (bp)]
                except IndexError:
                    UpperCamelCase				:   List[str]          =							"""0"""
                if aux == "1" and x == "1":
                    cont_bo += 1
            cont_loop += 1
        parity.append(cont_bo % 2    )

        qtd_bp += 1

    # Mount the message
    UpperCamelCase				:   List[str]          =							0  # parity bit counter
    for x in range(0						,size_par + len(snake_case_    )    ):
        if data_ord[x] is None:
            data_out.append(str(parity[cont_bp]    )    )
            cont_bp += 1
        else:
            data_out.append(data_ord[x]    )

    return data_out


def 					A_			(		snake_case_     :       Any						,snake_case_     :       Any    ):







    '''simple docstring'''
    UpperCamelCase				:   Tuple          =							[]
    # Parity bit counter
    UpperCamelCase				:   List[str]          =							0
    # Counter p data bit reading
    UpperCamelCase				:   Dict          =							0
    # list of parity received
    UpperCamelCase				:   Dict          =							[]
    UpperCamelCase				:   Dict          =							[]

    for x in range(1						,len(snake_case_    ) + 1    ):
        # Performs a template of bit positions - who should be given,
        #  and who should be parity
        if qtd_bp < size_par and (np.log(snake_case_    ) / np.log(2    )).is_integer():
            data_out_gab.append("""P"""    )
            UpperCamelCase				:   List[Any]          =							qtd_bp + 1
        else:
            data_out_gab.append("""D"""    )

        # Sorts the data to the new output size
        if data_out_gab[-1] == "D":
            data_output.append(data[cont_data]    )
        else:
            parity_received.append(data[cont_data]    )
        cont_data += 1

    # -----------calculates the parity with the data
    UpperCamelCase				:   List[str]          =							[]
    UpperCamelCase				:   Union[str, Any]          =							[]
    UpperCamelCase				:   List[str]          =							[bin(snake_case_    )[2:] for x in range(1						,size_par + len(snake_case_    ) + 1    )]

    #  sorted information data for the size of the output data
    UpperCamelCase				:   Optional[Any]          =							[]
    # Data position feedback + parity
    UpperCamelCase				:   Tuple          =							[]
    # Parity bit counter
    UpperCamelCase				:   Optional[int]          =							0
    # Counter p data bit reading
    UpperCamelCase				:   Dict          =							0

    for x in range(1						,size_par + len(snake_case_    ) + 1    ):
        # Performs a template position of bits - who should be given,
        # and who should be parity
        if qtd_bp < size_par and (np.log(snake_case_    ) / np.log(2    )).is_integer():
            data_out_gab.append("""P"""    )
            UpperCamelCase				:   str          =							qtd_bp + 1
        else:
            data_out_gab.append("""D"""    )

        # Sorts the data to the new output size
        if data_out_gab[-1] == "D":
            data_ord.append(data_output[cont_data]    )
            cont_data += 1
        else:
            data_ord.append(snake_case_    )

    # Calculates parity
    UpperCamelCase				:   str          =							0  # parity bit counter
    for bp in range(1						,size_par + 1    ):
        # Bit counter one for a certain parity
        UpperCamelCase				:   Union[str, Any]          =							0
        # Counter to control loop reading
        UpperCamelCase				:   Dict          =							0
        for x in data_ord:
            if x is not None:
                try:
                    UpperCamelCase				:   int          =							(bin_pos[cont_loop])[-1 * (bp)]
                except IndexError:
                    UpperCamelCase				:   Tuple          =							"""0"""
                if aux == "1" and x == "1":
                    cont_bo += 1
            cont_loop += 1
        parity.append(str(cont_bo % 2    )    )

        qtd_bp += 1

    # Mount the message
    UpperCamelCase				:   Any          =							0  # Parity bit counter
    for x in range(0						,size_par + len(snake_case_    )    ):
        if data_ord[x] is None:
            data_out.append(str(parity[cont_bp]    )    )
            cont_bp += 1
        else:
            data_out.append(data_ord[x]    )

    UpperCamelCase				:   Tuple          =							parity_received == parity
    return data_output, ack










"""simple docstring"""




def 					A_			(		snake_case_     :       Tuple						,snake_case_     :       Optional[Any]						,snake_case_     :       Optional[Any]    ):







    '''simple docstring'''
    assert b != 0, "This cannot accept modulo that is == 0"
    if n == 0:
        return 1

    if n % 2 == 1:
        return (bin_exp_mod(snake_case_						,n - 1						,snake_case_    ) * a) % b

    UpperCamelCase				:   List[Any]          =							bin_exp_mod(snake_case_						,n / 2						,snake_case_    )
    return (r * r) % b


if __name__ == "__main__":
  try:
    __A :		Any      							=    int(input('''Enter Base : ''').strip())
    __A :		Any      							=    int(input('''Enter Power : ''').strip())
    __A :		List[Any]      							=    int(input('''Enter Modulo : ''').strip())
  except ValueError:
    print('''Invalid literal for integer''')

  print(bin_exp_mod(BASE, POWER, MODULO))




