





"""simple docstring"""





import logging
import os
import threading
import time


try:
  import warnings
except ImportError:
  lowercase__				:Any				   =       None

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

try:
  import fcntl
except ImportError:
  lowercase__				:str				   =       None


# Backward compatibility
# ------------------------------------------------
try:
  TimeoutError
except NameError:
  lowercase__				:Union[str, Any]				   =       OSError


# Data
# ------------------------------------------------
lowercase__				:int				   =       [
    'Timeout',
    'BaseFileLock',
    'WindowsFileLock',
    'UnixFileLock',
    'SoftFileLock',
    'FileLock',
]

lowercase__				:Tuple				   =       '3.0.12'


lowercase__				:Dict				   =       None


def       lowerCamelCase_       (   )						->List[str]:





  """simple docstring"""


  global _logger
  __UpperCAmelCase    :						List[Any]       =						_logger or logging.getLogger(__name__  )
  return _logger




class 							snake_case							(			__UpperCAmelCase ):

      '''simple docstring'''



      def __init__(							self       :      Dict						,				__lowercase       :      Optional[Any] ):


        '''simple docstring'''




        __UpperCAmelCase    :						List[str]       =						lock_file
        return None







      def __str__(							self       :      Union[str, Any] ):


        '''simple docstring'''




        __UpperCAmelCase    :						str       =						f'''The file lock \'{self.lock_file}\' could not be acquired.'''
        return temp




class 							snake_case							:

      '''simple docstring'''



      def __init__(							self       :      List[str]						,				__lowercase       :      List[Any] ):


        '''simple docstring'''




        __UpperCAmelCase    :						List[Any]       =						lock
        return None

      def __enter__(							self       :      Tuple ):


        '''simple docstring'''




        return self.lock







      def __exit__(							self       :      Optional[Any]						,				__lowercase       :      List[Any]						,				__lowercase       :      Union[str, Any]						,				__lowercase       :      Any ):


        '''simple docstring'''




        self.lock.release()
        return None




class 							snake_case							:

      '''simple docstring'''



      def __init__(							self       :      int						,				__lowercase       :      List[Any]						,				__lowercase       :      List[Any]=-1						,				__lowercase       :      Tuple=None ):


        '''simple docstring'''




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

        # The default timeout value.
        __UpperCAmelCase    :						int       =						timeout

        # We use this lock primarily for the lock counter.
        __UpperCAmelCase    :						Optional[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.
        __UpperCAmelCase    :						Union[str, Any]       =						0
        return None

      @property
      def       A_					(							self       :      Tuple ):


        '''simple docstring'''




        return self._lock_file

      @property
      def       A_					(							self       :      int ):


        '''simple docstring'''




        return self._timeout

      @timeout.setter
      def       A_					(							self       :      Optional[int]						,				__lowercase       :      Any ):


        '''simple docstring'''




        __UpperCAmelCase    :						str       =						float(__lowercase )
        return None

      def       A_					(							self       :      int ):


        '''simple docstring'''




        raise NotImplementedError()

      def       A_					(							self       :      Optional[Any] ):


        '''simple docstring'''




        raise NotImplementedError()

      @property
      def       A_					(							self       :      str ):


        '''simple docstring'''




        return self._lock_file_fd is not None

      def       A_					(							self       :      int						,				__lowercase       :      List[Any]=None						,				__lowercase       :      Tuple=0.0_5 ):


        '''simple docstring'''




        if timeout is None:
          __UpperCAmelCase    :						Union[str, Any]       =						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

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

          raise
        return _Acquire_ReturnProxy(lock=self )

      def       A_					(							self       :      int						,				__lowercase       :      List[Any]=False ):


        '''simple docstring'''




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

            if self._lock_counter == 0 or force:
              __UpperCAmelCase    :						Tuple       =						id(self )
              __UpperCAmelCase    :						List[str]       =						self._lock_file

              logger().debug(f'''Attempting to release lock {lock_id} on {lock_filename}''' )
              self._release()
              __UpperCAmelCase    :						List[str]       =						0
              logger().debug(f'''Lock {lock_id} released on {lock_filename}''' )

        return None

      def __enter__(							self       :      Any ):


        '''simple docstring'''




        self.acquire()
        return self

      def __exit__(							self       :      int						,				__lowercase       :      Tuple						,				__lowercase       :      str						,				__lowercase       :      Dict ):


        '''simple docstring'''




        self.release()
        return None

      def __del__(							self       :      List[Any] ):


        '''simple docstring'''




        self.release(force=__lowercase )
        return None







      def       A_					(							self       :      str						,				__lowercase       :      str						,				__lowercase       :      int ):


        '''simple docstring'''




        __UpperCAmelCase    :						Optional[Any]       =						os.path.basename(__lowercase )
        if len(__lowercase ) > max_length and max_length > 0:
          __UpperCAmelCase    :						int       =						os.path.dirname(__lowercase )
          __UpperCAmelCase    :						int       =						str(hash(__lowercase ) )
          __UpperCAmelCase    :						Optional[Any]       =						filename[: max_length - len(__lowercase ) - 8] + '''...''' + hashed_filename + '''.lock'''
          return os.path.join(__lowercase						,				__lowercase )
        else:
          return path




class 							snake_case							(			__UpperCAmelCase ):

      '''simple docstring'''



      def __init__(							self       :      Optional[Any]						,				__lowercase       :      int						,				__lowercase       :      int=-1						,				__lowercase       :      Union[str, Any]=None ):


        '''simple docstring'''




        from .file_utils import relative_to_absolute_path

        super().__init__(__lowercase						,				timeout=__lowercase						,				max_filename_length=__lowercase )
        __UpperCAmelCase    :						Optional[int]       =						'''\\\\?\\''' + relative_to_absolute_path(self.lock_file )

      def       A_					(							self       :      Optional[Any] ):


        '''simple docstring'''




        __UpperCAmelCase    :						Dict       =						os.O_RDWR | os.O_CREAT | os.O_TRUNC

        try:
          __UpperCAmelCase    :						str       =						os.open(self._lock_file						,				__lowercase )
        except OSError:
          pass
        else:
          try:
            msvcrt.locking(__lowercase						,				msvcrt.LK_NBLCK						,				1 )
          except OSError:
            os.close(__lowercase )
          else:
            __UpperCAmelCase    :						Union[str, Any]       =						fd
        return None







      def       A_					(							self       :      Any ):


        '''simple docstring'''




        __UpperCAmelCase    :						Union[str, Any]       =						self._lock_file_fd
        __UpperCAmelCase    :						List[Any]       =						None
        msvcrt.locking(__lowercase						,				msvcrt.LK_UNLCK						,				1 )
        os.close(__lowercase )

        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							(			__UpperCAmelCase ):

      '''simple docstring'''



      def __init__(							self       :      Dict						,				__lowercase       :      Dict						,				__lowercase       :      Union[str, Any]=-1						,				__lowercase       :      Optional[int]=None ):


        '''simple docstring'''




        __UpperCAmelCase    :						Optional[int]       =						os.statvfs(os.path.dirname(__lowercase ) ).f_namemax
        super().__init__(__lowercase						,				timeout=__lowercase						,				max_filename_length=__lowercase )

      def       A_					(							self       :      Tuple ):


        '''simple docstring'''




        __UpperCAmelCase    :						Optional[int]       =						os.O_RDWR | os.O_CREAT | os.O_TRUNC
        __UpperCAmelCase    :						Union[str, Any]       =						os.open(self._lock_file						,				__lowercase )

        try:
          fcntl.flock(__lowercase						,				fcntl.LOCK_EX | fcntl.LOCK_NB )
        except OSError:
          os.close(__lowercase )
        else:
          __UpperCAmelCase    :						List[Any]       =						fd
        return None







      def       A_					(							self       :      List[Any] ):


        '''simple docstring'''




        __UpperCAmelCase    :						Tuple       =						self._lock_file_fd
        __UpperCAmelCase    :						Optional[int]       =						None
        fcntl.flock(__lowercase						,				fcntl.LOCK_UN )
        os.close(__lowercase )
        return None




class 							snake_case							(			__UpperCAmelCase ):

      '''simple docstring'''



      def       A_					(							self       :      Optional[int] ):


        '''simple docstring'''




        __UpperCAmelCase    :						Optional[Any]       =						os.O_WRONLY | os.O_CREAT | os.O_EXCL | os.O_TRUNC
        try:
          __UpperCAmelCase    :						Optional[Any]       =						os.open(self._lock_file						,				__lowercase )
        except OSError:
          pass
        else:
          __UpperCAmelCase    :						Any       =						fd
        return None







      def       A_					(							self       :      Dict ):


        '''simple docstring'''




        os.close(self._lock_file_fd )
        __UpperCAmelCase    :						Optional[Any]       =						None

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


lowercase__				:str				   =       None

if msvcrt:
  lowercase__				:Tuple				   =       WindowsFileLock
elif fcntl:
  lowercase__				:Union[str, Any]				   =       UnixFileLock
else:
  lowercase__				:List[Any]				   =       SoftFileLock

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






"""simple docstring"""





def       lowerCamelCase_       (   UpperCAmelCase_ = 10_00  )						->int:





  """simple docstring"""


  return sum(2 * a * ((a - 1) // 2) for a in range(3  ,			n + 1  )  )


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