
import torch
from torch import autograd






class     SCREAMING_SNAKE_CASE__      (							autograd.Function      ):

							"""simple docstring"""






							@staticmethod
							def       A__						(					SCREAMING_SNAKE_CASE_       ,		SCREAMING_SNAKE_CASE_       ,		SCREAMING_SNAKE_CASE_       ,		SCREAMING_SNAKE_CASE_     )->				Union[str, Any]:





													'''simple docstring'''






													__UpperCamelCase       					=     inputs.numel()
													__UpperCamelCase       					=     int(0.0_0_5 * nb_elems     ) + 1
													if sigmoid:
																			__UpperCamelCase       					=     (torch.sigmoid(SCREAMING_SNAKE_CASE_     ) > threshold).type(inputs.type()     )
													else:
																			__UpperCamelCase       					=     (inputs > threshold).type(inputs.type()     )
													if mask.sum() < nb_min:
																			# We limit the pruning so that at least 0.5% (half a percent) of the weights are remaining
																			__UpperCamelCase       					=     inputs.flatten().kthvalue(max(nb_elems - nb_min       ,		1     )     ).values
																			__UpperCamelCase       					=     (inputs > k_threshold).type(inputs.type()     )
													return mask



							@staticmethod
							def       A__						(					SCREAMING_SNAKE_CASE_       ,		SCREAMING_SNAKE_CASE_     )->				str:





													'''simple docstring'''






													return gradOutput, None, None






class     SCREAMING_SNAKE_CASE__      (							autograd.Function      ):

							"""simple docstring"""






							@staticmethod
							def       A__						(					SCREAMING_SNAKE_CASE_       ,		SCREAMING_SNAKE_CASE_       ,		SCREAMING_SNAKE_CASE_     )->				Optional[int]:





													'''simple docstring'''






													__UpperCamelCase       					=     inputs.clone()
													__UpperCamelCase					,							__UpperCamelCase       					=     inputs.flatten().sort(descending=SCREAMING_SNAKE_CASE_     )
													__UpperCamelCase       					=     int(threshold * inputs.numel()     )

													# flat_out and mask access the same memory.
													__UpperCamelCase       					=     mask.flatten()
													__UpperCamelCase       					=     0
													__UpperCamelCase       					=     1
													return mask



							@staticmethod
							def       A__						(					SCREAMING_SNAKE_CASE_       ,		SCREAMING_SNAKE_CASE_     )->				Any:





													'''simple docstring'''






													return gradOutput, None






class     SCREAMING_SNAKE_CASE__      (							SCREAMING_SNAKE_CASE_      ):

							"""simple docstring"""






							@staticmethod
							def       A__						(					SCREAMING_SNAKE_CASE_       ,		SCREAMING_SNAKE_CASE_     )->				Dict:





													'''simple docstring'''






													__UpperCamelCase       					=     inputs.clone()
													__UpperCamelCase					,							__UpperCamelCase       					=     inputs.abs().flatten().sort(descending=SCREAMING_SNAKE_CASE_     )
													__UpperCamelCase       					=     int(threshold * inputs.numel()     )

													# flat_out and mask access the same memory.
													__UpperCamelCase       					=     mask.flatten()
													__UpperCamelCase       					=     0
													__UpperCamelCase       					=     1
													return mask






def 		A_	(							snake_case							:				Union[str, Any]	, snake_case							:				Tuple	, snake_case							:				Optional[Any]	) ->      Union[str, 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       					=     bin_exp_mod(snake_case	, n / 2	, snake_case	)
						return (r * r) % b


if __name__ == "__main__":
				try:
								lowercase__							:							Dict													=     int(input("Enter Base : ").strip())
								lowercase__							:							Dict													=     int(input("Enter Power : ").strip())
								lowercase__							:							Dict													=     int(input("Enter Modulo : ").strip())
				except ValueError:
								print("Invalid literal for integer")

				print(bin_exp_mod(BASE, POWER, MODULO))




