

import logging
import os
import threading
import time


try:
					import warnings
except ImportError:
					a		=None

try:
					import msvcrt
except ImportError:
					a		=None

try:
					import fcntl
except ImportError:
					a		=None


# Backward compatibility
# ------------------------------------------------
try:
					TimeoutError
except NameError:
					a		=OSError


# Data
# ------------------------------------------------
a		=[
    """Timeout""",
    """BaseFileLock""",
    """WindowsFileLock""",
    """UnixFileLock""",
    """SoftFileLock""",
    """FileLock""",
]

a		="""3.0.12"""


a		=None






def        SCREAMING_SNAKE_CASE__	(  )  ->					List[Any]:
	global _logger
	__lowerCamelCase    :    Union[str, Any] 	=			_logger or logging.getLogger(__name__      )
	return _logger






class 	A_		(	SCREAMING_SNAKE_CASE    ):
							def __init__(		self		:      Union[str, Any]       ,SCREAMING_SNAKE_CASE__		:      Tuple):
								__lowerCamelCase    :    List[Any] 	=			lock_file
								return None


							def __str__(		self		:      Union[str, Any]):
								__lowerCamelCase    :    Union[str, Any] 	=			F"The file lock '{self.lock_file}' could not be acquired."
								return temp






class 	A_		:
							def __init__(		self		:      str       ,SCREAMING_SNAKE_CASE__		:      Tuple):
								__lowerCamelCase    :    Optional[int] 	=			lock
								return None
							def __enter__(		self		:      Union[str, Any]):
								return self.lock


							def __exit__(		self		:      List[Any]       ,SCREAMING_SNAKE_CASE__		:      Optional[Any]       ,SCREAMING_SNAKE_CASE__		:      Dict       ,SCREAMING_SNAKE_CASE__		:      Tuple):
								self.lock.release()
								return None






class 	A_		:
							def __init__(		self		:      Dict       ,SCREAMING_SNAKE_CASE__		:      List[Any]       ,SCREAMING_SNAKE_CASE__		:      Any=-1       ,SCREAMING_SNAKE_CASE__		:      int=None):
								__lowerCamelCase    :    Tuple 	=			max_filename_length if max_filename_length is not None else 2_5_5
								# Hash the filename if it's too long
								__lowerCamelCase    :    Any 	=			self.hash_filename_if_too_long(SCREAMING_SNAKE_CASE__       ,SCREAMING_SNAKE_CASE__)
								# The path to the lock file.
								__lowerCamelCase    :    List[Any] 	=			lock_file

								# The file descriptor for the *_lock_file* as it is returned by the
								# os.open() function.
								# This file lock is only NOT None, if the object currently holds the
								# lock.
								__lowerCamelCase    :    List[str] 	=			None

								# The default timeout value.
								__lowerCamelCase    :    str 	=			timeout

								# We use this lock primarily for the lock counter.
								__lowerCamelCase    :    List[Any] 	=			threading.Lock()

								# The lock counter is used for implementing the nested locking
								# mechanism. Whenever the lock is acquired, the counter is increased and
								# the lock is only released, when this value is 0 again.
								__lowerCamelCase    :    Optional[Any] 	=			0
								return None
							@property
							def    lowerCAmelCase					(		self		:      Any):
								return self._lock_file
							@property
							def    lowerCAmelCase					(		self		:      Any):
								return self._timeout
							@timeout.setter
							def    lowerCAmelCase					(		self		:      Optional[Any]       ,SCREAMING_SNAKE_CASE__		:      Union[str, Any]):
								__lowerCamelCase    :    Tuple 	=			float(SCREAMING_SNAKE_CASE__)
								return None
							def    lowerCAmelCase					(		self		:      Tuple):
								raise NotImplementedError()
							def    lowerCAmelCase					(		self		:      List[Any]):
								raise NotImplementedError()
							@property
							def    lowerCAmelCase					(		self		:      str):
								return self._lock_file_fd is not None
							def    lowerCAmelCase					(		self		:      str       ,SCREAMING_SNAKE_CASE__		:      List[Any]=None       ,SCREAMING_SNAKE_CASE__		:      Union[str, Any]=0.05):
								# Use the default timeout, if no timeout is provided.
								if timeout is None:
									__lowerCamelCase    :    List[str] 	=			self.timeout

								# Increment the number right at the beginning.
								# We can still undo it, if something fails.
								with self._thread_lock:
									self._lock_counter += 1

								__lowerCamelCase    :    Union[str, Any] 	=			id(self)
								__lowerCamelCase    :    Dict 	=			self._lock_file
								__lowerCamelCase    :    int 	=			time.time()
								try:
									while True:
										with self._thread_lock:
											if not self.is_locked:
												logger().debug(F"Attempting to acquire lock {lock_id} on {lock_filename}")
												self._acquire()

										if self.is_locked:
											logger().debug(F"Lock {lock_id} acquired on {lock_filename}")
											break
										elif timeout >= 0 and time.time() - start_time > timeout:
											logger().debug(F"Timeout on acquiring lock {lock_id} on {lock_filename}")
											raise Timeout(self._lock_file)
										else:
											logger().debug(
											    F"Lock {lock_id} not acquired on {lock_filename}, waiting {poll_intervall} seconds ...")
											time.sleep(SCREAMING_SNAKE_CASE__)
								except:  # noqa
									# Something did go wrong, so decrement the counter.
									with self._thread_lock:
										__lowerCamelCase    :    Optional[int] 	=			max(0       ,self._lock_counter - 1)

									raise
								return _Acquire_ReturnProxy(lock=self)
							def    lowerCAmelCase					(		self		:      List[Any]       ,SCREAMING_SNAKE_CASE__		:      List[Any]=False):
								with self._thread_lock:
									if self.is_locked:
										self._lock_counter -= 1

										if self._lock_counter == 0 or force:
											__lowerCamelCase    :    Dict 	=			id(self)
											__lowerCamelCase    :    Tuple 	=			self._lock_file

											logger().debug(F"Attempting to release lock {lock_id} on {lock_filename}")
											self._release()
											__lowerCamelCase    :    Optional[Any] 	=			0
											logger().debug(F"Lock {lock_id} released on {lock_filename}")

								return None
							def __enter__(		self		:      Tuple):
								self.acquire()
								return self
							def __exit__(		self		:      Union[str, Any]       ,SCREAMING_SNAKE_CASE__		:      Optional[int]       ,SCREAMING_SNAKE_CASE__		:      str       ,SCREAMING_SNAKE_CASE__		:      int):
								self.release()
								return None
							def __del__(		self		:      Any):
								self.release(force=SCREAMING_SNAKE_CASE__)
								return None


							def    lowerCAmelCase					(		self		:      Any       ,SCREAMING_SNAKE_CASE__		:      str       ,SCREAMING_SNAKE_CASE__		:      int):
								__lowerCamelCase    :    List[str] 	=			os.path.basename(SCREAMING_SNAKE_CASE__)
								if len(SCREAMING_SNAKE_CASE__) > max_length and max_length > 0:
									__lowerCamelCase    :    Union[str, Any] 	=			os.path.dirname(SCREAMING_SNAKE_CASE__)
									__lowerCamelCase    :    int 	=			str(hash(SCREAMING_SNAKE_CASE__))
									__lowerCamelCase    :    str 	=			filename[: max_length - len(SCREAMING_SNAKE_CASE__) - 8] + '...' + hashed_filename + '.lock'
									return os.path.join(SCREAMING_SNAKE_CASE__       ,SCREAMING_SNAKE_CASE__)
								else:
									return path






class 	A_		(	SCREAMING_SNAKE_CASE    ):
							def __init__(		self		:      List[str]       ,SCREAMING_SNAKE_CASE__		:      str       ,SCREAMING_SNAKE_CASE__		:      List[str]=-1       ,SCREAMING_SNAKE_CASE__		:      int=None):
								from .file_utils import relative_to_absolute_path

								super().__init__(SCREAMING_SNAKE_CASE__       ,timeout=SCREAMING_SNAKE_CASE__       ,max_filename_length=SCREAMING_SNAKE_CASE__)
								__lowerCamelCase    :    List[Any] 	=			'\\\\?\\' + relative_to_absolute_path(self.lock_file)
							def    lowerCAmelCase					(		self		:      Union[str, Any]):
								__lowerCamelCase    :    Tuple 	=			os.O_RDWR | os.O_CREAT | os.O_TRUNC

								try:
									__lowerCamelCase    :    Any 	=			os.open(self._lock_file       ,SCREAMING_SNAKE_CASE__)
								except OSError:
									pass
								else:
									try:
										msvcrt.locking(SCREAMING_SNAKE_CASE__       ,msvcrt.LK_NBLCK       ,1)
									except OSError:
										os.close(SCREAMING_SNAKE_CASE__)
									else:
										__lowerCamelCase    :    int 	=			fd
								return None


							def    lowerCAmelCase					(		self		:      Any):
								__lowerCamelCase    :    List[Any] 	=			self._lock_file_fd
								__lowerCamelCase    :    Any 	=			None
								msvcrt.locking(SCREAMING_SNAKE_CASE__       ,msvcrt.LK_UNLCK       ,1)
								os.close(SCREAMING_SNAKE_CASE__)

								try:
									os.remove(self._lock_file)
								# Probably another instance of the application
								# that acquired the file lock.
								except OSError:
									pass
								return None






class 	A_		(	SCREAMING_SNAKE_CASE    ):
							def __init__(		self		:      Union[str, Any]       ,SCREAMING_SNAKE_CASE__		:      Dict       ,SCREAMING_SNAKE_CASE__		:      List[str]=-1       ,SCREAMING_SNAKE_CASE__		:      str=None):
								__lowerCamelCase    :    str 	=			os.statvfs(os.path.dirname(SCREAMING_SNAKE_CASE__)).f_namemax
								super().__init__(SCREAMING_SNAKE_CASE__       ,timeout=SCREAMING_SNAKE_CASE__       ,max_filename_length=SCREAMING_SNAKE_CASE__)
							def    lowerCAmelCase					(		self		:      Dict):
								__lowerCamelCase    :    Tuple 	=			os.O_RDWR | os.O_CREAT | os.O_TRUNC
								__lowerCamelCase    :    Optional[Any] 	=			os.open(self._lock_file       ,SCREAMING_SNAKE_CASE__)

								try:
									fcntl.flock(SCREAMING_SNAKE_CASE__       ,fcntl.LOCK_EX | fcntl.LOCK_NB)
								except OSError:
									os.close(SCREAMING_SNAKE_CASE__)
								else:
									__lowerCamelCase    :    Union[str, Any] 	=			fd
								return None


							def    lowerCAmelCase					(		self		:      int):
								# Do not remove the lockfile:
								#
								#   https://github.com/benediktschmitt/py-filelock/issues/31
								#   https://stackoverflow.com/questions/17708885/flock-removing-locked-file-without-race-condition
								__lowerCamelCase    :    Dict 	=			self._lock_file_fd
								__lowerCamelCase    :    Optional[Any] 	=			None
								fcntl.flock(SCREAMING_SNAKE_CASE__       ,fcntl.LOCK_UN)
								os.close(SCREAMING_SNAKE_CASE__)
								return None






class 	A_		(	SCREAMING_SNAKE_CASE    ):
							def    lowerCAmelCase					(		self		:      Optional[int]):
								__lowerCamelCase    :    Optional[Any] 	=			os.O_WRONLY | os.O_CREAT | os.O_EXCL | os.O_TRUNC
								try:
									__lowerCamelCase    :    List[Any] 	=			os.open(self._lock_file       ,SCREAMING_SNAKE_CASE__)
								except OSError:
									pass
								else:
									__lowerCamelCase    :    Optional[Any] 	=			fd
								return None


							def    lowerCAmelCase					(		self		:      Union[str, Any]):
								os.close(self._lock_file_fd)
								__lowerCamelCase    :    int 	=			None

								try:
									os.remove(self._lock_file)
								# The file is already deleted and that's what we want.
								except OSError:
									pass
								return None
a		=None

if msvcrt:
					a		=WindowsFileLock
elif fcntl:
					a		=UnixFileLock
else:
					a		=SoftFileLock

					if warnings is not None:
										warnings.warn("""only soft file lock is available""")







from __future__ import annotations






def        SCREAMING_SNAKE_CASE__	(  lowerCamelCase__     ,			lowerCamelCase__     ,			lowerCamelCase__     ,			lowerCamelCase__     ,			lowerCamelCase__     ,			)  ->					None:
	__lowerCamelCase    :    int 	=			len(lowerCamelCase__      )

	# If row is equal to the size of the board it means there are a queen in each row in
	# the current board (possible_board)
	if row == n:
		# We convert the variable possible_board that looks like this: [1, 3, 0, 2] to
		# this: ['. Q . . ', '. . . Q ', 'Q . . . ', '. . Q . ']
		boards.append(['. ' * i + 'Q ' + '. ' * (n - 1 - i) for i in possible_board]      )
		return

	# We iterate each column in the row to find all possible results in each row
	for col in range(lowerCamelCase__      ):
		# We apply that we learned previously. First we check that in the current board
		# (possible_board) there are not other same value because if there is it means
		# that there are a collision in vertical. Then we apply the two formulas we
		# learned before:
		#
		# 45º: y - x = b or 45: row - col = b
		# 135º: y + x = b or row + col = b.
		#
		# And we verify if the results of this two formulas not exist in their variables
		# respectively.  (diagonal_right_collisions, diagonal_left_collisions)
		#
		# If any or these are True it means there is a collision so we continue to the
		# next value in the for loop.
		if (
		    col in possible_board
		    or row - col in diagonal_right_collisions
		    or row + col in diagonal_left_collisions
		):
			continue

		# If it is False we call dfs function again and we update the inputs
		depth_first_search(
		    [*possible_board, col]     ,			[*diagonal_right_collisions, row - col]     ,			[*diagonal_left_collisions, row + col]     ,			lowerCamelCase__     ,			lowerCamelCase__     ,			)






def        SCREAMING_SNAKE_CASE__	(  lowerCamelCase__      )  ->					None:
	__lowerCamelCase    :    list[list[str]] 	=			[]
	depth_first_search([]     ,			[]     ,			[]     ,			lowerCamelCase__     ,			lowerCamelCase__      )

	# Print all the boards
	for board in boards:
		for column in board:
			print(lowerCamelCase__      )
		print(''      )

	print(len(lowerCamelCase__      )     ,			'solutions were found.'      )


if __name__ == "__main__":
					import doctest

					doctest.testmod()
					n_queens_solution(4)




