def        __UpperCAmelCase    (       UpperCAmelCase,		UpperCAmelCase       )->       Tuple:



			"""simple docstring"""







			lowercase							=		[[] for _ in range(A__       )]
			lowercase							=		key - 1

			if key <= 0:
						raise ValueError('''Height of grid can\'t be 0 or negative'''       )
			if key == 1 or len(A__       ) <= key:
						return input_string

			for position, character in enumerate(A__       ):
						lowercase							=		position % (lowest * 2)  # puts it in bounds
						lowercase							=		min(A__,		lowest * 2 - num       )  # creates zigzag pattern
						temp_grid[num].append(A__       )
			lowercase							=		[''''''.join(A__       ) for row in temp_grid]
			lowercase							=		''''''.join(A__       )

			return output_string






def        __UpperCAmelCase    (       UpperCAmelCase,		UpperCAmelCase       )->       Optional[Any]:



			"""simple docstring"""







			lowercase							=		[]
			lowercase							=		key - 1

			if key <= 0:
						raise ValueError('''Height of grid can\'t be 0 or negative'''       )
			if key == 1:
						return input_string

			lowercase							=		[[] for _ in range(A__       )]  # generates template
			for position in range(len(A__       )       ):
						lowercase							=		position % (lowest * 2)  # puts it in bounds
						lowercase							=		min(A__,		lowest * 2 - num       )  # creates zigzag pattern
						temp_grid[num].append('''*'''       )

			lowercase							=		0
			for row in temp_grid:  # fills in the characters
						lowercase							=		input_string[counter : counter + len(A__       )]
						grid.append(list(A__       )       )
						counter += len(A__       )

			lowercase							=		''''''  # reads as zigzag
			for position in range(len(A__       )       ):
						lowercase							=		position % (lowest * 2)  # puts it in bounds
						lowercase							=		min(A__,		lowest * 2 - num       )  # creates zigzag pattern
						output_string += grid[num][0]
						grid[num].pop(0       )
			return output_string






def        __UpperCAmelCase    (       UpperCAmelCase       )->       Optional[int]:



			"""simple docstring"""







			lowercase							=		{}
			for key_guess in range(1,		len(A__       )       ):  # tries every key
						lowercase							=		decrypt(A__,		A__       )
			return results


if __name__ == "__main__":
						import doctest

						doctest.testmod()






from __future__ import annotations

from fractions import Fraction
from math import gcd, sqrt






def        __UpperCAmelCase    (       UpperCAmelCase       )->       bool:



			"""simple docstring"""







			lowercase							=		int(number**0.5       )
			return number == sq * sq






def        __UpperCAmelCase    (       UpperCAmelCase,		UpperCAmelCase,		UpperCAmelCase,		UpperCAmelCase,		UpperCAmelCase,		UpperCAmelCase       )->       tuple[int, int]:



			"""simple docstring"""







			lowercase							=		x_num * y_den * z_den + y_num * x_den * z_den + z_num * x_den * y_den
			lowercase							=		x_den * y_den * z_den
			lowercase							=		gcd(UpperCAmelCase,		UpperCAmelCase       )
			top //= hcf
			bottom //= hcf
			return top, bottom






def        __UpperCAmelCase    (       UpperCAmelCase = 35       )->       int:



			"""simple docstring"""







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

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

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

															# n=2
															lowercase							=		x_num * x_num * y_num * y_num
															lowercase							=		(
															    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							=		int(sqrt(UpperCAmelCase       )       )
																		lowercase							=		int(sqrt(UpperCAmelCase       )       )
																		lowercase							=		gcd(UpperCAmelCase,		UpperCAmelCase       )
																		z_num //= hcf
																		z_den //= hcf
																		if 0 < z_num < z_den <= order:
																					lowercase							=		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() = }")





