






import os
import socket
from contextlib import contextmanager

import torch

from ..commands.config.default import write_basic_config  # noqa: F401
from ..state import PartialState
from .dataclasses import DistributedType
from .imports import is_deepspeed_available, is_tpu_available
from .transformer_engine import convert_model
from .versions import is_torch_version


if is_deepspeed_available():
				from deepspeed import DeepSpeedEngine

if is_tpu_available(check_device=False):
				import torch_xla.core.xla_model as xm




def      __A					(     _lowercase ):

					'''simple docstring'''







					if is_torch_version('''<'''					,			'''2.0.0''' ) or not hasattr(_lowercase					,			'''_dynamo''' ):
										return False
					return isinstance(_lowercase					,			torch._dynamo.eval_frame.OptimizedModule )




def      __A					(     _lowercase					,			_lowercase = True ):

					'''simple docstring'''







					_A								= (torch.nn.parallel.DistributedDataParallel, torch.nn.DataParallel)

					_A								= is_compiled_module(_lowercase )
					if is_compiled:
										_A								= model
										_A								= model._orig_mod

					if is_deepspeed_available():
										options += (DeepSpeedEngine,)

					while isinstance(_lowercase					,			_lowercase ):
										_A								= model.module

					if not keep_fpaa_wrapper:
										_A								= getattr(_lowercase					,			'''forward''' )
										_A								= model.__dict__.pop('''_original_forward'''					,			_lowercase )
										if original_forward is not None:
															while hasattr(_lowercase					,			'''__wrapped__''' ):
																				_A								= forward.__wrapped__
																				if forward == original_forward:
																									break
															_A								= forward
										if getattr(_lowercase					,			'''_converted_to_transformer_engine'''					,			_lowercase ):
															convert_model(_lowercase					,			to_transformer_engine=_lowercase )

					if is_compiled:
										_A								= model
										_A								= compiled_model

					return model




def      __A					(     ):

					'''simple docstring'''







					PartialState().wait_for_everyone()




def      __A					(     _lowercase					,			_lowercase ):

					'''simple docstring'''







					if PartialState().distributed_type == DistributedType.TPU:
										xm.save(_lowercase					,			_lowercase )
					elif PartialState().local_process_index == 0:
										torch.save(_lowercase					,			_lowercase )




@contextmanager
def      __A					(     **_lowercase ):

					'''simple docstring'''







					for key, value in kwargs.items():
										_A								= str(_lowercase )

					yield

					for key in kwargs:
										if key.upper() in os.environ:
															del os.environ[key.upper()]




def      __A					(     _lowercase ):

					'''simple docstring'''







					if not hasattr(_lowercase					,			'''__qualname__''' ) and not hasattr(_lowercase					,			'''__name__''' ):
										_A								= getattr(_lowercase					,			'''__class__'''					,			_lowercase )
					if hasattr(_lowercase					,			'''__qualname__''' ):
										return obj.__qualname__
					if hasattr(_lowercase					,			'''__name__''' ):
										return obj.__name__
					return str(_lowercase )




def      __A					(     _lowercase					,			_lowercase ):

					'''simple docstring'''







					for key, value in source.items():
										if isinstance(_lowercase					,			_lowercase ):
															_A								= destination.setdefault(_lowercase					,			{} )
															merge_dicts(_lowercase					,			_lowercase )
										else:
															_A								= value

					return destination




def      __A					(     _lowercase = None ):

					'''simple docstring'''







					if port is None:
										_A								= 2_95_00
					with socket.socket(socket.AF_INET					,			socket.SOCK_STREAM ) as s:
										return s.connect_ex(('''localhost''', port) ) == 0











def      __A					(     _lowercase = 1_00_00_00 ):

					'''simple docstring'''







					_A								= 1
					_A								= 1
					_A								= {1: 1}

					for inputa in range(2					,			_lowercase ):
										_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())))



