


"""simple docstring"""
def   _a			( _SCREAMING_SNAKE_CASE			)      ->			Tuple:
							snake_case_          =						0
							snake_case_          =						len(_SCREAMING_SNAKE_CASE			)

							for i in range(n - 1			):
														for j in range(i + 1			,	_SCREAMING_SNAKE_CASE			):
																					if arr[i] > arr[j]:
																												num_inversions += 1

							return num_inversions







def   _a			( _SCREAMING_SNAKE_CASE			)      ->			Dict:
							if len(_SCREAMING_SNAKE_CASE			) <= 1:
														return arr, 0
							snake_case_          =						len(_SCREAMING_SNAKE_CASE			) // 2
							snake_case_          =						arr[0:mid]
							snake_case_          =						arr[mid:]

							snake_case_    ,  snake_case_          =						count_inversions_recursive(_SCREAMING_SNAKE_CASE			)
							snake_case_    ,  snake_case_          =						count_inversions_recursive(_SCREAMING_SNAKE_CASE			)
							snake_case_    ,  snake_case_          =						_count_cross_inversions(_SCREAMING_SNAKE_CASE			,	_SCREAMING_SNAKE_CASE			)

							snake_case_          =						inversion_p + inversions_q + cross_inversions
							return c, num_inversions







def   _a			( _SCREAMING_SNAKE_CASE			,	_SCREAMING_SNAKE_CASE			)      ->			Optional[Any]:
							snake_case_          =						[]
							snake_case_          =						snake_case_          =						snake_case_          =						0
							while i < len(_SCREAMING_SNAKE_CASE			) and j < len(_SCREAMING_SNAKE_CASE			):
														if p[i] > q[j]:
																					# if P[1] > Q[j], then P[k] > Q[k] for all  i < k <= len(P)
																					# These are all inversions. The claim emerges from the
																					# property that P is sorted.
																					num_inversion += len(_SCREAMING_SNAKE_CASE			) - i
																					r.append(q[j]			)
																					j += 1
														else:
																					r.append(p[i]			)
																					i += 1

							if i < len(_SCREAMING_SNAKE_CASE			):
														r.extend(p[i:]			)
							else:
														r.extend(q[j:]			)

							return r, num_inversion







def   _a			( )      ->			List[str]:
							snake_case_          =						[10, 2, 1, 5, 5, 2, 11]

							# this arr has 8 inversions:
							# (10, 2), (10, 1), (10, 5), (10, 5), (10, 2), (2, 1), (5, 2), (5, 2)

							snake_case_          =						count_inversions_bf(_SCREAMING_SNAKE_CASE			)
							snake_case_    ,  snake_case_          =						count_inversions_recursive(_SCREAMING_SNAKE_CASE			)

							assert num_inversions_bf == num_inversions_recursive == 8

							print("""number of inversions = """			,	_SCREAMING_SNAKE_CASE			)

							# testing an array with zero inversion (a sorted arr_1)

							arr_a.sort()
							snake_case_          =						count_inversions_bf(_SCREAMING_SNAKE_CASE			)
							snake_case_    ,  snake_case_          =						count_inversions_recursive(_SCREAMING_SNAKE_CASE			)

							assert num_inversions_bf == num_inversions_recursive == 0
							print("""number of inversions = """			,	_SCREAMING_SNAKE_CASE			)

							# an empty list should also have zero inversions
							snake_case_          =						[]
							snake_case_          =						count_inversions_bf(_SCREAMING_SNAKE_CASE			)
							snake_case_    ,  snake_case_          =						count_inversions_recursive(_SCREAMING_SNAKE_CASE			)

							assert num_inversions_bf == num_inversions_recursive == 0
							print("""number of inversions = """			,	_SCREAMING_SNAKE_CASE			)


if __name__ == "__main__":
				main()







"""simple docstring"""
from collections import defaultdict
from math import gcd







def   _a			( _SCREAMING_SNAKE_CASE = 1_500_000			)      ->			int:
							snake_case_          =						defaultdict(_SCREAMING_SNAKE_CASE			)
							snake_case_          =						2
							while 2 * euclid_m * (euclid_m + 1) <= limit:
														for euclid_n in range((euclid_m % 2) + 1			,	_SCREAMING_SNAKE_CASE			,	2			):
																					if gcd(_SCREAMING_SNAKE_CASE			,	_SCREAMING_SNAKE_CASE			) > 1:
																												continue
																					snake_case_          =						2 * euclid_m * (euclid_m + euclid_n)
																					for perimeter in range(_SCREAMING_SNAKE_CASE			,	limit + 1			,	_SCREAMING_SNAKE_CASE			):
																												frequencies[perimeter] += 1
														euclid_m += 1
							return sum(1 for frequency in frequencies.values() if frequency == 1			)


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



