


import logging
import os
import threading
import time


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

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

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


# Backward compatibility
# ------------------------------------------------
try:
   TimeoutError
except NameError:
   UpperCAmelCase_				:			Tuple   =	OSError


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

UpperCAmelCase_				:			Optional[Any]   =	'3.0.12'


UpperCAmelCase_				:			List[Any]   =	None







def 	SCREAMING_SNAKE_CASE_						(      )     ->		Tuple:

       """simple docstring"""

       global _logger
       a_ :		List[str]							=  _logger or logging.getLogger(__name__    )
       return _logger
class 			SCREAMING_SNAKE_CASE__  (    lowercase__      ):
      def __init__(	self    :	Dict					,							SCREAMING_SNAKE_CASE__    :	Any					)		->      Tuple:
             a_ :		int							=  lock_file
             return None

      def __str__(	self    :	str					)		->      Union[str, Any]:
             a_ :		Optional[Any]							=  F"""The file lock '{self.lock_file}' could not be acquired."""
             return temp
class 			SCREAMING_SNAKE_CASE__  :
      def __init__(	self    :	Any					,							SCREAMING_SNAKE_CASE__    :	Any					)		->      List[str]:
             a_ :		List[str]							=  lock
             return None
      def __enter__(	self    :	Union[str, Any]					)		->      Dict:
             return self.lock

      def __exit__(	self    :	Any					,							SCREAMING_SNAKE_CASE__    :	int					,							SCREAMING_SNAKE_CASE__    :	Dict					,							SCREAMING_SNAKE_CASE__    :	int					)		->      Optional[int]:
             self.lock.release()
             return None
class 			SCREAMING_SNAKE_CASE__  :
      def __init__(	self    :	Optional[int]					,							SCREAMING_SNAKE_CASE__    :	Any					,							SCREAMING_SNAKE_CASE__    :	Optional[int]=-1					,							SCREAMING_SNAKE_CASE__    :	Any=None					)		->      Optional[Any]:
             a_ :		int							=  max_filename_length if max_filename_length is not None else 2_5_5
             # Hash the filename if it's too long
             a_ :		List[Any]							=  self.hash_filename_if_too_long(SCREAMING_SNAKE_CASE__					,							SCREAMING_SNAKE_CASE__					)
             # The path to the lock file.
             a_ :		Dict							=  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.
             a_ :		Optional[int]							=  None

             # The default timeout value.
             a_ :		List[Any]							=  timeout

             # We use this lock primarily for the lock counter.
             a_ :		int							=  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.
             a_ :		Tuple							=  0
             return None
      @property
      def 	SCREAMING_SNAKE_CASE							(	self    :	List[str]					)		->      int:
             return self._lock_file
      @property
      def 	SCREAMING_SNAKE_CASE							(	self    :	Any					)		->      str:
             return self._timeout
      @timeout.setter
      def 	SCREAMING_SNAKE_CASE							(	self    :	Tuple					,							SCREAMING_SNAKE_CASE__    :	Any					)		->      Any:
             a_ :		List[str]							=  float(SCREAMING_SNAKE_CASE__					)
             return None
      def 	SCREAMING_SNAKE_CASE							(	self    :	Any					)		->      List[str]:
             raise NotImplementedError()
      def 	SCREAMING_SNAKE_CASE							(	self    :	Dict					)		->      Any:
             raise NotImplementedError()
      @property
      def 	SCREAMING_SNAKE_CASE							(	self    :	Any					)		->      List[str]:
             return self._lock_file_fd is not None
      def 	SCREAMING_SNAKE_CASE							(	self    :	str					,							SCREAMING_SNAKE_CASE__    :	Dict=None					,							SCREAMING_SNAKE_CASE__    :	Tuple=0.05					)		->      int:
             # Use the default timeout, if no timeout is provided.
             if timeout is None:
                    a_ :		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

             a_ :		Union[str, Any]							=  id(self					)
             a_ :		Optional[int]							=  self._lock_file
             a_ :		Dict							=  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:
                           a_ :		Any							=  max(0					,							self._lock_counter - 1					)

                    raise
             return _Acquire_ReturnProxy(lock=self					)
      def 	SCREAMING_SNAKE_CASE							(	self    :	Union[str, Any]					,							SCREAMING_SNAKE_CASE__    :	Tuple=False					)		->      str:
             with self._thread_lock:
                    if self.is_locked:
                           self._lock_counter -= 1

                           if self._lock_counter == 0 or force:
                                  a_ :		Optional[Any]							=  id(self					)
                                  a_ :		str							=  self._lock_file

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

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

      def 	SCREAMING_SNAKE_CASE							(	self    :	Optional[Any]					,							SCREAMING_SNAKE_CASE__    :	str					,							SCREAMING_SNAKE_CASE__    :	int					)		->      str:
             a_ :		Optional[Any]							=  os.path.basename(SCREAMING_SNAKE_CASE__					)
             if len(SCREAMING_SNAKE_CASE__					) > max_length and max_length > 0:
                    a_ :		Union[str, Any]							=  os.path.dirname(SCREAMING_SNAKE_CASE__					)
                    a_ :		int							=  str(hash(SCREAMING_SNAKE_CASE__					)					)
                    a_ :		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 			SCREAMING_SNAKE_CASE__  (    lowercase__      ):
      def __init__(	self    :	List[Any]					,							SCREAMING_SNAKE_CASE__    :	Any					,							SCREAMING_SNAKE_CASE__    :	List[str]=-1					,							SCREAMING_SNAKE_CASE__    :	List[str]=None					)		->      str:
             from .file_utils import relative_to_absolute_path

             super().__init__(SCREAMING_SNAKE_CASE__					,							timeout=SCREAMING_SNAKE_CASE__					,							max_filename_length=SCREAMING_SNAKE_CASE__					)
             a_ :		int							=  '\\\\?\\' + relative_to_absolute_path(self.lock_file					)
      def 	SCREAMING_SNAKE_CASE							(	self    :	int					)		->      Optional[Any]:
             a_ :		Optional[Any]							=  os.O_RDWR | os.O_CREAT | os.O_TRUNC

             try:
                    a_ :		List[str]							=  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:
                           a_ :		int							=  fd
             return None

      def 	SCREAMING_SNAKE_CASE							(	self    :	Optional[Any]					)		->      List[Any]:
             a_ :		Dict							=  self._lock_file_fd
             a_ :		Tuple							=  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 			SCREAMING_SNAKE_CASE__  (    lowercase__      ):
      def __init__(	self    :	List[str]					,							SCREAMING_SNAKE_CASE__    :	Tuple					,							SCREAMING_SNAKE_CASE__    :	Union[str, Any]=-1					,							SCREAMING_SNAKE_CASE__    :	Tuple=None					)		->      Union[str, Any]:
             a_ :		Dict							=  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 	SCREAMING_SNAKE_CASE							(	self    :	List[str]					)		->      List[Any]:
             a_ :		Dict							=  os.O_RDWR | os.O_CREAT | os.O_TRUNC
             a_ :		List[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:
                    a_ :		Any							=  fd
             return None

      def 	SCREAMING_SNAKE_CASE							(	self    :	Optional[int]					)		->      str:
             # 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
             a_ :		int							=  self._lock_file_fd
             a_ :		Optional[Any]							=  None
             fcntl.flock(SCREAMING_SNAKE_CASE__					,							fcntl.LOCK_UN					)
             os.close(SCREAMING_SNAKE_CASE__					)
             return None
class 			SCREAMING_SNAKE_CASE__  (    lowercase__      ):
      def 	SCREAMING_SNAKE_CASE							(	self    :	List[str]					)		->      str:
             a_ :		str							=  os.O_WRONLY | os.O_CREAT | os.O_EXCL | os.O_TRUNC
             try:
                    a_ :		Optional[Any]							=  os.open(self._lock_file					,							SCREAMING_SNAKE_CASE__					)
             except OSError:
                    pass
             else:
                    a_ :		Tuple							=  fd
             return None

      def 	SCREAMING_SNAKE_CASE							(	self    :	List[Any]					)		->      Optional[int]:
             os.close(self._lock_file_fd					)
             a_ :		Dict							=  None

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

if msvcrt:
   UpperCAmelCase_				:			List[str]   =	WindowsFileLock
elif fcntl:
   UpperCAmelCase_				:			Optional[int]   =	UnixFileLock
else:
   UpperCAmelCase_				:			Optional[int]   =	SoftFileLock

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






from __future__ import annotations

UpperCAmelCase_				:			Dict   =	[True] * 100_0001
UpperCAmelCase_				:			Any   =	2
while i * i <= 100_0000:
   if seive[i]:
      for j in range(i * i, 100_0001, i):
         UpperCAmelCase_				:			Tuple   =	False
   i += 1







def 	SCREAMING_SNAKE_CASE_						(      __A			:      int    )     ->		bool:

       """simple docstring"""

       return seive[n]







def 	SCREAMING_SNAKE_CASE_						(      __A			:      int    )     ->		bool:

       """simple docstring"""

       return any(digit in '02468' for digit in str(__A    )    )







def 	SCREAMING_SNAKE_CASE_						(      __A			:      int = 1_00_00_00    )     ->		list[int]:

       """simple docstring"""

       a_ :		Dict							=  [2]  # result already includes the number 2.
       for num in range(3  ,   limit + 1  ,   2    ):
              if is_prime(__A    ) and not contains_an_even_digit(__A    ):
                     a_ :		Dict							=  str(__A    )
                     a_ :		Any							=  [int(str_num[j:] + str_num[:j]    ) for j in range(len(__A    )    )]
                     if all(is_prime(__A    ) for i in list_nums    ):
                            result.append(__A    )
       return result







def 	SCREAMING_SNAKE_CASE_						(      )     ->		int:

       """simple docstring"""

       return len(find_circular_primes()    )


if __name__ == "__main__":
   print(F'{len(find_circular_primes()) = }')


