




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_ 		=  1000

class 			_lowerCamelCase    :

      """simple docstring"""

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

          __UpperCamelCase		,   __UpperCamelCase			=    img.shape[1], img.shape[0]
          __UpperCamelCase			=    mplfigure.Figure(frameon=lowerCamelCase__					)
          __UpperCamelCase			=    fig.get_dpi()
          __UpperCamelCase			=    (width * scale + 1E-2) / dpi
          __UpperCamelCase			=    (height * scale + 1E-2) / dpi
          fig.set_size_inches(lowerCamelCase__			,							lowerCamelCase__					)
          __UpperCamelCase			=    fig.add_axes([0.0, 0.0, 1.0, 1.0]					)
          ax.axis('''off'''					)
          ax.set_xlim(0.0			,							lowerCamelCase__					)
          ax.set_ylim(lowerCamelCase__					)

          __UpperCamelCase			=    saveas
          __UpperCamelCase			=    rgb
          __UpperCamelCase			=    pynb
          __UpperCamelCase			=    img
          __UpperCamelCase			=    edgecolor
          __UpperCamelCase			=    0.5
          __UpperCamelCase			=    linestyle
          __UpperCamelCase			=    int(np.sqrt(min(lowerCamelCase__			,							lowerCamelCase__					)					) * scale // 3					)
          __UpperCamelCase			=    width
          __UpperCamelCase			=    height
          __UpperCamelCase			=    scale
          __UpperCamelCase			=    fig
          __UpperCamelCase			=    ax
          __UpperCamelCase			=    pad
          __UpperCamelCase			=    idaobj
          __UpperCamelCase			=    idaattr
          __UpperCamelCase			=    FigureCanvasAgg(lowerCamelCase__					)







      def    snake_case						(  self       :			Optional[int]			,							snake_case       :			Optional[Any]			,							snake_case       :			str=None					):
          if color is None:
              __UpperCamelCase			=    self.edgecolor
          ((__UpperCamelCase)		,   (__UpperCamelCase)		,   (__UpperCamelCase)		,   (__UpperCamelCase))			=    box
          __UpperCamelCase			=    xa - xa
          __UpperCamelCase			=    ya - ya
          self.ax.add_patch(
              mpl.patches.Rectangle(
                  (xa, ya)			,							lowerCamelCase__			,							lowerCamelCase__			,							fill=lowerCamelCase__			,							edgecolor=lowerCamelCase__			,							linewidth=self.font_size // 3			,							alpha=self.alpha			,							linestyle=self.linestyle			,							)					)







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

          __UpperCamelCase			=    [self._random_color(maximum=1					) for _ in range(len(lowerCamelCase__					)					)]
          __UpperCamelCase			=    [assigned_colors[idx] for idx in sorted_idxs]
          if obj_ids is not None:
              __UpperCamelCase			=    self._create_text_labels_attr(lowerCamelCase__			,							lowerCamelCase__			,							lowerCamelCase__			,							lowerCamelCase__					)
              for i in range(len(lowerCamelCase__					)					):
                  __UpperCamelCase			=    assigned_colors[i]
                  self.add_box(boxes[i]			,							lowerCamelCase__					)
                  self.draw_labels(labels[i]			,							boxes[i]			,							lowerCamelCase__					)







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

          __UpperCamelCase			=    (ya - ya) / np.sqrt(self.height * self.width					)
          __UpperCamelCase			=    self._change_color_brightness(lowerCamelCase__			,							brightness_factor=0.7					)
          __UpperCamelCase			=    np.clip((height_ratio - 0.02) / 0.08 + 1			,							1.2			,							2					)
          font_size *= 0.75 * self.font_size

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







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







      def    snake_case						(  self       :			List[Any]			,							snake_case       :			Optional[int]=None					):
          if saveas is None:
              __UpperCamelCase			=    self.saveas
          if saveas.lower().endswith('''.jpg'''					) or saveas.lower().endswith('''.png'''					):
              cva.imwrite(
                  lowerCamelCase__			,							self._get_buffer()[:, :, ::-1]			,							)
          else:
              self.fig.savefig(lowerCamelCase__					)







      def    snake_case						(  self       :			Tuple			,							snake_case       :			List[Any]			,							snake_case       :			List[Any]			,							snake_case       :			int			,							snake_case       :			Any					):
          __UpperCamelCase			=    [self.idaobj[i] for i in classes]
          __UpperCamelCase			=    [self.idaattr[i] for i in attr_classes]
          __UpperCamelCase			=    [
              F"{label} {score:.2f} {attr} {attr_score:.2f}"
              for label, score, attr, attr_score in zip(lowerCamelCase__			,							lowerCamelCase__			,							lowerCamelCase__			,							lowerCamelCase__					)
          ]
          return labels







      def    snake_case						(  self       :			Tuple			,							snake_case       :			List[Any]			,							snake_case       :			Dict					):
          __UpperCamelCase			=    [self.idaobj[i] for i in classes]
          if scores is not None:
              if labels is None:
                  __UpperCamelCase			=    ['''{:.0f}%'''.format(s * 100					) for s in scores]
              else:
                  __UpperCamelCase			=    ['''{} {:.0f}%'''.format(lowerCamelCase__			,							s * 100					) for li, s in zip(lowerCamelCase__			,							lowerCamelCase__					)]
          return labels







      def    snake_case						(  self       :			str			,							snake_case       :			Union[str, Any]=255					):
          __UpperCamelCase			=    np.random.randint(0			,							len(_COLORS					)					)
          __UpperCamelCase			=    _COLORS[idx] * maximum
          if not self.rgb:
              __UpperCamelCase			=    ret[::-1]
          return ret







      def    snake_case						(  self       :			Any					):
          if not self.pynb:
              __UpperCamelCase		,   __UpperCamelCase			=    self.canvas.print_to_buffer()
              if (width, height) != (self.width, self.height):
                  __UpperCamelCase			=    cva.resize(self.img			,							(width, height)					)
              else:
                  __UpperCamelCase			=    self.img
          else:
              __UpperCamelCase			=    io.BytesIO()  # works for cairo backend
              self.canvas.print_rgba(lowerCamelCase__					)
              __UpperCamelCase		,   __UpperCamelCase			=    self.width, self.height
              __UpperCamelCase			=    buf.getvalue()
              __UpperCamelCase			=    self.img

          __UpperCamelCase			=    np.frombuffer(lowerCamelCase__			,							dtype='''uint8'''					)
          __UpperCamelCase			=    buffer.reshape(lowerCamelCase__			,							lowerCamelCase__			,							4					)
          __UpperCamelCase		,   __UpperCamelCase			=    np.split(lowerCamelCase__			,							[3]			,							axis=2					)

          try:
              import numexpr as ne  # fuse them with numexpr

              __UpperCamelCase			=    ne.evaluate('''img * (1 - alpha / 255.0) + rgb * (alpha / 255.0)'''					)
          except ImportError:
              __UpperCamelCase			=    alpha.astype('''float32'''					) / 255.0
              __UpperCamelCase			=    img * (1 - alpha) + rgb * alpha

          return visualized_image.astype('''uint8'''					)







      def    snake_case						(  self       :			int			,							snake_case       :			Optional[int]			,							snake_case       :			List[Any]					):
          assert brightness_factor >= -1.0 and brightness_factor <= 1.0
          __UpperCamelCase			=    mplc.to_rgb(lowerCamelCase__					)
          __UpperCamelCase			=    colorsys.rgb_to_hls(*mplc.to_rgb(lowerCamelCase__					)					)
          __UpperCamelCase			=    polygon_color[1] + (brightness_factor * polygon_color[1])
          __UpperCamelCase			=    0.0 if modified_lightness < 0.0 else modified_lightness
          __UpperCamelCase			=    1.0 if modified_lightness > 1.0 else modified_lightness
          __UpperCamelCase			=    colorsys.hls_to_rgb(polygon_color[0]			,							lowerCamelCase__			,							polygon_color[2]					)
          return modified_color







a_ 		=  (
    np.array(
        [
            0.000,
            0.447,
            0.741,
            0.850,
            0.325,
            0.098,
            0.929,
            0.694,
            0.125,
            0.494,
            0.184,
            0.556,
            0.466,
            0.674,
            0.188,
            0.301,
            0.745,
            0.933,
            0.635,
            0.078,
            0.184,
            0.300,
            0.300,
            0.300,
            0.600,
            0.600,
            0.600,
            1.000,
            0.000,
            0.000,
            1.000,
            0.500,
            0.000,
            0.749,
            0.749,
            0.000,
            0.000,
            1.000,
            0.000,
            0.000,
            0.000,
            1.000,
            0.667,
            0.000,
            1.000,
            0.333,
            0.333,
            0.000,
            0.333,
            0.667,
            0.000,
            0.333,
            1.000,
            0.000,
            0.667,
            0.333,
            0.000,
            0.667,
            0.667,
            0.000,
            0.667,
            1.000,
            0.000,
            1.000,
            0.333,
            0.000,
            1.000,
            0.667,
            0.000,
            1.000,
            1.000,
            0.000,
            0.000,
            0.333,
            0.500,
            0.000,
            0.667,
            0.500,
            0.000,
            1.000,
            0.500,
            0.333,
            0.000,
            0.500,
            0.333,
            0.333,
            0.500,
            0.333,
            0.667,
            0.500,
            0.333,
            1.000,
            0.500,
            0.667,
            0.000,
            0.500,
            0.667,
            0.333,
            0.500,
            0.667,
            0.667,
            0.500,
            0.667,
            1.000,
            0.500,
            1.000,
            0.000,
            0.500,
            1.000,
            0.333,
            0.500,
            1.000,
            0.667,
            0.500,
            1.000,
            1.000,
            0.500,
            0.000,
            0.333,
            1.000,
            0.000,
            0.667,
            1.000,
            0.000,
            1.000,
            1.000,
            0.333,
            0.000,
            1.000,
            0.333,
            0.333,
            1.000,
            0.333,
            0.667,
            1.000,
            0.333,
            1.000,
            1.000,
            0.667,
            0.000,
            1.000,
            0.667,
            0.333,
            1.000,
            0.667,
            0.667,
            1.000,
            0.667,
            1.000,
            1.000,
            1.000,
            0.000,
            1.000,
            1.000,
            0.333,
            1.000,
            1.000,
            0.667,
            1.000,
            0.333,
            0.000,
            0.000,
            0.500,
            0.000,
            0.000,
            0.667,
            0.000,
            0.000,
            0.833,
            0.000,
            0.000,
            1.000,
            0.000,
            0.000,
            0.000,
            0.167,
            0.000,
            0.000,
            0.333,
            0.000,
            0.000,
            0.500,
            0.000,
            0.000,
            0.667,
            0.000,
            0.000,
            0.833,
            0.000,
            0.000,
            1.000,
            0.000,
            0.000,
            0.000,
            0.167,
            0.000,
            0.000,
            0.333,
            0.000,
            0.000,
            0.500,
            0.000,
            0.000,
            0.667,
            0.000,
            0.000,
            0.833,
            0.000,
            0.000,
            1.000,
            0.000,
            0.000,
            0.000,
            0.143,
            0.143,
            0.143,
            0.857,
            0.857,
            0.857,
            1.000,
            1.000,
            1.000,
        ]
    )
    .astype(np.floataa)
    .reshape(-1, 3)
)







"""simple docstring"""






from __future__ import annotations



def     a_		(   lowerCamelCase			):
				for r in range(1   ,     lowerCamelCase			):
								UpperCAmelCase__			 =				[]
								for x in range(n - 1			):
												UpperCAmelCase__			 =				pow(lowerCamelCase   ,     lowerCamelCase   ,     lowerCamelCase			)
												if val in li:
																break
												li.append(lowerCamelCase			)
								else:
												return r
				return None


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

												lowerCAmelCase__    :    Union[str, Any]			=      pow(b_public, a_private, q)
												lowerCAmelCase__    :    Tuple			=      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)



