



'''simple docstring'''

import collections
import inspect
import unittest

from transformers import DonutSwinConfig
from transformers.testing_utils import require_torch, slow, torch_device
from transformers.utils import is_torch_available

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


if is_torch_available():
		import torch
		from torch import nn

		from transformers import DonutSwinModel
		from transformers.models.donut.modeling_donut_swin import DONUT_SWIN_PRETRAINED_MODEL_ARCHIVE_LIST



class 		lowerCamelCase__   :




					'''simple docstring'''



					def __init__(	self					:						List[str]  ,	UpperCamelCase_					:						str  ,	UpperCamelCase_					:						Tuple=13  ,	UpperCamelCase_					:						Optional[int]=32  ,	UpperCamelCase_					:						Dict=2  ,	UpperCamelCase_					:						Union[str, Any]=3  ,	UpperCamelCase_					:						Dict=16  ,	UpperCamelCase_					:						List[Any]=[1, 2, 1]  ,	UpperCamelCase_					:						int=[2, 2, 4]  ,	UpperCamelCase_					:						List[str]=2  ,	UpperCamelCase_					:						Tuple=2.0  ,	UpperCamelCase_					:						Optional[Any]=True  ,	UpperCamelCase_					:						Any=0.0  ,	UpperCamelCase_					:						Optional[Any]=0.0  ,	UpperCamelCase_					:						Any=0.1  ,	UpperCamelCase_					:						Dict="gelu"  ,	UpperCamelCase_					:						Optional[int]=False  ,	UpperCamelCase_					:						Tuple=True  ,	UpperCamelCase_					:						Tuple=0.02  ,	UpperCamelCase_					:						Union[str, Any]=1E-5  ,	UpperCamelCase_					:						Dict=True  ,	UpperCamelCase_					:						List[str]=None  ,	UpperCamelCase_					:						Optional[int]=True  ,	UpperCamelCase_					:						List[str]=10  ,	UpperCamelCase_					:						str=8  ,	)	->							Union[str, Any]:



						'''simple docstring'''





						_lowercase       :							str  	=		parent
						_lowercase       :							Tuple  	=		batch_size
						_lowercase       :							str  	=		image_size
						_lowercase       :							Union[str, Any]  	=		patch_size
						_lowercase       :							List[Any]  	=		num_channels
						_lowercase       :							List[str]  	=		embed_dim
						_lowercase       :							List[str]  	=		depths
						_lowercase       :							Optional[int]  	=		num_heads
						_lowercase       :							Tuple  	=		window_size
						_lowercase       :							Optional[Any]  	=		mlp_ratio
						_lowercase       :							Dict  	=		qkv_bias
						_lowercase       :							Union[str, Any]  	=		hidden_dropout_prob
						_lowercase       :							Dict  	=		attention_probs_dropout_prob
						_lowercase       :							int  	=		drop_path_rate
						_lowercase       :							Union[str, Any]  	=		hidden_act
						_lowercase       :							Optional[Any]  	=		use_absolute_embeddings
						_lowercase       :							Union[str, Any]  	=		patch_norm
						_lowercase       :							int  	=		layer_norm_eps
						_lowercase       :							Dict  	=		initializer_range
						_lowercase       :							Union[str, Any]  	=		is_training
						_lowercase       :							Optional[int]  	=		scope
						_lowercase       :							List[Any]  	=		use_labels
						_lowercase       :							Optional[Any]  	=		type_sequence_label_size
						_lowercase       :							str  	=		encoder_stride




					def     __UpperCAmelCase  (	self					:						Optional[Any]       )	->							List[str]:



						'''simple docstring'''





						_lowercase       :							List[Any]  	=		floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]       )

						_lowercase       :							Tuple  	=		None
						if self.use_labels:
							_lowercase       :							List[str]  	=		ids_tensor([self.batch_size]  ,	self.type_sequence_label_size       )

						_lowercase       :							int  	=		self.get_config()

						return config, pixel_values, labels




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



						'''simple docstring'''





						return DonutSwinConfig(
						    image_size=self.image_size  ,	patch_size=self.patch_size  ,	num_channels=self.num_channels  ,	embed_dim=self.embed_dim  ,	depths=self.depths  ,	num_heads=self.num_heads  ,	window_size=self.window_size  ,	mlp_ratio=self.mlp_ratio  ,	qkv_bias=self.qkv_bias  ,	hidden_dropout_prob=self.hidden_dropout_prob  ,	attention_probs_dropout_prob=self.attention_probs_dropout_prob  ,	drop_path_rate=self.drop_path_rate  ,	hidden_act=self.hidden_act  ,	use_absolute_embeddings=self.use_absolute_embeddings  ,	path_norm=self.patch_norm  ,	layer_norm_eps=self.layer_norm_eps  ,	initializer_range=self.initializer_range  ,	encoder_stride=self.encoder_stride  ,	)




					def     __UpperCAmelCase  (	self					:						int  ,	UpperCamelCase_					:						Optional[Any]  ,	UpperCamelCase_					:						Any  ,	UpperCamelCase_					:						Tuple       )	->							Dict:



						'''simple docstring'''





						_lowercase       :							Any  	=		DonutSwinModel(config=UpperCamelCase_       )
						model.to(UpperCamelCase_       )
						model.eval()
						_lowercase       :							Tuple  	=		model(UpperCamelCase_       )

						_lowercase       :							Union[str, Any]  	=		((config.image_size // config.patch_size) ** 2) // (4 ** (len(config.depths       ) - 1))
						_lowercase       :							str  	=		int(config.embed_dim * 2 ** (len(config.depths       ) - 1)       )

						self.parent.assertEqual(result.last_hidden_state.shape  ,	(self.batch_size, expected_seq_len, expected_dim)       )




					def     __UpperCAmelCase  (	self					:						List[Any]       )	->							Optional[int]:



						'''simple docstring'''





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






@require_torch
class 		lowerCamelCase__   (    A						, A						, unittest.TestCase  ):




					'''simple docstring'''



					A_         =    (DonutSwinModel,) if is_torch_available() else ()
					A_         =    {"""feature-extraction""": DonutSwinModel} if is_torch_available() else {}
					A_         =    True

					A_         =    False
					A_         =    False
					A_         =    False




					def     __UpperCAmelCase  (	self					:						Dict       )	->							Union[str, Any]:



						'''simple docstring'''





						_lowercase       :							Dict  	=		DonutSwinModelTester(self       )
						_lowercase       :							Dict  	=		ConfigTester(self  ,	config_class=UpperCamelCase_  ,	embed_dim=37       )




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



						'''simple docstring'''





						self.create_and_test_config_common_properties()
						self.config_tester.create_and_test_config_to_json_string()
						self.config_tester.create_and_test_config_to_json_file()
						self.config_tester.create_and_test_config_from_and_save_pretrained()
						self.config_tester.create_and_test_config_with_num_labels()
						self.config_tester.check_config_can_be_init_without_params()
						self.config_tester.check_config_arguments_init()




					def     __UpperCAmelCase  (	self					:						List[Any]       )	->							str:



						'''simple docstring'''





						return




					def     __UpperCAmelCase  (	self					:						int       )	->							Tuple:



						'''simple docstring'''





						_lowercase       :							Tuple  	=		self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_model(*UpperCamelCase_       )




					def     __UpperCAmelCase  (	self					:						List[Any]       )	->							Optional[Any]:



						'''simple docstring'''





						pass




					def     __UpperCAmelCase  (	self					:						Optional[Any]       )	->							List[Any]:



						'''simple docstring'''





						_lowercase	,     _lowercase       :							int  	=		self.model_tester.prepare_config_and_inputs_for_common()

						for model_class in self.all_model_classes:
							_lowercase       :							Optional[Any]  	=		model_class(UpperCamelCase_       )
							self.assertIsInstance(model.get_input_embeddings()  ,	(nn.Module)       )
							_lowercase       :							str  	=		model.get_output_embeddings()
							self.assertTrue(x is None or isinstance(UpperCamelCase_  ,	nn.Linear       )       )




					def     __UpperCAmelCase  (	self					:						Dict       )	->							Optional[Any]:



						'''simple docstring'''





						_lowercase	,     _lowercase       :							Optional[Any]  	=		self.model_tester.prepare_config_and_inputs_for_common()

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

							_lowercase       :							Dict  	=		['pixel_values']
							self.assertListEqual(arg_names[:1]  ,	UpperCamelCase_       )




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



						'''simple docstring'''





						_lowercase	,     _lowercase       :							Union[str, Any]  	=		self.model_tester.prepare_config_and_inputs_for_common()
						_lowercase       :							Dict  	=		True

						for model_class in self.all_model_classes:
							_lowercase       :							List[str]  	=		True
							_lowercase       :							Dict  	=		False
							_lowercase       :							List[str]  	=		True
							_lowercase       :							List[str]  	=		model_class(UpperCamelCase_       )
							model.to(UpperCamelCase_       )
							model.eval()
							with torch.no_grad():
								_lowercase       :							List[Any]  	=		model(**self._prepare_for_class(UpperCamelCase_  ,	UpperCamelCase_       )       )
							_lowercase       :							Tuple  	=		outputs.attentions
							_lowercase       :							List[Any]  	=		len(self.model_tester.depths       )
							self.assertEqual(len(UpperCamelCase_       )  ,	UpperCamelCase_       )

							# check that output_attentions also work using config
							del inputs_dict["output_attentions"]
							_lowercase       :							Tuple  	=		True
							_lowercase       :							Dict  	=		config.window_size**2
							_lowercase       :							Tuple  	=		model_class(UpperCamelCase_       )
							model.to(UpperCamelCase_       )
							model.eval()
							with torch.no_grad():
								_lowercase       :							Optional[int]  	=		model(**self._prepare_for_class(UpperCamelCase_  ,	UpperCamelCase_       )       )
							_lowercase       :							Optional[int]  	=		outputs.attentions
							self.assertEqual(len(UpperCamelCase_       )  ,	UpperCamelCase_       )

							self.assertListEqual(
							    list(attentions[0].shape[-3:]       )  ,	[self.model_tester.num_heads[0], window_size_squared, window_size_squared]  ,	)
							_lowercase       :							Dict  	=		len(UpperCamelCase_       )

							# Check attention is always last and order is fine
							_lowercase       :							int  	=		True
							_lowercase       :							Any  	=		True
							_lowercase       :							Optional[Any]  	=		model_class(UpperCamelCase_       )
							model.to(UpperCamelCase_       )
							model.eval()
							with torch.no_grad():
								_lowercase       :							str  	=		model(**self._prepare_for_class(UpperCamelCase_  ,	UpperCamelCase_       )       )

							if hasattr(self.model_tester  ,	'num_hidden_states_types'       ):
								_lowercase       :							Dict  	=		self.model_tester.num_hidden_states_types
							else:
								# also another +1 for reshaped_hidden_states
								_lowercase       :							Tuple  	=		2
							self.assertEqual(out_len + added_hidden_states  ,	len(UpperCamelCase_       )       )

							_lowercase       :							Dict  	=		outputs.attentions

							self.assertEqual(len(UpperCamelCase_       )  ,	UpperCamelCase_       )

							self.assertListEqual(
							    list(self_attentions[0].shape[-3:]       )  ,	[self.model_tester.num_heads[0], window_size_squared, window_size_squared]  ,	)




					def     __UpperCAmelCase  (	self					:						int  ,	UpperCamelCase_					:						Tuple  ,	UpperCamelCase_					:						List[str]  ,	UpperCamelCase_					:						Tuple  ,	UpperCamelCase_					:						Optional[int]       )	->							Optional[Any]:



						'''simple docstring'''





						_lowercase       :							List[Any]  	=		model_class(UpperCamelCase_       )
						model.to(UpperCamelCase_       )
						model.eval()

						with torch.no_grad():
							_lowercase       :							List[str]  	=		model(**self._prepare_for_class(UpperCamelCase_  ,	UpperCamelCase_       )       )

						_lowercase       :							Dict  	=		outputs.hidden_states

						_lowercase       :							Any  	=		getattr(
						    self.model_tester  ,	'expected_num_hidden_layers'  ,	len(self.model_tester.depths       ) + 1       )
						self.assertEqual(len(UpperCamelCase_       )  ,	UpperCamelCase_       )

						# DonutSwin has a different seq_length
						_lowercase       :							Dict  	=		(
						    config.patch_size
						    if isinstance(config.patch_size  ,	collections.abc.Iterable       )
						    else (config.patch_size, config.patch_size)
						)

						_lowercase       :							Union[str, Any]  	=		(image_size[1] // patch_size[1]) * (image_size[0] // patch_size[0])

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

						_lowercase       :							int  	=		outputs.reshaped_hidden_states
						self.assertEqual(len(UpperCamelCase_       )  ,	UpperCamelCase_       )

						_lowercase	,     _lowercase	,     _lowercase	,     _lowercase       :							Optional[int]  	=		reshaped_hidden_states[0].shape
						_lowercase       :							Optional[Any]  	=		(
						    reshaped_hidden_states[0].view(UpperCamelCase_  ,	UpperCamelCase_  ,	height * width       ).permute(0  ,	2  ,	1       )
						)
						self.assertListEqual(
						    list(reshaped_hidden_states.shape[-2:]       )  ,	[num_patches, self.model_tester.embed_dim]  ,	)




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



						'''simple docstring'''





						_lowercase	,     _lowercase       :							str  	=		self.model_tester.prepare_config_and_inputs_for_common()

						_lowercase       :							Optional[int]  	=		(
						    self.model_tester.image_size
						    if isinstance(self.model_tester.image_size  ,	collections.abc.Iterable       )
						    else (self.model_tester.image_size, self.model_tester.image_size)
						)

						for model_class in self.all_model_classes:
							_lowercase       :							Optional[Any]  	=		True
							self.check_hidden_states_output(UpperCamelCase_  ,	UpperCamelCase_  ,	UpperCamelCase_  ,	UpperCamelCase_       )

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

							self.check_hidden_states_output(UpperCamelCase_  ,	UpperCamelCase_  ,	UpperCamelCase_  ,	UpperCamelCase_       )




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



						'''simple docstring'''





						_lowercase	,     _lowercase       :							List[Any]  	=		self.model_tester.prepare_config_and_inputs_for_common()
						_lowercase       :							List[str]  	=		3

						_lowercase       :							Tuple  	=		(
						    self.model_tester.image_size
						    if isinstance(self.model_tester.image_size  ,	collections.abc.Iterable       )
						    else (self.model_tester.image_size, self.model_tester.image_size)
						)
						_lowercase       :							Union[str, Any]  	=		(
						    config.patch_size
						    if isinstance(config.patch_size  ,	collections.abc.Iterable       )
						    else (config.patch_size, config.patch_size)
						)

						_lowercase       :							int  	=		image_size[0] + patch_size[0] - (image_size[0] % patch_size[0])
						_lowercase       :							Tuple  	=		image_size[1] + patch_size[1] - (image_size[1] % patch_size[1])

						for model_class in self.all_model_classes:
							_lowercase       :							List[str]  	=		True
							self.check_hidden_states_output(UpperCamelCase_  ,	UpperCamelCase_  ,	UpperCamelCase_  ,	(padded_height, padded_width)       )

							# check that output_hidden_states also work using config
							del inputs_dict["output_hidden_states"]
							_lowercase       :							Optional[Any]  	=		True
							self.check_hidden_states_output(UpperCamelCase_  ,	UpperCamelCase_  ,	UpperCamelCase_  ,	(padded_height, padded_width)       )




					@slow
					def     __UpperCAmelCase  (	self					:						Optional[Any]       )	->							Tuple:



						'''simple docstring'''





						for model_name in DONUT_SWIN_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
							_lowercase       :							List[str]  	=		DonutSwinModel.from_pretrained(UpperCamelCase_       )
							self.assertIsNotNone(UpperCamelCase_       )




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



						'''simple docstring'''





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

						_lowercase       :							Dict  	=		_config_zero_init(UpperCamelCase_       )
						for model_class in self.all_model_classes:
							_lowercase       :							List[Any]  	=		model_class(config=UpperCamelCase_       )
							for name, param in model.named_parameters():
								if "embeddings" not in name and 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'''  ,	)





'''simple docstring'''

def     __UpperCamelCase					(				_lowercase = 1000       )			->      int:
	_lowercase       :							Optional[int]  	=		[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)
	_lowercase       :							List[Any]  	=		[0, 0, 6, 6, 5, 5, 5, 7, 6, 6]

	_lowercase       :							Any  	=		0

	for i in range(1,					n + 1       ):
		if i < 1000:
			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 // 1000] + 8
	return count


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