





import unittest

from transformers import FunnelConfig, FunnelTokenizer, is_torch_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device

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


if is_torch_available():
     import torch

     from transformers import (
         MODEL_FOR_PRETRAINING_MAPPING,
         FunnelBaseModel,
         FunnelForMaskedLM,
         FunnelForMultipleChoice,
         FunnelForPreTraining,
         FunnelForQuestionAnswering,
         FunnelForSequenceClassification,
         FunnelForTokenClassification,
         FunnelModel,
     )







class 						_lowerCAmelCase:

  """simple docstring"""







  def __init__( self  ,    UpperCAmelCase  ,    UpperCAmelCase=13  ,    UpperCAmelCase=7  ,    UpperCAmelCase=True  ,    UpperCAmelCase=True  ,    UpperCAmelCase=True  ,    UpperCAmelCase=True  ,    UpperCAmelCase=99  ,    UpperCAmelCase=[1, 1, 2]  ,    UpperCAmelCase=1  ,    UpperCAmelCase=32  ,    UpperCAmelCase=4  ,    UpperCAmelCase=8  ,    UpperCAmelCase=37  ,    UpperCAmelCase="gelu_new"  ,    UpperCAmelCase=0.1  ,    UpperCAmelCase=0.1  ,    UpperCAmelCase=0.0  ,    UpperCAmelCase=5_12  ,    UpperCAmelCase=3  ,    UpperCAmelCase=0.02  ,    UpperCAmelCase=3  ,    UpperCAmelCase=4  ,    UpperCAmelCase=None  ,    UpperCAmelCase=False  ,    )-> Any:
     __A				 =       parent
     __A				 =       batch_size
     __A				 =       seq_length
     __A				 =       is_training
     __A				 =       use_input_mask
     __A				 =       use_token_type_ids
     __A				 =       use_labels
     __A				 =       vocab_size
     __A				 =       block_sizes
     __A				 =       num_decoder_layers
     __A				 =       d_model
     __A				 =       n_head
     __A				 =       d_head
     __A				 =       d_inner
     __A				 =       hidden_act
     __A				 =       hidden_dropout
     __A				 =       attention_dropout
     __A				 =       activation_dropout
     __A				 =       max_position_embeddings
     __A				 =       type_vocab_size
     __A				 =       2
     __A				 =       num_labels
     __A				 =       num_choices
     __A				 =       scope
     __A				 =       initializer_std

     # Used in the tests to check the size of the first attention layer
     __A				 =       n_head
     # Used in the tests to check the size of the first hidden state
     __A				 =       self.d_model
     # Used in the tests to check the number of output hidden states/attentions
     __A				 =       sum(self.block_sizes     ) + (0 if base else self.num_decoder_layers)
     # FunnelModel adds two hidden layers: input embeddings and the sum of the upsampled encoder hidden state with
     # the last hidden state of the first block (which is the first hidden state of the decoder).
     if not base:
        __A				 =       self.num_hidden_layers + 2

  def 		SCREAMING_SNAKE_CASE__	( self     )-> str:
     __A				 =       ids_tensor([self.batch_size, self.seq_length]  ,    self.vocab_size     )

     __A				 =       None
     if self.use_input_mask:
        __A				 =       ids_tensor([self.batch_size, self.seq_length]  ,    vocab_size=2     )

     __A				 =       None
     if self.use_token_type_ids:
        __A				 =       ids_tensor([self.batch_size, self.seq_length]  ,    self.type_vocab_size     )

     __A				 =       None
     __A				 =       None
     __A				 =       None
     if self.use_labels:
        __A				 =       ids_tensor([self.batch_size]  ,    self.type_sequence_label_size     )
        __A				 =       ids_tensor([self.batch_size, self.seq_length]  ,    self.num_labels     )
        __A				 =       ids_tensor([self.batch_size]  ,    self.num_choices     )
        __A				 =       ids_tensor([self.batch_size, self.seq_length]  ,    1     )

     __A				 =       self.get_config()

     return (
         config,
         input_ids,
         token_type_ids,
         input_mask,
         sequence_labels,
         token_labels,
         choice_labels,
         fake_token_labels,
     )

  def 		SCREAMING_SNAKE_CASE__	( self     )-> List[Any]:
     return FunnelConfig(
         vocab_size=self.vocab_size  ,    block_sizes=self.block_sizes  ,    num_decoder_layers=self.num_decoder_layers  ,    d_model=self.d_model  ,    n_head=self.n_head  ,    d_head=self.d_head  ,    d_inner=self.d_inner  ,    hidden_act=self.hidden_act  ,    hidden_dropout=self.hidden_dropout  ,    attention_dropout=self.attention_dropout  ,    activation_dropout=self.activation_dropout  ,    max_position_embeddings=self.max_position_embeddings  ,    type_vocab_size=self.type_vocab_size  ,    initializer_std=self.initializer_std  ,    )

  def 		SCREAMING_SNAKE_CASE__	( self  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    )-> Dict:
     __A				 =       FunnelModel(config=UpperCAmelCase     )
     model.to(UpperCAmelCase     )
     model.eval()
     __A				 =       model(UpperCAmelCase  ,    attention_mask=UpperCAmelCase  ,    token_type_ids=UpperCAmelCase     )
     __A				 =       model(UpperCAmelCase  ,    token_type_ids=UpperCAmelCase     )
     __A				 =       model(UpperCAmelCase     )
     self.parent.assertEqual(result.last_hidden_state.shape  ,    (self.batch_size, self.seq_length, self.d_model)     )

     __A				 =       False
     __A				 =       model(UpperCAmelCase     )
     self.parent.assertEqual(result.last_hidden_state.shape  ,    (self.batch_size, self.seq_length, self.d_model)     )

     __A				 =       False
     __A				 =       model(UpperCAmelCase     )
     self.parent.assertEqual(result.last_hidden_state.shape  ,    (self.batch_size, self.seq_length, self.d_model)     )

  def 		SCREAMING_SNAKE_CASE__	( self  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    )-> List[Any]:
     __A				 =       FunnelBaseModel(config=UpperCAmelCase     )
     model.to(UpperCAmelCase     )
     model.eval()
     __A				 =       model(UpperCAmelCase  ,    attention_mask=UpperCAmelCase  ,    token_type_ids=UpperCAmelCase     )
     __A				 =       model(UpperCAmelCase  ,    token_type_ids=UpperCAmelCase     )
     __A				 =       model(UpperCAmelCase     )
     self.parent.assertEqual(result.last_hidden_state.shape  ,    (self.batch_size, 2, self.d_model)     )

     __A				 =       False
     __A				 =       model(UpperCAmelCase     )
     self.parent.assertEqual(result.last_hidden_state.shape  ,    (self.batch_size, 3, self.d_model)     )

     __A				 =       False
     __A				 =       model(UpperCAmelCase     )
     self.parent.assertEqual(result.last_hidden_state.shape  ,    (self.batch_size, 2, self.d_model)     )

  def 		SCREAMING_SNAKE_CASE__	( self  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    )-> Any:
     __A				 =       self.num_labels
     __A				 =       FunnelForPreTraining(config=UpperCAmelCase     )
     model.to(UpperCAmelCase     )
     model.eval()
     __A				 =       model(UpperCAmelCase  ,    attention_mask=UpperCAmelCase  ,    token_type_ids=UpperCAmelCase  ,    labels=UpperCAmelCase     )
     self.parent.assertEqual(result.logits.shape  ,    (self.batch_size, self.seq_length)     )

  def 		SCREAMING_SNAKE_CASE__	( self  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    )-> List[str]:
     __A				 =       FunnelForMaskedLM(config=UpperCAmelCase     )
     model.to(UpperCAmelCase     )
     model.eval()
     __A				 =       model(UpperCAmelCase  ,    attention_mask=UpperCAmelCase  ,    token_type_ids=UpperCAmelCase  ,    labels=UpperCAmelCase     )
     self.parent.assertEqual(result.logits.shape  ,    (self.batch_size, self.seq_length, self.vocab_size)     )

  def 		SCREAMING_SNAKE_CASE__	( self  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    )-> List[str]:
     __A				 =       self.num_labels
     __A				 =       FunnelForSequenceClassification(UpperCAmelCase     )
     model.to(UpperCAmelCase     )
     model.eval()
     __A				 =       model(UpperCAmelCase  ,    attention_mask=UpperCAmelCase  ,    token_type_ids=UpperCAmelCase  ,    labels=UpperCAmelCase     )
     self.parent.assertEqual(result.logits.shape  ,    (self.batch_size, self.num_labels)     )

  def 		SCREAMING_SNAKE_CASE__	( self  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    )-> Optional[Any]:
     __A				 =       self.num_choices
     __A				 =       FunnelForMultipleChoice(config=UpperCAmelCase     )
     model.to(UpperCAmelCase     )
     model.eval()
     __A				 =       input_ids.unsqueeze(1     ).expand(-1  ,    self.num_choices  ,    -1     ).contiguous()
     __A				 =       token_type_ids.unsqueeze(1     ).expand(-1  ,    self.num_choices  ,    -1     ).contiguous()
     __A				 =       input_mask.unsqueeze(1     ).expand(-1  ,    self.num_choices  ,    -1     ).contiguous()
     __A				 =       model(
         UpperCAmelCase  ,    attention_mask=UpperCAmelCase  ,    token_type_ids=UpperCAmelCase  ,    labels=UpperCAmelCase  ,    )
     self.parent.assertEqual(result.logits.shape  ,    (self.batch_size, self.num_choices)     )

  def 		SCREAMING_SNAKE_CASE__	( self  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    )-> Any:
     __A				 =       self.num_labels
     __A				 =       FunnelForTokenClassification(config=UpperCAmelCase     )
     model.to(UpperCAmelCase     )
     model.eval()
     __A				 =       model(UpperCAmelCase  ,    attention_mask=UpperCAmelCase  ,    token_type_ids=UpperCAmelCase  ,    labels=UpperCAmelCase     )
     self.parent.assertEqual(result.logits.shape  ,    (self.batch_size, self.seq_length, self.num_labels)     )

  def 		SCREAMING_SNAKE_CASE__	( self  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    )-> List[str]:
     __A				 =       FunnelForQuestionAnswering(config=UpperCAmelCase     )
     model.to(UpperCAmelCase     )
     model.eval()
     __A				 =       model(
         UpperCAmelCase  ,    attention_mask=UpperCAmelCase  ,    token_type_ids=UpperCAmelCase  ,    start_positions=UpperCAmelCase  ,    end_positions=UpperCAmelCase  ,    )
     self.parent.assertEqual(result.start_logits.shape  ,    (self.batch_size, self.seq_length)     )
     self.parent.assertEqual(result.end_logits.shape  ,    (self.batch_size, self.seq_length)     )





  def 		SCREAMING_SNAKE_CASE__	( self     )-> Any:
     __A				 =       self.prepare_config_and_inputs()
     (
         (
         __A						
     ) ,						(
         __A						
     ) ,						(
         __A						
     ) ,						(
         __A						
     ) ,						(
         __A						
     ) ,						(
         __A						
     ) ,						(
         __A						
     ) ,						(
         __A						
     ) ,												
     )				 =       config_and_inputs
     __A				 =       {'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
     return config, inputs_dict







@require_torch
class 						_lowerCAmelCase(						A__		,   A__		,   unittest.TestCase):

  """simple docstring"""







  lowerCamelCase__      					=   False
  lowerCamelCase__      					=   False
  lowerCamelCase__      					=   (
      (
          FunnelModel,
          FunnelForMaskedLM,
          FunnelForPreTraining,
          FunnelForQuestionAnswering,
          FunnelForTokenClassification,
      )
      if is_torch_available()
      else ()
  )
  lowerCamelCase__      					=   (
      {
          '''feature-extraction''': (FunnelBaseModel, FunnelModel),
          '''fill-mask''': FunnelForMaskedLM,
          '''question-answering''': FunnelForQuestionAnswering,
          '''text-classification''': FunnelForSequenceClassification,
          '''token-classification''': FunnelForTokenClassification,
          '''zero-shot''': FunnelForSequenceClassification,
      }
      if is_torch_available()
      else {}
  )

  def 		SCREAMING_SNAKE_CASE__	( self  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase=False     )-> int:
     __A				 =       super()._prepare_for_class(UpperCAmelCase  ,    UpperCAmelCase  ,    return_labels=UpperCAmelCase     )

     if return_labels:
        if model_class in get_values(UpperCAmelCase     ):
           __A				 =       torch.zeros(
               (self.model_tester.batch_size, self.model_tester.seq_length)  ,    dtype=torch.long  ,    device=UpperCAmelCase     )
     return inputs_dict

  def 		SCREAMING_SNAKE_CASE__	( self     )-> Optional[int]:
     __A				 =       FunnelModelTester(self     )
     __A				 =       ConfigTester(self  ,    config_class=UpperCAmelCase     )

  def 		SCREAMING_SNAKE_CASE__	( self     )-> Optional[int]:
     self.config_tester.run_common_tests()

  def 		SCREAMING_SNAKE_CASE__	( self     )-> Union[str, Any]:
     __A				 =       self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_model(*UpperCAmelCase     )

  def 		SCREAMING_SNAKE_CASE__	( self     )-> str:
     __A				 =       self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_pretraining(*UpperCAmelCase     )

  def 		SCREAMING_SNAKE_CASE__	( self     )-> Optional[int]:
     __A				 =       self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_masked_lm(*UpperCAmelCase     )

  def 		SCREAMING_SNAKE_CASE__	( self     )-> Dict:
     __A				 =       self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_token_classification(*UpperCAmelCase     )

  def 		SCREAMING_SNAKE_CASE__	( self     )-> List[Any]:
     __A				 =       self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_question_answering(*UpperCAmelCase     )





  def 		SCREAMING_SNAKE_CASE__	( self  ,    UpperCAmelCase     )-> Optional[Any]:
     if hasattr(UpperCAmelCase  ,    '''weight'''     ) and module.weight is not None:
        module.weight.data.fill_(3     )
     if hasattr(UpperCAmelCase  ,    '''bias'''     ) and module.bias is not None:
        module.bias.data.fill_(3     )

     for param in ["r_w_bias", "r_r_bias", "r_kernel", "r_s_bias", "seg_embed"]:
        if hasattr(UpperCAmelCase  ,    UpperCAmelCase     ) and getattr(UpperCAmelCase  ,    UpperCAmelCase     ) is not None:
           __A				 =       getattr(UpperCAmelCase  ,    UpperCAmelCase     )
           weight.data.fill_(3     )







@require_torch
class 						_lowerCAmelCase(						A__		,   unittest.TestCase):

  """simple docstring"""







  lowerCamelCase__      					=   False
  lowerCamelCase__      					=   False
  lowerCamelCase__      					=   (
      (FunnelBaseModel, FunnelForMultipleChoice, FunnelForSequenceClassification) if is_torch_available() else ()
  )

  def 		SCREAMING_SNAKE_CASE__	( self     )-> Optional[int]:
     __A				 =       FunnelModelTester(self  ,    base=UpperCAmelCase     )
     __A				 =       ConfigTester(self  ,    config_class=UpperCAmelCase     )

  def 		SCREAMING_SNAKE_CASE__	( self     )-> Optional[int]:
     self.config_tester.run_common_tests()

  def 		SCREAMING_SNAKE_CASE__	( self     )-> str:
     __A				 =       self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_base_model(*UpperCAmelCase     )

  def 		SCREAMING_SNAKE_CASE__	( self     )-> List[str]:
     __A				 =       self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_sequence_classification(*UpperCAmelCase     )

  def 		SCREAMING_SNAKE_CASE__	( self     )-> List[Any]:
     __A				 =       self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_multiple_choice(*UpperCAmelCase     )

  def 		SCREAMING_SNAKE_CASE__	( self     )-> Any:
     __A ,						__A				 =       self.model_tester.prepare_config_and_inputs_for_common()
     __A				 =       True

     for model_class in self.all_model_classes:
        if model_class.__name__ == "FunnelBaseModel":
           continue
        __A				 =       model_class(UpperCAmelCase     )
        model.to(UpperCAmelCase     )
        model.train()
        __A				 =       self._prepare_for_class(UpperCAmelCase  ,    UpperCAmelCase  ,    return_labels=UpperCAmelCase     )
        __A				 =       model(**UpperCAmelCase     ).loss
        loss.backward()





  def 		SCREAMING_SNAKE_CASE__	( self  ,    UpperCAmelCase     )-> int:
     if hasattr(UpperCAmelCase  ,    '''weight'''     ) and module.weight is not None:
        module.weight.data.fill_(3     )
     if hasattr(UpperCAmelCase  ,    '''bias'''     ) and module.bias is not None:
        module.bias.data.fill_(3     )

     for param in ["r_w_bias", "r_r_bias", "r_kernel", "r_s_bias", "seg_embed"]:
        if hasattr(UpperCAmelCase  ,    UpperCAmelCase     ) and getattr(UpperCAmelCase  ,    UpperCAmelCase     ) is not None:
           __A				 =       getattr(UpperCAmelCase  ,    UpperCAmelCase     )
           weight.data.fill_(3     )







@require_torch
@require_sentencepiece
@require_tokenizers
class 						_lowerCAmelCase(						unittest.TestCase):

  """simple docstring"""







  def 		SCREAMING_SNAKE_CASE__	( self     )-> Union[str, Any]:
     __A				 =       13
     __A				 =       7
     __A				 =       torch.arange(0  ,    batch_size * sequence_length     ).long().reshape(UpperCAmelCase  ,    UpperCAmelCase     )
     __A				 =       [0, 1, 2, 3, 4, 5, 6, 4, 1, 3, 5, 0, 1]
     __A				 =       torch.tensor([[2] + [0] * a + [1] * (sequence_length - a - 1) for a in lengths]     )

     __A				 =       FunnelModel.from_pretrained('''sgugger/funnel-random-tiny'''     )
     __A				 =       model(UpperCAmelCase  ,    token_type_ids=UpperCAmelCase     )[0].abs()

     __A				 =       torch.tensor(2344.8352     )
     __A				 =       torch.tensor(0.8052     )
     self.assertTrue(torch.allclose(output.sum()  ,    UpperCAmelCase  ,    atol=1e-4     )     )
     self.assertTrue(torch.allclose(output.mean()  ,    UpperCAmelCase  ,    atol=1e-4     )     )

     __A				 =       torch.tensor([[1] * 7, [1] * 4 + [0] * 3] * 6 + [[0, 1, 1, 0, 0, 1, 1]]     )
     __A				 =       model(UpperCAmelCase  ,    attention_mask=UpperCAmelCase  ,    token_type_ids=UpperCAmelCase     )[0].abs()

     __A				 =       torch.tensor(2343.8425     )
     __A				 =       torch.tensor(0.8049     )
     self.assertTrue(torch.allclose(output.sum()  ,    UpperCAmelCase  ,    atol=1e-4     )     )
     self.assertTrue(torch.allclose(output.mean()  ,    UpperCAmelCase  ,    atol=1e-4     )     )





  @slow
  def 		SCREAMING_SNAKE_CASE__	( self     )-> Optional[int]:
     __A				 =       FunnelTokenizer.from_pretrained('''huggingface/funnel-small'''     )
     __A				 =       FunnelModel.from_pretrained('''huggingface/funnel-small'''     )
     __A				 =       tokenizer('''Hello! I am the Funnel Transformer model.'''  ,    return_tensors='''pt'''     )
     __A				 =       model(**UpperCAmelCase     )[0]

     __A				 =       torch.tensor(235.7246     )
     __A				 =       torch.tensor(0.0256     )
     self.assertTrue(torch.allclose(output.sum()  ,    UpperCAmelCase  ,    atol=1e-4     )     )
     self.assertTrue(torch.allclose(output.mean()  ,    UpperCAmelCase  ,    atol=1e-4     )     )








def 				__UpperCamelCase  (		snake_case = 1_0_0     )  ->						int:


   '''simple docstring'''







   __A				 =       [[0 for _ in range(snake_case     )] for _ in range(m + 1     )]
   for i in range(m + 1     ):
      __A				 =       1

   for n in range(m + 1     ):
      for k in range(1    ,	snake_case     ):
         memo[n][k] += memo[n][k - 1]
         if n > k:
            memo[n][k] += memo[n - k - 1][k]

   return memo[m][m - 1] - 1


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

