


import unittest

from transformers import MobileBertConfig, 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, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
       import torch

       from transformers import (
           MODEL_FOR_PRETRAINING_MAPPING,
           MobileBertForMaskedLM,
           MobileBertForMultipleChoice,
           MobileBertForNextSentencePrediction,
           MobileBertForPreTraining,
           MobileBertForQuestionAnswering,
           MobileBertForSequenceClassification,
           MobileBertForTokenClassification,
           MobileBertModel,
       )





class  lowerCAmelCase__:






    '''simple docstring'''





    def __init__(	self				:   int       ,   __snake_case				:   int       ,   __snake_case				:   Dict=13       ,   __snake_case				:   str=7       ,   __snake_case				:   Dict=True       ,   __snake_case				:   Optional[int]=True       ,   __snake_case				:   int=True       ,   __snake_case				:   List[Any]=True       ,   __snake_case				:   Dict=99       ,   __snake_case				:   str=64       ,   __snake_case				:   Optional[int]=32       ,   __snake_case				:   List[Any]=5       ,   __snake_case				:   Optional[Any]=4       ,   __snake_case				:   List[str]=37       ,   __snake_case				:   Optional[Any]="gelu"       ,   __snake_case				:   Optional[int]=0.1       ,   __snake_case				:   int=0.1       ,   __snake_case				:   str=512       ,   __snake_case				:   str=16       ,   __snake_case				:   Tuple=2       ,   __snake_case				:   Any=0.02       ,   __snake_case				:   Tuple=3       ,   __snake_case				:   str=4       ,   __snake_case				:   Optional[int]=None       ,   ):





       '''simple docstring'''
       UpperCAmelCase_							:      Optional[int]						=   parent
       UpperCAmelCase_							:      List[Any]						=   batch_size
       UpperCAmelCase_							:      str						=   seq_length
       UpperCAmelCase_							:      Tuple						=   is_training
       UpperCAmelCase_							:      Union[str, Any]						=   use_input_mask
       UpperCAmelCase_							:      Optional[int]						=   use_token_type_ids
       UpperCAmelCase_							:      int						=   use_labels
       UpperCAmelCase_							:      Tuple						=   vocab_size
       UpperCAmelCase_							:      List[str]						=   hidden_size
       UpperCAmelCase_							:      Any						=   embedding_size
       UpperCAmelCase_							:      Any						=   num_hidden_layers
       UpperCAmelCase_							:      Union[str, Any]						=   num_attention_heads
       UpperCAmelCase_							:      Optional[int]						=   intermediate_size
       UpperCAmelCase_							:      List[Any]						=   hidden_act
       UpperCAmelCase_							:      int						=   hidden_dropout_prob
       UpperCAmelCase_							:      Tuple						=   attention_probs_dropout_prob
       UpperCAmelCase_							:      Dict						=   max_position_embeddings
       UpperCAmelCase_							:      List[Any]						=   type_vocab_size
       UpperCAmelCase_							:      Optional[Any]						=   type_sequence_label_size
       UpperCAmelCase_							:      Any						=   initializer_range
       UpperCAmelCase_							:      Union[str, Any]						=   num_labels
       UpperCAmelCase_							:      Dict						=   num_choices
       UpperCAmelCase_							:      List[Any]						=   scope





    def 					_lowerCamelCase (	self				:   Optional[Any]	):





       '''simple docstring'''
       UpperCAmelCase_							:      Any						=   ids_tensor([self.batch_size, self.seq_length]       ,   self.vocab_size	)

       UpperCAmelCase_							:      Optional[int]						=   None
       if self.use_input_mask:
          UpperCAmelCase_							:      Any						=   random_attention_mask([self.batch_size, self.seq_length]	)

       UpperCAmelCase_							:      Tuple						=   None
       if self.use_token_type_ids:
          UpperCAmelCase_							:      Union[str, Any]						=   ids_tensor([self.batch_size, self.seq_length]       ,   self.type_vocab_size	)

       UpperCAmelCase_							:      Any						=   None
       UpperCAmelCase_							:      str						=   None
       UpperCAmelCase_							:      List[str]						=   None
       if self.use_labels:
          UpperCAmelCase_							:      Optional[Any]						=   ids_tensor([self.batch_size]       ,   self.type_sequence_label_size	)
          UpperCAmelCase_							:      Any						=   ids_tensor([self.batch_size, self.seq_length]       ,   self.num_labels	)
          UpperCAmelCase_							:      str						=   ids_tensor([self.batch_size]       ,   self.num_choices	)

       UpperCAmelCase_							:      List[Any]						=   self.get_config()

       return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels





    def 					_lowerCamelCase (	self				:   Tuple	):





       '''simple docstring'''
       return MobileBertConfig(
           vocab_size=self.vocab_size       ,   hidden_size=self.hidden_size       ,   num_hidden_layers=self.num_hidden_layers       ,   num_attention_heads=self.num_attention_heads       ,   intermediate_size=self.intermediate_size       ,   embedding_size=self.embedding_size       ,   hidden_act=self.hidden_act       ,   hidden_dropout_prob=self.hidden_dropout_prob       ,   attention_probs_dropout_prob=self.attention_probs_dropout_prob       ,   max_position_embeddings=self.max_position_embeddings       ,   type_vocab_size=self.type_vocab_size       ,   is_decoder=UpperCamelCase__       ,   initializer_range=self.initializer_range       ,   )





    def 					_lowerCamelCase (	self				:   List[Any]       ,   __snake_case				:   int       ,   __snake_case				:   int       ,   __snake_case				:   Any       ,   __snake_case				:   Optional[int]       ,   __snake_case				:   List[str]       ,   __snake_case				:   List[Any]       ,   __snake_case				:   Dict	):





       '''simple docstring'''
       UpperCAmelCase_							:      List[str]						=   MobileBertModel(config=UpperCamelCase__	)
       model.to(UpperCamelCase__	)
       model.eval()
       UpperCAmelCase_							:      int						=   model(UpperCamelCase__       ,   attention_mask=UpperCamelCase__       ,   token_type_ids=UpperCamelCase__	)
       UpperCAmelCase_							:      Dict						=   model(UpperCamelCase__       ,   token_type_ids=UpperCamelCase__	)
       UpperCAmelCase_							:      Tuple						=   model(UpperCamelCase__	)

       self.parent.assertEqual(result.last_hidden_state.shape       ,   (self.batch_size, self.seq_length, self.hidden_size)	)
       self.parent.assertEqual(result.pooler_output.shape       ,   (self.batch_size, self.hidden_size)	)





    def 					_lowerCamelCase (	self				:   List[str]       ,   __snake_case				:   List[Any]       ,   __snake_case				:   List[Any]       ,   __snake_case				:   Any       ,   __snake_case				:   List[str]       ,   __snake_case				:   int       ,   __snake_case				:   Union[str, Any]       ,   __snake_case				:   Union[str, Any]	):





       '''simple docstring'''
       UpperCAmelCase_							:      List[Any]						=   MobileBertForMaskedLM(config=UpperCamelCase__	)
       model.to(UpperCamelCase__	)
       model.eval()
       UpperCAmelCase_							:      int						=   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 					_lowerCamelCase (	self				:   Any       ,   __snake_case				:   Any       ,   __snake_case				:   Optional[int]       ,   __snake_case				:   List[Any]       ,   __snake_case				:   List[Any]       ,   __snake_case				:   List[str]       ,   __snake_case				:   Optional[int]       ,   __snake_case				:   Tuple	):





       '''simple docstring'''
       UpperCAmelCase_							:      Dict						=   MobileBertForNextSentencePrediction(config=UpperCamelCase__	)
       model.to(UpperCamelCase__	)
       model.eval()
       UpperCAmelCase_							:      Tuple						=   model(
           UpperCamelCase__       ,   attention_mask=UpperCamelCase__       ,   token_type_ids=UpperCamelCase__       ,   labels=UpperCamelCase__       ,   )
       self.parent.assertEqual(result.logits.shape       ,   (self.batch_size, 2)	)





    def 					_lowerCamelCase (	self				:   Optional[int]       ,   __snake_case				:   Any       ,   __snake_case				:   List[str]       ,   __snake_case				:   Dict       ,   __snake_case				:   Dict       ,   __snake_case				:   Any       ,   __snake_case				:   Dict       ,   __snake_case				:   int	):





       '''simple docstring'''
       UpperCAmelCase_							:      Optional[Any]						=   MobileBertForPreTraining(config=UpperCamelCase__	)
       model.to(UpperCamelCase__	)
       model.eval()
       UpperCAmelCase_							:      Union[str, Any]						=   model(
           UpperCamelCase__       ,   attention_mask=UpperCamelCase__       ,   token_type_ids=UpperCamelCase__       ,   labels=UpperCamelCase__       ,   next_sentence_label=UpperCamelCase__       ,   )
       self.parent.assertEqual(result.prediction_logits.shape       ,   (self.batch_size, self.seq_length, self.vocab_size)	)
       self.parent.assertEqual(result.seq_relationship_logits.shape       ,   (self.batch_size, 2)	)





    def 					_lowerCamelCase (	self				:   Optional[int]       ,   __snake_case				:   List[Any]       ,   __snake_case				:   Union[str, Any]       ,   __snake_case				:   Union[str, Any]       ,   __snake_case				:   Any       ,   __snake_case				:   Union[str, Any]       ,   __snake_case				:   List[Any]       ,   __snake_case				:   str	):





       '''simple docstring'''
       UpperCAmelCase_							:      Dict						=   MobileBertForQuestionAnswering(config=UpperCamelCase__	)
       model.to(UpperCamelCase__	)
       model.eval()
       UpperCAmelCase_							:      Optional[Any]						=   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 					_lowerCamelCase (	self				:   Tuple       ,   __snake_case				:   Dict       ,   __snake_case				:   Any       ,   __snake_case				:   Optional[int]       ,   __snake_case				:   Dict       ,   __snake_case				:   Union[str, Any]       ,   __snake_case				:   Any       ,   __snake_case				:   List[Any]	):





       '''simple docstring'''
       UpperCAmelCase_							:      List[str]						=   self.num_labels
       UpperCAmelCase_							:      Union[str, Any]						=   MobileBertForSequenceClassification(UpperCamelCase__	)
       model.to(UpperCamelCase__	)
       model.eval()
       UpperCAmelCase_							:      Optional[Any]						=   model(UpperCamelCase__       ,   attention_mask=UpperCamelCase__       ,   token_type_ids=UpperCamelCase__       ,   labels=UpperCamelCase__	)
       self.parent.assertEqual(result.logits.shape       ,   (self.batch_size, self.num_labels)	)





    def 					_lowerCamelCase (	self				:   Optional[int]       ,   __snake_case				:   List[Any]       ,   __snake_case				:   List[Any]       ,   __snake_case				:   Optional[int]       ,   __snake_case				:   List[str]       ,   __snake_case				:   List[str]       ,   __snake_case				:   List[Any]       ,   __snake_case				:   Any	):





       '''simple docstring'''
       UpperCAmelCase_							:      List[Any]						=   self.num_labels
       UpperCAmelCase_							:      str						=   MobileBertForTokenClassification(config=UpperCamelCase__	)
       model.to(UpperCamelCase__	)
       model.eval()
       UpperCAmelCase_							:      Dict						=   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 					_lowerCamelCase (	self				:   str       ,   __snake_case				:   Tuple       ,   __snake_case				:   Optional[Any]       ,   __snake_case				:   Optional[Any]       ,   __snake_case				:   List[str]       ,   __snake_case				:   Any       ,   __snake_case				:   List[str]       ,   __snake_case				:   Optional[int]	):





       '''simple docstring'''
       UpperCAmelCase_							:      Dict						=   self.num_choices
       UpperCAmelCase_							:      int						=   MobileBertForMultipleChoice(config=UpperCamelCase__	)
       model.to(UpperCamelCase__	)
       model.eval()
       UpperCAmelCase_							:      str						=   input_ids.unsqueeze(1	).expand(-1       ,   self.num_choices       ,   -1	).contiguous()
       UpperCAmelCase_							:      Union[str, Any]						=   token_type_ids.unsqueeze(1	).expand(-1       ,   self.num_choices       ,   -1	).contiguous()
       UpperCAmelCase_							:      Dict						=   input_mask.unsqueeze(1	).expand(-1       ,   self.num_choices       ,   -1	).contiguous()
       UpperCAmelCase_							:      Optional[Any]						=   model(
           UpperCamelCase__       ,   attention_mask=UpperCamelCase__       ,   token_type_ids=UpperCamelCase__       ,   labels=UpperCamelCase__       ,   )
       self.parent.assertEqual(result.logits.shape       ,   (self.batch_size, self.num_choices)	)





    def 					_lowerCamelCase (	self				:   Optional[int]	):





       '''simple docstring'''
       UpperCAmelCase_							:      Union[str, Any]						=   self.prepare_config_and_inputs()
       (
           (
           UpperCAmelCase_ 
       )		,      (
           UpperCAmelCase_ 
       )		,      (
           UpperCAmelCase_ 
       )		,      (
           UpperCAmelCase_ 
       )		,      (
           UpperCAmelCase_ 
       )		,      (
           UpperCAmelCase_ 
       )		,      (
           UpperCAmelCase_ 
       )		,       
       )							:      Union[str, Any]						=   config_and_inputs
       UpperCAmelCase_							:      int						=   {'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
       return config, inputs_dict





@require_torch
class  lowerCAmelCase__(    lowercase_    ,    lowercase_    ,    unittest.TestCase						):






    '''simple docstring'''





    A_  :     List[Any]			= (
        (
            MobileBertModel,
            MobileBertForMaskedLM,
            MobileBertForMultipleChoice,
            MobileBertForNextSentencePrediction,
            MobileBertForPreTraining,
            MobileBertForQuestionAnswering,
            MobileBertForSequenceClassification,
            MobileBertForTokenClassification,
        )
        if is_torch_available()
        else ()
    )
    A_  :     int			= (
        {
            '''feature-extraction''': MobileBertModel,
            '''fill-mask''': MobileBertForMaskedLM,
            '''question-answering''': MobileBertForQuestionAnswering,
            '''text-classification''': MobileBertForSequenceClassification,
            '''token-classification''': MobileBertForTokenClassification,
            '''zero-shot''': MobileBertForSequenceClassification,
        }
        if is_torch_available()
        else {}
    )
    A_  :     List[str]			= True





    def 					_lowerCamelCase (	self				:   Dict       ,   __snake_case				:   Union[str, Any]       ,   __snake_case				:   List[str]       ,   __snake_case				:   Any=False	):





       '''simple docstring'''
       UpperCAmelCase_							:      List[str]						=   super()._prepare_for_class(UpperCamelCase__       ,   UpperCamelCase__       ,   return_labels=UpperCamelCase__	)

       if return_labels:
          if model_class in get_values(UpperCamelCase__	):
             UpperCAmelCase_							:      Tuple						=   torch.zeros(
                 (self.model_tester.batch_size, self.model_tester.seq_length)       ,   dtype=torch.long       ,   device=UpperCamelCase__	)
             UpperCAmelCase_							:      List[str]						=   torch.zeros(
                 self.model_tester.batch_size       ,   dtype=torch.long       ,   device=UpperCamelCase__	)
       return inputs_dict





    def 					_lowerCamelCase (	self				:   int	):





       '''simple docstring'''
       UpperCAmelCase_							:      List[Any]						=   MobileBertModelTester(self	)
       UpperCAmelCase_							:      int						=   ConfigTester(self       ,   config_class=UpperCamelCase__       ,   hidden_size=37	)





    def 					_lowerCamelCase (	self				:   Tuple	):





       '''simple docstring'''
       self.config_tester.run_common_tests()





    def 					_lowerCamelCase (	self				:   Any	):





       '''simple docstring'''
       UpperCAmelCase_							:      int						=   self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mobilebert_model(*UpperCamelCase__	)





    def 					_lowerCamelCase (	self				:   Dict	):





       '''simple docstring'''
       UpperCAmelCase_							:      Any						=   self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mobilebert_for_masked_lm(*UpperCamelCase__	)





    def 					_lowerCamelCase (	self				:   int	):





       '''simple docstring'''
       UpperCAmelCase_							:      str						=   self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mobilebert_for_multiple_choice(*UpperCamelCase__	)





    def 					_lowerCamelCase (	self				:   Union[str, Any]	):





       '''simple docstring'''
       UpperCAmelCase_							:      str						=   self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mobilebert_for_next_sequence_prediction(*UpperCamelCase__	)





    def 					_lowerCamelCase (	self				:   List[Any]	):





       '''simple docstring'''
       UpperCAmelCase_							:      Tuple						=   self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mobilebert_for_pretraining(*UpperCamelCase__	)





    def 					_lowerCamelCase (	self				:   List[str]	):





       '''simple docstring'''
       UpperCAmelCase_							:      Union[str, Any]						=   self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mobilebert_for_question_answering(*UpperCamelCase__	)





    def 					_lowerCamelCase (	self				:   List[str]	):





       '''simple docstring'''
       UpperCAmelCase_							:      List[str]						=   self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mobilebert_for_sequence_classification(*UpperCamelCase__	)





    def 					_lowerCamelCase (	self				:   Optional[int]	):





       '''simple docstring'''
       UpperCAmelCase_							:      Dict						=   self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mobilebert_for_token_classification(*UpperCamelCase__	)





def      snake_case_						( __lowercase       ):
   return torch.tensor(
       __lowercase			,       dtype=torch.long			,       device=__lowercase			,       )


__UpperCamelCase				:  Optional[Any]      					=		1E-3





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






    '''simple docstring'''





    @slow
    def 					_lowerCamelCase (	self				:   str	):





       '''simple docstring'''
       UpperCAmelCase_							:      Optional[Any]						=   MobileBertModel.from_pretrained('''google/mobilebert-uncased'''	).to(UpperCamelCase__	)
       UpperCAmelCase_							:      Any						=   _long_tensor([[101, 7_110, 1_005, 1_056, 2_023, 11_333, 17_413, 1_029, 102]]	)
       with torch.no_grad():
          UpperCAmelCase_							:      str						=   model(UpperCamelCase__	)[0]
       UpperCAmelCase_							:      Tuple						=   torch.Size((1, 9, 512)	)
       self.assertEqual(output.shape       ,   UpperCamelCase__	)
       UpperCAmelCase_							:      Tuple						=   torch.tensor(
           [
               [
                   [-2.473_6526E07, 8.269_1656E04, 1.652_1838E05],
                   [-5.754_1704E-01, 3.905_6022E00, 4.401_1507E00],
                   [2.604_7359E00, 1.567_7652E00, -1.732_4188E-01],
               ]
           ]       ,   device=UpperCamelCase__       ,   )

       # MobileBERT results range from 10e0 to 10e8. Even a 0.0000001% difference with a value of 10e8 results in a
       # ~1 difference, it's therefore not a good idea to measure using addition.
       # Here, we instead divide the expected result with the result in order to obtain ~1. We then check that the
       # result is held between bounds: 1 - TOLERANCE < expected_result / result < 1 + TOLERANCE
       UpperCAmelCase_							:      Optional[Any]						=   torch.all((expected_slice / output[..., :3, :3]) >= 1 - TOLERANCE	)
       UpperCAmelCase_							:      List[Any]						=   torch.all((expected_slice / output[..., :3, :3]) <= 1 + TOLERANCE	)

       self.assertTrue(lower_bound and upper_bound	)



# This code is adapted from OpenAI's release
# https://github.com/openai/human-eval/blob/master/human_eval/execution.py

import contextlib
import faulthandler
import io
import multiprocessing
import os
import platform
import signal
import tempfile
def      snake_case_						( __lowercase			,       __lowercase			,       __lowercase			,       __lowercase       ):
   UpperCAmelCase_							:      int						=   multiprocessing.Manager()
   UpperCAmelCase_							:      Union[str, Any]						=   manager.list()

   UpperCAmelCase_							:      int						=   multiprocessing.Process(target=__lowercase			,       args=(check_program, result, timeout)       )
   p.start()
   p.join(timeout=timeout + 1       )
   if p.is_alive():
      p.kill()

   if not result:
      result.append('''timed out'''       )

   return {
       "task_id": task_id,
       "passed": result[0] == "passed",
       "result": result[0],
       "completion_id": completion_id,
   }
def      snake_case_						( __lowercase			,       __lowercase			,       __lowercase       ):
   with create_tempdir():
      # These system calls are needed when cleaning up tempdir.
      import os
      import shutil

      UpperCAmelCase_							:      str						=   shutil.rmtree
      UpperCAmelCase_							:      Tuple						=   os.rmdir
      UpperCAmelCase_							:      Dict						=   os.chdir

      # Disable functionalities that can make destructive changes to the test.
      reliability_guard()

      # Run program.
      try:
         UpperCAmelCase_							:      Optional[int]						=   {}
         with swallow_io():
            with time_limit(__lowercase       ):
               exec(__lowercase			,       __lowercase       )
         result.append('''passed'''       )
      except TimeoutException:
         result.append('''timed out'''       )
      except BaseException as e:
         result.append(F'''failed: {e}'''       )

      # Needed for cleaning up.
      UpperCAmelCase_							:      Optional[int]						=   rmtree
      UpperCAmelCase_							:      Optional[Any]						=   rmdir
      UpperCAmelCase_							:      Optional[Any]						=   chdir
@contextlib.contextmanager
def      snake_case_						( __lowercase       ):
   def signal_handler(__lowercase			,       __lowercase       ):
      raise TimeoutException('''Timed out!'''       )

   signal.setitimer(signal.ITIMER_REAL			,       __lowercase       )
   signal.signal(signal.SIGALRM			,       __lowercase       )
   try:
      yield
   finally:
      signal.setitimer(signal.ITIMER_REAL			,       0       )
@contextlib.contextmanager
def      snake_case_						( ):
   UpperCAmelCase_							:      Optional[Any]						=   WriteOnlyStringIO()
   with contextlib.redirect_stdout(__lowercase       ):
      with contextlib.redirect_stderr(__lowercase       ):
         with redirect_stdin(__lowercase       ):
            yield
@contextlib.contextmanager
def      snake_case_						( ):
   with tempfile.TemporaryDirectory() as dirname:
      with chdir(__lowercase       ):
         yield dirname





class  lowerCAmelCase__(    snake_case__						):






    '''simple docstring'''





    pass





class  lowerCAmelCase__(    io.StringIO						):






    '''simple docstring'''





    def 					_lowerCamelCase (	self				:   Dict       ,   *__snake_case				:   List[Any]       ,   **__snake_case				:   int	):





       '''simple docstring'''
       raise OSError





    def 					_lowerCamelCase (	self				:   Dict       ,   *__snake_case				:   int       ,   **__snake_case				:   Any	):





       '''simple docstring'''
       raise OSError





    def 					_lowerCamelCase (	self				:   int       ,   *__snake_case				:   List[str]       ,   **__snake_case				:   Optional[Any]	):





       '''simple docstring'''
       raise OSError





    def 					_lowerCamelCase (	self				:   Union[str, Any]       ,   *__snake_case				:   Optional[Any]       ,   **__snake_case				:   List[Any]	):





       '''simple docstring'''
       return False





class  lowerCAmelCase__(    contextlib._RedirectStream						):  # type: ignore






    '''simple docstring'''





    A_  :     Optional[Any]			= 'stdin'





@contextlib.contextmanager
def      snake_case_						( __lowercase       ):
   if root == ".":
      yield
      return
   UpperCAmelCase_							:      Tuple						=   os.getcwd()
   os.chdir(__lowercase       )
   try:
      yield
   except BaseException as exc:
      raise exc
   finally:
      os.chdir(__lowercase       )


def      snake_case_						( __lowercase=None       ):

   if maximum_memory_bytes is not None:
      import resource

      resource.setrlimit(resource.RLIMIT_AS			,       (maximum_memory_bytes, maximum_memory_bytes)       )
      resource.setrlimit(resource.RLIMIT_DATA			,       (maximum_memory_bytes, maximum_memory_bytes)       )
      if not platform.uname().system == "Darwin":
         resource.setrlimit(resource.RLIMIT_STACK			,       (maximum_memory_bytes, maximum_memory_bytes)       )

   faulthandler.disable()

   import builtins

   UpperCAmelCase_							:      Any						=   None
   UpperCAmelCase_							:      Any						=   None

   import os

   UpperCAmelCase_							:      Union[str, Any]						=   '''1'''

   UpperCAmelCase_							:      List[str]						=   None
   UpperCAmelCase_							:      Dict						=   None
   UpperCAmelCase_							:      Any						=   None
   UpperCAmelCase_							:      Optional[int]						=   None
   UpperCAmelCase_							:      List[str]						=   None
   UpperCAmelCase_							:      List[Any]						=   None
   UpperCAmelCase_							:      Union[str, Any]						=   None
   UpperCAmelCase_							:      str						=   None
   UpperCAmelCase_							:      Dict						=   None
   UpperCAmelCase_							:      int						=   None
   UpperCAmelCase_							:      Dict						=   None
   UpperCAmelCase_							:      List[Any]						=   None
   UpperCAmelCase_							:      List[Any]						=   None
   UpperCAmelCase_							:      Optional[Any]						=   None
   UpperCAmelCase_							:      Optional[Any]						=   None
   UpperCAmelCase_							:      Dict						=   None
   UpperCAmelCase_							:      Optional[Any]						=   None
   UpperCAmelCase_							:      Optional[Any]						=   None
   UpperCAmelCase_							:      Optional[Any]						=   None
   UpperCAmelCase_							:      List[Any]						=   None
   UpperCAmelCase_							:      int						=   None
   UpperCAmelCase_							:      Union[str, Any]						=   None
   UpperCAmelCase_							:      List[Any]						=   None
   UpperCAmelCase_							:      Dict						=   None
   UpperCAmelCase_							:      Union[str, Any]						=   None
   UpperCAmelCase_							:      Dict						=   None
   UpperCAmelCase_							:      Any						=   None

   import shutil

   UpperCAmelCase_							:      Union[str, Any]						=   None
   UpperCAmelCase_							:      Dict						=   None
   UpperCAmelCase_							:      Tuple						=   None

   import subprocess

   UpperCAmelCase_							:      Dict						=   None  # type: ignore

   UpperCAmelCase_							:      Union[str, Any]						=   None

   import sys

   UpperCAmelCase_							:      Optional[Any]						=   None
   UpperCAmelCase_							:      List[Any]						=   None
   UpperCAmelCase_							:      List[Any]						=   None
   UpperCAmelCase_							:      List[str]						=   None
   UpperCAmelCase_							:      Dict						=   None