





"""simple docstring"""




import inspect
import unittest

import requests

from transformers import MgpstrConfig
from transformers.testing_utils import require_torch, require_vision, slow, torch_device
from transformers.utils import is_torch_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
						import torch
						from torch import nn

						from transformers import MgpstrForSceneTextRecognition


if is_vision_available():
						from PIL import Image

						from transformers import MgpstrProcessor




class 					_a		:






				def __init__(					self						:       str,					lowerCAmelCase__						:       List[str],					lowerCAmelCase__						:       List[str]=False,					lowerCAmelCase__						:       int=1_3,					lowerCAmelCase__						:       str=(3_2, 1_2_8),					lowerCAmelCase__						:       List[Any]=4,					lowerCAmelCase__						:       Any=3,					lowerCAmelCase__						:       Union[str, Any]=2_7,					lowerCAmelCase__						:       List[Any]=3_8,					lowerCAmelCase__						:       Union[str, Any]=9_9,					lowerCAmelCase__						:       Optional[Any]=9_9,					lowerCAmelCase__						:       Any=3_2,					lowerCAmelCase__						:       Dict=5,					lowerCAmelCase__						:       Optional[int]=4,					lowerCAmelCase__						:       Optional[int]=4.0,					lowerCAmelCase__						:       int=2_5_7,					lowerCAmelCase__						:       Any=None,					)      -> str:




										'''simple docstring'''



										_UpperCamelCase     :   Optional[int]      =       parent
										_UpperCamelCase     :   str      =       is_training
										_UpperCamelCase     :   Union[str, Any]      =       batch_size
										_UpperCamelCase     :   int      =       image_size
										_UpperCamelCase     :   List[str]      =       patch_size
										_UpperCamelCase     :   List[str]      =       num_channels
										_UpperCamelCase     :   str      =       max_token_length
										_UpperCamelCase     :   Union[str, Any]      =       num_character_labels
										_UpperCamelCase     :   int      =       num_bpe_labels
										_UpperCamelCase     :   Optional[int]      =       num_wordpiece_labels
										_UpperCamelCase     :   Optional[Any]      =       hidden_size
										_UpperCamelCase     :   List[str]      =       num_hidden_layers
										_UpperCamelCase     :   int      =       num_attention_heads
										_UpperCamelCase     :   str      =       mlp_ratio
										_UpperCamelCase     :   Any      =       patch_embeds_hidden_size
										_UpperCamelCase     :   Optional[int]      =       output_hidden_states






				def 							snake_case      (					self						:       List[Any]				)      -> Any:




										'''simple docstring'''



										_UpperCamelCase     :   Union[str, Any]      =       floats_tensor([self.batch_size, self.num_channels, self.image_size[0], self.image_size[1]]				)
										_UpperCamelCase     :   Union[str, Any]      =       self.get_config()
										return config, pixel_values






				def 							snake_case      (					self						:       str				)      -> Optional[int]:




										'''simple docstring'''



										return MgpstrConfig(
										    image_size=self.image_size,					patch_size=self.patch_size,					num_channels=self.num_channels,					max_token_length=self.max_token_length,					num_character_labels=self.num_character_labels,					num_bpe_labels=self.num_bpe_labels,					num_wordpiece_labels=self.num_wordpiece_labels,					hidden_size=self.hidden_size,					num_hidden_layers=self.num_hidden_layers,					num_attention_heads=self.num_attention_heads,					mlp_ratio=self.mlp_ratio,					output_hidden_states=self.output_hidden_states,					)






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




										'''simple docstring'''



										_UpperCamelCase     :   Union[str, Any]      =       MgpstrForSceneTextRecognition(lowerCAmelCase__				)
										model.to(lowerCAmelCase__				)
										model.eval()
										with torch.no_grad():
																_UpperCamelCase     :   Union[str, Any]      =       model(lowerCAmelCase__				)
										self.parent.assertEqual(
										    generated_ids[0][0].shape,					(self.batch_size, self.max_token_length, self.num_character_labels)				)






				def 							snake_case      (					self						:       Union[str, Any]				)      -> Tuple:




										'''simple docstring'''



										_UpperCamelCase     :   Optional[int]      =       self.prepare_config_and_inputs()
										_UpperCamelCase  ,				_UpperCamelCase     :   Union[str, Any]      =       config_and_inputs
										_UpperCamelCase     :   Optional[Any]      =       {'''pixel_values''': pixel_values}
										return config, inputs_dict




@require_torch
class 					_a		( _lowerCAmelCase      ,							_lowerCAmelCase      ,							unittest.TestCase							):
				UpperCamelCase								=       (MgpstrForSceneTextRecognition,) if is_torch_available() else ()
				UpperCamelCase								=       {'''feature-extraction''': MgpstrForSceneTextRecognition} if is_torch_available() else {}
				UpperCamelCase								=       False

				UpperCamelCase								=       False
				UpperCamelCase								=       False
				UpperCamelCase								=       False
				UpperCamelCase								=       False






				def 							snake_case      (					self						:       Union[str, Any]				)      -> Optional[int]:




										'''simple docstring'''



										_UpperCamelCase     :   Optional[Any]      =       MgpstrModelTester(self				)
										_UpperCamelCase     :   Union[str, Any]      =       ConfigTester(self,					config_class=lowerCAmelCase__,					has_text_modality=lowerCAmelCase__				)






				def 							snake_case      (					self						:       Any				)      -> Tuple:




										'''simple docstring'''



										self.config_tester.run_common_tests()






				def 							snake_case      (					self						:       str				)      -> List[str]:




										'''simple docstring'''



										_UpperCamelCase     :   Optional[int]      =       self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_model(*lowerCAmelCase__				)






				@unittest.skip(reason='''MgpstrModel does not use inputs_embeds'''				)
				def 							snake_case      (					self						:       int				)      -> List[Any]:




										'''simple docstring'''



										pass






				def 							snake_case      (					self						:       int				)      -> Union[str, Any]:




										'''simple docstring'''



										_UpperCamelCase  ,				_UpperCamelCase     :   Union[str, Any]      =       self.model_tester.prepare_config_and_inputs_for_common()

										for model_class in self.all_model_classes:
																_UpperCamelCase     :   Optional[int]      =       model_class(lowerCAmelCase__				)
																self.assertIsInstance(model.get_input_embeddings(),					(nn.Module)				)
																_UpperCamelCase     :   Optional[int]      =       model.get_output_embeddings()
																self.assertTrue(x is None or isinstance(lowerCAmelCase__,					nn.Linear				)				)






				def 							snake_case      (					self						:       Optional[Any]				)      -> Tuple:




										'''simple docstring'''



										_UpperCamelCase  ,				_UpperCamelCase     :   List[Any]      =       self.model_tester.prepare_config_and_inputs_for_common()

										for model_class in self.all_model_classes:
																_UpperCamelCase     :   List[Any]      =       model_class(lowerCAmelCase__				)
																_UpperCamelCase     :   str      =       inspect.signature(model.forward				)
																# signature.parameters is an OrderedDict => so arg_names order is deterministic
																_UpperCamelCase     :   Dict      =       [*signature.parameters.keys()]

																_UpperCamelCase     :   List[Any]      =       ['''pixel_values''']
																self.assertListEqual(arg_names[:1],					lowerCAmelCase__				)






				@unittest.skip(reason='''MgpstrModel does not support feedforward chunking'''				)
				def 							snake_case      (					self						:       Optional[int]				)      -> Any:




										'''simple docstring'''



										pass






				def 							snake_case      (					self						:       Dict				)      -> List[Any]:




										'''simple docstring'''



										_UpperCamelCase  ,				_UpperCamelCase     :   Union[str, Any]      =       self.model_tester.prepare_config_and_inputs_for_common()

										for model_class in self.all_model_classes:
																if not model_class.supports_gradient_checkpointing:
																						continue

																_UpperCamelCase     :   Optional[Any]      =       True
																_UpperCamelCase     :   Union[str, Any]      =       model_class(lowerCAmelCase__				)
																self.assertTrue(model.is_gradient_checkpointing				)






				def 							snake_case      (					self						:       Any				)      -> List[Any]:




										'''simple docstring'''



										def check_hidden_states_output(lowerCAmelCase__						:       Union[str, Any],					lowerCAmelCase__						:       Any,					lowerCAmelCase__						:       List[str]				):
																_UpperCamelCase     :   Optional[int]      =       model_class(lowerCAmelCase__				)
																model.to(lowerCAmelCase__				)
																model.eval()

																with torch.no_grad():
																						_UpperCamelCase     :   Optional[int]      =       model(**self._prepare_for_class(lowerCAmelCase__,					lowerCAmelCase__				)				)

																_UpperCamelCase     :   str      =       outputs.hidden_states

																_UpperCamelCase     :   Tuple      =       getattr(
																    self.model_tester,					'''expected_num_hidden_layers''',					self.model_tester.num_hidden_layers + 1				)
																self.assertEqual(len(lowerCAmelCase__				),					lowerCAmelCase__				)

																self.assertListEqual(
																    list(hidden_states[0].shape[-2:]				),					[self.model_tester.patch_embeds_hidden_size, self.model_tester.hidden_size],					)

										_UpperCamelCase  ,				_UpperCamelCase     :   Any      =       self.model_tester.prepare_config_and_inputs_for_common()

										for model_class in self.all_model_classes:
																_UpperCamelCase     :   Any      =       True
																check_hidden_states_output(lowerCAmelCase__,					lowerCAmelCase__,					lowerCAmelCase__				)

																# check that output_hidden_states also work using config
																del inputs_dict["output_hidden_states"]
																_UpperCamelCase     :   Dict      =       True

																check_hidden_states_output(lowerCAmelCase__,					lowerCAmelCase__,					lowerCAmelCase__				)






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




										'''simple docstring'''



										_UpperCamelCase  ,				_UpperCamelCase     :   Optional[int]      =       self.model_tester.prepare_config_and_inputs_for_common()

										_UpperCamelCase     :   Union[str, Any]      =       _config_zero_init(lowerCAmelCase__				)
										for model_class in self.all_model_classes:
																_UpperCamelCase     :   Union[str, Any]      =       model_class(config=lowerCAmelCase__				)
																for name, param in model.named_parameters():
																						if isinstance(lowerCAmelCase__,					(nn.Linear, nn.Convad, nn.LayerNorm)				):
																												if param.requires_grad:
																																		self.assertIn(
																																		    ((param.data.mean() * 1e9).round() / 1e9).item(),					[0.0, 1.0],					msg=f"""Parameter {name} of model {model_class} seems not properly initialized""",					)






				@unittest.skip(reason='''Retain_grad is tested in individual model tests'''				)
				def 							snake_case      (					self						:       int				)      -> Tuple:




										'''simple docstring'''



										pass





def 			a_							(				):
						_UpperCamelCase     :   Any      =       '''https://i.postimg.cc/ZKwLg2Gw/367-14.png'''
						_UpperCamelCase     :   Optional[int]      =       Image.open(requests.get(_lowercase			,		stream=_lowercase  ).raw  ).convert('''RGB'''  )
						return im






@require_vision
@require_torch
class 					_a		( unittest.TestCase							):






				@slow
				def 							snake_case      (					self						:       List[str]				)      -> List[Any]:




										'''simple docstring'''



										_UpperCamelCase     :   List[Any]      =       '''alibaba-damo/mgp-str-base'''
										_UpperCamelCase     :   Optional[int]      =       MgpstrForSceneTextRecognition.from_pretrained(lowerCAmelCase__				).to(lowerCAmelCase__				)
										_UpperCamelCase     :   Union[str, Any]      =       MgpstrProcessor.from_pretrained(lowerCAmelCase__				)

										_UpperCamelCase     :   Any      =       prepare_img()
										_UpperCamelCase     :   List[str]      =       processor(images=lowerCAmelCase__,					return_tensors='''pt'''				).pixel_values.to(lowerCAmelCase__				)

										# forward pass
										with torch.no_grad():
																_UpperCamelCase     :   List[str]      =       model(lowerCAmelCase__				)

										# verify the logits
										self.assertEqual(outputs.logits[0].shape,					torch.Size((1, 2_7, 3_8)				)				)

										_UpperCamelCase     :   List[Any]      =       processor.batch_decode(outputs.logits				)
										_UpperCamelCase     :   List[str]      =       '''ticket'''

										self.assertEqual(out_strs['''generated_text'''][0],					lowerCAmelCase__				)

										_UpperCamelCase     :   int      =       torch.tensor(
										    [[[-39.5_397, -44.4_024, -36.1_844], [-61.4_709, -63.8_639, -58.3_454], [-74.0_225, -68.5_494, -71.2_164]]],					device=lowerCAmelCase__,					)

										self.assertTrue(torch.allclose(outputs.logits[0][:, 1:4, 1:4],					lowerCAmelCase__,					atol=1e-4				)				)










'''simple docstring'''






def 				_lowerCamelCase(	UpperCamelCase__     :			int = 1_000		)		->	int:
    A							:							Optional[Any]				=    [0, 3, 3, 5, 4, 4, 3, 5, 5, 4, 3, 6, 6, 8, 8, 7, 7, 9, 8, 8]
    # number of letters in twenty, thirty, ..., ninety (0 for numbers less than
    # 20 due to inconsistency in teens)
    A							:							Tuple				=    [0, 0, 6, 6, 5, 5, 5, 7, 6, 6]

    A							:							str				=    0

    for i in range(1     ,							n + 1		):
        if i < 1_000:
            if i >= 100:
                # add number of letters for "n hundred"
                count += ones_counts[i // 100] + 7

                if i % 100 != 0:
                    # add number of letters for "and" if number is not multiple
                    # of 100
                    count += 3

            if 0 < i % 100 < 20:
                # add number of letters for one, two, three, ..., nineteen
                # (could be combined with below if not for inconsistency in
                # teens)
                count += ones_counts[i % 100]
            else:
                # add number of letters for twenty, twenty one, ..., ninety
                # nine
                count += ones_counts[i % 10]
                count += tens_counts[(i % 100 - i % 10) // 10]
        else:
            count += ones_counts[i // 1_000] + 8
    return count


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