
import logging
import os
import threading
import time


try:
					import warnings
except ImportError:
					SCREAMING_SNAKE_CASE							:Optional[Any]							 =				None

try:
					import msvcrt
except ImportError:
					SCREAMING_SNAKE_CASE							:str							 =				None

try:
					import fcntl
except ImportError:
					SCREAMING_SNAKE_CASE							:Optional[Any]							 =				None


# Backward compatibility
# ------------------------------------------------
try:
					TimeoutError
except NameError:
					SCREAMING_SNAKE_CASE							:Dict							 =				OSError


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

SCREAMING_SNAKE_CASE							:str							 =				'3.0.12'


SCREAMING_SNAKE_CASE							:Optional[int]							 =				None


def 						UpperCAmelCase			(	)		->	str:







				"""simple docstring"""



				global _logger
				__A   			= _logger or logging.getLogger(__name__						)
				return _logger





class 							UpperCAmelCase      (  __a  ):




	'''simple docstring'''





	def __init__(       self					: List[Any]							,A					: int ):
					__A   			= lock_file
					return None







	def __str__(       self					: str ):
					__A   			= f'''The file lock \'{self.lock_file}\' could not be acquired.'''
					return temp





class 							UpperCAmelCase      :




	'''simple docstring'''





	def __init__(       self					: Tuple							,A					: str ):
					__A   			= lock
					return None






	def __enter__(       self					: int ):
					return self.lock







	def __exit__(       self					: str							,A					: List[str]							,A					: List[Any]							,A					: Any ):
					self.lock.release()
					return None





class 							UpperCAmelCase      :




	'''simple docstring'''





	def __init__(       self					: Tuple							,A					: Any							,A					: Dict=-1							,A					: Optional[Any]=None ):
					__A   			= max_filename_length if max_filename_length is not None else 2_55
					# Hash the filename if it's too long
					__A   			= self.hash_filename_if_too_long(_A							,_A )
					# The path to the lock file.
					__A   			= 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   			= None

					# The default timeout value.
					__A   			= timeout

					# We use this lock primarily for the lock counter.
					__A   			= 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   			= 0
					return None






	@property
	def 				UpperCamelCase_  (       self					: Union[str, Any] ):
					return self._lock_file






	@property
	def 				UpperCamelCase_  (       self					: str ):
					return self._timeout






	@timeout.setter
	def 				UpperCamelCase_  (       self					: str							,A					: Dict ):
					__A   			= float(_A )
					return None






	def 				UpperCamelCase_  (       self					: Optional[int] ):
					raise NotImplementedError()






	def 				UpperCamelCase_  (       self					: Tuple ):
					raise NotImplementedError()






	@property
	def 				UpperCamelCase_  (       self					: List[Any] ):
					return self._lock_file_fd is not None






	def 				UpperCamelCase_  (       self					: str							,A					: List[Any]=None							,A					: Optional[Any]=0.05 ):


					if timeout is None:
									__A   			= 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   			= id(self )
					__A   			= self._lock_file
					__A   			= 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(_A )
					except:  # noqa
									# Something did go wrong, so decrement the counter.
									with self._thread_lock:
													__A   			= max(0							,self._lock_counter - 1 )

									raise
					return _Acquire_ReturnProxy(lock=self )






	def 				UpperCamelCase_  (       self					: int							,A					: Any=False ):


					with self._thread_lock:
									if self.is_locked:
													self._lock_counter -= 1

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

																	logger().debug(f'''Attempting to release lock {lock_id} on {lock_filename}''' )
																	self._release()
																	__A   			= 0
																	logger().debug(f'''Lock {lock_id} released on {lock_filename}''' )

					return None






	def __enter__(       self					: Union[str, Any] ):
					self.acquire()
					return self






	def __exit__(       self					: Optional[int]							,A					: int							,A					: str							,A					: Any ):
					self.release()
					return None






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







	def 				UpperCamelCase_  (       self					: List[str]							,A					: str							,A					: int ):
					__A   			= os.path.basename(_A )
					if len(_A ) > max_length and max_length > 0:
									__A   			= os.path.dirname(_A )
									__A   			= str(hash(_A ) )
									__A   			= filename[: max_length - len(_A ) - 8] + '''...''' + hashed_filename + '''.lock'''
									return os.path.join(_A							,_A )
					else:
									return path





class 							UpperCAmelCase      (  __a  ):




	'''simple docstring'''





	def __init__(       self					: Tuple							,A					: Optional[int]							,A					: List[str]=-1							,A					: Dict=None ):
					from .file_utils import relative_to_absolute_path

					super().__init__(_A							,timeout=_A							,max_filename_length=_A )
					__A   			= '''\\\\?\\''' + relative_to_absolute_path(self.lock_file )






	def 				UpperCamelCase_  (       self					: Tuple ):
					__A   			= os.O_RDWR | os.O_CREAT | os.O_TRUNC

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







	def 				UpperCamelCase_  (       self					: int ):
					__A   			= self._lock_file_fd
					__A   			= None
					msvcrt.locking(_A							,msvcrt.LK_UNLCK							,1 )
					os.close(_A )

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





class 							UpperCAmelCase      (  __a  ):




	'''simple docstring'''





	def __init__(       self					: str							,A					: Any							,A					: Any=-1							,A					: List[str]=None ):
					__A   			= os.statvfs(os.path.dirname(_A ) ).f_namemax
					super().__init__(_A							,timeout=_A							,max_filename_length=_A )






	def 				UpperCamelCase_  (       self					: int ):
					__A   			= os.O_RDWR | os.O_CREAT | os.O_TRUNC
					__A   			= os.open(self._lock_file							,_A )

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







	def 				UpperCamelCase_  (       self					: Union[str, Any] ):
					__A   			= self._lock_file_fd
					__A   			= None
					fcntl.flock(_A							,fcntl.LOCK_UN )
					os.close(_A )
					return None





class 							UpperCAmelCase      (  __a  ):




	'''simple docstring'''





	def 				UpperCamelCase_  (       self					: int ):
					__A   			= os.O_WRONLY | os.O_CREAT | os.O_EXCL | os.O_TRUNC
					try:
									__A   			= os.open(self._lock_file							,_A )
					except OSError:
									pass
					else:
									__A   			= fd
					return None







	def 				UpperCamelCase_  (       self					: Union[str, Any] ):
					os.close(self._lock_file_fd )
					__A   			= None

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





SCREAMING_SNAKE_CASE							:int							 =				None

if msvcrt:
					SCREAMING_SNAKE_CASE							:Dict							 =				WindowsFileLock
elif fcntl:
					SCREAMING_SNAKE_CASE							:List[str]							 =				UnixFileLock
else:
					SCREAMING_SNAKE_CASE							:int							 =				SoftFileLock

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




'''simple docstring'''
def 					a__       (					lowerCAmelCase__						)    ->	int:
    UpperCAmelCase__			:		Tuple													=				0
    while num > 0:
        digit_sum += num % 10
        num //= 10
    return digit_sum





def 					a__       (					lowerCAmelCase__ = 1_00						)    ->	int:
    UpperCAmelCase__			:		Dict													=				1
    UpperCAmelCase__			:		str													=				2

    for i in range(2  ,					max_n + 1						):
        UpperCAmelCase__			:		Tuple													=				pre_numerator
        UpperCAmelCase__			:		Tuple													=				2 * i // 3 if i % 3 == 0 else 1
        UpperCAmelCase__			:		str													=				cur_numerator
        UpperCAmelCase__			:		List[str]													=				e_cont * pre_numerator + temp

    return sum_digits(lowerCAmelCase__						)


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