



import multiprocessing
import os
from typing import BinaryIO, Optional, Union

import fsspec

from .. import Dataset, Features, NamedSplit, config
from ..formatting import query_table
from ..packaged_modules.json.json import Json
from ..utils import logging
from ..utils.typing import NestedDataStructureLike, PathLike
from .abc import AbstractDatasetReader



class 						UpperCAmelCase_					( a):







							def __init__(     self,    __a,    __a = None,    __a = None,    __a = None,    __a = False,    __a = False,    __a = None,    __a = None,    **__a,    ):

														'''simple docstring'''

														super().__init__(
														    __a,    split=__a,    features=__a,    cache_dir=__a,    keep_in_memory=__a,    streaming=__a,    num_proc=__a,    **__a,    )
														_lowerCAmelCase  :							List[Any]				     =					field
														_lowerCAmelCase  :							Tuple				     =					path_or_paths if isinstance(__a,    __a) else {self.split: path_or_paths}
														_lowerCAmelCase  :							str				     =					Json(
														    cache_dir=__a,    data_files=__a,    features=__a,    field=__a,    **__a,    )







							def      snake_case__   (     self):

														'''simple docstring'''

														if self.streaming:
																					_lowerCAmelCase  :							List[Any]				     =					self.builder.as_streaming_dataset(split=self.split)
														# Build regular (map-style) dataset
														else:
																					_lowerCAmelCase  :							Optional[Any]				     =					None
																					_lowerCAmelCase  :							str				     =					None
																					_lowerCAmelCase  :							Optional[int]				     =					None
																					_lowerCAmelCase  :							Union[str, Any]				     =					None

																					self.builder.download_and_prepare(
																					    download_config=__a,    download_mode=__a,    verification_mode=__a,    base_path=__a,    num_proc=self.num_proc,    )
																					_lowerCAmelCase  :							Optional[Any]				     =					self.builder.as_dataset(
																					    split=self.split,    verification_mode=__a,    in_memory=self.keep_in_memory)
														return dataset



class 						UpperCAmelCase_					:







							def __init__(     self,    __a,    __a,    __a = None,    __a = None,    **__a,    ):

														'''simple docstring'''

														if num_proc is not None and num_proc <= 0:
																					raise ValueError(f"num_proc {num_proc} must be an integer > 0.")

														_lowerCAmelCase  :							int				     =					dataset
														_lowerCAmelCase  :							Dict				     =					path_or_buf
														_lowerCAmelCase  :							Any				     =					batch_size if batch_size else config.DEFAULT_MAX_BATCH_SIZE
														_lowerCAmelCase  :							int				     =					num_proc
														_lowerCAmelCase  :							Dict				     =					"utf-8"
														_lowerCAmelCase  :							List[str]				     =					to_json_kwargs







							def      snake_case__   (     self):

														'''simple docstring'''

														_lowerCAmelCase  :							Optional[int]				     =					self.to_json_kwargs.pop("path_or_buf",    __a)
														_lowerCAmelCase  :							List[Any]				     =					self.to_json_kwargs.pop("orient",    "records")
														_lowerCAmelCase  :							int				     =					self.to_json_kwargs.pop("lines",    True if orient == "records" else False)
														_lowerCAmelCase  :							List[Any]				     =					self.to_json_kwargs.pop("index",    False if orient in ["split", "table"] else True)
														_lowerCAmelCase  :							Dict				     =					self.to_json_kwargs.pop("compression",    __a)

														if compression not in [None, "infer", "gzip", "bz2", "xz"]:
																					raise NotImplementedError(f"`datasets` currently does not support {compression} compression")

														if isinstance(self.path_or_buf,    (str, bytes, os.PathLike)):
																					with fsspec.open(self.path_or_buf,    "wb",    compression=__a) as buffer:
																												_lowerCAmelCase  :							Dict				     =					self._write(file_obj=__a,    orient=__a,    lines=__a,    index=__a,    **self.to_json_kwargs)
														else:
																					if compression:
																												raise NotImplementedError(
																												    f"The compression parameter is not supported when writing to a buffer, but compression={compression}"
																												    " was passed. Please provide a local path instead.")
																					_lowerCAmelCase  :							Tuple				     =					self._write(
																					    file_obj=self.path_or_buf,    orient=__a,    lines=__a,    index=__a,    **self.to_json_kwargs)
														return written







							def      snake_case__   (     self,    __a):

														'''simple docstring'''

														_lowerCAmelCase     ,					_lowerCAmelCase     ,					_lowerCAmelCase     ,					_lowerCAmelCase     ,					_lowerCAmelCase  :							Optional[int]				     =					args

														_lowerCAmelCase  :							Optional[int]				     =					query_table(
														    table=self.dataset.data,    key=slice(__a,    offset + self.batch_size),    indices=self.dataset._indices,    )
														_lowerCAmelCase  :							str				     =					batch.to_pandas().to_json(
														    path_or_buf=__a,    orient=__a,    lines=__a,    index=__a,    **__a)
														if not json_str.endswith("\n"):
																					json_str += "\n"
														return json_str.encode(self.encoding)







							def      snake_case__   (     self,    __a,    __a,    __a,    __a,    **__a,    ):

														'''simple docstring'''

														_lowerCAmelCase  :							Optional[int]				     =					0

														if self.num_proc is None or self.num_proc == 1:
																					for offset in logging.tqdm(
																					    range(0,    len(self.dataset),    self.batch_size),    unit="ba",    disable=not logging.is_progress_bar_enabled(),    desc="Creating json from Arrow format",    ):
																												_lowerCAmelCase  :							Any				     =					self._batch_json((offset, orient, lines, index, to_json_kwargs))
																												written += file_obj.write(__a)
														else:
																					_lowerCAmelCase     ,					_lowerCAmelCase  :							Tuple				     =					len(self.dataset), self.batch_size
																					with multiprocessing.Pool(self.num_proc) as pool:
																												for json_str in logging.tqdm(
																												    pool.imap(
																												        self._batch_json,    [(offset, orient, lines, index, to_json_kwargs) for offset in range(0,    __a,    __a)],    ),    total=(num_rows // batch_size) + 1 if num_rows % batch_size else num_rows // batch_size,    unit="ba",    disable=not logging.is_progress_bar_enabled(),    desc="Creating json from Arrow format",    ):
																																			written += file_obj.write(__a)

														return written





def        A       (      _lowerCamelCase = 1_000_000						):





							'''simple docstring'''




							_lowerCAmelCase  :							Any				     =					1
							_lowerCAmelCase  :							Optional[Any]				     =					1
							_lowerCAmelCase  :							List[str]				     =					{1: 1}

							for inputa in range(2       ,				_lowerCamelCase						):
														_lowerCAmelCase  :							int				     =					0
														_lowerCAmelCase  :							Any				     =					inputa

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

														if inputa not in counters:
																					_lowerCAmelCase  :							Tuple				     =					counter

														if counter > pre_counter:
																					_lowerCAmelCase  :							Union[str, Any]				     =					inputa
																					_lowerCAmelCase  :							Union[str, Any]				     =					counter
							return largest_number


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