
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		:   Tuple			       =    1_000



class       a_   :






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

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

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






			def       UpperCamelCase_							(			self							, __UpperCamelCase							, __UpperCamelCase=None     ):
									if color is None:
															_lowercase									=				self.edgecolor
									((_lowercase)					,	(_lowercase)					,	(_lowercase)					,	(_lowercase))									=				box
									_lowercase									=				xa - xa
									_lowercase									=				ya - ya
									self.ax.add_patch(
									    mpl.patches.Rectangle(
									        (xa, ya)							, __snake_case							, __snake_case							, fill=__snake_case							, edgecolor=__snake_case							, linewidth=self.font_size // 3							, alpha=self.alpha							, linestyle=self.linestyle							, )     )






			def       UpperCamelCase_							(			self							, __UpperCamelCase							, __UpperCamelCase=None							, __UpperCamelCase=None							, __UpperCamelCase=None							, __UpperCamelCase=None     ):
									if len(boxes.shape     ) > 2:
															_lowercase									=				boxes[0]
									if len(obj_ids.shape     ) > 1:
															_lowercase									=				obj_ids[0]
									if len(obj_scores.shape     ) > 1:
															_lowercase									=				obj_scores[0]
									if len(attr_ids.shape     ) > 1:
															_lowercase									=				attr_ids[0]
									if len(attr_scores.shape     ) > 1:
															_lowercase									=				attr_scores[0]
									if isinstance(__snake_case							, torch.Tensor     ):
															_lowercase									=				boxes.numpy()
									if isinstance(__snake_case							, __snake_case     ):
															_lowercase									=				np.array(__snake_case     )
									assert isinstance(__snake_case							, np.ndarray     )
									_lowercase									=				np.prod(boxes[:, 2:] - boxes[:, :2]							, axis=1     )
									_lowercase									=				np.argsort(-areas     ).tolist()
									_lowercase									=				boxes[sorted_idxs] if boxes is not None else None
									_lowercase									=				obj_ids[sorted_idxs] if obj_ids is not None else None
									_lowercase									=				obj_scores[sorted_idxs] if obj_scores is not None else None
									_lowercase									=				attr_ids[sorted_idxs] if attr_ids is not None else None
									_lowercase									=				attr_scores[sorted_idxs] if attr_scores is not None else None

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






			def       UpperCamelCase_							(			self							, __UpperCamelCase							, __UpperCamelCase							, __UpperCamelCase     ):
									_lowercase					,	_lowercase					,	_lowercase					,	_lowercase									=				box
									_lowercase									=				(xa, ya)
									_lowercase									=				(ya - ya) * (xa - xa)
									_lowercase									=				_SMALL_OBJ * self.scale
									if instance_area < small or ya - ya < 40 * self.scale:
															if ya >= self.height - 5:
																					_lowercase									=				(xa, ya)
															else:
																					_lowercase									=				(xa, ya)

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

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






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






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






			def       UpperCamelCase_							(			self							, __UpperCamelCase							, __UpperCamelCase							, __UpperCamelCase							, __UpperCamelCase     ):
									_lowercase									=				[self.idaobj[i] for i in classes]
									_lowercase									=				[self.idaattr[i] for i in attr_classes]
									_lowercase									=				[
									    f"""{label} {score:.2f} {attr} {attr_score:.2f}"""
									    for label, score, attr, attr_score in zip(__snake_case							, __snake_case							, __snake_case							, __snake_case     )
									]
									return labels






			def       UpperCamelCase_							(			self							, __UpperCamelCase							, __UpperCamelCase     ):
									_lowercase									=				[self.idaobj[i] for i in classes]
									if scores is not None:
															if labels is None:
																					_lowercase									=				["""{:.0f}%""".format(s * 100     ) for s in scores]
															else:
																					_lowercase									=				["""{} {:.0f}%""".format(__snake_case							, s * 100     ) for li, s in zip(__snake_case							, __snake_case     )]
									return labels






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






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

									_lowercase									=				np.frombuffer(__snake_case							, dtype="""uint8"""     )
									_lowercase									=				buffer.reshape(__snake_case							, __snake_case							, 4     )
									_lowercase					,	_lowercase									=				np.split(__snake_case							, [3]							, axis=2     )

									try:
															import numexpr as ne  # fuse them with numexpr

															_lowercase									=				ne.evaluate("""img * (1 - alpha / 255.0) + rgb * (alpha / 255.0)"""     )
									except ImportError:
															_lowercase									=				alpha.astype("""float32"""     ) / 2_55.0
															_lowercase									=				img * (1 - alpha) + rgb * alpha

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






			def       UpperCamelCase_							(			self							, __UpperCamelCase							, __UpperCamelCase     ):
									assert brightness_factor >= -1.0 and brightness_factor <= 1.0
									_lowercase									=				mplc.to_rgb(__snake_case     )
									_lowercase									=				colorsys.rgb_to_hls(*mplc.to_rgb(__snake_case     )     )
									_lowercase									=				polygon_color[1] + (brightness_factor * polygon_color[1])
									_lowercase									=				0.0 if modified_lightness < 0.0 else modified_lightness
									_lowercase									=				1.0 if modified_lightness > 1.0 else modified_lightness
									_lowercase									=				colorsys.hls_to_rgb(polygon_color[0]							, __snake_case							, polygon_color[2]     )
									return modified_color







A		:   Union[str, Any]			       =    (
    np.array(
        [
            0.0_00,
            0.4_47,
            0.7_41,
            0.8_50,
            0.3_25,
            0.0_98,
            0.9_29,
            0.6_94,
            0.1_25,
            0.4_94,
            0.1_84,
            0.5_56,
            0.4_66,
            0.6_74,
            0.1_88,
            0.3_01,
            0.7_45,
            0.9_33,
            0.6_35,
            0.0_78,
            0.1_84,
            0.3_00,
            0.3_00,
            0.3_00,
            0.6_00,
            0.6_00,
            0.6_00,
            1.0_00,
            0.0_00,
            0.0_00,
            1.0_00,
            0.5_00,
            0.0_00,
            0.7_49,
            0.7_49,
            0.0_00,
            0.0_00,
            1.0_00,
            0.0_00,
            0.0_00,
            0.0_00,
            1.0_00,
            0.6_67,
            0.0_00,
            1.0_00,
            0.3_33,
            0.3_33,
            0.0_00,
            0.3_33,
            0.6_67,
            0.0_00,
            0.3_33,
            1.0_00,
            0.0_00,
            0.6_67,
            0.3_33,
            0.0_00,
            0.6_67,
            0.6_67,
            0.0_00,
            0.6_67,
            1.0_00,
            0.0_00,
            1.0_00,
            0.3_33,
            0.0_00,
            1.0_00,
            0.6_67,
            0.0_00,
            1.0_00,
            1.0_00,
            0.0_00,
            0.0_00,
            0.3_33,
            0.5_00,
            0.0_00,
            0.6_67,
            0.5_00,
            0.0_00,
            1.0_00,
            0.5_00,
            0.3_33,
            0.0_00,
            0.5_00,
            0.3_33,
            0.3_33,
            0.5_00,
            0.3_33,
            0.6_67,
            0.5_00,
            0.3_33,
            1.0_00,
            0.5_00,
            0.6_67,
            0.0_00,
            0.5_00,
            0.6_67,
            0.3_33,
            0.5_00,
            0.6_67,
            0.6_67,
            0.5_00,
            0.6_67,
            1.0_00,
            0.5_00,
            1.0_00,
            0.0_00,
            0.5_00,
            1.0_00,
            0.3_33,
            0.5_00,
            1.0_00,
            0.6_67,
            0.5_00,
            1.0_00,
            1.0_00,
            0.5_00,
            0.0_00,
            0.3_33,
            1.0_00,
            0.0_00,
            0.6_67,
            1.0_00,
            0.0_00,
            1.0_00,
            1.0_00,
            0.3_33,
            0.0_00,
            1.0_00,
            0.3_33,
            0.3_33,
            1.0_00,
            0.3_33,
            0.6_67,
            1.0_00,
            0.3_33,
            1.0_00,
            1.0_00,
            0.6_67,
            0.0_00,
            1.0_00,
            0.6_67,
            0.3_33,
            1.0_00,
            0.6_67,
            0.6_67,
            1.0_00,
            0.6_67,
            1.0_00,
            1.0_00,
            1.0_00,
            0.0_00,
            1.0_00,
            1.0_00,
            0.3_33,
            1.0_00,
            1.0_00,
            0.6_67,
            1.0_00,
            0.3_33,
            0.0_00,
            0.0_00,
            0.5_00,
            0.0_00,
            0.0_00,
            0.6_67,
            0.0_00,
            0.0_00,
            0.8_33,
            0.0_00,
            0.0_00,
            1.0_00,
            0.0_00,
            0.0_00,
            0.0_00,
            0.1_67,
            0.0_00,
            0.0_00,
            0.3_33,
            0.0_00,
            0.0_00,
            0.5_00,
            0.0_00,
            0.0_00,
            0.6_67,
            0.0_00,
            0.0_00,
            0.8_33,
            0.0_00,
            0.0_00,
            1.0_00,
            0.0_00,
            0.0_00,
            0.0_00,
            0.1_67,
            0.0_00,
            0.0_00,
            0.3_33,
            0.0_00,
            0.0_00,
            0.5_00,
            0.0_00,
            0.0_00,
            0.6_67,
            0.0_00,
            0.0_00,
            0.8_33,
            0.0_00,
            0.0_00,
            1.0_00,
            0.0_00,
            0.0_00,
            0.0_00,
            0.1_43,
            0.1_43,
            0.1_43,
            0.8_57,
            0.8_57,
            0.8_57,
            1.0_00,
            1.0_00,
            1.0_00,
        ]
    )
    .astype(np.floataa)
    .reshape(-1, 3)
)

def   UpperCamelCase__     (    SCREAMING_SNAKE_CASE_  :  int					)     ->    int:
						return n * (2 * n - 1)




def   UpperCamelCase__     (    SCREAMING_SNAKE_CASE_  :  int					)     ->    bool:
						_lowercase									=				(1 + 24 * n) ** 0.5
						return ((1 + root) / 6) % 1 == 0




def   UpperCamelCase__     (    SCREAMING_SNAKE_CASE_  :  int = 1_44					)     ->    int:
						_lowercase									=				start
						_lowercase									=				hexagonal_num(SCREAMING_SNAKE_CASE_					)
						while not is_pentagonal(SCREAMING_SNAKE_CASE_					):
												n += 1
												_lowercase									=				hexagonal_num(SCREAMING_SNAKE_CASE_					)
						return num


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