





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


__UpperCAmelCase				=      10_00

class 		__a							:



       def __init__(     self	:   Union[str, Any]					,			UpperCAmelCase	:   Optional[int]					,			UpperCAmelCase	:   Any=1.2					,			UpperCAmelCase	:   Any="g"					,			UpperCAmelCase	:   Optional[Any]=0.5					,			UpperCAmelCase	:   List[str]="-"					,			UpperCAmelCase	:   List[Any]="test_out.jpg"					,			UpperCAmelCase	:   Union[str, Any]=True					,			UpperCAmelCase	:   str=False					,			UpperCAmelCase	:   Dict=None					,			UpperCAmelCase	:   List[str]=None					,			UpperCAmelCase	:   Optional[int]=0.7					,			):






           if isinstance(UpperCAmelCase					,			torch.Tensor			):
               lowerCAmelCase_					:	Union[str, Any]						=   img.numpy().astype("""np.uint8"""			)
           if isinstance(UpperCAmelCase					,			UpperCAmelCase			):
               lowerCAmelCase_					:	List[str]						=   img_tensorize(UpperCAmelCase			)
           assert isinstance(UpperCAmelCase					,			np.ndarray			)

           lowerCAmelCase_		,		lowerCAmelCase_					:	str						=   img.shape[1], img.shape[0]
           lowerCAmelCase_					:	Optional[int]						=   mplfigure.Figure(frameon=UpperCAmelCase			)
           lowerCAmelCase_					:	List[Any]						=   fig.get_dpi()
           lowerCAmelCase_					:	Dict						=   (width * scale + 1e-2) / dpi
           lowerCAmelCase_					:	Optional[Any]						=   (height * scale + 1e-2) / dpi
           fig.set_size_inches(UpperCAmelCase					,			UpperCAmelCase			)
           lowerCAmelCase_					:	Tuple						=   fig.add_axes([0.0, 0.0, 1.0, 1.0]			)
           ax.axis("""off"""			)
           ax.set_xlim(0.0					,			UpperCAmelCase			)
           ax.set_ylim(UpperCAmelCase			)

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



       def  A							(     self	:   int					,			UpperCAmelCase	:   List[str]					,			UpperCAmelCase	:   Union[str, Any]=None			):






           if color is None:
               lowerCAmelCase_					:	str						=   self.edgecolor
           ((lowerCAmelCase_)		,		(lowerCAmelCase_)		,		(lowerCAmelCase_)		,		(lowerCAmelCase_))					:	Optional[int]						=   box
           lowerCAmelCase_					:	Dict						=   xa - xa
           lowerCAmelCase_					:	List[str]						=   ya - ya
           self.ax.add_patch(
               mpl.patches.Rectangle(
                   (xa, ya)					,			UpperCAmelCase					,			UpperCAmelCase					,			fill=UpperCAmelCase					,			edgecolor=UpperCAmelCase					,			linewidth=self.font_size // 3					,			alpha=self.alpha					,			linestyle=self.linestyle					,			)			)



       def  A							(     self	:   Optional[int]					,			UpperCAmelCase	:   Dict					,			UpperCAmelCase	:   List[str]=None					,			UpperCAmelCase	:   Any=None					,			UpperCAmelCase	:   Dict=None					,			UpperCAmelCase	:   Union[str, Any]=None			):






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

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



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

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

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



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



       def  A							(     self	:   List[str]					,			UpperCAmelCase	:   Optional[int]=None			):






           if saveas is None:
               lowerCAmelCase_					:	Any						=   self.saveas
           if saveas.lower().endswith(""".jpg"""			) or saveas.lower().endswith(""".png"""			):
               cva.imwrite(
                   UpperCAmelCase					,			self._get_buffer()[:, :, ::-1]					,			)
           else:
               self.fig.savefig(UpperCAmelCase			)



       def  A							(     self	:   List[Any]					,			UpperCAmelCase	:   Optional[Any]					,			UpperCAmelCase	:   int					,			UpperCAmelCase	:   Optional[Any]					,			UpperCAmelCase	:   Any			):
           lowerCAmelCase_					:	Tuple						=   [self.idaobj[i] for i in classes]
           lowerCAmelCase_					:	Tuple						=   [self.idaattr[i] for i in attr_classes]
           lowerCAmelCase_					:	Any						=   [
               F'{label} {score:.2f} {attr} {attr_score:.2f}'
               for label, score, attr, attr_score in zip(UpperCAmelCase					,			UpperCAmelCase					,			UpperCAmelCase					,			UpperCAmelCase			)
           ]
           return labels



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



       def  A							(     self	:   Any					,			UpperCAmelCase	:   Optional[Any]=2_55			):
           lowerCAmelCase_					:	Tuple						=   np.random.randint(0					,			len(_COLORS			)			)
           lowerCAmelCase_					:	str						=   _COLORS[idx] * maximum
           if not self.rgb:
               lowerCAmelCase_					:	Tuple						=   ret[::-1]
           return ret



       def  A							(     self	:   List[Any]			):






           if not self.pynb:
               lowerCAmelCase_		,		lowerCAmelCase_					:	Dict						=   self.canvas.print_to_buffer()
               if (width, height) != (self.width, self.height):
                   lowerCAmelCase_					:	Union[str, Any]						=   cva.resize(self.img					,			(width, height)			)
               else:
                   lowerCAmelCase_					:	Any						=   self.img
           else:
               lowerCAmelCase_					:	Optional[int]						=   io.BytesIO()  # works for cairo backend
               self.canvas.print_rgba(UpperCAmelCase			)
               lowerCAmelCase_		,		lowerCAmelCase_					:	Any						=   self.width, self.height
               lowerCAmelCase_					:	List[str]						=   buf.getvalue()
               lowerCAmelCase_					:	List[str]						=   self.img

           lowerCAmelCase_					:	Tuple						=   np.frombuffer(UpperCAmelCase					,			dtype="""uint8"""			)
           lowerCAmelCase_					:	str						=   buffer.reshape(UpperCAmelCase					,			UpperCAmelCase					,			4			)
           lowerCAmelCase_		,		lowerCAmelCase_					:	Union[str, Any]						=   np.split(UpperCAmelCase					,			[3]					,			axis=2			)

           try:
               import numexpr as ne  # fuse them with numexpr

               lowerCAmelCase_					:	Tuple						=   ne.evaluate("""img * (1 - alpha / 255.0) + rgb * (alpha / 255.0)"""			)
           except ImportError:
               lowerCAmelCase_					:	Any						=   alpha.astype("""float32"""			) / 2_55.0
               lowerCAmelCase_					:	List[Any]						=   img * (1 - alpha) + rgb * alpha

           return visualized_image.astype("""uint8"""			)



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






__UpperCAmelCase				=      (
    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)
)









from __future__ import annotations

import math
from itertools import permutations
def 			__UpperCamelCase				(			lowercase__	:       int		)	->      bool:
    '''simple docstring'''





    if 1 < number < 4:
        # 2 and 3 are primes
        return True
    elif number < 2 or number % 2 == 0 or number % 3 == 0:
        # Negatives, 0, 1, all even numbers, all multiples of 3 are not primes
        return False

    # All primes number are in format of 6k +/- 1
    for i in range(5		,    int(math.sqrt(lowercase__		) + 1		)		,    6		):
        if number % i == 0 or number % (i + 2) == 0:
            return False
    return True
def 			__UpperCamelCase				(			lowercase__	:       int = 7		)	->      int:
    '''simple docstring'''





    lowerCAmelCase_					:	str						=   """""".join(str(lowercase__		) for i in range(1		,    n + 1		)		)
    lowerCAmelCase_					:	Any						=   [int("""""".join(lowercase__		)		) for i in permutations(lowercase__		,    lowercase__		)]
    lowerCAmelCase_					:	List[Any]						=   [num for num in perm_list if is_prime(lowercase__		)]
    return max(lowercase__		) if pandigitals else 0


if __name__ == "__main__":
  print(f"""{solution() = }""")


