

"""simple docstring"""


from typing import Any, Dict, List, Union

from ..utils import add_end_docstrings, is_torch_available, is_vision_available, logging, requires_backends
from .base import PIPELINE_INIT_ARGS, ChunkPipeline


if is_vision_available():
			from PIL import Image

			from ..image_utils import load_image

if is_torch_available():
			import torch

			from transformers.modeling_outputs import BaseModelOutput

			from ..models.auto.modeling_auto import MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING

__A						   =			logging.get_logger(__name__)





@add_end_docstrings(_snake_case  )
class     snake_case	(				_snake_case  ):

				def __init__(	self							:				Any     ,  **UpperCamelCase__							:				Union[str, Any])->   Dict:



						'''simple docstring'''


						super().__init__(**_lowerCamelCase)

						if self.framework == "tf":
								raise ValueError(f"The {self.__class__} is only available in PyTorch.")

						requires_backends(self     ,  "vision")
						self.check_model_type(_lowerCamelCase)

				def __call__(	self							:				Union[str, Any]     ,  UpperCamelCase__							:				str     ,  UpperCamelCase__							:				Optional[int] = None     ,  **UpperCamelCase__							:				Tuple     ,  )->   List[str]:



						'''simple docstring'''


						if "text_queries" in kwargs:
								__lowerCAmelCase:       Tuple          =			kwargs.pop("text_queries")

						if isinstance(_lowerCamelCase     ,  (str, Image.Image)):
								__lowerCAmelCase:       Any          =			{'''image''': image, '''candidate_labels''': candidate_labels}
						else:
								__lowerCAmelCase:       Optional[int]          =			image
						__lowerCAmelCase:       Optional[Any]          =			super().__call__(_lowerCamelCase     ,  **_lowerCamelCase)
						return results

				def 							lowercase_     (	self							:				int     ,  **UpperCamelCase__							:				Optional[Any])->   Tuple:



						'''simple docstring'''


						__lowerCAmelCase:       Any          =			{}
						if "threshold" in kwargs:
								__lowerCAmelCase:       List[str]          =			kwargs['''threshold''']
						if "top_k" in kwargs:
								__lowerCAmelCase:       Optional[int]          =			kwargs['''top_k''']
						return {}, {}, postprocess_params

				def 							lowercase_     (	self							:				int     ,  UpperCamelCase__							:				Dict)->   Union[str, Any]:



						'''simple docstring'''


						__lowerCAmelCase:       Dict          =			load_image(inputs["image"])
						__lowerCAmelCase:       List[Any]          =			inputs['''candidate_labels''']
						if isinstance(_lowerCamelCase     ,  _lowerCamelCase):
								__lowerCAmelCase:       Tuple          =			candidate_labels.split(",")

						__lowerCAmelCase:       Optional[int]          =			torch.tensor([[image.height, image.width]]     ,  dtype=torch.intaa)
						for i, candidate_label in enumerate(_lowerCamelCase):
								__lowerCAmelCase:       Optional[Any]          =			self.tokenizer(_lowerCamelCase     ,  return_tensors=self.framework)
								__lowerCAmelCase:       Optional[int]          =			self.image_processor(_lowerCamelCase     ,  return_tensors=self.framework)
								yield {
								    "is_last": i == len(_lowerCamelCase) - 1,
								    "target_size": target_size,
								    "candidate_label": candidate_label,
								    **text_inputs,
								    **image_features,
								}

				def 							lowercase_     (	self							:				Dict     ,  UpperCamelCase__							:				int)->   Tuple:



						'''simple docstring'''


						__lowerCAmelCase:       int          =			model_inputs.pop("target_size")
						__lowerCAmelCase:       int          =			model_inputs.pop("candidate_label")
						__lowerCAmelCase:       Optional[Any]          =			model_inputs.pop("is_last")

						__lowerCAmelCase:       Dict          =			self.model(**_lowerCamelCase)

						__lowerCAmelCase:       str          =			{'''target_size''': target_size, '''candidate_label''': candidate_label, '''is_last''': is_last, **outputs}
						return model_outputs

				def 							lowercase_     (	self							:				List[Any]     ,  UpperCamelCase__							:				List[Any]     ,  UpperCamelCase__							:				Tuple=0.1     ,  UpperCamelCase__							:				Tuple=None)->   List[str]:



						'''simple docstring'''


						__lowerCAmelCase:       int          =			[]
						for model_output in model_outputs:
								__lowerCAmelCase:       List[Any]          =			model_output['''candidate_label''']
								__lowerCAmelCase:       Union[str, Any]          =			BaseModelOutput(_lowerCamelCase)
								__lowerCAmelCase:       Union[str, Any]          =			self.image_processor.post_process_object_detection(
								    outputs=_lowerCamelCase     ,  threshold=_lowerCamelCase     ,  target_sizes=model_output["target_size"])[0]

								for index in outputs["scores"].nonzero():
										__lowerCAmelCase:       str          =			outputs['''scores'''][index].item()
										__lowerCAmelCase:       Dict          =			self._get_bounding_box(outputs["boxes"][index][0])

										__lowerCAmelCase:       Tuple          =			{'''score''': score, '''label''': label, '''box''': box}
										results.append(_lowerCamelCase)

						__lowerCAmelCase:       Optional[int]          =			sorted(_lowerCamelCase     ,  key=lambda UpperCamelCase__: x["score"]     ,  reverse=_lowerCamelCase)
						if top_k:
								__lowerCAmelCase:       Optional[int]          =			results[:top_k]

						return results




				def 							lowercase_     (	self							:				Any     ,  UpperCamelCase__							:				Tuple)->   Optional[int]:



						'''simple docstring'''


						if self.framework != "pt":
								raise ValueError("The ZeroShotObjectDetectionPipeline is only available in PyTorch.")
						__lowerCAmelCase:       int          =			box.int().tolist()
						__lowerCAmelCase:       List[Any]          =			{
						    '''xmin''': xmin,
						    '''ymin''': ymin,
						    '''xmax''': xmax,
						    '''ymax''': ymax,
						}
						return bbox






def 				__lowerCamelCase						( UpperCAmelCase_						:		int = 1000						):




      """simple docstring"""





      a							,				a						:int 							=       1, 1
      a						:Any 							=       2
      while True:
            a						:Optional[int] 							=       0
            a						:str 							=       fa + fa
            a							,				a						:List[Any] 							=       fa, f
            index += 1
            for _ in str(UpperCAmelCase_						):
                  i += 1
            if i == n:
                  break
      return index


if __name__ == "__main__":
     print(solution(int(str(input()).strip())))





