


from typing import Optional

import torch
import torch.utils.checkpoint
from torch import Tensor, nn
from torch.nn import BCEWithLogitsLoss, CrossEntropyLoss, MSELoss

from ...activations import ACTaFN
from ...file_utils import add_code_sample_docstrings, add_start_docstrings, add_start_docstrings_to_model_forward
from ...modeling_outputs import (
    BaseModelOutputWithNoAttention,
    BaseModelOutputWithPoolingAndNoAttention,
    ImageClassifierOutputWithNoAttention,
)
from ...modeling_utils import PreTrainedModel
from ...utils import logging
from .configuration_regnet import RegNetConfig


__UpperCamelCase				:  Tuple      					=							logging.get_logger(__name__)

# General docstring
__UpperCamelCase				:  List[str]      					=							'RegNetConfig'

# Base docstring
__UpperCamelCase				:  Dict      					=							'facebook/regnet-y-040'
__UpperCamelCase				:  int      					=							[1, 1088, 7, 7]

# Image classification docstring
__UpperCamelCase				:  Optional[Any]      					=							'facebook/regnet-y-040'
__UpperCamelCase				:  Optional[int]      					=							'tabby, tabby cat'

__UpperCamelCase				:  List[Any]      					=							[
    'facebook/regnet-y-040',
    # See all regnet models at https://huggingface.co/models?filter=regnet
]





class  lowerCAmelCase__(    nn.Module						):






    '''simple docstring'''





    def __init__(	self				:   Any       ,   __snake_case				:   int       ,   __snake_case				:   int       ,   __snake_case				:   int = 3       ,   __snake_case				:   int = 1       ,   __snake_case				:   int = 1       ,   __snake_case				:   Optional[str] = "relu"       ,   ):





       '''simple docstring'''
       super().__init__()
       UpperCAmelCase_							:      Union[str, Any]						=   nn.Convad(
           __snake_case       ,   __snake_case       ,   kernel_size=__snake_case       ,   stride=__snake_case       ,   padding=kernel_size // 2       ,   groups=__snake_case       ,   bias=__snake_case       ,   )
       UpperCAmelCase_							:      Union[str, Any]						=   nn.BatchNormad(__snake_case	)
       UpperCAmelCase_							:      List[str]						=   ACTaFN[activation] if activation is not None else nn.Identity()





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





       '''simple docstring'''
       UpperCAmelCase_							:      Optional[Any]						=   self.convolution(__snake_case	)
       UpperCAmelCase_							:      int						=   self.normalization(__snake_case	)
       UpperCAmelCase_							:      Optional[Any]						=   self.activation(__snake_case	)
       return hidden_state





class  lowerCAmelCase__(    nn.Module						):






    '''simple docstring'''





    def __init__(	self				:   List[str]       ,   __snake_case				:   RegNetConfig	):





       '''simple docstring'''
       super().__init__()
       UpperCAmelCase_							:      Dict						=   RegNetConvLayer(
           config.num_channels       ,   config.embedding_size       ,   kernel_size=3       ,   stride=2       ,   activation=config.hidden_act	)
       UpperCAmelCase_							:      Optional[Any]						=   config.num_channels





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





       '''simple docstring'''
       UpperCAmelCase_							:      str						=   pixel_values.shape[1]
       if num_channels != self.num_channels:
          raise ValueError(
              '''Make sure that the channel dimension of the pixel values match with the one set in the configuration.'''	)
       UpperCAmelCase_							:      Tuple						=   self.embedder(__snake_case	)
       return hidden_state





class  lowerCAmelCase__(    nn.Module						):






    '''simple docstring'''





    def __init__(	self				:   Tuple       ,   __snake_case				:   int       ,   __snake_case				:   int       ,   __snake_case				:   int = 2	):





       '''simple docstring'''
       super().__init__()
       UpperCAmelCase_							:      int						=   nn.Convad(__snake_case       ,   __snake_case       ,   kernel_size=1       ,   stride=__snake_case       ,   bias=__snake_case	)
       UpperCAmelCase_							:      List[Any]						=   nn.BatchNormad(__snake_case	)





    def 					_lowerCamelCase (	self				:   Optional[int]       ,   __snake_case				:   Tensor	):





       '''simple docstring'''
       UpperCAmelCase_							:      Optional[Any]						=   self.convolution(__snake_case	)
       UpperCAmelCase_							:      Optional[Any]						=   self.normalization(__snake_case	)
       return hidden_state





class  lowerCAmelCase__(    nn.Module						):






    '''simple docstring'''





    def __init__(	self				:   List[str]       ,   __snake_case				:   int       ,   __snake_case				:   int	):





       '''simple docstring'''
       super().__init__()

       UpperCAmelCase_							:      Any						=   nn.AdaptiveAvgPoolad((1, 1)	)
       UpperCAmelCase_							:      Any						=   nn.Sequential(
           nn.Convad(__snake_case       ,   __snake_case       ,   kernel_size=1	)       ,   nn.ReLU()       ,   nn.Convad(__snake_case       ,   __snake_case       ,   kernel_size=1	)       ,   nn.Sigmoid()       ,   )





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





       '''simple docstring'''
       # b c h w -> b c 1 1
       UpperCAmelCase_							:      List[str]						=   self.pooler(__snake_case	)
       UpperCAmelCase_							:      List[Any]						=   self.attention(__snake_case	)
       UpperCAmelCase_							:      Optional[int]						=   hidden_state * attention
       return hidden_state





class  lowerCAmelCase__(    nn.Module						):






    '''simple docstring'''





    def __init__(	self				:   Tuple       ,   __snake_case				:   RegNetConfig       ,   __snake_case				:   int       ,   __snake_case				:   int       ,   __snake_case				:   int = 1	):





       '''simple docstring'''
       super().__init__()
       UpperCAmelCase_							:      str						=   in_channels != out_channels or stride != 1
       UpperCAmelCase_							:      List[str]						=   max(1       ,   out_channels // config.groups_width	)
       UpperCAmelCase_							:      Dict						=   (
           RegNetShortCut(__snake_case       ,   __snake_case       ,   stride=__snake_case	) if should_apply_shortcut else nn.Identity()
       )
       UpperCAmelCase_							:      Optional[Any]						=   nn.Sequential(
           RegNetConvLayer(__snake_case       ,   __snake_case       ,   kernel_size=1       ,   activation=config.hidden_act	)       ,   RegNetConvLayer(__snake_case       ,   __snake_case       ,   stride=__snake_case       ,   groups=__snake_case       ,   activation=config.hidden_act	)       ,   RegNetConvLayer(__snake_case       ,   __snake_case       ,   kernel_size=1       ,   activation=__snake_case	)       ,   )
       UpperCAmelCase_							:      int						=   ACTaFN[config.hidden_act]





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





       '''simple docstring'''
       UpperCAmelCase_							:      Union[str, Any]						=   hidden_state
       UpperCAmelCase_							:      Union[str, Any]						=   self.layer(__snake_case	)
       UpperCAmelCase_							:      Union[str, Any]						=   self.shortcut(__snake_case	)
       hidden_state += residual
       UpperCAmelCase_							:      List[Any]						=   self.activation(__snake_case	)
       return hidden_state





class  lowerCAmelCase__(    nn.Module						):






    '''simple docstring'''





    def __init__(	self				:   List[str]       ,   __snake_case				:   RegNetConfig       ,   __snake_case				:   int       ,   __snake_case				:   int       ,   __snake_case				:   int = 1	):





       '''simple docstring'''
       super().__init__()
       UpperCAmelCase_							:      Any						=   in_channels != out_channels or stride != 1
       UpperCAmelCase_							:      Optional[Any]						=   max(1       ,   out_channels // config.groups_width	)
       UpperCAmelCase_							:      Tuple						=   (
           RegNetShortCut(__snake_case       ,   __snake_case       ,   stride=__snake_case	) if should_apply_shortcut else nn.Identity()
       )
       UpperCAmelCase_							:      int						=   nn.Sequential(
           RegNetConvLayer(__snake_case       ,   __snake_case       ,   kernel_size=1       ,   activation=config.hidden_act	)       ,   RegNetConvLayer(__snake_case       ,   __snake_case       ,   stride=__snake_case       ,   groups=__snake_case       ,   activation=config.hidden_act	)       ,   RegNetSELayer(__snake_case       ,   reduced_channels=int(round(in_channels / 4	)	)	)       ,   RegNetConvLayer(__snake_case       ,   __snake_case       ,   kernel_size=1       ,   activation=__snake_case	)       ,   )
       UpperCAmelCase_							:      Optional[Any]						=   ACTaFN[config.hidden_act]





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





       '''simple docstring'''
       UpperCAmelCase_							:      Any						=   hidden_state
       UpperCAmelCase_							:      Optional[Any]						=   self.layer(__snake_case	)
       UpperCAmelCase_							:      Union[str, Any]						=   self.shortcut(__snake_case	)
       hidden_state += residual
       UpperCAmelCase_							:      Tuple						=   self.activation(__snake_case	)
       return hidden_state





class  lowerCAmelCase__(    nn.Module						):






    '''simple docstring'''





    def __init__(	self				:   Any       ,   __snake_case				:   RegNetConfig       ,   __snake_case				:   int       ,   __snake_case				:   int       ,   __snake_case				:   int = 2       ,   __snake_case				:   int = 2       ,   ):





       '''simple docstring'''
       super().__init__()

       UpperCAmelCase_							:      Union[str, Any]						=   RegNetXLayer if config.layer_type == '''x''' else RegNetYLayer

       UpperCAmelCase_							:      List[Any]						=   nn.Sequential(
           # downsampling is done in the first layer with stride of 2
           layer(
               __snake_case       ,   __snake_case       ,   __snake_case       ,   stride=__snake_case       ,   )       ,   *[layer(__snake_case       ,   __snake_case       ,   __snake_case	) for _ in range(depth - 1	)]       ,   )





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





       '''simple docstring'''
       UpperCAmelCase_							:      Union[str, Any]						=   self.layers(__snake_case	)
       return hidden_state





class  lowerCAmelCase__(    nn.Module						):






    '''simple docstring'''





    def __init__(	self				:   List[str]       ,   __snake_case				:   RegNetConfig	):





       '''simple docstring'''
       super().__init__()
       UpperCAmelCase_							:      Optional[Any]						=   nn.ModuleList([]	)
       # based on `downsample_in_first_stage`, the first layer of the first stage may or may not downsample the input
       self.stages.append(
           RegNetStage(
               __snake_case       ,   config.embedding_size       ,   config.hidden_sizes[0]       ,   stride=2 if config.downsample_in_first_stage else 1       ,   depth=config.depths[0]       ,   )	)
       UpperCAmelCase_							:      Optional[int]						=   zip(config.hidden_sizes       ,   config.hidden_sizes[1:]	)
       for (in_channels, out_channels), depth in zip(__snake_case       ,   config.depths[1:]	):
          self.stages.append(RegNetStage(__snake_case       ,   __snake_case       ,   __snake_case       ,   depth=__snake_case	)	)





    def 					_lowerCamelCase (	self				:   List[str]       ,   __snake_case				:   Tensor       ,   __snake_case				:   bool = False       ,   __snake_case				:   bool = True	):





       '''simple docstring'''
       UpperCAmelCase_							:      List[str]						=   () if output_hidden_states else None

       for stage_module in self.stages:
          if output_hidden_states:
             UpperCAmelCase_							:      Union[str, Any]						=   hidden_states + (hidden_state,)

          UpperCAmelCase_							:      str						=   stage_module(__snake_case	)

       if output_hidden_states:
          UpperCAmelCase_							:      Optional[int]						=   hidden_states + (hidden_state,)

       if not return_dict:
          return tuple(v for v in [hidden_state, hidden_states] if v is not None	)

       return BaseModelOutputWithNoAttention(last_hidden_state=__snake_case       ,   hidden_states=__snake_case	)





class  lowerCAmelCase__(    snake_case__						):






    '''simple docstring'''





    A_  :     Dict			= RegNetConfig
    A_  :     Dict			= 'regnet'
    A_  :     Union[str, Any]			= 'pixel_values'
    A_  :     Union[str, Any]			= True





    def 					_lowerCamelCase (	self				:   str       ,   __snake_case				:   Any	):





       '''simple docstring'''
       if isinstance(__snake_case       ,   nn.Convad	):
          nn.init.kaiming_normal_(module.weight       ,   mode='''fan_out'''       ,   nonlinearity='''relu'''	)
       elif isinstance(__snake_case       ,   (nn.BatchNormad, nn.GroupNorm)	):
          nn.init.constant_(module.weight       ,   1	)
          nn.init.constant_(module.bias       ,   0	)





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





       '''simple docstring'''
       if isinstance(__snake_case       ,   __snake_case	):
          UpperCAmelCase_							:      str						=   value





__UpperCamelCase				:  Tuple      					=							R'\n    This model is a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass. Use it\n    as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and\n    behavior.\n\n    Parameters:\n        config ([`RegNetConfig`]): Model configuration class with all the parameters of the model.\n            Initializing with a config file does not load the weights associated with the model, only the\n            configuration. Check out the [`~PreTrainedModel.from_pretrained`] method to load the model weights.\n'

__UpperCamelCase				:  Union[str, Any]      					=							R'\n    Args:\n        pixel_values (`torch.FloatTensor` of shape `(batch_size, num_channels, height, width)`):\n            Pixel values. Pixel values can be obtained using [`AutoImageProcessor`]. See\n            [`ConvNextImageProcessor.__call__`] for details.\n\n        output_hidden_states (`bool`, *optional*):\n            Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for\n            more detail.\n        return_dict (`bool`, *optional*):\n            Whether or not to return a [`~file_utils.ModelOutput`] instead of a plain tuple.\n'





@add_start_docstrings(
    'The bare RegNet model outputting raw features without any specific head on top.'    ,    snake_case__    ,    )
# Copied from transformers.models.resnet.modeling_resnet.ResNetModel with RESNET->REGNET,ResNet->RegNet
class  lowerCAmelCase__(    snake_case__						):






    '''simple docstring'''





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





       '''simple docstring'''
       super().__init__(__snake_case	)
       UpperCAmelCase_							:      List[str]						=   config
       UpperCAmelCase_							:      List[Any]						=   RegNetEmbeddings(__snake_case	)
       UpperCAmelCase_							:      Optional[Any]						=   RegNetEncoder(__snake_case	)
       UpperCAmelCase_							:      Optional[Any]						=   nn.AdaptiveAvgPoolad((1, 1)	)
       # Initialize weights and apply final processing
       self.post_init()





    @add_start_docstrings_to_model_forward(__snake_case	)
    @add_code_sample_docstrings(
        checkpoint=_CHECKPOINT_FOR_DOC       ,   output_type=__snake_case       ,   config_class=_CONFIG_FOR_DOC       ,   modality='''vision'''       ,   expected_output=_EXPECTED_OUTPUT_SHAPE       ,   )
    def 					_lowerCamelCase (	self				:   List[str]       ,   __snake_case				:   Tensor       ,   __snake_case				:   Optional[bool] = None       ,   __snake_case				:   Optional[bool] = None	):





       '''simple docstring'''
       UpperCAmelCase_							:      Any						=   (
           output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
       )
       UpperCAmelCase_							:      Any						=   return_dict if return_dict is not None else self.config.use_return_dict

       UpperCAmelCase_							:      Union[str, Any]						=   self.embedder(__snake_case	)

       UpperCAmelCase_							:      Optional[int]						=   self.encoder(
           __snake_case       ,   output_hidden_states=__snake_case       ,   return_dict=__snake_case	)

       UpperCAmelCase_							:      List[Any]						=   encoder_outputs[0]

       UpperCAmelCase_							:      int						=   self.pooler(__snake_case	)

       if not return_dict:
          return (last_hidden_state, pooled_output) + encoder_outputs[1:]

       return BaseModelOutputWithPoolingAndNoAttention(
           last_hidden_state=__snake_case       ,   pooler_output=__snake_case       ,   hidden_states=encoder_outputs.hidden_states       ,   )





@add_start_docstrings(
    '\n    RegNet Model with an image classification head on top (a linear layer on top of the pooled features), e.g. for\n    ImageNet.\n    '    ,    snake_case__    ,    )
# Copied from transformers.models.resnet.modeling_resnet.ResNetForImageClassification with RESNET->REGNET,ResNet->RegNet,resnet->regnet
class  lowerCAmelCase__(    snake_case__						):






    '''simple docstring'''





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





       '''simple docstring'''
       super().__init__(__snake_case	)
       UpperCAmelCase_							:      Optional[Any]						=   config.num_labels
       UpperCAmelCase_							:      Any						=   RegNetModel(__snake_case	)
       # classification head
       UpperCAmelCase_							:      List[str]						=   nn.Sequential(
           nn.Flatten()       ,   nn.Linear(config.hidden_sizes[-1]       ,   config.num_labels	) if config.num_labels > 0 else nn.Identity()       ,   )
       # initialize weights and apply final processing
       self.post_init()





    @add_start_docstrings_to_model_forward(__snake_case	)
    @add_code_sample_docstrings(
        checkpoint=_IMAGE_CLASS_CHECKPOINT       ,   output_type=__snake_case       ,   config_class=_CONFIG_FOR_DOC       ,   expected_output=_IMAGE_CLASS_EXPECTED_OUTPUT       ,   )
    def 					_lowerCamelCase (	self				:   Any       ,   __snake_case				:   Optional[torch.FloatTensor] = None       ,   __snake_case				:   Optional[torch.LongTensor] = None       ,   __snake_case				:   Optional[bool] = None       ,   __snake_case				:   Optional[bool] = None       ,   ):





       '''simple docstring'''
       UpperCAmelCase_							:      Optional[Any]						=   return_dict if return_dict is not None else self.config.use_return_dict

       UpperCAmelCase_							:      Dict						=   self.regnet(__snake_case       ,   output_hidden_states=__snake_case       ,   return_dict=__snake_case	)

       UpperCAmelCase_							:      Union[str, Any]						=   outputs.pooler_output if return_dict else outputs[1]

       UpperCAmelCase_							:      str						=   self.classifier(__snake_case	)

       UpperCAmelCase_							:      Union[str, Any]						=   None

       if labels is not None:
          if self.config.problem_type is None:
             if self.num_labels == 1:
                UpperCAmelCase_							:      Dict						=   '''regression'''
             elif self.num_labels > 1 and (labels.dtype == torch.long or labels.dtype == torch.int):
                UpperCAmelCase_							:      Any						=   '''single_label_classification'''
             else:
                UpperCAmelCase_							:      Any						=   '''multi_label_classification'''
          if self.config.problem_type == "regression":
             UpperCAmelCase_							:      Union[str, Any]						=   MSELoss()
             if self.num_labels == 1:
                UpperCAmelCase_							:      int						=   loss_fct(logits.squeeze()       ,   labels.squeeze()	)
             else:
                UpperCAmelCase_							:      Union[str, Any]						=   loss_fct(__snake_case       ,   __snake_case	)
          elif self.config.problem_type == "single_label_classification":
             UpperCAmelCase_							:      Union[str, Any]						=   CrossEntropyLoss()
             UpperCAmelCase_							:      Union[str, Any]						=   loss_fct(logits.view(-1       ,   self.num_labels	)       ,   labels.view(-1	)	)
          elif self.config.problem_type == "multi_label_classification":
             UpperCAmelCase_							:      Tuple						=   BCEWithLogitsLoss()
             UpperCAmelCase_							:      int						=   loss_fct(__snake_case       ,   __snake_case	)

       if not return_dict:
          UpperCAmelCase_							:      Optional[int]						=   (logits,) + outputs[2:]
          return (loss,) + output if loss is not None else output

       return ImageClassifierOutputWithNoAttention(loss=__snake_case       ,   logits=__snake_case       ,   hidden_states=outputs.hidden_states	)



# 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