import argparse
import json
import os
import sys
import tempfile
import unittest
from argparse import Namespace
from dataclasses import dataclass, field
from enum import Enum
from pathlib import Path
from typing import List, Literal, Optional

import yaml

from transformers import HfArgumentParser, TrainingArguments
from transformers.hf_argparser import make_choice_type_function, string_to_bool


# Since Python 3.10, we can use the builtin `|` operator for Union types
# See PEP 604: https://peps.python.org/pep-0604
__lowerCamelCase      :			Dict							       =		sys.version_info >= (3, 10)



def      __SCREAMING_SNAKE_CASE  ( __UpperCamelCase   :	Union[str, Any]=None			,					__UpperCamelCase   :	List[Any]=None     ):







  """simple docstring"""





  return field(default_factory=lambda: default			,					metadata=UpperCAmelCase__     )







@dataclass
class __snake_case    :
   lowerCAmelCase_														=							42
   lowerCAmelCase_														=							42
   lowerCAmelCase_														=							42
   lowerCAmelCase_														=							42







@dataclass
class __snake_case    :
   lowerCAmelCase_														=							42
   lowerCAmelCase_														=							field(default="toto"       ,		metadata={"help": "help message"}		)







@dataclass
class __snake_case    :
   lowerCAmelCase_														=							False
   lowerCAmelCase_														=							True
   lowerCAmelCase_														=							None







class __snake_case    (						_UpperCAmelCase		):
   lowerCAmelCase_														=							"titi"
   lowerCAmelCase_														=							"toto"







class __snake_case    (						_UpperCAmelCase		):
   lowerCAmelCase_														=							"titi"
   lowerCAmelCase_														=							"toto"
   lowerCAmelCase_														=							42







@dataclass
class __snake_case    :
   lowerCAmelCase_														=							"toto"




   def      __a						(   self      :    Optional[Any]				):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__      							=				BasicEnum(self.foo				)







@dataclass
class __snake_case    :
   lowerCAmelCase_														=							"toto"




   def      __a						(   self      :    Dict				):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__      							=				MixedTypeEnum(self.foo				)







@dataclass
class __snake_case    :
   lowerCAmelCase_														=							None
   lowerCAmelCase_														=							field(default=_UpperCAmelCase       ,		metadata={"help": "help message"}		)
   lowerCAmelCase_														=							None
   lowerCAmelCase_														=							list_field(default=[]		)
   lowerCAmelCase_														=							list_field(default=[]		)







@dataclass
class __snake_case    :
   lowerCAmelCase_														=							list_field(default=[]		)
   lowerCAmelCase_														=							list_field(default=[1, 2, 3]		)
   lowerCAmelCase_														=							list_field(default=["Hallo", "Bonjour", "Hello"]		)
   lowerCAmelCase_														=							list_field(default=[0.1, 0.2, 0.3]		)







@dataclass
class __snake_case    :
   lowerCAmelCase_														=							field()
   lowerCAmelCase_														=							field()
   lowerCAmelCase_														=							field()




   def      __a						(   self      :    str				):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__      							=				BasicEnum(self.required_enum				)







@dataclass
class __snake_case    :
   lowerCAmelCase_														=							42
   lowerCAmelCase_														=							field()
   lowerCAmelCase_														=							None
   lowerCAmelCase_														=							field(default="toto"       ,		metadata={"help": "help message"}		)
   lowerCAmelCase_														=							list_field(default=["Hallo", "Bonjour", "Hello"]		)


if is_python_no_less_than_3_10:







   @dataclass
   class __snake_case    :
      lowerCAmelCase_														=							False
      lowerCAmelCase_														=							True
      lowerCAmelCase_														=							None







   @dataclass
   class __snake_case    :
      lowerCAmelCase_														=							None
      lowerCAmelCase_														=							field(default=_UpperCAmelCase       ,		metadata={"help": "help message"}		)
      lowerCAmelCase_														=							None
      lowerCAmelCase_														=							list_field(default=[]		)
      lowerCAmelCase_														=							list_field(default=[]		)







class __snake_case    (						unittest.TestCase		):




   def      __a						(   self      :    str	,     _lowercase      :    argparse.ArgumentParser	,     _lowercase      :    argparse.ArgumentParser				):



     """simple docstring"""






     self.assertEqual(len(a._actions				)	,     len(b._actions				)				)
     for x, y in zip(a._actions	,     b._actions				):
       SCREAMING_SNAKE_CASE__      							=				{k: v for k, v in vars(lowercase_				).items() if k != """container"""}
       SCREAMING_SNAKE_CASE__      							=				{k: v for k, v in vars(lowercase_				).items() if k != """container"""}

       # Choices with mixed type have custom function as "type"
       # So we need to compare results directly for equality
       if xx.get("""choices"""	,     lowercase_				) and yy.get("""choices"""	,     lowercase_				):
         for expected_choice in yy["choices"] + xx["choices"]:
           self.assertEqual(xx["""type"""](lowercase_				)	,     yy["""type"""](lowercase_				)				)
         del xx["type"], yy["type"]

       self.assertEqual(lowercase_	,     lowercase_				)




   def      __a						(   self      :    List[str]				):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__      							=				HfArgumentParser(lowercase_				)

     SCREAMING_SNAKE_CASE__      							=				argparse.ArgumentParser()
     expected.add_argument("""--foo"""	,     type=lowercase_	,     required=lowercase_				)
     expected.add_argument("""--bar"""	,     type=lowercase_	,     required=lowercase_				)
     expected.add_argument("""--baz"""	,     type=lowercase_	,     required=lowercase_				)
     expected.add_argument("""--flag"""	,     type=lowercase_	,     default=lowercase_	,     const=lowercase_	,     nargs="""?"""				)
     self.argparsersEqual(lowercase_	,     lowercase_				)

     SCREAMING_SNAKE_CASE__      							=				["""--foo""", """1""", """--baz""", """quux""", """--bar""", """0.5"""]
     (SCREAMING_SNAKE_CASE__						)      							=				parser.parse_args_into_dataclasses(lowercase_	,     look_for_args_file=lowercase_				)
     self.assertFalse(example.flag				)




   def      __a						(   self      :    Optional[Any]				):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__      							=				HfArgumentParser(lowercase_				)

     SCREAMING_SNAKE_CASE__      							=				argparse.ArgumentParser()
     expected.add_argument("""--foo"""	,     default=42	,     type=lowercase_				)
     expected.add_argument("""--baz"""	,     default="""toto"""	,     type=lowercase_	,     help="""help message"""				)
     self.argparsersEqual(lowercase_	,     lowercase_				)




   def      __a						(   self      :    Tuple				):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__      							=				argparse.ArgumentParser()
     expected.add_argument("""--foo"""	,     type=lowercase_	,     default=lowercase_	,     const=lowercase_	,     nargs="""?"""				)
     expected.add_argument("""--baz"""	,     type=lowercase_	,     default=lowercase_	,     const=lowercase_	,     nargs="""?"""				)
     # A boolean no_* argument always has to come after its "default: True" regular counter-part
     # and its default must be set to False
     expected.add_argument("""--no_baz"""	,     action="""store_false"""	,     default=lowercase_	,     dest="""baz"""				)
     expected.add_argument("""--opt"""	,     type=lowercase_	,     default=lowercase_				)

     SCREAMING_SNAKE_CASE__      							=				[WithDefaultBoolExample]
     if is_python_no_less_than_3_10:
       dataclass_types.append(lowercase_				)

     for dataclass_type in dataclass_types:
       SCREAMING_SNAKE_CASE__      							=				HfArgumentParser(lowercase_				)
       self.argparsersEqual(lowercase_	,     lowercase_				)

       SCREAMING_SNAKE_CASE__      							=				parser.parse_args([]				)
       self.assertEqual(lowercase_	,     Namespace(foo=lowercase_	,     baz=lowercase_	,     opt=lowercase_				)				)

       SCREAMING_SNAKE_CASE__      							=				parser.parse_args(["""--foo""", """--no_baz"""]				)
       self.assertEqual(lowercase_	,     Namespace(foo=lowercase_	,     baz=lowercase_	,     opt=lowercase_				)				)

       SCREAMING_SNAKE_CASE__      							=				parser.parse_args(["""--foo""", """--baz"""]				)
       self.assertEqual(lowercase_	,     Namespace(foo=lowercase_	,     baz=lowercase_	,     opt=lowercase_				)				)

       SCREAMING_SNAKE_CASE__      							=				parser.parse_args(["""--foo""", """True""", """--baz""", """True""", """--opt""", """True"""]				)
       self.assertEqual(lowercase_	,     Namespace(foo=lowercase_	,     baz=lowercase_	,     opt=lowercase_				)				)

       SCREAMING_SNAKE_CASE__      							=				parser.parse_args(["""--foo""", """False""", """--baz""", """False""", """--opt""", """False"""]				)
       self.assertEqual(lowercase_	,     Namespace(foo=lowercase_	,     baz=lowercase_	,     opt=lowercase_				)				)




   def      __a						(   self      :    Optional[Any]				):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__      							=				HfArgumentParser(lowercase_				)

     SCREAMING_SNAKE_CASE__      							=				argparse.ArgumentParser()
     expected.add_argument(
         """--foo"""	,     default="""toto"""	,     choices=["""titi""", """toto""", 42]	,     type=make_choice_type_function(["""titi""", """toto""", 42]				)	,     )
     self.argparsersEqual(lowercase_	,     lowercase_				)

     SCREAMING_SNAKE_CASE__      							=				parser.parse_args([]				)
     self.assertEqual(args.foo	,     """toto"""				)
     SCREAMING_SNAKE_CASE__      							=				parser.parse_args_into_dataclasses([]				)[0]
     self.assertEqual(enum_ex.foo	,     MixedTypeEnum.toto				)

     SCREAMING_SNAKE_CASE__      							=				parser.parse_args(["""--foo""", """titi"""]				)
     self.assertEqual(args.foo	,     """titi"""				)
     SCREAMING_SNAKE_CASE__      							=				parser.parse_args_into_dataclasses(["""--foo""", """titi"""]				)[0]
     self.assertEqual(enum_ex.foo	,     MixedTypeEnum.titi				)

     SCREAMING_SNAKE_CASE__      							=				parser.parse_args(["""--foo""", """42"""]				)
     self.assertEqual(args.foo	,     42				)
     SCREAMING_SNAKE_CASE__      							=				parser.parse_args_into_dataclasses(["""--foo""", """42"""]				)[0]
     self.assertEqual(enum_ex.foo	,     MixedTypeEnum.fourtytwo				)




   def      __a						(   self      :    Optional[int]				):



     """simple docstring"""






     @dataclass
     class __snake_case    :
        lowerCAmelCase_														=							"toto"





     SCREAMING_SNAKE_CASE__      							=				HfArgumentParser(lowercase_				)

     SCREAMING_SNAKE_CASE__      							=				argparse.ArgumentParser()
     expected.add_argument(
         """--foo"""	,     default="""toto"""	,     choices=("""titi""", """toto""", 42)	,     type=make_choice_type_function(["""titi""", """toto""", 42]				)	,     )
     self.argparsersEqual(lowercase_	,     lowercase_				)

     SCREAMING_SNAKE_CASE__      							=				parser.parse_args([]				)
     self.assertEqual(args.foo	,     """toto"""				)

     SCREAMING_SNAKE_CASE__      							=				parser.parse_args(["""--foo""", """titi"""]				)
     self.assertEqual(args.foo	,     """titi"""				)

     SCREAMING_SNAKE_CASE__      							=				parser.parse_args(["""--foo""", """42"""]				)
     self.assertEqual(args.foo	,     42				)




   def      __a						(   self      :    Tuple				):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__      							=				HfArgumentParser(lowercase_				)

     SCREAMING_SNAKE_CASE__      							=				argparse.ArgumentParser()
     expected.add_argument("""--foo_int"""	,     nargs="""+"""	,     default=[]	,     type=lowercase_				)
     expected.add_argument("""--bar_int"""	,     nargs="""+"""	,     default=[1, 2, 3]	,     type=lowercase_				)
     expected.add_argument("""--foo_str"""	,     nargs="""+"""	,     default=["""Hallo""", """Bonjour""", """Hello"""]	,     type=lowercase_				)
     expected.add_argument("""--foo_float"""	,     nargs="""+"""	,     default=[0.1, 0.2, 0.3]	,     type=lowercase_				)

     self.argparsersEqual(lowercase_	,     lowercase_				)

     SCREAMING_SNAKE_CASE__      							=				parser.parse_args([]				)
     self.assertEqual(
         lowercase_	,     Namespace(foo_int=[]	,     bar_int=[1, 2, 3]	,     foo_str=["""Hallo""", """Bonjour""", """Hello"""]	,     foo_float=[0.1, 0.2, 0.3]				)	,     )

     SCREAMING_SNAKE_CASE__      							=				parser.parse_args("""--foo_int 1 --bar_int 2 3 --foo_str a b c --foo_float 0.1 0.7""".split()				)
     self.assertEqual(lowercase_	,     Namespace(foo_int=[1]	,     bar_int=[2, 3]	,     foo_str=["""a""", """b""", """c"""]	,     foo_float=[0.1, 0.7]				)				)




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



     """simple docstring"""






     SCREAMING_SNAKE_CASE__      							=				argparse.ArgumentParser()
     expected.add_argument("""--foo"""	,     default=lowercase_	,     type=lowercase_				)
     expected.add_argument("""--bar"""	,     default=lowercase_	,     type=lowercase_	,     help="""help message"""				)
     expected.add_argument("""--baz"""	,     default=lowercase_	,     type=lowercase_				)
     expected.add_argument("""--ces"""	,     nargs="""+"""	,     default=[]	,     type=lowercase_				)
     expected.add_argument("""--des"""	,     nargs="""+"""	,     default=[]	,     type=lowercase_				)

     SCREAMING_SNAKE_CASE__      							=				[OptionalExample]
     if is_python_no_less_than_3_10:
       dataclass_types.append(lowercase_				)

     for dataclass_type in dataclass_types:
       SCREAMING_SNAKE_CASE__      							=				HfArgumentParser(lowercase_				)

       self.argparsersEqual(lowercase_	,     lowercase_				)

       SCREAMING_SNAKE_CASE__      							=				parser.parse_args([]				)
       self.assertEqual(lowercase_	,     Namespace(foo=lowercase_	,     bar=lowercase_	,     baz=lowercase_	,     ces=[]	,     des=[]				)				)

       SCREAMING_SNAKE_CASE__      							=				parser.parse_args("""--foo 12 --bar 3.14 --baz 42 --ces a b c --des 1 2 3""".split()				)
       self.assertEqual(lowercase_	,     Namespace(foo=12	,     bar=3.14	,     baz="""42"""	,     ces=["""a""", """b""", """c"""]	,     des=[1, 2, 3]				)				)




   def      __a						(   self      :    str				):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__      							=				HfArgumentParser(lowercase_				)

     SCREAMING_SNAKE_CASE__      							=				argparse.ArgumentParser()
     expected.add_argument("""--required_list"""	,     nargs="""+"""	,     type=lowercase_	,     required=lowercase_				)
     expected.add_argument("""--required_str"""	,     type=lowercase_	,     required=lowercase_				)
     expected.add_argument(
         """--required_enum"""	,     type=make_choice_type_function(["""titi""", """toto"""]				)	,     choices=["""titi""", """toto"""]	,     required=lowercase_	,     )
     self.argparsersEqual(lowercase_	,     lowercase_				)




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



     """simple docstring"""






     SCREAMING_SNAKE_CASE__      							=				HfArgumentParser(lowercase_				)

     SCREAMING_SNAKE_CASE__      							=				argparse.ArgumentParser()
     expected.add_argument("""--foo"""	,     type=lowercase_	,     required=lowercase_				)
     expected.add_argument(
         """--required_enum"""	,     type=make_choice_type_function(["""titi""", """toto"""]				)	,     choices=["""titi""", """toto"""]	,     required=lowercase_	,     )
     expected.add_argument("""--opt"""	,     type=lowercase_	,     default=lowercase_				)
     expected.add_argument("""--baz"""	,     default="""toto"""	,     type=lowercase_	,     help="""help message"""				)
     expected.add_argument("""--foo_str"""	,     nargs="""+"""	,     default=["""Hallo""", """Bonjour""", """Hello"""]	,     type=lowercase_				)
     self.argparsersEqual(lowercase_	,     lowercase_				)




   def      __a						(   self      :    List[Any]				):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__      							=				HfArgumentParser(lowercase_				)

     SCREAMING_SNAKE_CASE__      							=				{
         """foo""": 12,
         """bar""": 3.14,
         """baz""": """42""",
         """flag""": True,
     }

     SCREAMING_SNAKE_CASE__      							=				parser.parse_dict(lowercase_				)[0]
     SCREAMING_SNAKE_CASE__      							=				BasicExample(**lowercase_				)
     self.assertEqual(lowercase_	,     lowercase_				)




   def      __a						(   self      :    Optional[Any]				):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__      							=				HfArgumentParser(lowercase_				)

     SCREAMING_SNAKE_CASE__      							=				{
         """foo""": 12,
         """bar""": 3.14,
         """baz""": """42""",
         """flag""": True,
         """extra""": 42,
     }

     self.assertRaises(lowercase_	,     parser.parse_dict	,     lowercase_	,     allow_extra_keys=lowercase_				)




   def      __a						(   self      :    Any				):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__      							=				HfArgumentParser(lowercase_				)

     SCREAMING_SNAKE_CASE__      							=				{
         """foo""": 12,
         """bar""": 3.14,
         """baz""": """42""",
         """flag""": True,
     }
     with tempfile.TemporaryDirectory() as tmp_dir:
       SCREAMING_SNAKE_CASE__      							=				os.path.join(lowercase_	,     """temp_json"""				)
       os.mkdir(lowercase_				)
       with open(temp_local_path + """.json"""	,     """w+"""				) as f:
         json.dump(lowercase_	,     lowercase_				)
       SCREAMING_SNAKE_CASE__      							=				parser.parse_yaml_file(Path(temp_local_path + """.json"""				)				)[0]

     SCREAMING_SNAKE_CASE__      							=				BasicExample(**lowercase_				)
     self.assertEqual(lowercase_	,     lowercase_				)




   def      __a						(   self      :    Dict				):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__      							=				HfArgumentParser(lowercase_				)

     SCREAMING_SNAKE_CASE__      							=				{
         """foo""": 12,
         """bar""": 3.14,
         """baz""": """42""",
         """flag""": True,
     }
     with tempfile.TemporaryDirectory() as tmp_dir:
       SCREAMING_SNAKE_CASE__      							=				os.path.join(lowercase_	,     """temp_yaml"""				)
       os.mkdir(lowercase_				)
       with open(temp_local_path + """.yaml"""	,     """w+"""				) as f:
         yaml.dump(lowercase_	,     lowercase_				)
       SCREAMING_SNAKE_CASE__      							=				parser.parse_yaml_file(Path(temp_local_path + """.yaml"""				)				)[0]
     SCREAMING_SNAKE_CASE__      							=				BasicExample(**lowercase_				)
     self.assertEqual(lowercase_	,     lowercase_				)




   def      __a						(   self      :    str				):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__      							=				HfArgumentParser(lowercase_				)
     self.assertIsNotNone(lowercase_				)

from __future__ import annotations

__lowerCamelCase      :			Tuple							       =		list[list[int]]

# assigning initial values to the grid
__lowerCamelCase      :			Matrix							       =		[
    [3, 0, 6, 5, 0, 8, 4, 0, 0],
    [5, 2, 0, 0, 0, 0, 0, 0, 0],
    [0, 8, 7, 0, 0, 0, 0, 3, 1],
    [0, 0, 3, 0, 1, 0, 0, 8, 0],
    [9, 0, 0, 8, 6, 3, 0, 0, 5],
    [0, 5, 0, 0, 9, 0, 6, 0, 0],
    [1, 3, 0, 0, 0, 0, 2, 5, 0],
    [0, 0, 0, 0, 0, 0, 0, 7, 4],
    [0, 0, 5, 2, 0, 6, 3, 0, 0],
]

# a grid with no solution
__lowerCamelCase      :			Matrix							       =		[
    [5, 0, 6, 5, 0, 8, 4, 0, 3],
    [5, 2, 0, 0, 0, 0, 0, 0, 2],
    [1, 8, 7, 0, 0, 0, 0, 3, 1],
    [0, 0, 3, 0, 1, 0, 0, 8, 0],
    [9, 0, 0, 8, 6, 3, 0, 0, 5],
    [0, 5, 0, 0, 9, 0, 6, 0, 0],
    [1, 3, 0, 0, 0, 0, 2, 5, 0],
    [0, 0, 0, 0, 0, 0, 0, 7, 4],
    [0, 0, 5, 2, 0, 6, 3, 0, 0],
]



def      __SCREAMING_SNAKE_CASE  ( __UpperCamelCase   :	Matrix			,					__UpperCamelCase   :	int			,					__UpperCamelCase   :	int			,					__UpperCamelCase   :	int     )							-> bool:







  """simple docstring"""





  for i in range(9     ):
    if grid[row][i] == n or grid[i][column] == n:
      return False

  for i in range(3     ):
    for j in range(3     ):
      if grid[(row - row % 3) + i][(column - column % 3) + j] == n:
        return False

  return True



def      __SCREAMING_SNAKE_CASE  ( __UpperCamelCase   :	Matrix     )							-> tuple[int, int] | None:







  """simple docstring"""





  for i in range(9     ):
    for j in range(9     ):
      if grid[i][j] == 0:
        return i, j
  return None



def      __SCREAMING_SNAKE_CASE  ( __UpperCamelCase   :	Matrix     )							-> Matrix | None:







  """simple docstring"""





  if location := find_empty_location(__UpperCamelCase     ):
    SCREAMING_SNAKE_CASE__							,					SCREAMING_SNAKE_CASE__      							=				location
  else:
    # If the location is ``None``, then the grid is solved.
    return grid

  for digit in range(1			,					10     ):
    if is_safe(__UpperCamelCase			,					__UpperCamelCase			,					__UpperCamelCase			,					__UpperCamelCase     ):
      SCREAMING_SNAKE_CASE__      							=				digit

      if sudoku(__UpperCamelCase     ) is not None:
        return grid

      SCREAMING_SNAKE_CASE__      							=				0

  return None



def      __SCREAMING_SNAKE_CASE  ( __UpperCamelCase   :	Matrix     )							-> None:







  """simple docstring"""





  for row in grid:
    for cell in row:
      print(__UpperCamelCase			,					end=""" """     )
    print()


if __name__ == "__main__":
   # make a copy of grid so that you can compare with the unmodified grid
   for example_grid in (initial_grid, no_solution):
      print('''\nExample grid:\n''' + '''=''' * 20)
      print_solution(example_grid)
      print('''\nExample grid solution:''')
      __lowerCamelCase      :			str							       =		sudoku(example_grid)
      if solution is not None:
         print_solution(solution)
      else:
         print('''Cannot find a solution.''')
