


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			=    1000







class lowerCAmelCase_						:

 '''simple docstring'''

 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(_UpperCAmelCase		,      torch.Tensor					):
             snake_case_       =      img.numpy().astype('''np.uint8'''					)
       if isinstance(_UpperCAmelCase		,      _UpperCAmelCase					):
             snake_case_       =      img_tensorize(_UpperCAmelCase					)
       assert isinstance(_UpperCAmelCase		,      np.ndarray					)

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

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



 def 						UpperCamelCase__     (	self		,      _UpperCAmelCase		,      _UpperCAmelCase=None					):
       if color is None:
             snake_case_       =      self.edgecolor
       ((snake_case_)       ,    (snake_case_)       ,    (snake_case_)       ,    (snake_case_))       =      box
       snake_case_       =      xa - xa
       snake_case_       =      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					):
       if len(boxes.shape					) > 2:
             snake_case_       =      boxes[0]
       if len(obj_ids.shape					) > 1:
             snake_case_       =      obj_ids[0]
       if len(obj_scores.shape					) > 1:
             snake_case_       =      obj_scores[0]
       if len(attr_ids.shape					) > 1:
             snake_case_       =      attr_ids[0]
       if len(attr_scores.shape					) > 1:
             snake_case_       =      attr_scores[0]
       if isinstance(_UpperCAmelCase		,      torch.Tensor					):
             snake_case_       =      boxes.numpy()
       if isinstance(_UpperCAmelCase		,      _UpperCAmelCase					):
             snake_case_       =      np.array(_UpperCAmelCase					)
       assert isinstance(_UpperCAmelCase		,      np.ndarray					)
       snake_case_       =      np.prod(boxes[:, 2:] - boxes[:, :2]		,      axis=1					)
       snake_case_       =      np.argsort(-areas					).tolist()
       snake_case_       =      boxes[sorted_idxs] if boxes is not None else None
       snake_case_       =      obj_ids[sorted_idxs] if obj_ids is not None else None
       snake_case_       =      obj_scores[sorted_idxs] if obj_scores is not None else None
       snake_case_       =      attr_ids[sorted_idxs] if attr_ids is not None else None
       snake_case_       =      attr_scores[sorted_idxs] if attr_scores is not None else None

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



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

       snake_case_       =      (ya - ya) / np.sqrt(self.height * self.width					)
       snake_case_       =      self._change_color_brightness(_UpperCAmelCase		,      brightness_factor=0.7					)
       snake_case_       =      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 						UpperCamelCase__     (	self		,      _UpperCAmelCase		,      _UpperCAmelCase		,      _UpperCAmelCase="g"		,      _UpperCAmelCase="left"		,      ):
       snake_case_       =      0
       snake_case_       =      self.font_size
       snake_case_       =      np.maximum(list(mplc.to_rgb(_UpperCAmelCase					)					)		,      0.2					)
       snake_case_       =      max(0.8		,      np.max(_UpperCAmelCase					)					)
       snake_case_       =      {
           '''facecolor''': '''black''',
           '''alpha''': self.alpha,
           '''pad''': self.pad,
           '''edgecolor''': '''none''',
       }
       snake_case_       ,    snake_case_       =      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					):
       if saveas is None:
             snake_case_       =      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					):
       snake_case_       =      [self.idaobj[i] for i in classes]
       snake_case_       =      [self.idaattr[i] for i in attr_classes]
       snake_case_       =      [
           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					):
       snake_case_       =      [self.idaobj[i] for i in classes]
       if scores is not None:
             if labels is None:
                   snake_case_       =      ['''{:.0f}%'''.format(s * 1_00					) for s in scores]
             else:
                   snake_case_       =      ['''{} {:.0f}%'''.format(_UpperCAmelCase		,      s * 1_00					) for li, s in zip(_UpperCAmelCase		,      _UpperCAmelCase					)]
       return labels



 def 						UpperCamelCase__     (	self		,      _UpperCAmelCase=2_55					):
       snake_case_       =      np.random.randint(0		,      len(_COLORS					)					)
       snake_case_       =      _COLORS[idx] * maximum
       if not self.rgb:
             snake_case_       =      ret[::-1]
       return ret



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

       snake_case_       =      np.frombuffer(_UpperCAmelCase		,      dtype='''uint8'''					)
       snake_case_       =      buffer.reshape(_UpperCAmelCase		,      _UpperCAmelCase		,      4					)
       snake_case_       ,    snake_case_       =      np.split(_UpperCAmelCase		,      [3]		,      axis=2					)

       try:
             import numexpr as ne  # fuse them with numexpr

             snake_case_       =      ne.evaluate('''img * (1 - alpha / 255.0) + rgb * (alpha / 255.0)'''					)
       except ImportError:
             snake_case_       =      alpha.astype('''float32'''					) / 255.0
             snake_case_       =      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
       snake_case_       =      mplc.to_rgb(_UpperCAmelCase					)
       snake_case_       =      colorsys.rgb_to_hls(*mplc.to_rgb(_UpperCAmelCase					)					)
       snake_case_       =      polygon_color[1] + (brightness_factor * polygon_color[1])
       snake_case_       =      0.0 if modified_lightness < 0.0 else modified_lightness
       snake_case_       =      1.0 if modified_lightness > 1.0 else modified_lightness
       snake_case_       =      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)
)



UpperCAmelCase			=    10**8






def        __lowerCAmelCase    (SCREAMING_SNAKE_CASE					)->  bool:




      """simple docstring"""

      if n % 10 == 0:
            return False
      snake_case_       =      str(SCREAMING_SNAKE_CASE					)
      return s == s[::-1]






def        __lowerCAmelCase    ()->  int:




      """simple docstring"""

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

      return sum(SCREAMING_SNAKE_CASE					)


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