


'''simple docstring'''

import logging
import os
import threading
import time


try:
					import warnings
except ImportError:
					a_						:       Dict      			=				None

try:
					import msvcrt
except ImportError:
					a_						:       Union[str, Any]      			=				None

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


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


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

a_						:       Dict      			=				"""3.0.12"""


a_						:       int      			=				None





def __snake_case      (   ):
	global _logger
	lowerCamelCase_  				=						_logger or logging.getLogger(__name__	)
	return _logger





class   snake_case					(					__a    ):





		"""simple docstring"""




		def __init__(					self    ,						UpperCamelCase  ):







			"""simple docstring"""
			lowerCamelCase_  				=						lock_file
			return None







		def __str__(					self  ):







			"""simple docstring"""
			lowerCamelCase_  				=						f'''The file lock \'{self.lock_file}\' could not be acquired.'''
			return temp





class   snake_case					:





		"""simple docstring"""




		def __init__(					self    ,						UpperCamelCase  ):







			"""simple docstring"""
			lowerCamelCase_  				=						lock
			return None






		def __enter__(					self  ):







			"""simple docstring"""
			return self.lock







		def __exit__(					self    ,						UpperCamelCase    ,						UpperCamelCase    ,						UpperCamelCase  ):







			"""simple docstring"""
			self.lock.release()
			return None





class   snake_case					:





		"""simple docstring"""




		def __init__(					self    ,						UpperCamelCase    ,						UpperCamelCase=-1    ,						UpperCamelCase=None  ):







			"""simple docstring"""
			lowerCamelCase_  				=						max_filename_length if max_filename_length is not None else 255
			# Hash the filename if it's too long
			lowerCamelCase_  				=						self.hash_filename_if_too_long(lowerCAmelCase_    ,						lowerCAmelCase_  )
			# The path to the lock file.
			lowerCamelCase_  				=						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_  				=						None

			# The default timeout value.
			lowerCamelCase_  				=						timeout

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






		@property
		def 						snake_case	(					self  ):







			"""simple docstring"""
			return self._lock_file






		@property
		def 						snake_case	(					self  ):







			"""simple docstring"""
			return self._timeout






		@timeout.setter
		def 						snake_case	(					self    ,						UpperCamelCase  ):







			"""simple docstring"""
			lowerCamelCase_  				=						float(lowerCAmelCase_  )
			return None






		def 						snake_case	(					self  ):







			"""simple docstring"""
			raise NotImplementedError()






		def 						snake_case	(					self  ):







			"""simple docstring"""
			raise NotImplementedError()






		@property
		def 						snake_case	(					self  ):







			"""simple docstring"""
			return self._lock_file_fd is not None






		def 						snake_case	(					self    ,						UpperCamelCase=None    ,						UpperCamelCase=0.05  ):







			"""simple docstring"""







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

				raise
			return _Acquire_ReturnProxy(lock=self  )






		def 						snake_case	(					self    ,						UpperCamelCase=False  ):







			"""simple docstring"""







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

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

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

			return None






		def __enter__(					self  ):







			"""simple docstring"""
			self.acquire()
			return self






		def __exit__(					self    ,						UpperCamelCase    ,						UpperCamelCase    ,						UpperCamelCase  ):







			"""simple docstring"""
			self.release()
			return None






		def __del__(					self  ):







			"""simple docstring"""
			self.release(force=lowerCAmelCase_  )
			return None







		def 						snake_case	(					self    ,						UpperCamelCase    ,						UpperCamelCase  ):







			"""simple docstring"""
			lowerCamelCase_  				=						os.path.basename(lowerCAmelCase_  )
			if len(lowerCAmelCase_  ) > max_length and max_length > 0:
				lowerCamelCase_  				=						os.path.dirname(lowerCAmelCase_  )
				lowerCamelCase_  				=						str(hash(lowerCAmelCase_  )  )
				lowerCamelCase_  				=						filename[: max_length - len(lowerCAmelCase_  ) - 8] + "..." + hashed_filename + ".lock"
				return os.path.join(lowerCAmelCase_    ,						lowerCAmelCase_  )
			else:
				return path





class   snake_case					(					__a    ):





		"""simple docstring"""




		def __init__(					self    ,						UpperCamelCase    ,						UpperCamelCase=-1    ,						UpperCamelCase=None  ):







			"""simple docstring"""
			from .file_utils import relative_to_absolute_path

			super().__init__(lowerCAmelCase_    ,						timeout=lowerCAmelCase_    ,						max_filename_length=lowerCAmelCase_  )
			lowerCamelCase_  				=						"\\\\?\\" + relative_to_absolute_path(self.lock_file  )






		def 						snake_case	(					self  ):







			"""simple docstring"""
			lowerCamelCase_  				=						os.O_RDWR | os.O_CREAT | os.O_TRUNC

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







		def 						snake_case	(					self  ):







			"""simple docstring"""
			lowerCamelCase_  				=						self._lock_file_fd
			lowerCamelCase_  				=						None
			msvcrt.locking(lowerCAmelCase_    ,						msvcrt.LK_UNLCK    ,						1  )
			os.close(lowerCAmelCase_  )

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





class   snake_case					(					__a    ):





		"""simple docstring"""




		def __init__(					self    ,						UpperCamelCase    ,						UpperCamelCase=-1    ,						UpperCamelCase=None  ):







			"""simple docstring"""
			lowerCamelCase_  				=						os.statvfs(os.path.dirname(lowerCAmelCase_  )  ).f_namemax
			super().__init__(lowerCAmelCase_    ,						timeout=lowerCAmelCase_    ,						max_filename_length=lowerCAmelCase_  )






		def 						snake_case	(					self  ):







			"""simple docstring"""
			lowerCamelCase_  				=						os.O_RDWR | os.O_CREAT | os.O_TRUNC
			lowerCamelCase_  				=						os.open(self._lock_file    ,						lowerCAmelCase_  )

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







		def 						snake_case	(					self  ):







			"""simple docstring"""
			lowerCamelCase_  				=						self._lock_file_fd
			lowerCamelCase_  				=						None
			fcntl.flock(lowerCAmelCase_    ,						fcntl.LOCK_UN  )
			os.close(lowerCAmelCase_  )
			return None





class   snake_case					(					__a    ):





		"""simple docstring"""




		def 						snake_case	(					self  ):







			"""simple docstring"""
			lowerCamelCase_  				=						os.O_WRONLY | os.O_CREAT | os.O_EXCL | os.O_TRUNC
			try:
				lowerCamelCase_  				=						os.open(self._lock_file    ,						lowerCAmelCase_  )
			except OSError:
				pass
			else:
				lowerCamelCase_  				=						fd
			return None







		def 						snake_case	(					self  ):







			"""simple docstring"""
			os.close(self._lock_file_fd  )
			lowerCamelCase_  				=						None

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



a_						:       int      			=				None

if msvcrt:
					a_						:       List[Any]      			=				WindowsFileLock
elif fcntl:
					a_						:       Optional[Any]      			=				UnixFileLock
else:
					a_						:       Dict      			=				SoftFileLock

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







'''simple docstring'''

def __snake_case      (   UpperCAmelCase_		:		int = 1000	):
 return sum(2 * a * ((a - 1) // 2) for a in range(3      ,       n + 1	)	)


if __name__ == "__main__":
     print(solution())



