


'''simple docstring'''


import logging
import os
import threading
import time


try:
				import warnings
except ImportError:
				UpperCAmelCase_		:   int							   =		None

try:
				import msvcrt
except ImportError:
				UpperCAmelCase_		:   int							   =		None

try:
				import fcntl
except ImportError:
				UpperCAmelCase_		:   List[Any]							   =		None


# Backward compatibility
# ------------------------------------------------
try:
				TimeoutError
except NameError:
				UpperCAmelCase_		:   List[str]							   =		OSError


# Data
# ------------------------------------------------
UpperCAmelCase_		:   List[Any]							   =		[
    'Timeout',
    'BaseFileLock',
    'WindowsFileLock',
    'UnixFileLock',
    'SoftFileLock',
    'FileLock',
]

UpperCAmelCase_		:   Dict							   =		'3.0.12'


UpperCAmelCase_		:   List[str]							   =		None







def 			snake_case_   (  ):







				"""simple docstring"""





				global _logger
				_SCREAMING_SNAKE_CASE :       Dict     		=      _logger or logging.getLogger(__name__     )
				return _logger





class     lowercase__  (						_snake_case					):





							'''simple docstring'''


							def __init__(    self    ,					__snake_case  ):
											_SCREAMING_SNAKE_CASE :       Any     		=      lock_file
											return None






							def __str__(    self  ):
											_SCREAMING_SNAKE_CASE :       Optional[int]     		=      f"""The file lock '{self.lock_file}' could not be acquired."""
											return temp





class     lowercase__  :





							'''simple docstring'''


							def __init__(    self    ,					__snake_case  ):
											_SCREAMING_SNAKE_CASE :       List[str]     		=      lock
											return None






							def __enter__(    self  ):
											return self.lock






							def __exit__(    self    ,					__snake_case    ,					__snake_case    ,					__snake_case  ):
											self.lock.release()
											return None





class     lowercase__  :





							'''simple docstring'''


							def __init__(    self    ,					__snake_case    ,					__snake_case=-1    ,					__snake_case=None  ):
											_SCREAMING_SNAKE_CASE :       str     		=      max_filename_length if max_filename_length is not None else 255
											# Hash the filename if it's too long
											_SCREAMING_SNAKE_CASE :       List[Any]     		=      self.hash_filename_if_too_long(__snake_case    ,					__snake_case  )
											# The path to the lock file.
											_SCREAMING_SNAKE_CASE :       Optional[int]     		=      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.
											_SCREAMING_SNAKE_CASE :       Any     		=      None

											# The default timeout value.
											_SCREAMING_SNAKE_CASE :       Optional[int]     		=      timeout

											# We use this lock primarily for the lock counter.
											_SCREAMING_SNAKE_CASE :       List[str]     		=      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.
											_SCREAMING_SNAKE_CASE :       int     		=      0
											return None






							@property
							def UpperCAmelCase_	(    self  ):
											return self._lock_file






							@property
							def UpperCAmelCase_	(    self  ):
											return self._timeout






							@timeout.setter
							def UpperCAmelCase_	(    self    ,					__snake_case  ):
											_SCREAMING_SNAKE_CASE :       Any     		=      float(__snake_case  )
											return None






							def UpperCAmelCase_	(    self  ):
											raise NotImplementedError()






							def UpperCAmelCase_	(    self  ):
											raise NotImplementedError()






							@property
							def UpperCAmelCase_	(    self  ):
											return self._lock_file_fd is not None






							def UpperCAmelCase_	(    self    ,					__snake_case=None    ,					__snake_case=0.05  ):
											# Use the default timeout, if no timeout is provided.
											if timeout is None:
															_SCREAMING_SNAKE_CASE :       Optional[int]     		=      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

											_SCREAMING_SNAKE_CASE :       Dict     		=      id(self  )
											_SCREAMING_SNAKE_CASE :       List[Any]     		=      self._lock_file
											_SCREAMING_SNAKE_CASE :       List[str]     		=      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(__snake_case  )
											except:  # noqa
															# Something did go wrong, so decrement the counter.
															with self._thread_lock:
																			_SCREAMING_SNAKE_CASE :       List[Any]     		=      max(0    ,					self._lock_counter - 1  )

															raise
											return _Acquire_ReturnProxy(lock=self  )






							def UpperCAmelCase_	(    self    ,					__snake_case=False  ):
											with self._thread_lock:
															if self.is_locked:
																			self._lock_counter -= 1

																			if self._lock_counter == 0 or force:
																							_SCREAMING_SNAKE_CASE :       int     		=      id(self  )
																							_SCREAMING_SNAKE_CASE :       int     		=      self._lock_file

																							logger().debug(f"""Attempting to release lock {lock_id} on {lock_filename}"""  )
																							self._release()
																							_SCREAMING_SNAKE_CASE :       str     		=      0
																							logger().debug(f"""Lock {lock_id} released on {lock_filename}"""  )

											return None






							def __enter__(    self  ):
											self.acquire()
											return self






							def __exit__(    self    ,					__snake_case    ,					__snake_case    ,					__snake_case  ):
											self.release()
											return None






							def __del__(    self  ):
											self.release(force=__snake_case  )
											return None






							def UpperCAmelCase_	(    self    ,					__snake_case    ,					__snake_case  ):
											_SCREAMING_SNAKE_CASE :       Dict     		=      os.path.basename(__snake_case  )
											if len(__snake_case  ) > max_length and max_length > 0:
															_SCREAMING_SNAKE_CASE :       Any     		=      os.path.dirname(__snake_case  )
															_SCREAMING_SNAKE_CASE :       Optional[int]     		=      str(hash(__snake_case  )  )
															_SCREAMING_SNAKE_CASE :       str     		=      filename[: max_length - len(__snake_case  ) - 8] + """...""" + hashed_filename + """.lock"""
															return os.path.join(__snake_case    ,					__snake_case  )
											else:
															return path





class     lowercase__  (						_snake_case					):





							'''simple docstring'''


							def __init__(    self    ,					__snake_case    ,					__snake_case=-1    ,					__snake_case=None  ):
											from .file_utils import relative_to_absolute_path

											super().__init__(__snake_case    ,					timeout=__snake_case    ,					max_filename_length=__snake_case  )
											_SCREAMING_SNAKE_CASE :       Dict     		=      """\\\\?\\""" + relative_to_absolute_path(self.lock_file  )






							def UpperCAmelCase_	(    self  ):
											_SCREAMING_SNAKE_CASE :       Union[str, Any]     		=      os.O_RDWR | os.O_CREAT | os.O_TRUNC

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






							def UpperCAmelCase_	(    self  ):
											_SCREAMING_SNAKE_CASE :       int     		=      self._lock_file_fd
											_SCREAMING_SNAKE_CASE :       List[str]     		=      None
											msvcrt.locking(__snake_case    ,					msvcrt.LK_UNLCK    ,					1  )
											os.close(__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     lowercase__  (						_snake_case					):





							'''simple docstring'''


							def __init__(    self    ,					__snake_case    ,					__snake_case=-1    ,					__snake_case=None  ):
											_SCREAMING_SNAKE_CASE :       Union[str, Any]     		=      os.statvfs(os.path.dirname(__snake_case  )  ).f_namemax
											super().__init__(__snake_case    ,					timeout=__snake_case    ,					max_filename_length=__snake_case  )






							def UpperCAmelCase_	(    self  ):
											_SCREAMING_SNAKE_CASE :       List[str]     		=      os.O_RDWR | os.O_CREAT | os.O_TRUNC
											_SCREAMING_SNAKE_CASE :       Tuple     		=      os.open(self._lock_file    ,					__snake_case  )

											try:
															fcntl.flock(__snake_case    ,					fcntl.LOCK_EX | fcntl.LOCK_NB  )
											except OSError:
															os.close(__snake_case  )
											else:
															_SCREAMING_SNAKE_CASE :       Dict     		=      fd
											return None






							def UpperCAmelCase_	(    self  ):
											# 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
											_SCREAMING_SNAKE_CASE :       Optional[Any]     		=      self._lock_file_fd
											_SCREAMING_SNAKE_CASE :       str     		=      None
											fcntl.flock(__snake_case    ,					fcntl.LOCK_UN  )
											os.close(__snake_case  )
											return None





class     lowercase__  (						_snake_case					):





							'''simple docstring'''


							def UpperCAmelCase_	(    self  ):
											_SCREAMING_SNAKE_CASE :       Any     		=      os.O_WRONLY | os.O_CREAT | os.O_EXCL | os.O_TRUNC
											try:
															_SCREAMING_SNAKE_CASE :       List[Any]     		=      os.open(self._lock_file    ,					__snake_case  )
											except OSError:
															pass
											else:
															_SCREAMING_SNAKE_CASE :       Optional[Any]     		=      fd
											return None






							def UpperCAmelCase_	(    self  ):
											os.close(self._lock_file_fd  )
											_SCREAMING_SNAKE_CASE :       int     		=      None

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



UpperCAmelCase_		:   List[Any]							   =		None

if msvcrt:
				UpperCAmelCase_		:   Tuple							   =		WindowsFileLock
elif fcntl:
				UpperCAmelCase_		:   Dict							   =		UnixFileLock
else:
				UpperCAmelCase_		:   Any							   =		SoftFileLock

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








'''simple docstring'''


from collections import defaultdict
from math import ceil, sqrt







def 			snake_case_   (  SCREAMING_SNAKE_CASE__ = 100_0000							,      SCREAMING_SNAKE_CASE__ = 10     ):







				"""simple docstring"""





				_SCREAMING_SNAKE_CASE :       defaultdict     		=      defaultdict(SCREAMING_SNAKE_CASE__     )

				for outer_width in range(3							,      (t_limit // 4) + 2     ):
								if outer_width * outer_width > t_limit:
												_SCREAMING_SNAKE_CASE :       int     		=      max(
												    ceil(sqrt(outer_width * outer_width - t_limit     )     )							,      1     )
								else:
												_SCREAMING_SNAKE_CASE :       List[str]     		=      1

								hole_width_lower_bound += (outer_width - hole_width_lower_bound) % 2

								for hole_width in range(SCREAMING_SNAKE_CASE__							,      outer_width - 1							,      2     ):
												count[outer_width * outer_width - hole_width * hole_width] += 1

				return sum(1 for n in count.values() if 1 <= n <= 10     )


if __name__ == "__main__":
				print(F"{solution() = }")




