code: 
  '''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_     			=       10_00
  
  
  class   a_  :
  
  
  
  
         def __init__(     self   ,   snake_case_   ,   snake_case_=1.2   ,   snake_case_="g"   ,   snake_case_=0.5   ,   snake_case_="-"   ,   snake_case_="test_out.jpg"   ,   snake_case_=True   ,   snake_case_=False   ,   snake_case_=None   ,   snake_case_=None   ,   snake_case_=0.7   ,   ):
           if isinstance(snake_case_   ,   torch.Tensor  ):
             _lowerCAmelCase       :  List[str]   				=					img.numpy().astype("""np.uint8"""  )
           if isinstance(snake_case_   ,   snake_case_  ):
             _lowerCAmelCase       :  Tuple   				=					img_tensorize(snake_case_  )
           assert isinstance(snake_case_   ,   np.ndarray  )
  
           _lowerCAmelCase				,					_lowerCAmelCase       :  List[str]   				=					img.shape[1], img.shape[0]
           _lowerCAmelCase       :  Dict   				=					mplfigure.Figure(frameon=snake_case_  )
           _lowerCAmelCase       :  Optional[int]   				=					fig.get_dpi()
           _lowerCAmelCase       :  int   				=					(width * scale + 1E-2) / dpi
           _lowerCAmelCase       :  Union[str, Any]   				=					(height * scale + 1E-2) / dpi
           fig.set_size_inches(snake_case_   ,   snake_case_  )
           _lowerCAmelCase       :  Dict   				=					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_  )
  
           _lowerCAmelCase       :  int   				=					saveas
           _lowerCAmelCase       :  Tuple   				=					rgb
           _lowerCAmelCase       :  Any   				=					pynb
           _lowerCAmelCase       :  Optional[Any]   				=					img
           _lowerCAmelCase       :  List[Any]   				=					edgecolor
           _lowerCAmelCase       :  str   				=					0.5
           _lowerCAmelCase       :  Optional[int]   				=					linestyle
           _lowerCAmelCase       :  List[str]   				=					int(np.sqrt(min(snake_case_   ,   snake_case_  )  ) * scale // 3  )
           _lowerCAmelCase       :  Any   				=					width
           _lowerCAmelCase       :  List[str]   				=					height
           _lowerCAmelCase       :  Optional[int]   				=					scale
           _lowerCAmelCase       :  List[str]   				=					fig
           _lowerCAmelCase       :  int   				=					ax
           _lowerCAmelCase       :  Optional[int]   				=					pad
           _lowerCAmelCase       :  Union[str, Any]   				=					idaobj
           _lowerCAmelCase       :  Any   				=					idaattr
           _lowerCAmelCase       :  str   				=					FigureCanvasAgg(snake_case_  )
  
  
  
  
         def 							__UpperCamelCase       (     self   ,   snake_case_   ,   snake_case_=None  ):
           if color is None:
             _lowerCAmelCase       :  List[Any]   				=					self.edgecolor
           ((_lowerCAmelCase)				,					(_lowerCAmelCase)				,					(_lowerCAmelCase)				,					(_lowerCAmelCase))       :  List[str]   				=					box
           _lowerCAmelCase       :  Tuple   				=					xa - xa
           _lowerCAmelCase       :  Dict   				=					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   ,   snake_case_   ,   snake_case_=None   ,   snake_case_=None   ,   snake_case_=None   ,   snake_case_=None  ):
           if len(boxes.shape  ) > 2:
             _lowerCAmelCase       :  int   				=					boxes[0]
           if len(obj_ids.shape  ) > 1:
             _lowerCAmelCase       :  Optional[Any]   				=					obj_ids[0]
           if len(obj_scores.shape  ) > 1:
             _lowerCAmelCase       :  Optional[Any]   				=					obj_scores[0]
           if len(attr_ids.shape  ) > 1:
             _lowerCAmelCase       :  int   				=					attr_ids[0]
           if len(attr_scores.shape  ) > 1:
             _lowerCAmelCase       :  Optional[int]   				=					attr_scores[0]
           if isinstance(snake_case_   ,   torch.Tensor  ):
             _lowerCAmelCase       :  List[Any]   				=					boxes.numpy()
           if isinstance(snake_case_   ,   snake_case_  ):
             _lowerCAmelCase       :  List[str]   				=					np.array(snake_case_  )
           assert isinstance(snake_case_   ,   np.ndarray  )
           _lowerCAmelCase       :  List[Any]   				=					np.prod(boxes[:, 2:] - boxes[:, :2]   ,   axis=1  )
           _lowerCAmelCase       :  Union[str, Any]   				=					np.argsort(-areas  ).tolist()
           _lowerCAmelCase       :  int   				=					boxes[sorted_idxs] if boxes is not None else None
           _lowerCAmelCase       :  str   				=					obj_ids[sorted_idxs] if obj_ids is not None else None
           _lowerCAmelCase       :  int   				=					obj_scores[sorted_idxs] if obj_scores is not None else None
           _lowerCAmelCase       :  Tuple   				=					attr_ids[sorted_idxs] if attr_ids is not None else None
           _lowerCAmelCase       :  Union[str, Any]   				=					attr_scores[sorted_idxs] if attr_scores is not None else None
  
           _lowerCAmelCase       :  Optional[int]   				=					[self._random_color(maximum=1  ) for _ in range(len(snake_case_  )  )]
           _lowerCAmelCase       :  Dict   				=					[assigned_colors[idx] for idx in sorted_idxs]
           if obj_ids is not None:
             _lowerCAmelCase       :  Optional[Any]   				=					self._create_text_labels_attr(snake_case_   ,   snake_case_   ,   snake_case_   ,   snake_case_  )
             for i in range(len(snake_case_  )  ):
               _lowerCAmelCase       :  str   				=					assigned_colors[i]
               self.add_box(boxes[i]   ,   snake_case_  )
               self.draw_labels(labels[i]   ,   boxes[i]   ,   snake_case_  )
  
  
  
  
         def 							__UpperCamelCase       (     self   ,   snake_case_   ,   snake_case_   ,   snake_case_  ):
           _lowerCAmelCase				,					_lowerCAmelCase				,					_lowerCAmelCase				,					_lowerCAmelCase       :  List[str]   				=					box
           _lowerCAmelCase       :  List[Any]   				=					(xa, ya)
           _lowerCAmelCase       :  Optional[int]   				=					(ya - ya) * (xa - xa)
           _lowerCAmelCase       :  Dict   				=					_SMALL_OBJ * self.scale
           if instance_area < small or ya - ya < 4_0 * self.scale:
             if ya >= self.height - 5:
               _lowerCAmelCase       :  Union[str, Any]   				=					(xa, ya)
             else:
               _lowerCAmelCase       :  Tuple   				=					(xa, ya)
  
           _lowerCAmelCase       :  Union[str, Any]   				=					(ya - ya) / np.sqrt(self.height * self.width  )
           _lowerCAmelCase       :  Union[str, Any]   				=					self._change_color_brightness(snake_case_   ,   brightness_factor=0.7  )
           _lowerCAmelCase       :  Optional[int]   				=					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   ,   snake_case_   ,   snake_case_   ,   snake_case_="g"   ,   snake_case_="left"   ,   ):
           _lowerCAmelCase       :  Any   				=					0
           _lowerCAmelCase       :  Dict   				=					self.font_size
           _lowerCAmelCase       :  Optional[Any]   				=					np.maximum(list(mplc.to_rgb(snake_case_  )  )   ,   0.2  )
           _lowerCAmelCase       :  Any   				=					max(0.8   ,   np.max(snake_case_  )  )
           _lowerCAmelCase       :  List[str]   				=					{
               """facecolor""": """black""",
               """alpha""": self.alpha,
               """pad""": self.pad,
               """edgecolor""": """none""",
           }
           _lowerCAmelCase				,					_lowerCAmelCase       :  Union[str, Any]   				=					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=1_0   ,   rotation=snake_case_   ,   )
  
  
  
  
         def 							__UpperCamelCase       (     self   ,   snake_case_=None  ):
           if saveas is None:
             _lowerCAmelCase       :  int   				=					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   ,   snake_case_   ,   snake_case_   ,   snake_case_   ,   snake_case_  ):
           _lowerCAmelCase       :  Optional[int]   				=					[self.idaobj[i] for i in classes]
           _lowerCAmelCase       :  int   				=					[self.idaattr[i] for i in attr_classes]
           _lowerCAmelCase       :  Optional[int]   				=					[
               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   ,   snake_case_   ,   snake_case_  ):
           _lowerCAmelCase       :  int   				=					[self.idaobj[i] for i in classes]
           if scores is not None:
             if labels is None:
               _lowerCAmelCase       :  List[str]   				=					["""{:.0f}%""".format(s * 1_0_0  ) for s in scores]
             else:
               _lowerCAmelCase       :  Optional[int]   				=					["""{} {:.0f}%""".format(snake_case_   ,   s * 1_0_0  ) for li, s in zip(snake_case_   ,   snake_case_  )]
           return labels
  
  
  
  
         def 							__UpperCamelCase       (     self   ,   snake_case_=2_5_5  ):
           _lowerCAmelCase       :  Optional[Any]   				=					np.random.randint(0   ,   len(_COLORS  )  )
           _lowerCAmelCase       :  Tuple   				=					_COLORS[idx] * maximum
           if not self.rgb:
             _lowerCAmelCase       :  Optional[Any]   				=					ret[::-1]
           return ret
  
  
  
  
         def 							__UpperCamelCase       (     self  ):
           if not self.pynb:
             _lowerCAmelCase				,					_lowerCAmelCase       :  Dict   				=					self.canvas.print_to_buffer()
             if (width, height) != (self.width, self.height):
               _lowerCAmelCase       :  Optional[int]   				=					cva.resize(self.img   ,   (width, height)  )
             else:
               _lowerCAmelCase       :  Tuple   				=					self.img
           else:
             _lowerCAmelCase       :  List[str]   				=					io.BytesIO()  # works for cairo backend
             self.canvas.print_rgba(snake_case_  )
             _lowerCAmelCase				,					_lowerCAmelCase       :  Any   				=					self.width, self.height
             _lowerCAmelCase       :  Dict   				=					buf.getvalue()
             _lowerCAmelCase       :  List[Any]   				=					self.img
  
           _lowerCAmelCase       :  List[Any]   				=					np.frombuffer(snake_case_   ,   dtype="""uint8"""  )
           _lowerCAmelCase       :  List[Any]   				=					buffer.reshape(snake_case_   ,   snake_case_   ,   4  )
           _lowerCAmelCase				,					_lowerCAmelCase       :  str   				=					np.split(snake_case_   ,   [3]   ,   axis=2  )
  
           try:
             import numexpr as ne  # fuse them with numexpr
  
             _lowerCAmelCase       :  Union[str, Any]   				=					ne.evaluate("""img * (1 - alpha / 255.0) + rgb * (alpha / 255.0)"""  )
           except ImportError:
             _lowerCAmelCase       :  Optional[int]   				=					alpha.astype("""float32"""  ) / 255.0
             _lowerCAmelCase       :  Tuple   				=					img * (1 - alpha) + rgb * alpha
  
           return visualized_image.astype("""uint8"""  )
  
  
  
  
  
  
  
         def 							__UpperCamelCase       (     self   ,   snake_case_   ,   snake_case_  ):
           assert brightness_factor >= -1.0 and brightness_factor <= 1.0
           _lowerCAmelCase       :  Union[str, Any]   				=					mplc.to_rgb(snake_case_  )
           _lowerCAmelCase       :  List[str]   				=					colorsys.rgb_to_hls(*mplc.to_rgb(snake_case_  )  )
           _lowerCAmelCase       :  Tuple   				=					polygon_color[1] + (brightness_factor * polygon_color[1])
           _lowerCAmelCase       :  int   				=					0.0 if modified_lightness < 0.0 else modified_lightness
           _lowerCAmelCase       :  Optional[Any]   				=					1.0 if modified_lightness > 1.0 else modified_lightness
           _lowerCAmelCase       :  str   				=					colorsys.hls_to_rgb(polygon_color[0]   ,   snake_case_   ,   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)
  )
  
  
  
style_context: 
  '''simple docstring'''
  
  import os
  
  
  def 	_UpperCAmelCase				(  )    ->						int:
    _lowerCAmelCase       :  Optional[int]   				=					os.path.dirname(os.path.realpath(_lowerCamelCase		)		)
    _lowerCAmelCase       :  Optional[Any]   				=					os.path.join(_lowerCamelCase  ,      """triangle.txt"""		)
  
    with open(_lowerCamelCase		) as in_file:
      _lowerCAmelCase       :  List[Any]   				=					[[int(_lowerCamelCase		) for i in line.split()] for line in in_file]
  
    while len(_lowerCamelCase		) != 1:
      _lowerCAmelCase       :  Any   				=					triangle.pop()
      _lowerCAmelCase       :  List[str]   				=					triangle[-1]
      for j in range(len(_lowerCamelCase		) - 1		):
        curr_row[j] += max(last_row[j]  ,      last_row[j + 1]		)
    return triangle[0][0]
  
  
  if __name__ == "__main__":
       print(solution())
  
  
  