






from collections import UserDict
from typing import List, Union

from ..utils import (
    add_end_docstrings,
    is_tf_available,
    is_torch_available,
    is_vision_available,
    logging,
    requires_backends,
)
from .base import PIPELINE_INIT_ARGS, Pipeline


if is_vision_available():
     from PIL import Image

     from ..image_utils import load_image

if is_torch_available():
     from ..models.auto.modeling_auto import MODEL_FOR_ZERO_SHOT_IMAGE_CLASSIFICATION_MAPPING

if is_tf_available():
     from ..models.auto.modeling_tf_auto import TF_MODEL_FOR_ZERO_SHOT_IMAGE_CLASSIFICATION_MAPPING
     from ..tf_utils import stable_softmax

lowerCamelCase__							=     logging.get_logger(__name__)




@add_end_docstrings(__UpperCAmelCase)
class 			snake_case__   (							__UpperCAmelCase):

       '''simple docstring'''



       def __init__(							self			,						**a__    ) ->      int:






            '''simple docstring'''





            super().__init__(**__SCREAMING_SNAKE_CASE    )

            requires_backends(self			,						"""vision"""    )
            self.check_model_type(
                TF_MODEL_FOR_ZERO_SHOT_IMAGE_CLASSIFICATION_MAPPING
                if self.framework == """tf"""
                else MODEL_FOR_ZERO_SHOT_IMAGE_CLASSIFICATION_MAPPING    )



       def __call__(							self			,						a__			,						**a__    ) ->      Tuple:






            '''simple docstring'''





            return super().__call__(__SCREAMING_SNAKE_CASE			,						**__SCREAMING_SNAKE_CASE    )



       def 					__lowercase						(							self			,						**a__    ) ->      int:






            '''simple docstring'''





            __snake_case			:Dict        =						{}
            if "candidate_labels" in kwargs:
                 __snake_case			:int        =						kwargs["""candidate_labels"""]
            if "hypothesis_template" in kwargs:
                 __snake_case			:Dict        =						kwargs["""hypothesis_template"""]

            return preprocess_params, {}, {}



       def 					__lowercase						(							self			,						a__			,						a__=None			,						a__="This is a photo of {}."    ) ->      Optional[Any]:






            '''simple docstring'''





            __snake_case			:str        =						load_image(__SCREAMING_SNAKE_CASE    )
            __snake_case			:Optional[Any]        =						self.image_processor(images=[image]			,						return_tensors=self.framework    )
            __snake_case			:Optional[Any]        =						candidate_labels
            __snake_case			:Optional[Any]        =						[hypothesis_template.format(__SCREAMING_SNAKE_CASE    ) for x in candidate_labels]
            __snake_case			:Any        =						self.tokenizer(__SCREAMING_SNAKE_CASE			,						return_tensors=self.framework			,						padding=__SCREAMING_SNAKE_CASE    )
            __snake_case			:List[str]        =						[text_inputs]
            return inputs



       def 					__lowercase						(							self			,						a__    ) ->      Optional[Any]:






            '''simple docstring'''





            __snake_case			:str        =						model_inputs.pop("""candidate_labels"""    )
            __snake_case			:List[str]        =						model_inputs.pop("""text_inputs"""    )
            if isinstance(text_inputs[0]			,						__SCREAMING_SNAKE_CASE    ):
                 __snake_case			:int        =						text_inputs[0]
            else:
                 # Batching case.
                 __snake_case			:List[Any]        =						text_inputs[0][0]

            __snake_case			:Union[str, Any]        =						self.model(**__SCREAMING_SNAKE_CASE			,						**__SCREAMING_SNAKE_CASE    )

            __snake_case			:str        =						{
                """candidate_labels""": candidate_labels,
                """logits""": outputs.logits_per_image,
            }
            return model_outputs



       def 					__lowercase						(							self			,						a__    ) ->      Union[str, Any]:






            '''simple docstring'''





            __snake_case			:Any        =						model_outputs.pop("""candidate_labels"""    )
            __snake_case			:Optional[Any]        =						model_outputs["""logits"""][0]
            if self.framework == "pt":
                 __snake_case			:Tuple        =						logits.softmax(dim=-1    ).squeeze(-1    )
                 __snake_case			:Optional[int]        =						probs.tolist()
                 if not isinstance(__SCREAMING_SNAKE_CASE			,						__SCREAMING_SNAKE_CASE    ):
                      __snake_case			:Optional[int]        =						[scores]
            elif self.framework == "tf":
                 __snake_case			:Union[str, Any]        =						stable_softmax(__SCREAMING_SNAKE_CASE			,						axis=-1    )
                 __snake_case			:Any        =						probs.numpy().tolist()
            else:
                 raise ValueError(F'''Unsupported framework: {self.framework}'''    )

            __snake_case			:Optional[int]        =						[
                {"""score""": score, """label""": candidate_label}
                for score, candidate_label in sorted(zip(__SCREAMING_SNAKE_CASE			,						__SCREAMING_SNAKE_CASE    )			,						key=lambda a__    : -x[0]    )
            ]
            return result










import os






def   UpperCamelCase  (       ):




     '''simple docstring'''






     __snake_case			:List[str]          =						os.path.dirname(os.path.realpath(snake_case__  )  )
     __snake_case			:Union[str, Any]          =						os.path.join(snake_case__	,"""triangle.txt"""  )

     with open(snake_case__  ) as f:
          __snake_case			:int          =						f.readlines()

     __snake_case			:int          =						[]
     for line in triangle:
          __snake_case			:List[Any]          =						[]
          for number in line.strip().split(""" """  ):
               numbers_from_line.append(int(snake_case__  )  )
          a.append(snake_case__  )

     for i in range(1	,len(snake_case__  )  ):
          for j in range(len(a[i]  )  ):
               __snake_case			:Union[str, Any]          =						a[i - 1][j] if j != len(a[i - 1]  ) else 0
               __snake_case			:Dict          =						a[i - 1][j - 1] if j > 0 else 0
               a[i][j] += max(snake_case__	,snake_case__  )
     return max(a[-1]  )


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


