'''simple docstring'''




from __future__ import annotations

from fractions import Fraction
from math import gcd, sqrt




def 							lowerCamelCase			(   UpperCAmelCase__ :      int				)    ->   bool:
       lowercase_      :    int       		= int(number**0.5				)
       return number == sq * sq




def 							lowerCamelCase			(   UpperCAmelCase__ :      int   ,   UpperCAmelCase__ :      int   ,   UpperCAmelCase__ :      int   ,   UpperCAmelCase__ :      int   ,   UpperCAmelCase__ :      int   ,   UpperCAmelCase__ :      int				)    ->   tuple[int, int]:
       lowercase_      :    int       		= x_num * y_den * z_den + y_num * x_den * z_den + z_num * x_den * y_den
       lowercase_      :    int       		= x_den * y_den * z_den
       lowercase_      :    int       		= gcd(UpperCAmelCase__   ,   UpperCAmelCase__				)
       top //= hcf
       bottom //= hcf
       return top, bottom




def 							lowerCamelCase			(   UpperCAmelCase__ :      int = 35				)    ->   int:
       lowercase_      :    set       		= set()
       lowercase_      :    int
       lowercase_      :    Fraction       		= Fraction(0				)
       lowercase_      :    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
                                   lowercase_      :    str       		= x_num * y_den + x_den * y_num
                                   lowercase_      :    Optional[int]       		= x_den * y_den
                                   lowercase_      :    Optional[int]       		= gcd(UpperCAmelCase__   ,   UpperCAmelCase__				)
                                   z_num //= hcf
                                   z_den //= hcf
                                   if 0 < z_num < z_den <= order:
                                          lowercase_      :    List[str]       		= add_three(
                                              UpperCAmelCase__   ,   UpperCAmelCase__   ,   UpperCAmelCase__   ,   UpperCAmelCase__   ,   UpperCAmelCase__   ,   UpperCAmelCase__				)
                                          unique_s.add(UpperCAmelCase__				)

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

                    # n=-1
                                   lowercase_      :    List[Any]       		= x_num * y_num
                                   lowercase_      :    Any       		= x_den * y_num + x_num * y_den
                                   lowercase_      :    Any       		= gcd(UpperCAmelCase__   ,   UpperCAmelCase__				)
                                   z_num //= hcf
                                   z_den //= hcf
                                   if 0 < z_num < z_den <= order:
                                          lowercase_      :    List[Any]       		= add_three(
                                              UpperCAmelCase__   ,   UpperCAmelCase__   ,   UpperCAmelCase__   ,   UpperCAmelCase__   ,   UpperCAmelCase__   ,   UpperCAmelCase__				)
                                          unique_s.add(UpperCAmelCase__				)

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

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

       return total.denominator + total.numerator


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






'''simple docstring'''




from __future__ import annotations




def 							lowerCamelCase			(   UpperCAmelCase__ :      list   ,   UpperCAmelCase__ :      int | None = None   ,   UpperCAmelCase__ :      int | None = None				)    ->   None:
							if start is None:
														lowercase_      :    Any       		= 0

							if end is None:
														lowercase_      :    List[Any]       		= len(UpperCAmelCase__				) - 1

							if start >= end:
														return

							lowercase_      :    Optional[int]       		= (start + end) // 2

							slowsort(UpperCAmelCase__   ,   UpperCAmelCase__   ,   UpperCAmelCase__				)
							slowsort(UpperCAmelCase__   ,   mid + 1   ,   UpperCAmelCase__				)

							if sequence[end] < sequence[mid]:
														lowercase_		,		lowercase_      :    Dict       		= sequence[mid], sequence[end]

							slowsort(UpperCAmelCase__   ,   UpperCAmelCase__   ,   end - 1				)


if __name__ == "__main__":
						from doctest import testmod

						testmod()





