


from typing import Dict, List, Optional, Tuple, Union

import torch

from ...models import AutoencoderKL, TransformeraDModel
from ...schedulers import KarrasDiffusionSchedulers
from ...utils import randn_tensor
from ..pipeline_utils import DiffusionPipeline, ImagePipelineOutput


class     __UpperCAmelCase							(       __A							):


     """simple docstring"""


     def __init__(	self  ,       __A  ,       __A  ,       __A  ,       __A = None  ,       ):
        super().__init__()
        self.register_modules(transformer=__A  ,       vae=__A  ,       scheduler=__A    )

        # create a imagenet -> id dictionary for easier use
        __a					=  {}
        if idalabel is not None:
           for key, value in idalabel.items():
              for label in value.split(""","""    ):
                 __a					=  int(__A    )
           __a					=  dict(sorted(self.labels.items()    )    )


     def 	snake_case_  (	self  ,       __A    ):

        if not isinstance(__A  ,       __A    ):
           __a					=  list(__A    )

        for l in label:
           if l not in self.labels:
              raise ValueError(
                  f'''{l} does not exist. Please make sure to select one of the following labels: \n {self.labels}.'''    )

        return [self.labels[l] for l in label]


     @torch.no_grad()
     def __call__(	self  ,       __A  ,       __A = 4.0  ,       __A = None  ,       __A = 50  ,       __A = "pil"  ,       __A = True  ,       ):
        __a					=  len(__A    )
        __a					=  self.transformer.config.sample_size
        __a					=  self.transformer.config.in_channels

        __a					=  randn_tensor(
            shape=(batch_size, latent_channels, latent_size, latent_size)  ,       generator=__A  ,       device=self.device  ,       dtype=self.transformer.dtype  ,       )
        __a					=  torch.cat([latents] * 2    ) if guidance_scale > 1 else latents

        __a					=  torch.tensor(__A  ,       device=self.device    ).reshape(-1    )
        __a					=  torch.tensor([1000] * batch_size  ,       device=self.device    )
        __a					=  torch.cat([class_labels, class_null]  ,       0    ) if guidance_scale > 1 else class_labels

        # set step values
        self.scheduler.set_timesteps(__A    )

        for t in self.progress_bar(self.scheduler.timesteps    ):
           if guidance_scale > 1:
              __a					=  latent_model_input[: len(__A    ) // 2]
              __a					=  torch.cat([half, half]  ,       dim=0    )
           __a					=  self.scheduler.scale_model_input(__A  ,       __A    )

           __a					=  t
           if not torch.is_tensor(__A    ):
              # TODO: this requires sync between CPU and GPU. So try to pass timesteps as tensors if you can
              # This would be a good case for the `match` statement (Python 3.10+)
              __a					=  latent_model_input.device.type == """mps"""
              if isinstance(__A  ,       __A    ):
                 __a					=  torch.floataa if is_mps else torch.floataa
              else:
                 __a					=  torch.intaa if is_mps else torch.intaa
              __a					=  torch.tensor([timesteps]  ,       dtype=__A  ,       device=latent_model_input.device    )
           elif len(timesteps.shape    ) == 0:
              __a					=  timesteps[None].to(latent_model_input.device    )
           # broadcast to batch dimension in a way that's compatible with ONNX/Core ML
           __a					=  timesteps.expand(latent_model_input.shape[0]    )
           # predict noise model_output
           __a					=  self.transformer(
               __A  ,       timestep=__A  ,       class_labels=__A    ).sample

           # perform guidance
           if guidance_scale > 1:
              __a	,    __a					=  noise_pred[:, :latent_channels], noise_pred[:, latent_channels:]
              __a	,    __a					=  torch.split(__A  ,       len(__A    ) // 2  ,       dim=0    )

              __a					=  uncond_eps + guidance_scale * (cond_eps - uncond_eps)
              __a					=  torch.cat([half_eps, half_eps]  ,       dim=0    )

              __a					=  torch.cat([eps, rest]  ,       dim=1    )

           # learned sigma
           if self.transformer.config.out_channels // 2 == latent_channels:
              __a	,    __a					=  torch.split(__A  ,       __A  ,       dim=1    )
           else:
              __a					=  noise_pred

           # compute previous image: x_t -> x_t-1
           __a					=  self.scheduler.step(__A  ,       __A  ,       __A    ).prev_sample

        if guidance_scale > 1:
           __a	,    __a					=  latent_model_input.chunk(2  ,       dim=0    )
        else:
           __a					=  latent_model_input

        __a					=  1 / self.vae.config.scaling_factor * latents
        __a					=  self.vae.decode(__A    ).sample

        __a					=  (samples / 2 + 0.5).clamp(0  ,       1    )

        # we always cast to float32 as this does not cause significant overhead and is compatible with bfloat16
        __a					=  samples.cpu().permute(0  ,       2  ,       3  ,       1    ).float().numpy()

        if output_type == "pil":
           __a					=  self.numpy_to_pil(__A    )

        if not return_dict:
           return (samples,)

        return ImagePipelineOutput(images=__A    )







def  a   (lowerCAmelCase__ = 1_000_000   ):
   __a					=  1
   __a					=  1
   __a					=  {1: 1}

   for inputa in range(2		,				lowerCAmelCase__   ):
      __a					=  0
      __a					=  inputa

      while True:
         if number in counters:
            counter += counters[number]
            break
         if number % 2 == 0:
            number //= 2
            counter += 1
         else:
            __a					=  (3 * number) + 1
            counter += 1

      if inputa not in counters:
         __a					=  counter

      if counter > pre_counter:
         __a					=  inputa
         __a					=  counter
   return largest_number


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



