"""simple docstring"""







import colorsys
import io

import cva
import matplotlib as mpl
import matplotlib.colors as mplc
import matplotlib.figure as mplfigure
import numpy as np
import torch
from matplotlib.backends.backend_agg import FigureCanvasAgg

from utils import img_tensorize


_a	:	int=					1_000

class 						UpperCamelCase     :



				def __init__(self							: List[Any]      ,    _A							: Dict      ,    _A							: Optional[int]=1.2      ,    _A							: str="g"      ,    _A							: List[str]=0.5      ,    _A							: Any="-"      ,    _A							: Dict="test_out.jpg"      ,    _A							: List[Any]=True      ,    _A							: Optional[Any]=False      ,    _A							: Tuple=None      ,    _A							: List[str]=None      ,    _A							: Union[str, Any]=0.7      ,    )       ->      Any:
					if isinstance(_A      ,    torch.Tensor):
						__snake_case     :				Tuple 						=					img.numpy().astype('np.uint8')
					if isinstance(_A      ,    _A):
						__snake_case     :				Tuple 						=					img_tensorize(_A)
					assert isinstance(_A      ,    np.ndarray)

					__snake_case     :				Dict 						=					img.shape[1], img.shape[0]
					__snake_case     :				Dict 						=					mplfigure.Figure(frameon=_A)
					__snake_case     :				str 						=					fig.get_dpi()
					__snake_case     :				str 						=					(width * scale + 1E-2) / dpi
					__snake_case     :				Union[str, Any] 						=					(height * scale + 1E-2) / dpi
					fig.set_size_inches(_A      ,    _A)
					__snake_case     :				List[Any] 						=					fig.add_axes([0.0, 0.0, 1.0, 1.0])
					ax.axis('off')
					ax.set_xlim(0.0      ,    _A)
					ax.set_ylim(_A)

					__snake_case     :				List[Any] 						=					saveas
					__snake_case     :				Optional[Any] 						=					rgb
					__snake_case     :				Dict 						=					pynb
					__snake_case     :				Tuple 						=					img
					__snake_case     :				str 						=					edgecolor
					__snake_case     :				int 						=					0.5
					__snake_case     :				Dict 						=					linestyle
					__snake_case     :				Optional[int] 						=					int(np.sqrt(min(_A      ,    _A)) * scale // 3)
					__snake_case     :				Optional[Any] 						=					width
					__snake_case     :				List[Any] 						=					height
					__snake_case     :				List[str] 						=					scale
					__snake_case     :				Optional[int] 						=					fig
					__snake_case     :				List[str] 						=					ax
					__snake_case     :				List[str] 						=					pad
					__snake_case     :				Any 						=					idaobj
					__snake_case     :				List[Any] 						=					idaattr
					__snake_case     :				Tuple 						=					FigureCanvasAgg(_A)



				def    _lowercase	(self							: str      ,    _A							: Union[str, Any]      ,    _A							: Tuple=None)       ->      List[Any]:
					if color is None:
						__snake_case     :				str 						=					self.edgecolor
					(__snake_case)     :				Optional[Any] 						=					box
					__snake_case     :				Optional[int] 						=					xa - xa
					__snake_case     :				Union[str, Any] 						=					ya - ya
					self.ax.add_patch(
					    mpl.patches.Rectangle(
					        (xa, ya)      ,    _A      ,    _A      ,    fill=_A      ,    edgecolor=_A      ,    linewidth=self.font_size // 3      ,    alpha=self.alpha      ,    linestyle=self.linestyle      ,    ))



				def    _lowercase	(self							: str      ,    _A							: List[Any]      ,    _A							: Any=None      ,    _A							: Union[str, Any]=None      ,    _A							: Optional[int]=None      ,    _A							: Optional[int]=None)       ->      Optional[int]:
					if len(boxes.shape) > 2:
						__snake_case     :				Optional[Any] 						=					boxes[0]
					if len(obj_ids.shape) > 1:
						__snake_case     :				Tuple 						=					obj_ids[0]
					if len(obj_scores.shape) > 1:
						__snake_case     :				List[str] 						=					obj_scores[0]
					if len(attr_ids.shape) > 1:
						__snake_case     :				Optional[Any] 						=					attr_ids[0]
					if len(attr_scores.shape) > 1:
						__snake_case     :				List[str] 						=					attr_scores[0]
					if isinstance(_A      ,    torch.Tensor):
						__snake_case     :				Tuple 						=					boxes.numpy()
					if isinstance(_A      ,    _A):
						__snake_case     :				str 						=					np.array(_A)
					assert isinstance(_A      ,    np.ndarray)
					__snake_case     :				str 						=					np.prod(boxes[:, 2:] - boxes[:, :2]      ,    axis=1)
					__snake_case     :				Union[str, Any] 						=					np.argsort(-areas).tolist()
					__snake_case     :				Dict 						=					boxes[sorted_idxs] if boxes is not None else None
					__snake_case     :				List[Any] 						=					obj_ids[sorted_idxs] if obj_ids is not None else None
					__snake_case     :				Dict 						=					obj_scores[sorted_idxs] if obj_scores is not None else None
					__snake_case     :				Optional[int] 						=					attr_ids[sorted_idxs] if attr_ids is not None else None
					__snake_case     :				Dict 						=					attr_scores[sorted_idxs] if attr_scores is not None else None

					__snake_case     :				Union[str, Any] 						=					[self._random_color(maximum=1) for _ in range(len(_A))]
					__snake_case     :				int 						=					[assigned_colors[idx] for idx in sorted_idxs]
					if obj_ids is not None:
						__snake_case     :				Tuple 						=					self._create_text_labels_attr(_A      ,    _A      ,    _A      ,    _A)
						for i in range(len(_A)):
							__snake_case     :				str 						=					assigned_colors[i]
							self.add_box(boxes[i]      ,    _A)
							self.draw_labels(labels[i]      ,    boxes[i]      ,    _A)



				def    _lowercase	(self							: Dict      ,    _A							: Optional[int]      ,    _A							: Optional[int]      ,    _A							: List[Any])       ->      Dict:
					__snake_case     :				List[str] 						=					box
					__snake_case     :				Tuple 						=					(xa, ya)
					__snake_case     :				Union[str, Any] 						=					(ya - ya) * (xa - xa)
					__snake_case     :				Optional[Any] 						=					_SMALL_OBJ * self.scale
					if instance_area < small or ya - ya < 40 * self.scale:
						if ya >= self.height - 5:
							__snake_case     :				str 						=					(xa, ya)
						else:
							__snake_case     :				Optional[Any] 						=					(xa, ya)

					__snake_case     :				int 						=					(ya - ya) / np.sqrt(self.height * self.width)
					__snake_case     :				str 						=					self._change_color_brightness(_A      ,    brightness_factor=0.7)
					__snake_case     :				str 						=					np.clip((height_ratio - 0.02) / 0.08 + 1      ,    1.2      ,    2)
					font_size *= 0.75 * self.font_size

					self.draw_text(
					    text=_A      ,    position=_A      ,    color=_A      ,    )



				def    _lowercase	(self							: Any      ,    _A							: Any      ,    _A							: Union[str, Any]      ,    _A							: Optional[Any]="g"      ,    _A							: Dict="left"      ,    )       ->      Dict:
					__snake_case     :				Union[str, Any] 						=					0
					__snake_case     :				Optional[int] 						=					self.font_size
					__snake_case     :				str 						=					np.maximum(list(mplc.to_rgb(_A))      ,    0.2)
					__snake_case     :				Optional[int] 						=					max(0.8      ,    np.max(_A))
					__snake_case     :				Dict 						=					{
					    """facecolor""": """black""",
					    """alpha""": self.alpha,
					    """pad""": self.pad,
					    """edgecolor""": """none""",
					}
					__snake_case     :				Dict 						=					position
					self.ax.text(
					    _A      ,    _A      ,    _A      ,    size=font_size * self.scale      ,    family='sans-serif'      ,    bbox=_A      ,    verticalalignment='top'      ,    horizontalalignment=_A      ,    color=_A      ,    zorder=10      ,    rotation=_A      ,    )



				def    _lowercase	(self							: Union[str, Any]      ,    _A							: Union[str, Any]=None)       ->      Tuple:
					if saveas is None:
						__snake_case     :				Optional[int] 						=					self.saveas
					if saveas.lower().endswith('.jpg') or saveas.lower().endswith('.png'):
						cva.imwrite(
						    _A      ,    self._get_buffer()[:, :, ::-1]      ,    )
					else:
						self.fig.savefig(_A)



				def    _lowercase	(self							: List[Any]      ,    _A							: str      ,    _A							: List[str]      ,    _A							: str      ,    _A							: str)       ->      Any:
					__snake_case     :				List[Any] 						=					[self.idaobj[i] for i in classes]
					__snake_case     :				int 						=					[self.idaattr[i] for i in attr_classes]
					__snake_case     :				List[str] 						=					[
					    f"{label} {score:.2f} {attr} {attr_score:.2f}"
					    for label, score, attr, attr_score in zip(_A      ,    _A      ,    _A      ,    _A)
					]
					return labels



				def    _lowercase	(self							: Optional[Any]      ,    _A							: List[Any]      ,    _A							: List[Any])       ->      Optional[int]:
					__snake_case     :				Any 						=					[self.idaobj[i] for i in classes]
					if scores is not None:
						if labels is None:
							__snake_case     :				Dict 						=					["""{:.0f}%""".format(s * 1_00) for s in scores]
						else:
							__snake_case     :				int 						=					["""{} {:.0f}%""".format(_A      ,    s * 1_00) for li, s in zip(_A      ,    _A)]
					return labels



				def    _lowercase	(self							: List[Any]      ,    _A							: Tuple=2_55)       ->      Optional[int]:
					__snake_case     :				Any 						=					np.random.randint(0      ,    len(_COLORS))
					__snake_case     :				Union[str, Any] 						=					_COLORS[idx] * maximum
					if not self.rgb:
						__snake_case     :				Any 						=					ret[::-1]
					return ret



				def    _lowercase	(self							: Dict)       ->      Tuple:
					if not self.pynb:
						__snake_case     :				Dict 						=					self.canvas.print_to_buffer()
						if (width, height) != (self.width, self.height):
							__snake_case     :				Tuple 						=					cva.resize(self.img      ,    (width, height))
						else:
							__snake_case     :				Dict 						=					self.img
					else:
						__snake_case     :				str 						=					io.BytesIO()  # works for cairo backend
						self.canvas.print_rgba(_A)
						__snake_case     :				Union[str, Any] 						=					self.width, self.height
						__snake_case     :				List[Any] 						=					buf.getvalue()
						__snake_case     :				Tuple 						=					self.img

					__snake_case     :				int 						=					np.frombuffer(_A      ,    dtype='uint8')
					__snake_case     :				Tuple 						=					buffer.reshape(_A      ,    _A      ,    4)
					__snake_case     :				Dict 						=					np.split(_A      ,    [3]      ,    axis=2)

					try:
						import numexpr as ne  # fuse them with numexpr

						__snake_case     :				Dict 						=					ne.evaluate('img * (1 - alpha / 255.0) + rgb * (alpha / 255.0)')
					except ImportError:
						__snake_case     :				Optional[Any] 						=					alpha.astype('float32') / 2_55.0
						__snake_case     :				List[str] 						=					img * (1 - alpha) + rgb * alpha

					return visualized_image.astype('uint8')






				def    _lowercase	(self							: int      ,    _A							: Dict      ,    _A							: Any)       ->      List[str]:
					assert brightness_factor >= -1.0 and brightness_factor <= 1.0
					__snake_case     :				Union[str, Any] 						=					mplc.to_rgb(_A)
					__snake_case     :				Tuple 						=					colorsys.rgb_to_hls(*mplc.to_rgb(_A))
					__snake_case     :				Optional[int] 						=					polygon_color[1] + (brightness_factor * polygon_color[1])
					__snake_case     :				Tuple 						=					0.0 if modified_lightness < 0.0 else modified_lightness
					__snake_case     :				Tuple 						=					1.0 if modified_lightness > 1.0 else modified_lightness
					__snake_case     :				Dict 						=					colorsys.hls_to_rgb(polygon_color[0]      ,    _A      ,    polygon_color[2])
					return modified_color







_a	:	Optional[Any]=					(
    np.array(
        [
            0.0_0_0,
            0.4_4_7,
            0.7_4_1,
            0.8_5_0,
            0.3_2_5,
            0.0_9_8,
            0.9_2_9,
            0.6_9_4,
            0.1_2_5,
            0.4_9_4,
            0.1_8_4,
            0.5_5_6,
            0.4_6_6,
            0.6_7_4,
            0.1_8_8,
            0.3_0_1,
            0.7_4_5,
            0.9_3_3,
            0.6_3_5,
            0.0_7_8,
            0.1_8_4,
            0.3_0_0,
            0.3_0_0,
            0.3_0_0,
            0.6_0_0,
            0.6_0_0,
            0.6_0_0,
            1.0_0_0,
            0.0_0_0,
            0.0_0_0,
            1.0_0_0,
            0.5_0_0,
            0.0_0_0,
            0.7_4_9,
            0.7_4_9,
            0.0_0_0,
            0.0_0_0,
            1.0_0_0,
            0.0_0_0,
            0.0_0_0,
            0.0_0_0,
            1.0_0_0,
            0.6_6_7,
            0.0_0_0,
            1.0_0_0,
            0.3_3_3,
            0.3_3_3,
            0.0_0_0,
            0.3_3_3,
            0.6_6_7,
            0.0_0_0,
            0.3_3_3,
            1.0_0_0,
            0.0_0_0,
            0.6_6_7,
            0.3_3_3,
            0.0_0_0,
            0.6_6_7,
            0.6_6_7,
            0.0_0_0,
            0.6_6_7,
            1.0_0_0,
            0.0_0_0,
            1.0_0_0,
            0.3_3_3,
            0.0_0_0,
            1.0_0_0,
            0.6_6_7,
            0.0_0_0,
            1.0_0_0,
            1.0_0_0,
            0.0_0_0,
            0.0_0_0,
            0.3_3_3,
            0.5_0_0,
            0.0_0_0,
            0.6_6_7,
            0.5_0_0,
            0.0_0_0,
            1.0_0_0,
            0.5_0_0,
            0.3_3_3,
            0.0_0_0,
            0.5_0_0,
            0.3_3_3,
            0.3_3_3,
            0.5_0_0,
            0.3_3_3,
            0.6_6_7,
            0.5_0_0,
            0.3_3_3,
            1.0_0_0,
            0.5_0_0,
            0.6_6_7,
            0.0_0_0,
            0.5_0_0,
            0.6_6_7,
            0.3_3_3,
            0.5_0_0,
            0.6_6_7,
            0.6_6_7,
            0.5_0_0,
            0.6_6_7,
            1.0_0_0,
            0.5_0_0,
            1.0_0_0,
            0.0_0_0,
            0.5_0_0,
            1.0_0_0,
            0.3_3_3,
            0.5_0_0,
            1.0_0_0,
            0.6_6_7,
            0.5_0_0,
            1.0_0_0,
            1.0_0_0,
            0.5_0_0,
            0.0_0_0,
            0.3_3_3,
            1.0_0_0,
            0.0_0_0,
            0.6_6_7,
            1.0_0_0,
            0.0_0_0,
            1.0_0_0,
            1.0_0_0,
            0.3_3_3,
            0.0_0_0,
            1.0_0_0,
            0.3_3_3,
            0.3_3_3,
            1.0_0_0,
            0.3_3_3,
            0.6_6_7,
            1.0_0_0,
            0.3_3_3,
            1.0_0_0,
            1.0_0_0,
            0.6_6_7,
            0.0_0_0,
            1.0_0_0,
            0.6_6_7,
            0.3_3_3,
            1.0_0_0,
            0.6_6_7,
            0.6_6_7,
            1.0_0_0,
            0.6_6_7,
            1.0_0_0,
            1.0_0_0,
            1.0_0_0,
            0.0_0_0,
            1.0_0_0,
            1.0_0_0,
            0.3_3_3,
            1.0_0_0,
            1.0_0_0,
            0.6_6_7,
            1.0_0_0,
            0.3_3_3,
            0.0_0_0,
            0.0_0_0,
            0.5_0_0,
            0.0_0_0,
            0.0_0_0,
            0.6_6_7,
            0.0_0_0,
            0.0_0_0,
            0.8_3_3,
            0.0_0_0,
            0.0_0_0,
            1.0_0_0,
            0.0_0_0,
            0.0_0_0,
            0.0_0_0,
            0.1_6_7,
            0.0_0_0,
            0.0_0_0,
            0.3_3_3,
            0.0_0_0,
            0.0_0_0,
            0.5_0_0,
            0.0_0_0,
            0.0_0_0,
            0.6_6_7,
            0.0_0_0,
            0.0_0_0,
            0.8_3_3,
            0.0_0_0,
            0.0_0_0,
            1.0_0_0,
            0.0_0_0,
            0.0_0_0,
            0.0_0_0,
            0.1_6_7,
            0.0_0_0,
            0.0_0_0,
            0.3_3_3,
            0.0_0_0,
            0.0_0_0,
            0.5_0_0,
            0.0_0_0,
            0.0_0_0,
            0.6_6_7,
            0.0_0_0,
            0.0_0_0,
            0.8_3_3,
            0.0_0_0,
            0.0_0_0,
            1.0_0_0,
            0.0_0_0,
            0.0_0_0,
            0.0_0_0,
            0.1_4_3,
            0.1_4_3,
            0.1_4_3,
            0.8_5_7,
            0.8_5_7,
            0.8_5_7,
            1.0_0_0,
            1.0_0_0,
            1.0_0_0,
        ]
    )
    .astype(np.floataa)
    .reshape(-1, 3)
)










'''simple docstring'''




from __future__ import annotations



def  __lowerCamelCase    (   _lowercase						) ->     int | None:
							for r in range(1      ,							_lowercase						):
														UpperCAmelCase	:						Dict					=						[]
														for x in range(n - 1						):
																					UpperCAmelCase	:						List[str]					=						pow(_lowercase      ,							_lowercase      ,							_lowercase						)
																					if val in li:
																												break
																					li.append(_lowercase						)
														else:
																					return r
							return None


if __name__ == "__main__":
							a  :     Dict       =       int(input("""Enter a prime number q: """))
							a  :     Union[str, Any]       =       find_primitive(q)
							if a is None:
														print(F'''Cannot find the primitive for the value: {a!r}''')
							else:
														a  :     str       =       int(input("""Enter private key of A: """))
														a  :     str       =       pow(a, a_private, q)
														a  :     List[Any]       =       int(input("""Enter private key of B: """))
														a  :     str       =       pow(a, b_private, q)

														a  :     Union[str, Any]       =       pow(b_public, a_private, q)
														a  :     List[Any]       =       pow(a_public, b_private, q)

														print("""The key value generated by A is: """, a_secret)
														print("""The key value generated by B is: """, b_secret)

