




import logging
import os
import threading
import time


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

try:
						import msvcrt
except ImportError:
						UpperCamelCase__ :   List[Any]						=							None

try:
						import fcntl
except ImportError:
						UpperCamelCase__ :   Tuple						=							None


# Backward compatibility
# ------------------------------------------------
try:
						TimeoutError
except NameError:
						UpperCamelCase__ :   List[Any]						=							OSError


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

UpperCamelCase__ :   List[str]						=							'''3.0.12'''


UpperCamelCase__ :   str						=							None





def        __UpperCAmelCase						(							)       ->  Optional[Any]:







			"""simple docstring"""





			global _logger
			SCREAMING_SNAKE_CASE_   : Tuple					  =      _logger or logging.getLogger(__name__  )
			return _logger







class 				lowerCAmelCase_       (					lowerCamelCase_							):






				def __init__(			self      ,snake_case__ ):
							SCREAMING_SNAKE_CASE_   : List[Any]					  =      lock_file
							return None






				def __str__(			self ):
							SCREAMING_SNAKE_CASE_   : Union[str, Any]					  =      F'The file lock \'{self.lock_file}\' could not be acquired.'
							return temp







class 				lowerCAmelCase_       :






				def __init__(			self      ,snake_case__ ):
							SCREAMING_SNAKE_CASE_   : Tuple					  =      lock
							return None






				def __enter__(			self ):
							return self.lock






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







class 				lowerCAmelCase_       :






				def __init__(			self      ,snake_case__      ,snake_case__=-1      ,snake_case__=None ):
							SCREAMING_SNAKE_CASE_   : int					  =      max_filename_length if max_filename_length is not None else 255
							# Hash the filename if it's too long
							SCREAMING_SNAKE_CASE_   : int					  =      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_   : Dict					  =      None

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

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






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






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






				@timeout.setter
				def 		snake_case	(			self      ,snake_case__ ):
							SCREAMING_SNAKE_CASE_   : Any					  =      float(snake_case__ )
							return None






				def 		snake_case	(			self ):
							raise NotImplementedError()






				def 		snake_case	(			self ):
							raise NotImplementedError()






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






				def 		snake_case	(			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_   : Tuple					  =      id(self )
							SCREAMING_SNAKE_CASE_   : Any					  =      self._lock_file
							SCREAMING_SNAKE_CASE_   : int					  =      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_   : Any					  =      max(0      ,self._lock_counter - 1 )

										raise
							return _Acquire_ReturnProxy(lock=self )






				def 		snake_case	(			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_   : Union[str, Any]					  =      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 		snake_case	(			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_   : str					  =      os.path.dirname(snake_case__ )
										SCREAMING_SNAKE_CASE_   : List[Any]					  =      str(hash(snake_case__ ) )
										SCREAMING_SNAKE_CASE_   : Optional[int]					  =      filename[: max_length - len(snake_case__ ) - 8] + '...' + hashed_filename + '.lock'
										return os.path.join(snake_case__      ,snake_case__ )
							else:
										return path







class 				lowerCAmelCase_       (					lowerCamelCase_							):






				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_   : Tuple					  =      '\\\\?\\' + relative_to_absolute_path(self.lock_file )






				def 		snake_case	(			self ):
							SCREAMING_SNAKE_CASE_   : List[str]					  =      os.O_RDWR | os.O_CREAT | os.O_TRUNC

							try:
										SCREAMING_SNAKE_CASE_   : List[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_   : int					  =      fd
							return None






				def 		snake_case	(			self ):
							SCREAMING_SNAKE_CASE_   : Any					  =      self._lock_file_fd
							SCREAMING_SNAKE_CASE_   : 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 				lowerCAmelCase_       (					lowerCamelCase_							):






				def __init__(			self      ,snake_case__      ,snake_case__=-1      ,snake_case__=None ):
							SCREAMING_SNAKE_CASE_   : str					  =      os.statvfs(os.path.dirname(snake_case__ ) ).f_namemax
							super().__init__(snake_case__      ,timeout=snake_case__      ,max_filename_length=snake_case__ )






				def 		snake_case	(			self ):
							SCREAMING_SNAKE_CASE_   : int					  =      os.O_RDWR | os.O_CREAT | os.O_TRUNC
							SCREAMING_SNAKE_CASE_   : Any					  =      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_   : Any					  =      fd
							return None






				def 		snake_case	(			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_   : int					  =      self._lock_file_fd
							SCREAMING_SNAKE_CASE_   : Any					  =      None
							fcntl.flock(snake_case__      ,fcntl.LOCK_UN )
							os.close(snake_case__ )
							return None







class 				lowerCAmelCase_       (					lowerCamelCase_							):






				def 		snake_case	(			self ):
							SCREAMING_SNAKE_CASE_   : Optional[Any]					  =      os.O_WRONLY | os.O_CREAT | os.O_EXCL | os.O_TRUNC
							try:
										SCREAMING_SNAKE_CASE_   : Dict					  =      os.open(self._lock_file      ,snake_case__ )
							except OSError:
										pass
							else:
										SCREAMING_SNAKE_CASE_   : int					  =      fd
							return None






				def 		snake_case	(			self ):
							os.close(self._lock_file_fd )
							SCREAMING_SNAKE_CASE_   : List[str]					  =      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__ :   Any						=							WindowsFileLock
elif fcntl:
						UpperCamelCase__ :   Any						=							UnixFileLock
else:
						UpperCamelCase__ :   List[str]						=							SoftFileLock

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











"""simple docstring"""
from __future__ import annotations

from fractions import Fraction
from math import gcd, sqrt

def 							snake_case (  A__		):
			UpperCAmelCase_	:					int     	=   int(number**0.5		)
			return number == sq * sq

def 							snake_case (  A__      ,A__      ,A__      ,A__      ,A__      ,A__		):
			UpperCAmelCase_	:					int     	=   x_num * y_den * z_den + y_num * x_den * z_den + z_num * x_den * y_den
			UpperCAmelCase_	:					int     	=   x_den * y_den * z_den
			UpperCAmelCase_	:					int     	=   gcd(A__      ,A__		)
			top //= hcf
			bottom //= hcf
			return top, bottom

def 							snake_case (  A__ = 35		):
			UpperCAmelCase_	:					set     	=   set()
			UpperCAmelCase_	:					int
			UpperCAmelCase_	:					Fraction     	=   Fraction(0		)
			UpperCAmelCase_	:					tuple[int, int]

			for x_num in range(1      ,order + 1		):
						for x_den in range(x_num + 1      ,order + 1		):
									for y_num in range(1      ,order + 1		):
												for y_den in range(y_num + 1      ,order + 1		):
															# n=1
															UpperCAmelCase_	:					Optional[int]     	=   x_num * y_den + x_den * y_num
															UpperCAmelCase_	:					List[Any]     	=   x_den * y_den
															UpperCAmelCase_	:					Tuple     	=   gcd(A__      ,A__		)
															z_num //= hcf
															z_den //= hcf
															if 0 < z_num < z_den <= order:
																		UpperCAmelCase_	:					int     	=   add_three(
																		    A__      ,A__      ,A__      ,A__      ,A__      ,A__		)
																		unique_s.add(A__		)

															# n=2
															UpperCAmelCase_	:					Optional[Any]     	=   (
															    x_num * x_num * y_den * y_den + x_den * x_den * y_num * y_num
															)
															UpperCAmelCase_	:					Dict     	=   x_den * x_den * y_den * y_den
															if is_sq(A__		) and is_sq(A__		):
																		UpperCAmelCase_	:					int     	=   int(sqrt(A__		)		)
																		UpperCAmelCase_	:					Any     	=   int(sqrt(A__		)		)
																		UpperCAmelCase_	:					str     	=   gcd(A__      ,A__		)
																		z_num //= hcf
																		z_den //= hcf
																		if 0 < z_num < z_den <= order:
																					UpperCAmelCase_	:					Tuple     	=   add_three(
																					    A__      ,A__      ,A__      ,A__      ,A__      ,A__		)
																					unique_s.add(A__		)

                    # n=-1
															UpperCAmelCase_	:					Optional[int]     	=   x_num * y_num
															UpperCAmelCase_	:					Dict     	=   x_den * y_num + x_num * y_den
															UpperCAmelCase_	:					Union[str, Any]     	=   gcd(A__      ,A__		)
															z_num //= hcf
															z_den //= hcf
															if 0 < z_num < z_den <= order:
																		UpperCAmelCase_	:					List[Any]     	=   add_three(
																		    A__      ,A__      ,A__      ,A__      ,A__      ,A__		)
																		unique_s.add(A__		)

															# n=2
															UpperCAmelCase_	:					Optional[Any]     	=   x_num * x_num * y_num * y_num
															UpperCAmelCase_	:					Dict     	=   (
															    x_den * x_den * y_num * y_num + x_num * x_num * y_den * y_den
															)
															if is_sq(A__		) and is_sq(A__		):
																		UpperCAmelCase_	:					str     	=   int(sqrt(A__		)		)
																		UpperCAmelCase_	:					int     	=   int(sqrt(A__		)		)
																		UpperCAmelCase_	:					Optional[Any]     	=   gcd(A__      ,A__		)
																		z_num //= hcf
																		z_den //= hcf
																		if 0 < z_num < z_den <= order:
																					UpperCAmelCase_	:					Optional[int]     	=   add_three(
																					    A__      ,A__      ,A__      ,A__      ,A__      ,A__		)
																					unique_s.add(A__		)

			for num, den in unique_s:
						total += Fraction(A__      ,A__		)

			return total.denominator + total.numerator


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



