



from __future__ import annotations

from fractions import Fraction
from math import gcd, sqrt





def 		a__      (		_UpperCamelCase      :			int				):
   __lowerCamelCase    				=     int(number**0.5				)
   return number == sq * sq





def 		a__      (		_UpperCamelCase      :			int			,_UpperCamelCase      :			int			,_UpperCamelCase      :			int			,_UpperCamelCase      :			int			,_UpperCamelCase      :			int			,_UpperCamelCase      :			int				):
   __lowerCamelCase    				=     x_num * y_den * z_den + y_num * x_den * z_den + z_num * x_den * y_den
   __lowerCamelCase    				=     x_den * y_den * z_den
   __lowerCamelCase    				=     gcd(_UpperCamelCase			,_UpperCamelCase				)
   top //= hcf
   bottom //= hcf
   return top, bottom





def 		a__      (		_UpperCamelCase      :			int = 35				):
   __lowerCamelCase    				=     set()
   __lowerCamelCase    				=     42
   __lowerCamelCase    				=     Fraction(0				)
   __lowerCamelCase    				=     42

   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
               __lowerCamelCase    				=     x_num * y_den + x_den * y_num
               __lowerCamelCase    				=     x_den * y_den
               __lowerCamelCase    				=     gcd(_UpperCamelCase			,_UpperCamelCase				)
               z_num //= hcf
               z_den //= hcf
               if 0 < z_num < z_den <= order:
                  __lowerCamelCase    				=     add_three(
                      _UpperCamelCase			,_UpperCamelCase			,_UpperCamelCase			,_UpperCamelCase			,_UpperCamelCase			,_UpperCamelCase				)
                  unique_s.add(_UpperCamelCase				)

               # n=2
               __lowerCamelCase    				=     (
                   x_num * x_num * y_den * y_den + x_den * x_den * y_num * y_num
               )
               __lowerCamelCase    				=     x_den * x_den * y_den * y_den
               if is_sq(_UpperCamelCase				) and is_sq(_UpperCamelCase				):
                  __lowerCamelCase    				=     int(sqrt(_UpperCamelCase				)				)
                  __lowerCamelCase    				=     int(sqrt(_UpperCamelCase				)				)
                  __lowerCamelCase    				=     gcd(_UpperCamelCase			,_UpperCamelCase				)
                  z_num //= hcf
                  z_den //= hcf
                  if 0 < z_num < z_den <= order:
                     __lowerCamelCase    				=     add_three(
                         _UpperCamelCase			,_UpperCamelCase			,_UpperCamelCase			,_UpperCamelCase			,_UpperCamelCase			,_UpperCamelCase				)
                     unique_s.add(_UpperCamelCase				)

                    # n=-1
               __lowerCamelCase    				=     x_num * y_num
               __lowerCamelCase    				=     x_den * y_num + x_num * y_den
               __lowerCamelCase    				=     gcd(_UpperCamelCase			,_UpperCamelCase				)
               z_num //= hcf
               z_den //= hcf
               if 0 < z_num < z_den <= order:
                  __lowerCamelCase    				=     add_three(
                      _UpperCamelCase			,_UpperCamelCase			,_UpperCamelCase			,_UpperCamelCase			,_UpperCamelCase			,_UpperCamelCase				)
                  unique_s.add(_UpperCamelCase				)

               # n=2
               __lowerCamelCase    				=     x_num * x_num * y_num * y_num
               __lowerCamelCase    				=     (
                   x_den * x_den * y_num * y_num + x_num * x_num * y_den * y_den
               )
               if is_sq(_UpperCamelCase				) and is_sq(_UpperCamelCase				):
                  __lowerCamelCase    				=     int(sqrt(_UpperCamelCase				)				)
                  __lowerCamelCase    				=     int(sqrt(_UpperCamelCase				)				)
                  __lowerCamelCase    				=     gcd(_UpperCamelCase			,_UpperCamelCase				)
                  z_num //= hcf
                  z_den //= hcf
                  if 0 < z_num < z_den <= order:
                     __lowerCamelCase    				=     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() = }")











from __future__ import annotations

from math import ceil, floor, sqrt





def 		a__      (		_UpperCamelCase      :			int = 2_00_00_00				):
   __lowerCamelCase    				=     [0]
   __lowerCamelCase    				=     42

   for idx in range(1			,ceil(sqrt(target * 2				) * 1.1				)				):
      triangle_numbers.append(triangle_numbers[-1] + idx				)

   # we want this to be as close as possible to target
   __lowerCamelCase    				=     0
   # the area corresponding to the grid that gives the product closest to target
   __lowerCamelCase    				=     0
   # an estimate of b, using the quadratic formula
   __lowerCamelCase    				=     42
   # the largest integer less than b_estimate
   __lowerCamelCase    				=     42
   # the largest integer less than b_estimate
   __lowerCamelCase    				=     42
   # the triangle number corresponding to b_floor
   __lowerCamelCase    				=     42
   # the triangle number corresponding to b_ceil
   __lowerCamelCase    				=     42

   for idx_a, triangle_a in enumerate(triangle_numbers[1:]			,1				):
      __lowerCamelCase    				=     (-1 + sqrt(1 + 8 * target / triangle_a				)) / 2
      __lowerCamelCase    				=     floor(_UpperCamelCase				)
      __lowerCamelCase    				=     ceil(_UpperCamelCase				)
      __lowerCamelCase    				=     triangle_numbers[b_floor]
      __lowerCamelCase    				=     triangle_numbers[b_ceil]

      if abs(target - triangle_b_first_guess * triangle_a				) < abs(
          target - best_product				):
         __lowerCamelCase    				=     triangle_b_first_guess * triangle_a
         __lowerCamelCase    				=     idx_a * b_floor

      if abs(target - triangle_b_second_guess * triangle_a				) < abs(
          target - best_product				):
         __lowerCamelCase    				=     triangle_b_second_guess * triangle_a
         __lowerCamelCase    				=     idx_a * b_ceil

   return area


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






