



import tempfile
import unittest

import numpy as np
from huggingface_hub import HfFolder, delete_repo
from requests.exceptions import HTTPError

from transformers import BertConfig, is_flax_available
from transformers.testing_utils import TOKEN, USER, is_staging_test, require_flax


if is_flax_available():
							import os

							from flax.core.frozen_dict import unfreeze
							from flax.traverse_util import flatten_dict

							from transformers import FlaxBertModel

							__snake_case    :		List[Any]  ='0.12'  # assumed parallelism: 8



@require_flax
@is_staging_test
class 	lowerCamelCase__      (							unittest.TestCase):




		'''simple docstring'''



		@classmethod
		def 		lowerCAmelCase__				(cls			)					->      str:

						"""simple docstring"""






						lowerCAmelCase__					:    Dict												=					TOKEN
						HfFolder.save_token(_UpperCAmelCase			)



		@classmethod
		def 		lowerCAmelCase__				(cls			)					->      List[str]:

						"""simple docstring"""






						try:
										delete_repo(token=cls._token		,repo_id='''test-model-flax'''			)
						except HTTPError:
										pass

						try:
										delete_repo(token=cls._token		,repo_id='''valid_org/test-model-flax-org'''			)
						except HTTPError:
										pass



		def 		lowerCAmelCase__				(self			)					->      Tuple:

						"""simple docstring"""






						lowerCAmelCase__					:    Union[str, Any]												=					BertConfig(
						    vocab_size=99		,hidden_size=32		,num_hidden_layers=5		,num_attention_heads=4		,intermediate_size=37			)
						lowerCAmelCase__					:    Optional[int]												=					FlaxBertModel(_UpperCAmelCase			)
						model.push_to_hub('''test-model-flax'''		,use_auth_token=self._token			)

						lowerCAmelCase__					:    str												=					FlaxBertModel.from_pretrained(f"""{USER}/test-model-flax"""			)

						lowerCAmelCase__					:    str												=					flatten_dict(unfreeze(model.params			)			)
						lowerCAmelCase__					:    List[Any]												=					flatten_dict(unfreeze(new_model.params			)			)

						for key in base_params.keys():
										lowerCAmelCase__					:    Dict												=					(base_params[key] - new_params[key]).sum().item()
										self.assertLessEqual(_UpperCAmelCase		,1e-3		,msg=f"""{key} not identical"""			)

						# Reset repo
						delete_repo(token=self._token		,repo_id='''test-model-flax'''			)

						# Push to hub via save_pretrained
						with tempfile.TemporaryDirectory() as tmp_dir:
										model.save_pretrained(_UpperCAmelCase		,repo_id='''test-model-flax'''		,push_to_hub=_UpperCAmelCase		,use_auth_token=self._token			)

						lowerCAmelCase__					:    Optional[Any]												=					FlaxBertModel.from_pretrained(f"""{USER}/test-model-flax"""			)

						lowerCAmelCase__					:    Any												=					flatten_dict(unfreeze(model.params			)			)
						lowerCAmelCase__					:    Union[str, Any]												=					flatten_dict(unfreeze(new_model.params			)			)

						for key in base_params.keys():
										lowerCAmelCase__					:    Tuple												=					(base_params[key] - new_params[key]).sum().item()
										self.assertLessEqual(_UpperCAmelCase		,1e-3		,msg=f"""{key} not identical"""			)



		def 		lowerCAmelCase__				(self			)					->      int:

						"""simple docstring"""






						lowerCAmelCase__					:    Any												=					BertConfig(
						    vocab_size=99		,hidden_size=32		,num_hidden_layers=5		,num_attention_heads=4		,intermediate_size=37			)
						lowerCAmelCase__					:    Optional[Any]												=					FlaxBertModel(_UpperCAmelCase			)
						model.push_to_hub('''valid_org/test-model-flax-org'''		,use_auth_token=self._token			)

						lowerCAmelCase__					:    List[Any]												=					FlaxBertModel.from_pretrained('''valid_org/test-model-flax-org'''			)

						lowerCAmelCase__					:    Optional[int]												=					flatten_dict(unfreeze(model.params			)			)
						lowerCAmelCase__					:    Dict												=					flatten_dict(unfreeze(new_model.params			)			)

						for key in base_params.keys():
										lowerCAmelCase__					:    Any												=					(base_params[key] - new_params[key]).sum().item()
										self.assertLessEqual(_UpperCAmelCase		,1e-3		,msg=f"""{key} not identical"""			)

						# Reset repo
						delete_repo(token=self._token		,repo_id='''valid_org/test-model-flax-org'''			)

						# Push to hub via save_pretrained
						with tempfile.TemporaryDirectory() as tmp_dir:
										model.save_pretrained(
										    _UpperCAmelCase		,repo_id='''valid_org/test-model-flax-org'''		,push_to_hub=_UpperCAmelCase		,use_auth_token=self._token			)

						lowerCAmelCase__					:    int												=					FlaxBertModel.from_pretrained('''valid_org/test-model-flax-org'''			)

						lowerCAmelCase__					:    Any												=					flatten_dict(unfreeze(model.params			)			)
						lowerCAmelCase__					:    Any												=					flatten_dict(unfreeze(new_model.params			)			)

						for key in base_params.keys():
										lowerCAmelCase__					:    Any												=					(base_params[key] - new_params[key]).sum().item()
										self.assertLessEqual(_UpperCAmelCase		,1e-3		,msg=f"""{key} not identical"""			)






def      lowerCAmelCase__		(   lowerCamelCase_		:		Tuple	,lowerCamelCase_		:		Optional[Any]):





				'''simple docstring'''

				lowerCAmelCase__					:    Dict												=					True
				lowerCAmelCase__					:    Tuple												=					flatten_dict(modela.params)
				lowerCAmelCase__					:    int												=					flatten_dict(modela.params)
				for key in flat_params_a.keys():
								if np.sum(np.abs(flat_params_a[key] - flat_params_a[key])) > 1E-4:
												lowerCAmelCase__					:    List[str]												=					False

				return models_are_equal



@require_flax
class 	lowerCamelCase__      (							unittest.TestCase):




		'''simple docstring'''



		def 		lowerCAmelCase__				(self			)					->      Optional[int]:

						"""simple docstring"""






						lowerCAmelCase__					:    List[Any]												=					BertConfig.from_pretrained('''hf-internal-testing/tiny-bert-flax-only'''			)
						lowerCAmelCase__					:    Tuple												=					FlaxBertModel(_UpperCAmelCase			)

						lowerCAmelCase__					:    List[Any]												=					'''bert'''
						with tempfile.TemporaryDirectory() as tmp_dir:
										model.save_pretrained(os.path.join(_UpperCAmelCase		,_UpperCAmelCase			)			)

										with self.assertRaises(_UpperCAmelCase			):
														lowerCAmelCase__					:    Union[str, Any]												=					FlaxBertModel.from_pretrained(_UpperCAmelCase			)

										lowerCAmelCase__					:    Any												=					FlaxBertModel.from_pretrained(_UpperCAmelCase		,subfolder=_UpperCAmelCase			)

						self.assertTrue(check_models_equal(_UpperCAmelCase		,_UpperCAmelCase			)			)



		def 		lowerCAmelCase__				(self			)					->      Any:

						"""simple docstring"""






						lowerCAmelCase__					:    Any												=					BertConfig.from_pretrained('''hf-internal-testing/tiny-bert-flax-only'''			)
						lowerCAmelCase__					:    Optional[int]												=					FlaxBertModel(_UpperCAmelCase			)

						lowerCAmelCase__					:    int												=					'''bert'''
						with tempfile.TemporaryDirectory() as tmp_dir:
										model.save_pretrained(os.path.join(_UpperCAmelCase		,_UpperCAmelCase			)		,max_shard_size='''10KB'''			)

										with self.assertRaises(_UpperCAmelCase			):
														lowerCAmelCase__					:    Any												=					FlaxBertModel.from_pretrained(_UpperCAmelCase			)

										lowerCAmelCase__					:    Dict												=					FlaxBertModel.from_pretrained(_UpperCAmelCase		,subfolder=_UpperCAmelCase			)

						self.assertTrue(check_models_equal(_UpperCAmelCase		,_UpperCAmelCase			)			)



		def 		lowerCAmelCase__				(self			)					->      Dict:

						"""simple docstring"""






						lowerCAmelCase__					:    str												=					'''bert'''
						lowerCAmelCase__					:    int												=					'''hf-internal-testing/tiny-random-bert-subfolder'''

						with self.assertRaises(_UpperCAmelCase			):
										lowerCAmelCase__					:    int												=					FlaxBertModel.from_pretrained(_UpperCAmelCase			)

						lowerCAmelCase__					:    str												=					FlaxBertModel.from_pretrained(_UpperCAmelCase		,subfolder=_UpperCAmelCase			)

						self.assertIsNotNone(_UpperCAmelCase			)



		def 		lowerCAmelCase__				(self			)					->      Optional[Any]:

						"""simple docstring"""






						lowerCAmelCase__					:    Any												=					'''bert'''
						lowerCAmelCase__					:    Tuple												=					'''hf-internal-testing/tiny-random-bert-sharded-subfolder'''
						with self.assertRaises(_UpperCAmelCase			):
										lowerCAmelCase__					:    Optional[Any]												=					FlaxBertModel.from_pretrained(_UpperCAmelCase			)

						lowerCAmelCase__					:    str												=					FlaxBertModel.from_pretrained(_UpperCAmelCase		,subfolder=_UpperCAmelCase			)

						self.assertIsNotNone(_UpperCAmelCase			)






def      lowerCAmelCase__		(   lowerCamelCase_		:		int = 1000):





				'''simple docstring'''

				lowerCAmelCase__						,		lowerCAmelCase__					:    int												=					1, 1
				lowerCAmelCase__					:    Any												=					2
				while True:
								lowerCAmelCase__					:    Optional[Any]												=					0
								lowerCAmelCase__					:    Any												=					fa + fa
								lowerCAmelCase__						,		lowerCAmelCase__					:    Optional[Any]												=					fa, f
								index += 1
								for _ in str(lowerCamelCase_):
												i += 1
								if i == n:
												break
				return index


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

