

import baseaa
import io
import json
import os
from copy import deepcopy

from ..optimizer import AcceleratedOptimizer
from ..scheduler import AcceleratedScheduler
class        A_ :


    '''simple docstring'''






    def __init__(self  ,   lowercase__	)  ->   Any:



        if isinstance(__a  ,   __a	):
            # Don't modify user's data should they want to reuse it (e.g. in tests), because once we
            # modified it, it will not be accepted here again, since `auto` values would have been overridden
            __UpperCAmelCase					       =      deepcopy(__a	)
        elif os.path.exists(__a	):
            with io.open(__a  ,   '''r'''  ,   encoding='''utf-8'''	) as f:
                __UpperCAmelCase					       =      json.load(__a	)
        else:
            try:
                __UpperCAmelCase					       =      baseaa.urlsafe_baadecode(__a	).decode('''utf-8'''	)
                __UpperCAmelCase					       =      json.loads(__a	)
            except (UnicodeDecodeError, AttributeError, ValueError):
                raise ValueError(
                    F'''Expected a string path to an existing deepspeed config, or a dictionary, or a base64 encoded string. Received: {config_file_or_dict}'''	)

        __UpperCAmelCase					       =      config

        self.set_stage_and_offload()


    def   lowerCAmelCase_    (self	)  ->   List[str]:
        __UpperCAmelCase					       =      self.get_value('''zero_optimization.stage'''  ,   -1	)

        # offload
        __UpperCAmelCase					       =      False
        if self.is_zeroa() or self.is_zeroa():
            __UpperCAmelCase					       =      set(['''cpu''', '''nvme''']	)
            __UpperCAmelCase					       =      set(
                [
                    self.get_value('''zero_optimization.offload_optimizer.device'''	),
                    self.get_value('''zero_optimization.offload_param.device'''	),
                ]	)
            if len(offload_devices & offload_devices_valid	) > 0:
                __UpperCAmelCase					       =      True


    def   lowerCAmelCase_    (self  ,   lowercase__	)  ->   List[str]:
        __UpperCAmelCase					       =      self.config

        # find the config node of interest if it exists
        __UpperCAmelCase					       =      ds_key_long.split('''.'''	)
        __UpperCAmelCase					       =      nodes.pop()
        for node in nodes:
            __UpperCAmelCase					       =      config.get(__a	)
            if config is None:
                return None, ds_key

        return config, ds_key


    def   lowerCAmelCase_    (self  ,   lowercase__  ,   lowercase__=None	)  ->   Any:
        __UpperCAmelCase       ,  __UpperCAmelCase					       =      self.find_config_node(__a	)
        if config is None:
            return default
        return config.get(__a  ,   __a	)


    def   lowerCAmelCase_    (self  ,   lowercase__  ,   lowercase__=False	)  ->   Union[str, Any]:
        __UpperCAmelCase					       =      self.config

        # find the config node of interest if it exists
        __UpperCAmelCase					       =      ds_key_long.split('''.'''	)
        for node in nodes:
            __UpperCAmelCase					       =      config
            __UpperCAmelCase					       =      config.get(__a	)
            if config is None:
                if must_exist:
                    raise ValueError(F'''Can\'t find {ds_key_long} entry in the config: {self.config}'''	)
                else:
                    return

        # if found remove it
        if parent_config is not None:
            parent_config.pop(__a	)


    def   lowerCAmelCase_    (self  ,   lowercase__	)  ->   int:
        __UpperCAmelCase					       =      self.get_value(__a	)
        return False if value is None else bool(__a	)


    def   lowerCAmelCase_    (self  ,   lowercase__	)  ->   str:
        __UpperCAmelCase					       =      self.get_value(__a	)
        return False if value is None else not bool(__a	)


    def   lowerCAmelCase_    (self	)  ->   str:
        return self._stage == 2


    def   lowerCAmelCase_    (self	)  ->   List[str]:
        return self._stage == 3






    def   lowerCAmelCase_    (self	)  ->   Dict:
        return self._offload






class        A_ :


    '''simple docstring'''






    def __init__(self  ,   lowercase__	)  ->   List[str]:
        __UpperCAmelCase					       =      engine






    def   lowerCAmelCase_    (self  ,   lowercase__  ,   **lowercase__	)  ->   Dict:
        self.engine.backward(__a  ,   **__a	)

        # Deepspeed's `engine.step` performs the following operations:
        # - gradient accumulation check
        # - gradient clipping
        # - optimizer step
        # - zero grad
        # - checking overflow
        # - lr_scheduler step (only if engine.lr_scheduler is not None)
        self.engine.step()
        # and this plugin overrides the above calls with no-ops when Accelerate runs under
        # Deepspeed, but allows normal functionality for non-Deepspeed cases thus enabling a simple
        # training loop that works transparently under many training regimes.






class        A_ (   UpperCAmelCase_    ):


    '''simple docstring'''






    def __init__(self  ,   lowercase__	)  ->   Optional[Any]:
        super().__init__(__a  ,   device_placement=__a  ,   scaler=__a	)
        __UpperCAmelCase					       =      hasattr(self.optimizer  ,   '''overflow'''	)


    def   lowerCAmelCase_    (self  ,   lowercase__=None	)  ->   Optional[Any]:
        pass  # `accelerator.backward(loss)` is doing that automatically. Therefore, its implementation is not needed


    def   lowerCAmelCase_    (self	)  ->   int:
        pass  # `accelerator.backward(loss)` is doing that automatically. Therefore, its implementation is not needed






    @property
    def   lowerCAmelCase_    (self	)  ->   Union[str, Any]:



        if self.__has_overflow__:
            return self.optimizer.overflow
        return False






class        A_ (   UpperCAmelCase_    ):


    '''simple docstring'''






    def __init__(self  ,   lowercase__  ,   lowercase__	)  ->   Optional[Any]:
        super().__init__(__a  ,   __a	)






    def   lowerCAmelCase_    (self	)  ->   Optional[Any]:
        pass  # `accelerator.backward(loss)` is doing that automatically. Therefore, its implementation is not needed






class        A_ :


    '''simple docstring'''






    def __init__(self  ,   lowercase__  ,   lowercase__=0.001  ,   lowercase__=0  ,   **lowercase__	)  ->   Tuple:
        __UpperCAmelCase					       =      params
        __UpperCAmelCase					       =      lr
        __UpperCAmelCase					       =      weight_decay
        __UpperCAmelCase					       =      kwargs






class        A_ :


    '''simple docstring'''






    def __init__(self  ,   lowercase__  ,   lowercase__=None  ,   lowercase__=0  ,   **lowercase__	)  ->   str:
        __UpperCAmelCase					       =      optimizer
        __UpperCAmelCase					       =      total_num_steps
        __UpperCAmelCase					       =      warmup_num_steps
        __UpperCAmelCase					       =      kwargs









def      __lowercase(						UpperCAmelCase__			):


      """simple docstring"""



      if n == 1 or not isinstance(UpperCAmelCase__ , UpperCAmelCase__			):
            return 0
      elif n == 2:
            return 1
      else:
            lowerCamelCase             =		[0, 1]
            for i in range(2 , n + 1			):
                  sequence.append(sequence[i - 1] + sequence[i - 2]			)

            return sequence[n]

def      __lowercase(						UpperCAmelCase__			):


      """simple docstring"""



      lowerCamelCase             =		0
      lowerCamelCase             =		2

      while digits < n:
            index += 1
            lowerCamelCase             =		len(str(fibonacci(UpperCAmelCase__			)			)			)

      return index

def      __lowercase(						UpperCAmelCase__ = 1000			):


      """simple docstring"""



      return fibonacci_digits_index(UpperCAmelCase__			)


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