





import copy
import os
from typing import Union

from ...configuration_utils import PretrainedConfig
from ...utils import logging


_lowerCamelCase :    int  							= logging.get_logger(__name__)

_lowerCamelCase :    Union[str, Any]  							= {
    '''google/pix2struct-textcaps-base''': (
        '''https://huggingface.co/google/pix2struct-textcaps-base/resolve/main/config.json'''
    ),
}


class 						lowerCamelCase       (__lowerCamelCase      ):







							"""simple docstring"""




							UpperCAmelCase_      						=   "pix2struct_text_model"
							UpperCAmelCase_      						=   ["past_key_values"]
							UpperCAmelCase_      						=   {
							    "hidden_size": "hidden_size",
							    "num_attention_heads": "num_heads",
							    "num_hidden_layers": "num_layers",
							}






							def __init__( self     :					Tuple,			_UpperCAmelCase     :					int=5_0_2_4_4,			_UpperCAmelCase     :					str=7_6_8,			_UpperCAmelCase     :					Any=6_4,			_UpperCAmelCase     :					Tuple=2_0_4_8,			_UpperCAmelCase     :					List[Any]=1_2,			_UpperCAmelCase     :					List[Any]=1_2,			_UpperCAmelCase     :					Dict=3_2,			_UpperCAmelCase     :					Dict=1_2_8,			_UpperCAmelCase     :					Dict=0.1,			_UpperCAmelCase     :					List[str]=1E-6,			_UpperCAmelCase     :					Optional[int]=1.0,			_UpperCAmelCase     :					int="gelu_new",			_UpperCAmelCase     :					str=0,			_UpperCAmelCase     :					Tuple=False,			_UpperCAmelCase     :					Dict=0,			_UpperCAmelCase     :					List[str]=1,			_UpperCAmelCase     :					Tuple=False,			_UpperCAmelCase     :					List[Any]=True,			**_UpperCAmelCase     :					Dict,			)				->			List[Any]:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__       :      int     =						vocab_size
														SCREAMING_SNAKE_CASE__       :      Optional[int]     =						hidden_size
														SCREAMING_SNAKE_CASE__       :      int     =						d_kv
														SCREAMING_SNAKE_CASE__       :      Tuple     =						d_ff
														SCREAMING_SNAKE_CASE__       :      Optional[int]     =						num_layers
														SCREAMING_SNAKE_CASE__       :      Dict     =						num_heads
														SCREAMING_SNAKE_CASE__       :      Dict     =						relative_attention_num_buckets
														SCREAMING_SNAKE_CASE__       :      Optional[int]     =						relative_attention_max_distance
														SCREAMING_SNAKE_CASE__       :      Optional[Any]     =						dropout_rate
														SCREAMING_SNAKE_CASE__       :      Dict     =						layer_norm_epsilon
														SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						initializer_factor
														SCREAMING_SNAKE_CASE__       :      Any     =						use_cache

														SCREAMING_SNAKE_CASE__       :      Dict     =						eos_token_id
														SCREAMING_SNAKE_CASE__       :      Any     =						decoder_start_token_id

														# for backwards compatibility
														SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						dense_act_fn

														super().__init__(
														    pad_token_id=_UpperCAmelCase,			eos_token_id=_UpperCAmelCase,			decoder_start_token_id=_UpperCAmelCase,			tie_word_embeddings=_UpperCAmelCase,			is_decoder=_UpperCAmelCase,			**_UpperCAmelCase,			)






							@classmethod
							def  A_     ( cls     :					Optional[Any],			_UpperCAmelCase     :					Union[str, os.PathLike],			**_UpperCAmelCase     :					Optional[Any]						)				->			"PretrainedConfig":





														"""simple docstring"""
														cls._set_token_in_kwargs(_UpperCAmelCase						)

														SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__       :      int     =						cls.get_config_dict(_UpperCAmelCase,			**_UpperCAmelCase						)

														# get the text config dict if we are loading from Pix2StructConfig
														if config_dict.get("model_type"						) == "pix2struct":
																					SCREAMING_SNAKE_CASE__       :      List[Any]     =						config_dict["text_config"]

														if "model_type" in config_dict and hasattr(cls,			"model_type"						) and config_dict["model_type"] != cls.model_type:
																					logger.warning(
																					    F'''You are using a model of type {config_dict["model_type"]} to instantiate a model of type '''
																					    F'''{cls.model_type}. This is not supported for all configurations of models and can yield errors.'''						)

														return cls.from_dict(_UpperCAmelCase,			**_UpperCAmelCase						)


class 						lowerCamelCase       (__lowerCamelCase      ):







							"""simple docstring"""




							UpperCAmelCase_      						=   "pix2struct_vision_model"






							def __init__( self     :					Optional[Any],			_UpperCAmelCase     :					Any=7_6_8,			_UpperCAmelCase     :					List[str]=7_6_8,			_UpperCAmelCase     :					Optional[int]=2_0_4_8,			_UpperCAmelCase     :					List[Any]=6_4,			_UpperCAmelCase     :					List[Any]=1_2,			_UpperCAmelCase     :					int=1_2,			_UpperCAmelCase     :					List[str]="gelu_new",			_UpperCAmelCase     :					Any=1E-6,			_UpperCAmelCase     :					str=0.0,			_UpperCAmelCase     :					List[str]=0.0,			_UpperCAmelCase     :					Dict=1E-10,			_UpperCAmelCase     :					int=1.0,			_UpperCAmelCase     :					Any=4_0_9_6,			_UpperCAmelCase     :					Any=3_2,			_UpperCAmelCase     :					List[str]=1_2_8,			**_UpperCAmelCase     :					str,			)				->			List[str]:





														"""simple docstring"""
														super().__init__(**_UpperCAmelCase						)

														SCREAMING_SNAKE_CASE__       :      Any     =						hidden_size
														SCREAMING_SNAKE_CASE__       :      Tuple     =						patch_embed_hidden_size
														SCREAMING_SNAKE_CASE__       :      str     =						d_ff
														SCREAMING_SNAKE_CASE__       :      Optional[int]     =						dropout_rate
														SCREAMING_SNAKE_CASE__       :      List[str]     =						num_hidden_layers
														SCREAMING_SNAKE_CASE__       :      List[Any]     =						num_attention_heads
														SCREAMING_SNAKE_CASE__       :      Optional[Any]     =						initializer_range
														SCREAMING_SNAKE_CASE__       :      List[str]     =						initializer_factor
														SCREAMING_SNAKE_CASE__       :      Dict     =						attention_dropout
														SCREAMING_SNAKE_CASE__       :      Any     =						layer_norm_eps
														SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						dense_act_fn
														SCREAMING_SNAKE_CASE__       :      Tuple     =						seq_len
														SCREAMING_SNAKE_CASE__       :      Any     =						relative_attention_num_buckets
														SCREAMING_SNAKE_CASE__       :      Tuple     =						relative_attention_max_distance
														SCREAMING_SNAKE_CASE__       :      List[Any]     =						d_kv






							@classmethod
							def  A_     ( cls     :					List[str],			_UpperCAmelCase     :					Union[str, os.PathLike],			**_UpperCAmelCase     :					Any						)				->			"PretrainedConfig":





														"""simple docstring"""
														cls._set_token_in_kwargs(_UpperCAmelCase						)

														SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__       :      List[Any]     =						cls.get_config_dict(_UpperCAmelCase,			**_UpperCAmelCase						)

														# get the vision config dict if we are loading from Pix2StructConfig
														if config_dict.get("model_type"						) == "pix2struct":
																					SCREAMING_SNAKE_CASE__       :      str     =						config_dict["vision_config"]

														if "model_type" in config_dict and hasattr(cls,			"model_type"						) and config_dict["model_type"] != cls.model_type:
																					logger.warning(
																					    F'''You are using a model of type {config_dict["model_type"]} to instantiate a model of type '''
																					    F'''{cls.model_type}. This is not supported for all configurations of models and can yield errors.'''						)

														return cls.from_dict(_UpperCAmelCase,			**_UpperCAmelCase						)


class 						lowerCamelCase       (__lowerCamelCase      ):







							"""simple docstring"""




							UpperCAmelCase_      						=   "pix2struct"
							UpperCAmelCase_      						=   True






							def __init__( self     :					Any,			_UpperCAmelCase     :					Union[str, Any]=None,			_UpperCAmelCase     :					List[Any]=None,			_UpperCAmelCase     :					List[Any]=1.0,			_UpperCAmelCase     :					Any=0.02,			_UpperCAmelCase     :					int=False,			_UpperCAmelCase     :					Any=False,			_UpperCAmelCase     :					Optional[Any]=True,			**_UpperCAmelCase     :					Union[str, Any],			)				->			Union[str, Any]:





														"""simple docstring"""
														super().__init__(tie_word_embeddings=_UpperCAmelCase,			is_encoder_decoder=_UpperCAmelCase,			**_UpperCAmelCase						)

														if text_config is None:
																					SCREAMING_SNAKE_CASE__       :      Any     =						{}
																					logger.info("text_config is None. Initializing the Pix2StructTextConfig with default values."						)

														if vision_config is None:
																					SCREAMING_SNAKE_CASE__       :      Optional[int]     =						{}
																					logger.info("vision_config is None. Initializing the Pix2StructVisionConfig with default values."						)

														SCREAMING_SNAKE_CASE__       :      Optional[int]     =						PixaStructTextConfig(**_UpperCAmelCase						)
														SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						PixaStructVisionConfig(**_UpperCAmelCase						)

														SCREAMING_SNAKE_CASE__       :      int     =						self.text_config.decoder_start_token_id
														SCREAMING_SNAKE_CASE__       :      List[Any]     =						self.text_config.pad_token_id
														SCREAMING_SNAKE_CASE__       :      List[Any]     =						self.text_config.eos_token_id

														SCREAMING_SNAKE_CASE__       :      List[str]     =						initializer_factor
														SCREAMING_SNAKE_CASE__       :      int     =						initializer_range

														SCREAMING_SNAKE_CASE__       :      List[str]     =						self.initializer_range
														SCREAMING_SNAKE_CASE__       :      str     =						self.initializer_range

														SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						is_vqa






							@classmethod
							def  A_     ( cls     :					str,			_UpperCAmelCase     :					PixaStructTextConfig,			_UpperCAmelCase     :					PixaStructVisionConfig,			**_UpperCAmelCase     :					Optional[int]						)				->			str:





														"""simple docstring"""
														return cls(text_config=text_config.to_dict(),			vision_config=vision_config.to_dict(),			**_UpperCAmelCase						)






							def  A_     ( self     :					Any						)				->			Any:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						copy.deepcopy(self.__dict__						)
														SCREAMING_SNAKE_CASE__       :      int     =						self.text_config.to_dict()
														SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						self.vision_config.to_dict()
														SCREAMING_SNAKE_CASE__       :      List[Any]     =						self.__class__.model_type
														return output













_lowerCamelCase :    dict[tuple[int, int, int], int]  							= {}




def _a (  SCREAMING_SNAKE_CASE__      :  int			,				SCREAMING_SNAKE_CASE__      :  int			,				SCREAMING_SNAKE_CASE__      :  int       )	->    int:

							'''simple docstring'''






							if late == 3 or absent == 2:
														return 0

							# if we have no days left, and have not failed any other rules,
							# we have a prize string
							if days == 0:
														return 1

							# No easy solution, so now we need to do the recursive calculation

							# First, check if the combination is already in the cache, and
							# if yes, return the stored value from there since we already
							# know the number of possible prize strings from this point on
							SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						(days, absent, late)
							if key in cache:
														return cache[key]

							# now we calculate the three possible ways that can unfold from
							# this point on, depending on our attendance today

							# 1) if we are late (but not absent), the "absent" counter stays as
							# it is, but the "late" counter increases by one
							SCREAMING_SNAKE_CASE__       :      Tuple     =						_calculate(days - 1			,				SCREAMING_SNAKE_CASE__			,				late + 1       )

							# 2) if we are absent, the "absent" counter increases by 1, and the
							# "late" counter resets to 0
							SCREAMING_SNAKE_CASE__       :      Dict     =						_calculate(days - 1			,				absent + 1			,				0       )

							# 3) if we are on time, this resets the "late" counter and keeps the
							# absent counter
							SCREAMING_SNAKE_CASE__       :      Any     =						_calculate(days - 1			,				SCREAMING_SNAKE_CASE__			,				0       )

							SCREAMING_SNAKE_CASE__       :      str     =						state_late + state_absent + state_ontime

							SCREAMING_SNAKE_CASE__       :      Optional[int]     =						prizestrings
							return prizestrings




def _a (  SCREAMING_SNAKE_CASE__      :  int = 30       )	->    int:

							'''simple docstring'''






							return _calculate(SCREAMING_SNAKE_CASE__			,				absent=0			,				late=0       )


if __name__ == "__main__":
		print(solution())






