






"""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


_UpperCamelCase						=		1_0_0_0

class 	a					:







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

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

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







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







    def       UpperCamelCase_				(      self							,		_lowerCamelCase							,		_lowerCamelCase							,		_lowerCamelCase	):
      lowercase							   =	box
      lowercase							   =	(xa, ya)
      lowercase							   =	(ya - ya) * (xa - xa)
      lowercase							   =	_SMALL_OBJ * self.scale
      if instance_area < small or ya - ya < 4_0 * 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(UpperCamelCase__							,		brightness_factor=0.7	)
      lowercase							   =	np.clip((height_ratio - 0.0_2) / 0.0_8 + 1							,		1.2							,		2	)
      font_size *= 0.7_5 * self.font_size

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







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







    def       UpperCamelCase_				(      self							,		_lowerCamelCase=None	):
      if saveas is None:
        lowercase							   =	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       UpperCamelCase_				(      self							,		_lowerCamelCase							,		_lowerCamelCase							,		_lowerCamelCase							,		_lowerCamelCase	):
      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(UpperCamelCase__							,		UpperCamelCase__							,		UpperCamelCase__							,		UpperCamelCase__	)
      ]
      return labels







    def       UpperCamelCase_				(      self							,		_lowerCamelCase							,		_lowerCamelCase	):
      lowercase							   =	[self.idaobj[i] for i in classes]
      if scores is not None:
        if labels is None:
          lowercase							   =	["{:.0f}%".format(s * 1_0_0	) for s in scores]
        else:
          lowercase							   =	["{} {:.0f}%".format(UpperCamelCase__							,		s * 1_0_0	) for li, s in zip(UpperCamelCase__							,		UpperCamelCase__	)]
      return labels







    def       UpperCamelCase_				(      self							,		_lowerCamelCase=2_5_5	):
      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							   =	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(UpperCamelCase__	)
        lowercase							   =	self.width, self.height
        lowercase							   =	buf.getvalue()
        lowercase							   =	self.img

      lowercase							   =	np.frombuffer(UpperCamelCase__							,		dtype='uint8'	)
      lowercase							   =	buffer.reshape(UpperCamelCase__							,		UpperCamelCase__							,		4	)
      lowercase							   =	np.split(UpperCamelCase__							,		[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_5_5.0
        lowercase							   =	img * (1 - alpha) + rgb * alpha

      return visualized_image.astype('uint8'	)







    def       UpperCamelCase_				(      self							,		_lowerCamelCase							,		_lowerCamelCase	):
      assert brightness_factor >= -1.0 and brightness_factor <= 1.0
      lowercase							   =	mplc.to_rgb(UpperCamelCase__	)
      lowercase							   =	colorsys.rgb_to_hls(*mplc.to_rgb(UpperCamelCase__	)	)
      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]							,		UpperCamelCase__							,		polygon_color[2]	)
      return modified_color


_UpperCamelCase						=		(
    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"""



_UpperCamelCase		:  str						=		1_0**8
def 						_SCREAMING_SNAKE_CASE			(   __snake_case      :  int   ):





  '''simple docstring'''





  if n % 10 == 0:
    return False
  lowercase							   =	str(__snake_case   )
  return s == s[::-1]
def 						_SCREAMING_SNAKE_CASE			(   ):





  '''simple docstring'''





  lowercase							   =	set()
  lowercase							   =	1
  lowercase							   =	5
  while sum_squares < LIMIT:
    lowercase							   =	first_square + 1
    while sum_squares < LIMIT:
      if is_palindrome(__snake_case   ):
        answer.add(__snake_case   )
      last_square += 1
      sum_squares += last_square**2
    first_square += 1
    lowercase							   =	first_square**2 + (first_square + 1) ** 2

  return sum(__snake_case   )


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


