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

class __lowerCAmelCase						:





     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      ,	):

      '''simple docstring'''




      if isinstance(__UpperCAmelCase      ,	torch.Tensor ):
       __UpperCamelCase							    =			img.numpy().astype('np.uint8' )
      if isinstance(__UpperCAmelCase      ,	__UpperCAmelCase ):
       __UpperCamelCase							    =			img_tensorize(__UpperCAmelCase )
      assert isinstance(__UpperCAmelCase      ,	np.ndarray )

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

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





     def 		UpperCAmelCase   (      self      ,	__UpperCAmelCase      ,	__UpperCAmelCase=None ):

      '''simple docstring'''




      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)      ,	__UpperCAmelCase      ,	__UpperCAmelCase      ,	fill=__UpperCAmelCase      ,	edgecolor=__UpperCAmelCase      ,	linewidth=self.font_size // 3      ,	alpha=self.alpha      ,	linestyle=self.linestyle      ,	) )





     def 		UpperCAmelCase   (      self      ,	__UpperCAmelCase      ,	__UpperCAmelCase=None      ,	__UpperCAmelCase=None      ,	__UpperCAmelCase=None      ,	__UpperCAmelCase=None ):

      '''simple docstring'''




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





     def 		UpperCAmelCase   (      self      ,	__UpperCAmelCase      ,	__UpperCAmelCase      ,	__UpperCAmelCase ):

      '''simple docstring'''




      __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(__UpperCAmelCase      ,	brightness_factor=0.7 )
      __UpperCamelCase							    =			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      ,	__UpperCAmelCase      ,	__UpperCAmelCase      ,	__UpperCAmelCase="g"      ,	__UpperCAmelCase="left"      ,	):

      '''simple docstring'''




      __UpperCamelCase							    =			0
      __UpperCamelCase							    =			self.font_size
      __UpperCamelCase							    =			np.maximum(list(mplc.to_rgb(__UpperCAmelCase ) )      ,	0.2 )
      __UpperCamelCase							    =			max(0.8      ,	np.max(__UpperCAmelCase ) )
      __UpperCamelCase							    =			{
          'facecolor': 'black',
          'alpha': self.alpha,
          'pad': self.pad,
          'edgecolor': 'none',
      }
      __UpperCamelCase    ,      __UpperCamelCase							    =			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 		UpperCAmelCase   (      self      ,	__UpperCAmelCase=None ):

      '''simple docstring'''




      if saveas is None:
       __UpperCamelCase							    =			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      ,	__UpperCAmelCase      ,	__UpperCAmelCase      ,	__UpperCAmelCase      ,	__UpperCAmelCase ):

      '''simple docstring'''




      __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(__UpperCAmelCase      ,	__UpperCAmelCase      ,	__UpperCAmelCase      ,	__UpperCAmelCase )
      ]
      return labels





     def 		UpperCAmelCase   (      self      ,	__UpperCAmelCase      ,	__UpperCAmelCase ):

      '''simple docstring'''




      __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(__UpperCAmelCase      ,	s * 100 ) for li, s in zip(__UpperCAmelCase      ,	__UpperCAmelCase )]
      return labels





     def 		UpperCAmelCase   (      self      ,	__UpperCAmelCase=255 ):

      '''simple docstring'''




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





     def 		UpperCAmelCase   (      self ):

      '''simple docstring'''




      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(__UpperCAmelCase )
       __UpperCamelCase    ,      __UpperCamelCase							    =			self.width, self.height
       __UpperCamelCase							    =			buf.getvalue()
       __UpperCamelCase							    =			self.img

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

      return visualized_image.astype('uint8' )







     def 		UpperCAmelCase   (      self      ,	__UpperCAmelCase      ,	__UpperCAmelCase ):

      '''simple docstring'''




      assert brightness_factor >= -1.0 and brightness_factor <= 1.0
      __UpperCamelCase							    =			mplc.to_rgb(__UpperCAmelCase )
      __UpperCamelCase							    =			colorsys.rgb_to_hls(*mplc.to_rgb(__UpperCAmelCase ) )
      __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]      ,	__UpperCAmelCase      ,	polygon_color[2] )
      return modified_color


UpperCamelCase      :							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)
)





"""simple docstring"""

UpperCamelCase      :							int          =					1_0**8






def 				A		(							snake_case :int						) ->      bool:
 if n % 1_0 == 0:
  return False
 __UpperCamelCase							    =			str(snake_case						)
 return s == s[::-1]






def 				A		(							) ->      int:
 __UpperCamelCase							    =			set()
 __UpperCamelCase							    =			1
 __UpperCamelCase							    =			5
 while sum_squares < LIMIT:
  __UpperCamelCase							    =			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
  __UpperCamelCase							    =			first_square**2 + (first_square + 1) ** 2

 return sum(snake_case						)


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



