"""simple docstring"""





import os
import tempfile
import unittest

from transformers import NezhaConfig, is_torch_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, require_torch_gpu, slow, torch_device

from ...generation.test_utils import GenerationTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
    import torch

    from transformers import (
        MODEL_FOR_PRETRAINING_MAPPING,
        NezhaForMaskedLM,
        NezhaForMultipleChoice,
        NezhaForNextSentencePrediction,
        NezhaForPreTraining,
        NezhaForQuestionAnswering,
        NezhaForSequenceClassification,
        NezhaForTokenClassification,
        NezhaModel,
    )
    from transformers.models.nezha.modeling_nezha import NEZHA_PRETRAINED_MODEL_ARCHIVE_LIST
class  _snake_case     :






      def __init__(       self      :			Optional[Any]							,					UpperCAmelCase      :			Tuple							,					UpperCAmelCase      :			Optional[Any]=13							,					UpperCAmelCase      :			List[str]=7							,					UpperCAmelCase      :			Union[str, Any]=True							,					UpperCAmelCase      :			List[Any]=True							,					UpperCAmelCase      :			Any=True							,					UpperCAmelCase      :			List[str]=True							,					UpperCAmelCase      :			Any=99							,					UpperCAmelCase      :			Tuple=32							,					UpperCAmelCase      :			List[Any]=5							,					UpperCAmelCase      :			Dict=4							,					UpperCAmelCase      :			Union[str, Any]=37							,					UpperCAmelCase      :			Dict="gelu"							,					UpperCAmelCase      :			Union[str, Any]=0.1							,					UpperCAmelCase      :			Tuple=0.1							,					UpperCAmelCase      :			str=128							,					UpperCAmelCase      :			int=32							,					UpperCAmelCase      :			Union[str, Any]=16							,					UpperCAmelCase      :			Dict=2							,					UpperCAmelCase      :			Union[str, Any]=0.0_2							,					UpperCAmelCase      :			str=3							,					UpperCAmelCase      :			Optional[Any]=4							,					UpperCAmelCase      :			List[Any]=None							,					):
             __lowerCamelCase					:		List[Any]		   =     parent
             __lowerCamelCase					:		Dict		   =     batch_size
             __lowerCamelCase					:		List[Any]		   =     seq_length
             __lowerCamelCase					:		Any		   =     is_training
             __lowerCamelCase					:		int		   =     use_input_mask
             __lowerCamelCase					:		int		   =     use_token_type_ids
             __lowerCamelCase					:		Optional[int]		   =     use_labels
             __lowerCamelCase					:		int		   =     vocab_size
             __lowerCamelCase					:		List[Any]		   =     hidden_size
             __lowerCamelCase					:		int		   =     num_hidden_layers
             __lowerCamelCase					:		List[Any]		   =     num_attention_heads
             __lowerCamelCase					:		str		   =     intermediate_size
             __lowerCamelCase					:		Any		   =     hidden_act
             __lowerCamelCase					:		str		   =     hidden_dropout_prob
             __lowerCamelCase					:		Any		   =     attention_probs_dropout_prob
             __lowerCamelCase					:		List[Any]		   =     max_position_embeddings
             __lowerCamelCase					:		Optional[int]		   =     type_vocab_size
             __lowerCamelCase					:		Optional[Any]		   =     type_sequence_label_size
             __lowerCamelCase					:		Optional[Any]		   =     initializer_range
             __lowerCamelCase					:		Dict		   =     num_labels
             __lowerCamelCase					:		Optional[Any]		   =     num_choices
             __lowerCamelCase					:		Dict		   =     scope






      def       lowerCamelCase__     (       self      :			Tuple    ):
             __lowerCamelCase					:		Optional[int]		   =     ids_tensor([self.batch_size, self.seq_length]							,					self.vocab_size    )

             __lowerCamelCase					:		str		   =     None
             if self.use_input_mask:
                    __lowerCamelCase					:		Tuple		   =     random_attention_mask([self.batch_size, self.seq_length]    )

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

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

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

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






      def       lowerCamelCase__     (       self      :			Union[str, Any]    ):
             return NezhaConfig(
                 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							,					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=__a							,					initializer_range=self.initializer_range							,					)






      def       lowerCamelCase__     (       self      :			List[str]    ):
             (
                 __lowerCamelCase			
             )					:		List[Any]		   =     self.prepare_config_and_inputs()

             __lowerCamelCase					:		Tuple		   =     True
             __lowerCamelCase					:		List[Any]		   =     floats_tensor([self.batch_size, self.seq_length, self.hidden_size]    )
             __lowerCamelCase					:		Optional[int]		   =     ids_tensor([self.batch_size, self.seq_length]							,					vocab_size=2    )

             return (
                 config,
                 input_ids,
                 token_type_ids,
                 input_mask,
                 sequence_labels,
                 token_labels,
                 choice_labels,
                 encoder_hidden_states,
                 encoder_attention_mask,
             )






      def       lowerCamelCase__     (       self      :			Dict							,					UpperCAmelCase      :			List[Any]							,					UpperCAmelCase      :			Union[str, Any]							,					UpperCAmelCase      :			Union[str, Any]							,					UpperCAmelCase      :			List[str]							,					UpperCAmelCase      :			List[str]							,					UpperCAmelCase      :			int							,					UpperCAmelCase      :			List[Any]    ):
             __lowerCamelCase					:		Tuple		   =     NezhaModel(config=__a    )
             model.to(__a    )
             model.eval()
             __lowerCamelCase					:		List[Any]		   =     model(__a							,					attention_mask=__a							,					token_type_ids=__a    )
             __lowerCamelCase					:		str		   =     model(__a							,					token_type_ids=__a    )
             __lowerCamelCase					:		Any		   =     model(__a    )
             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      :			Any							,					UpperCAmelCase      :			Dict							,					UpperCAmelCase      :			Tuple							,					UpperCAmelCase      :			str							,					UpperCAmelCase      :			List[str]							,					UpperCAmelCase      :			List[str]							,					UpperCAmelCase      :			Optional[Any]							,					UpperCAmelCase      :			List[Any]							,					UpperCAmelCase      :			Tuple							,					UpperCAmelCase      :			Tuple							,					):
             __lowerCamelCase					:		Optional[Any]		   =     True
             __lowerCamelCase					:		Union[str, Any]		   =     NezhaModel(__a    )
             model.to(__a    )
             model.eval()
             __lowerCamelCase					:		int		   =     model(
                 __a							,					attention_mask=__a							,					token_type_ids=__a							,					encoder_hidden_states=__a							,					encoder_attention_mask=__a							,					)
             __lowerCamelCase					:		List[str]		   =     model(
                 __a							,					attention_mask=__a							,					token_type_ids=__a							,					encoder_hidden_states=__a							,					)
             __lowerCamelCase					:		List[str]		   =     model(__a							,					attention_mask=__a							,					token_type_ids=__a    )
             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      :			Tuple							,					UpperCAmelCase      :			Optional[int]							,					UpperCAmelCase      :			List[str]							,					UpperCAmelCase      :			Union[str, Any]							,					UpperCAmelCase      :			Union[str, Any]							,					UpperCAmelCase      :			str							,					UpperCAmelCase      :			Optional[Any]							,					UpperCAmelCase      :			Optional[int]    ):
             __lowerCamelCase					:		Union[str, Any]		   =     NezhaForMaskedLM(config=__a    )
             model.to(__a    )
             model.eval()
             __lowerCamelCase					:		Optional[Any]		   =     model(__a							,					attention_mask=__a							,					token_type_ids=__a							,					labels=__a    )
             self.parent.assertEqual(result.logits.shape							,					(self.batch_size, self.seq_length, self.vocab_size)    )






      def       lowerCamelCase__     (       self      :			str							,					UpperCAmelCase      :			List[Any]							,					UpperCAmelCase      :			Optional[int]							,					UpperCAmelCase      :			List[Any]							,					UpperCAmelCase      :			str							,					UpperCAmelCase      :			Optional[Any]							,					UpperCAmelCase      :			List[Any]							,					UpperCAmelCase      :			Dict    ):
             __lowerCamelCase					:		Optional[int]		   =     NezhaForNextSentencePrediction(config=__a    )
             model.to(__a    )
             model.eval()
             __lowerCamelCase					:		List[Any]		   =     model(
                 __a							,					attention_mask=__a							,					token_type_ids=__a							,					labels=__a							,					)
             self.parent.assertEqual(result.logits.shape							,					(self.batch_size, 2)    )






      def       lowerCamelCase__     (       self      :			Dict							,					UpperCAmelCase      :			List[Any]							,					UpperCAmelCase      :			int							,					UpperCAmelCase      :			List[Any]							,					UpperCAmelCase      :			Union[str, Any]							,					UpperCAmelCase      :			Optional[int]							,					UpperCAmelCase      :			List[Any]							,					UpperCAmelCase      :			Optional[int]    ):
             __lowerCamelCase					:		List[Any]		   =     NezhaForPreTraining(config=__a    )
             model.to(__a    )
             model.eval()
             __lowerCamelCase					:		Any		   =     model(
                 __a							,					attention_mask=__a							,					token_type_ids=__a							,					labels=__a							,					next_sentence_label=__a							,					)
             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      :			List[Any]							,					UpperCAmelCase      :			str							,					UpperCAmelCase      :			Any							,					UpperCAmelCase      :			Optional[int]							,					UpperCAmelCase      :			Union[str, Any]							,					UpperCAmelCase      :			Tuple							,					UpperCAmelCase      :			Dict							,					UpperCAmelCase      :			List[str]    ):
             __lowerCamelCase					:		str		   =     NezhaForQuestionAnswering(config=__a    )
             model.to(__a    )
             model.eval()
             __lowerCamelCase					:		int		   =     model(
                 __a							,					attention_mask=__a							,					token_type_ids=__a							,					start_positions=__a							,					end_positions=__a							,					)
             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      :			Any							,					UpperCAmelCase      :			List[Any]							,					UpperCAmelCase      :			Optional[int]							,					UpperCAmelCase      :			Tuple							,					UpperCAmelCase      :			List[Any]							,					UpperCAmelCase      :			str							,					UpperCAmelCase      :			int							,					UpperCAmelCase      :			Optional[int]    ):
             __lowerCamelCase					:		int		   =     self.num_labels
             __lowerCamelCase					:		List[Any]		   =     NezhaForSequenceClassification(__a    )
             model.to(__a    )
             model.eval()
             __lowerCamelCase					:		str		   =     model(__a							,					attention_mask=__a							,					token_type_ids=__a							,					labels=__a    )
             self.parent.assertEqual(result.logits.shape							,					(self.batch_size, self.num_labels)    )






      def       lowerCamelCase__     (       self      :			Tuple							,					UpperCAmelCase      :			Dict							,					UpperCAmelCase      :			Dict							,					UpperCAmelCase      :			Any							,					UpperCAmelCase      :			str							,					UpperCAmelCase      :			List[str]							,					UpperCAmelCase      :			Optional[Any]							,					UpperCAmelCase      :			Dict    ):
             __lowerCamelCase					:		List[str]		   =     self.num_labels
             __lowerCamelCase					:		int		   =     NezhaForTokenClassification(config=__a    )
             model.to(__a    )
             model.eval()
             __lowerCamelCase					:		Optional[int]		   =     model(__a							,					attention_mask=__a							,					token_type_ids=__a							,					labels=__a    )
             self.parent.assertEqual(result.logits.shape							,					(self.batch_size, self.seq_length, self.num_labels)    )






      def       lowerCamelCase__     (       self      :			Any							,					UpperCAmelCase      :			List[Any]							,					UpperCAmelCase      :			int							,					UpperCAmelCase      :			Union[str, Any]							,					UpperCAmelCase      :			Optional[Any]							,					UpperCAmelCase      :			Tuple							,					UpperCAmelCase      :			List[Any]							,					UpperCAmelCase      :			Dict    ):
             __lowerCamelCase					:		Any		   =     self.num_choices
             __lowerCamelCase					:		Union[str, Any]		   =     NezhaForMultipleChoice(config=__a    )
             model.to(__a    )
             model.eval()
             __lowerCamelCase					:		Any		   =     input_ids.unsqueeze(1    ).expand(-1							,					self.num_choices							,					-1    ).contiguous()
             __lowerCamelCase					:		Tuple		   =     token_type_ids.unsqueeze(1    ).expand(-1							,					self.num_choices							,					-1    ).contiguous()
             __lowerCamelCase					:		Optional[Any]		   =     input_mask.unsqueeze(1    ).expand(-1							,					self.num_choices							,					-1    ).contiguous()
             __lowerCamelCase					:		Tuple		   =     model(
                 __a							,					attention_mask=__a							,					token_type_ids=__a							,					labels=__a							,					)
             self.parent.assertEqual(result.logits.shape							,					(self.batch_size, self.num_choices)    )







      def       lowerCamelCase__     (       self      :			Optional[Any]    ):
             __lowerCamelCase					:		Optional[Any]		   =     self.prepare_config_and_inputs()
             (
                 __lowerCamelCase			
             )					:		Optional[Any]		   =     config_and_inputs
             __lowerCamelCase					:		Optional[Any]		   =     {"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": input_mask}
             return config, inputs_dict

@require_torch
class  _snake_case     (					__lowercase				, __lowercase				, __lowercase				, unittest.TestCase		):
      snake_case__			  =			(
          (
              NezhaModel,
              NezhaForMaskedLM,
              NezhaForMultipleChoice,
              NezhaForNextSentencePrediction,
              NezhaForPreTraining,
              NezhaForQuestionAnswering,
              NezhaForSequenceClassification,
              NezhaForTokenClassification,
          )
          if is_torch_available()
          else ()
      )
      snake_case__			  =			(
          {
              '''feature-extraction''': NezhaModel,
              '''fill-mask''': NezhaForMaskedLM,
              '''question-answering''': NezhaForQuestionAnswering,
              '''text-classification''': NezhaForSequenceClassification,
              '''token-classification''': NezhaForTokenClassification,
              '''zero-shot''': NezhaForSequenceClassification,
          }
          if is_torch_available()
          else {}
      )
      snake_case__			  =			True






      def       lowerCamelCase__     (       self      :			str							,					UpperCAmelCase      :			Any							,					UpperCAmelCase      :			str							,					UpperCAmelCase      :			int=False    ):
             __lowerCamelCase					:		Dict		   =     super()._prepare_for_class(__a							,					__a							,					return_labels=__a    )

             if return_labels:
                    if model_class in get_values(__a    ):
                           __lowerCamelCase					:		int		   =     torch.zeros(
                               (self.model_tester.batch_size, self.model_tester.seq_length)							,					dtype=torch.long							,					device=__a    )
                           __lowerCamelCase					:		str		   =     torch.zeros(
                               self.model_tester.batch_size							,					dtype=torch.long							,					device=__a    )
             return inputs_dict






      def       lowerCamelCase__     (       self      :			Tuple    ):
             __lowerCamelCase					:		Union[str, Any]		   =     NezhaModelTester(self    )
             __lowerCamelCase					:		Optional[Any]		   =     ConfigTester(self							,					config_class=__a							,					hidden_size=37    )






      def       lowerCamelCase__     (       self      :			str    ):
             self.config_tester.run_common_tests()






      def       lowerCamelCase__     (       self      :			Union[str, Any]    ):
             __lowerCamelCase					:		str		   =     self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_model(*__a    )






      def       lowerCamelCase__     (       self      :			Optional[int]    ):
             __lowerCamelCase					:		Dict		   =     self.model_tester.prepare_config_and_inputs_for_decoder()
             self.model_tester.create_and_check_model_as_decoder(*__a    )






      def       lowerCamelCase__     (       self      :			Union[str, Any]    ):
             # This regression test was failing with PyTorch < 1.3
             (
                 __lowerCamelCase			
             )					:		Tuple		   =     self.model_tester.prepare_config_and_inputs_for_decoder()

             __lowerCamelCase					:		Dict		   =     None

             self.model_tester.create_and_check_model_as_decoder(
                 __a							,					__a							,					__a							,					__a							,					__a							,					__a							,					__a							,					__a							,					__a							,					)






      def       lowerCamelCase__     (       self      :			int    ):
             __lowerCamelCase					:		Optional[Any]		   =     self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_for_masked_lm(*__a    )






      def       lowerCamelCase__     (       self      :			Optional[Any]    ):
             __lowerCamelCase					:		Optional[Any]		   =     self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_for_multiple_choice(*__a    )






      def       lowerCamelCase__     (       self      :			Optional[int]    ):
             __lowerCamelCase					:		Dict		   =     self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_for_next_sequence_prediction(*__a    )






      def       lowerCamelCase__     (       self      :			str    ):
             __lowerCamelCase					:		Tuple		   =     self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_for_pretraining(*__a    )






      def       lowerCamelCase__     (       self      :			int    ):
             __lowerCamelCase					:		Tuple		   =     self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_for_question_answering(*__a    )






      def       lowerCamelCase__     (       self      :			Dict    ):
             __lowerCamelCase					:		Optional[Any]		   =     self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_for_sequence_classification(*__a    )






      def       lowerCamelCase__     (       self      :			List[Any]    ):
             __lowerCamelCase					:		Any		   =     self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_for_token_classification(*__a    )






      @slow
      def       lowerCamelCase__     (       self      :			Tuple    ):
             for model_name in NEZHA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                    __lowerCamelCase					:		Optional[int]		   =     NezhaModel.from_pretrained(__a    )
                    self.assertIsNotNone(__a    )







      @slow
      @require_torch_gpu
      def       lowerCamelCase__     (       self      :			List[Any]    ):
             __lowerCamelCase					:		Optional[int]		   =     self.model_tester.prepare_config_and_inputs_for_common()
             for model_class in self.all_model_classes:
                    # NezhaForMultipleChoice behaves incorrectly in JIT environments.
                    if model_class == NezhaForMultipleChoice:
                           return

                    __lowerCamelCase					:		int		   =     True
                    __lowerCamelCase					:		Dict		   =     model_class(config=__a    )

                    __lowerCamelCase					:		int		   =     self._prepare_for_class(__a							,					__a    )
                    __lowerCamelCase					:		Optional[Any]		   =     torch.jit.trace(
                        __a							,					(inputs_dict["input_ids"].to("cpu"    ), inputs_dict["attention_mask"].to("cpu"    ))    )

                    with tempfile.TemporaryDirectory() as tmp:
                           torch.jit.save(__a							,					os.path.join(__a							,					"bert.pt"    )    )
                           __lowerCamelCase					:		Union[str, Any]		   =     torch.jit.load(os.path.join(__a							,					"bert.pt"    )							,					map_location=__a    )
                           loaded(inputs_dict["input_ids"].to(__a    )							,					inputs_dict["attention_mask"].to(__a    )    )

@require_torch
class  _snake_case     (					unittest.TestCase		):






      @slow
      def       lowerCamelCase__     (       self      :			Optional[Any]    ):
             __lowerCamelCase					:		List[str]		   =     NezhaModel.from_pretrained("sijunhe/nezha-cn-base"    )
             __lowerCamelCase					:		Tuple		   =     torch.tensor([[0, 1, 2, 3, 4, 5]]    )
             __lowerCamelCase					:		Any		   =     torch.tensor([[0, 1, 1, 1, 1, 1]]    )
             with torch.no_grad():
                    __lowerCamelCase					:		Optional[int]		   =     model(__a							,					attention_mask=__a    )[0]
             __lowerCamelCase					:		Union[str, Any]		   =     torch.Size((1, 6, 768)    )
             self.assertEqual(output.shape							,					__a    )
             __lowerCamelCase					:		Any		   =     torch.tensor([[[0.0_6_8_5, 0.2_4_4_1, 0.1_1_0_2], [0.0_6_0_0, 0.1_9_0_6, 0.1_3_4_9], [0.0_2_2_1, 0.0_8_1_9, 0.0_5_8_6]]]    )

             self.assertTrue(torch.allclose(output[:, 1:4, 1:4]							,					__a							,					atol=1E-4    )    )







      @slow
      def       lowerCamelCase__     (       self      :			List[str]    ):
             __lowerCamelCase					:		Tuple		   =     NezhaForMaskedLM.from_pretrained("sijunhe/nezha-cn-base"    )
             __lowerCamelCase					:		Union[str, Any]		   =     torch.tensor([[0, 1, 2, 3, 4, 5]]    )
             __lowerCamelCase					:		List[Any]		   =     torch.tensor([[1, 1, 1, 1, 1, 1]]    )
             with torch.no_grad():
                    __lowerCamelCase					:		Tuple		   =     model(__a							,					attention_mask=__a    )[0]
             __lowerCamelCase					:		Dict		   =     torch.Size((1, 6, 21128)    )
             self.assertEqual(output.shape							,					__a    )
             __lowerCamelCase					:		str		   =     torch.tensor(
                 [[-2.7_9_3_9, -1.7_9_0_2, -2.2_1_8_9], [-2.8_5_8_5, -1.8_9_0_8, -2.3_7_2_3], [-2.6_4_9_9, -1.7_7_5_0, -2.2_5_5_8]]    )

             self.assertTrue(torch.allclose(output[:, 1:4, 1:4]							,					__a							,					atol=1E-4    )    )
"""simple docstring"""





from __future__ import annotations


def    lowercase_   (   _lowerCamelCase:	list[list[int]]      ) ->      bool:



							'''simple docstring'''

							__lowerCamelCase					:		str		   =     len(_lowerCamelCase      )
							# We need to create solution object to save path.
							__lowerCamelCase					:		List[Any]		   =     [[0 for _ in range(_lowerCamelCase      )] for _ in range(_lowerCamelCase      )]
							__lowerCamelCase					:		Dict		   =     run_maze(_lowerCamelCase						,   0						,   0						,   _lowerCamelCase      )
							if solved:
														print("\n".join(str(_lowerCamelCase      ) for row in solutions      )      )
							else:
														print("No solution exists!"      )
							return solved


def    lowercase_   (   _lowerCamelCase:	list[list[int]]						,   _lowerCamelCase:	int						,   _lowerCamelCase:	int						,   _lowerCamelCase:	list[list[int]]      ) ->      bool:



							'''simple docstring'''

							__lowerCamelCase					:		Dict		   =     len(_lowerCamelCase      )
							# Final check point.
							if i == j == (size - 1):
														__lowerCamelCase					:		Optional[Any]		   =     1
														return True

							__lowerCamelCase					:		int		   =     (not i < 0) and (not j < 0)  # Check lower bounds
							__lowerCamelCase					:		Union[str, Any]		   =     (i < size) and (j < size)  # Check upper bounds

							if lower_flag and upper_flag:
														# check for already visited and block points.
														__lowerCamelCase					:		List[Any]		   =     (not solutions[i][j]) and (not maze[i][j])
														if block_flag:
																					# check visited
																					__lowerCamelCase					:		Dict		   =     1

																					# check for directions
																					if (
																					    run_maze(_lowerCamelCase						,   i + 1						,   _lowerCamelCase						,   _lowerCamelCase      )
																					    or run_maze(_lowerCamelCase						,   _lowerCamelCase						,   j + 1						,   _lowerCamelCase      )
																					    or run_maze(_lowerCamelCase						,   i - 1						,   _lowerCamelCase						,   _lowerCamelCase      )
																					    or run_maze(_lowerCamelCase						,   _lowerCamelCase						,   j - 1						,   _lowerCamelCase      )
																					):
																												return True

																					__lowerCamelCase					:		List[str]		   =     0
																					return False
							return False


if __name__ == "__main__":
				import doctest

				doctest.testmod()