

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


SCREAMING_SNAKE_CASE						:Union[str, Any]      =			1000






class 		__magic_name__ :






     def __init__(							self						,		_lowercase						,		_lowercase=1.2						,		_lowercase="g"						,		_lowercase=0.5						,		_lowercase="-"						,		_lowercase="test_out.jpg"						,		_lowercase=True						,		_lowercase=False						,		_lowercase=None						,		_lowercase=None						,		_lowercase=0.7						,		)->			Dict:
         if isinstance(_lowercase						,		torch.Tensor     ):
             UpperCamelCase_          =		img.numpy().astype("np.uint8"     )
         if isinstance(_lowercase						,		_lowercase     ):
             UpperCamelCase_          =		img_tensorize(_lowercase     )
         assert isinstance(_lowercase						,		np.ndarray     )

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

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






     def      UpperCAmelCase_							(							self						,		_lowercase						,		_lowercase=None     )->			List[str]:
         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)						,		_lowercase						,		_lowercase						,		fill=_lowercase						,		edgecolor=_lowercase						,		linewidth=self.font_size // 3						,		alpha=self.alpha						,		linestyle=self.linestyle						,		)     )






     def      UpperCAmelCase_							(							self						,		_lowercase						,		_lowercase=None						,		_lowercase=None						,		_lowercase=None						,		_lowercase=None     )->			Any:
         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(_lowercase						,		torch.Tensor     ):
             UpperCamelCase_          =		boxes.numpy()
         if isinstance(_lowercase						,		_lowercase     ):
             UpperCamelCase_          =		np.array(_lowercase     )
         assert isinstance(_lowercase						,		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(_lowercase     )     )]
         UpperCamelCase_          =		[assigned_colors[idx] for idx in sorted_idxs]
         if obj_ids is not None:
             UpperCamelCase_          =		self._create_text_labels_attr(_lowercase						,		_lowercase						,		_lowercase						,		_lowercase     )
             for i in range(len(_lowercase     )     ):
                 UpperCamelCase_          =		assigned_colors[i]
                 self.add_box(boxes[i]						,		_lowercase     )
                 self.draw_labels(labels[i]						,		boxes[i]						,		_lowercase     )






     def      UpperCAmelCase_							(							self						,		_lowercase						,		_lowercase						,		_lowercase     )->			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(_lowercase						,		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=_lowercase						,		position=_lowercase						,		color=_lowercase						,		)






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






     def      UpperCAmelCase_							(							self						,		_lowercase=None     )->			int:
         if saveas is None:
             UpperCamelCase_          =		self.saveas
         if saveas.lower().endswith(".jpg"     ) or saveas.lower().endswith(".png"     ):
             cva.imwrite(
                 _lowercase						,		self._get_buffer()[:, :, ::-1]						,		)
         else:
             self.fig.savefig(_lowercase     )






     def      UpperCAmelCase_							(							self						,		_lowercase						,		_lowercase						,		_lowercase						,		_lowercase     )->			Tuple:
         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(_lowercase						,		_lowercase						,		_lowercase						,		_lowercase     )
         ]
         return labels






     def      UpperCAmelCase_							(							self						,		_lowercase						,		_lowercase     )->			int:
         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(_lowercase						,		s * 100     ) for li, s in zip(_lowercase						,		_lowercase     )]
         return labels






     def      UpperCAmelCase_							(							self						,		_lowercase=255     )->			Optional[Any]:
         UpperCamelCase_          =		np.random.randint(0						,		len(_COLORS     )     )
         UpperCamelCase_          =		_COLORS[idx] * maximum
         if not self.rgb:
             UpperCamelCase_          =		ret[::-1]
         return ret






     def      UpperCAmelCase_							(							self     )->			int:
         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(_lowercase     )
             UpperCamelCase_   ,    UpperCamelCase_          =		self.width, self.height
             UpperCamelCase_          =		buf.getvalue()
             UpperCamelCase_          =		self.img

         UpperCamelCase_          =		np.frombuffer(_lowercase						,		dtype="uint8"     )
         UpperCamelCase_          =		buffer.reshape(_lowercase						,		_lowercase						,		4     )
         UpperCamelCase_   ,    UpperCamelCase_          =		np.split(_lowercase						,		[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      UpperCAmelCase_							(							self						,		_lowercase						,		_lowercase     )->			List[str]:
         assert brightness_factor >= -1.0 and brightness_factor <= 1.0
         UpperCamelCase_          =		mplc.to_rgb(_lowercase     )
         UpperCamelCase_          =		colorsys.rgb_to_hls(*mplc.to_rgb(_lowercase     )     )
         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]						,		_lowercase						,		polygon_color[2]     )
         return modified_color
SCREAMING_SNAKE_CASE						:str      =			(
    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'''
import math
from itertools import permutations


def       a__    (  _SCREAMING_SNAKE_CASE					:    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(_SCREAMING_SNAKE_CASE							) + 1							)     ,							6							):
		if number % i == 0 or number % (i + 2) == 0:
			return False
	return True


def       a__    (  _SCREAMING_SNAKE_CASE					:    int     ,							_SCREAMING_SNAKE_CASE					:    list							)			-> bool:


	"""simple docstring"""





	UpperCAmelCase_ , UpperCAmelCase_			:	Any      =   0, len(_SCREAMING_SNAKE_CASE							) - 1
	while left <= right:
		UpperCAmelCase_			:	List[str]      =   (left + right) // 2
		if prime_list[middle] == target:
			return True
		elif prime_list[middle] < target:
			UpperCAmelCase_			:	Dict      =   middle + 1
		else:
			UpperCAmelCase_			:	int      =   middle - 1

	return False


def       a__    (  )			-> Tuple:


	"""simple docstring"""





	UpperCAmelCase_			:	Dict      =   [n for n in range(10_01     ,							1_00_00     ,							2							) if is_prime(_SCREAMING_SNAKE_CASE							)]
	UpperCAmelCase_			:	Optional[int]      =   []

	for number in prime_list:
		UpperCAmelCase_			:	Optional[Any]      =   []

		for prime_member in permutations(list(str(_SCREAMING_SNAKE_CASE							)							)							):
			UpperCAmelCase_			:	List[Any]      =   int("".join(_SCREAMING_SNAKE_CASE							)							)

			if prime % 2 == 0:
				continue

			if search(_SCREAMING_SNAKE_CASE     ,							_SCREAMING_SNAKE_CASE							):
				tmp_numbers.append(_SCREAMING_SNAKE_CASE							)

		tmp_numbers.sort()
		if len(_SCREAMING_SNAKE_CASE							) >= 3:
			candidates.append(_SCREAMING_SNAKE_CASE							)

	UpperCAmelCase_			:	Tuple      =   []
	for candidate in candidates:
		UpperCAmelCase_			:	Union[str, Any]      =   len(_SCREAMING_SNAKE_CASE							)
		UpperCAmelCase_			:	Any      =   False

		for i in range(_SCREAMING_SNAKE_CASE							):
			for j in range(i + 1     ,							_SCREAMING_SNAKE_CASE							):
				for k in range(j + 1     ,							_SCREAMING_SNAKE_CASE							):
					if (
					    abs(candidate[i] - candidate[j]							)
					    == abs(candidate[j] - candidate[k]							)
					    and len({candidate[i], candidate[j], candidate[k]}							) == 3
					):
						passed.append(
						    sorted([candidate[i], candidate[j], candidate[k]]							)							)
						UpperCAmelCase_			:	Optional[Any]      =   True

					if found:
						break
				if found:
					break
			if found:
				break

	UpperCAmelCase_			:	Any      =   set()
	for seq in passed:
		answer.add("".join([str(_SCREAMING_SNAKE_CASE							) for i in seq]							)							)

	return max(int(_SCREAMING_SNAKE_CASE							) for x in answer							)


if __name__ == "__main__":
					print(solution())




