






import gc
import inspect
import unittest

import torch
from parameterized import parameterized

from diffusers import PriorTransformer
from diffusers.utils import floats_tensor, slow, torch_all_close, torch_device
from diffusers.utils.testing_utils import enable_full_determinism

from .test_modeling_common import ModelTesterMixin


enable_full_determinism()





class 						SCREAMING_SNAKE_CASE				( snake_case  ,	unittest.TestCase					):





							"""simple docstring"""

							A_						  =					PriorTransformer
							A_						  =					"hidden_states"

							@property
							def       __A (  self:   List[str]   )    ->				Dict:
												_A								= 4
												_A								= 8
												_A								= 7

												_A								= floats_tensor((batch_size, embedding_dim)   ).to(__A   )

												_A								= floats_tensor((batch_size, embedding_dim)   ).to(__A   )
												_A								= floats_tensor((batch_size, num_embeddings, embedding_dim)   ).to(__A   )

												return {
												    "hidden_states": hidden_states,
												    "timestep": 2,
												    "proj_embedding": proj_embedding,
												    "encoder_hidden_states": encoder_hidden_states,
												}

							def       __A (  self:   Union[str, Any]		,     __A:   List[Any]=0   )    ->				str:
												torch.manual_seed(__A   )
												_A								= 4
												_A								= 8
												_A								= 7

												_A								= torch.randn((batch_size, embedding_dim)   ).to(__A   )

												_A								= torch.randn((batch_size, embedding_dim)   ).to(__A   )
												_A								= torch.randn((batch_size, num_embeddings, embedding_dim)   ).to(__A   )

												return {
												    "hidden_states": hidden_states,
												    "timestep": 2,
												    "proj_embedding": proj_embedding,
												    "encoder_hidden_states": encoder_hidden_states,
												}

							@property
							def       __A (  self:   Dict   )    ->				int:
												return (4, 8)

							@property
							def       __A (  self:   Any   )    ->				Dict:
												return (4, 8)

							def       __A (  self:   List[Any]   )    ->				List[str]:
												_A								= {
												    '''num_attention_heads''': 2,
												    '''attention_head_dim''': 4,
												    '''num_layers''': 2,
												    '''embedding_dim''': 8,
												    '''num_embeddings''': 7,
												    '''additional_embeddings''': 4,
												}
												_A								= self.dummy_input
												return init_dict, inputs_dict

							def       __A (  self:   Optional[Any]   )    ->				str:
												_A							,_A								= PriorTransformer.from_pretrained(
												    '''hf-internal-testing/prior-dummy'''		,     output_loading_info=__A   )
												self.assertIsNotNone(__A   )
												self.assertEqual(len(loading_info['''missing_keys''']   )		,     0   )

												model.to(__A   )
												_A								= model(**self.dummy_input   )[0]

												assert hidden_states is not None, "Make sure output is not None"

							def       __A (  self:   Tuple   )    ->				List[Any]:
												_A							,_A								= self.prepare_init_args_and_inputs_for_common()

												_A								= self.model_class(**__A   )
												_A								= inspect.signature(model.forward   )
												# signature.parameters is an OrderedDict => so arg_names order is deterministic
												_A								= [*signature.parameters.keys()]

												_A								= ['''hidden_states''', '''timestep''']
												self.assertListEqual(arg_names[:2]		,     __A   )



							def       __A (  self:   Optional[Any]   )    ->				int:
												_A								= PriorTransformer.from_pretrained('''hf-internal-testing/prior-dummy'''   )
												_A								= model.to(__A   )

												if hasattr(__A		,     '''set_default_attn_processor'''   ):
																	model.set_default_attn_processor()

												_A								= self.get_dummy_seed_input()

												with torch.no_grad():
																	_A								= model(**__A   )[0]

												_A								= output[0, :5].flatten().cpu()
												print(__A   )

												# Since the VAE Gaussian prior's generator is seeded on the appropriate device,
												# the expected output slices are not the same for CPU and GPU.
												_A								= torch.tensor([-1.3_436, -0.2_870, 0.7_538, 0.4_368, -0.0_239]   )
												self.assertTrue(torch_all_close(__A		,     __A		,     rtol=1e-2   )   )





@slow
class 						SCREAMING_SNAKE_CASE				( unittest.TestCase					):





							"""simple docstring"""

							def       __A (  self:   int		,     __A:   Optional[Any]=1		,     __A:   List[Any]=7_68		,     __A:   List[str]=77		,     __A:   List[Any]=0   )    ->				Any:
												torch.manual_seed(__A   )
												_A								= batch_size
												_A								= embedding_dim
												_A								= num_embeddings

												_A								= torch.randn((batch_size, embedding_dim)   ).to(__A   )

												_A								= torch.randn((batch_size, embedding_dim)   ).to(__A   )
												_A								= torch.randn((batch_size, num_embeddings, embedding_dim)   ).to(__A   )

												return {
												    "hidden_states": hidden_states,
												    "timestep": 2,
												    "proj_embedding": proj_embedding,
												    "encoder_hidden_states": encoder_hidden_states,
												}

							def       __A (  self:   Optional[Any]   )    ->				Any:
												# clean up the VRAM after each test
												super().tearDown()
												gc.collect()
												torch.cuda.empty_cache()



							@parameterized.expand(
							    [
							        # fmt: off
							        [13, [-0.5_861,  0.1_283, -0.0_931,  0.0_882,  0.4_476,  0.1_329, -0.0_498,  0.0_640]],
							        [37, [-0.4_913,  0.0_110, -0.0_483,  0.0_541,  0.4_954, -0.0_170,  0.0_354,  0.1_651]],
							        # fmt: on
							    ]   )
							def       __A (  self:   Any		,     __A:   Tuple		,     __A:   int   )    ->				Dict:
												_A								= PriorTransformer.from_pretrained('''kandinsky-community/kandinsky-2-1-prior'''		,     subfolder='''prior'''   )
												model.to(__A   )
												_A								= self.get_dummy_seed_input(seed=__A   )

												with torch.no_grad():
																	_A								= model(**__A   )[0]

												assert list(sample.shape   ) == [1, 7_68]

												_A								= sample[0, :8].flatten().cpu()
												print(__A   )
												_A								= torch.tensor(__A   )

												assert torch_all_close(__A		,     __A		,     atol=1e-3   )












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())))



