


'''simple docstring'''




import argparse
import json
import re
import string
import sys
from collections import Counter

def       __UpperCamelCase     (     _A     :					List[str]					)     ->   Any:




	"""simple docstring"""





	def remove_articles(_A     :					List[str]					):
		return re.sub(r'\b(a|an|the)\b'       , ' '       , _A					)

	def white_space_fix(_A     :					Dict					):
		return " ".join(text.split()					)

	def remove_punc(_A     :					Optional[Any]					):
		lowerCAmelCase       :     int   				=			set(string.punctuation					)
		return "".join(ch for ch in text if ch not in exclude					)

	def lower(_A     :					Any					):
		return text.lower()

	return white_space_fix(remove_articles(remove_punc(lower(_A					)					)					)					)

def       __UpperCamelCase     (     _A     :					Optional[int]       , _A     :					str					)     ->   Optional[int]:




	"""simple docstring"""





	lowerCAmelCase       :     int   				=			normalize_answer(_A					).split()
	lowerCAmelCase       :     Tuple   				=			normalize_answer(_A					).split()
	lowerCAmelCase       :     Optional[Any]   				=			Counter(_A					) & Counter(_A					)
	lowerCAmelCase       :     Union[str, Any]   				=			sum(common.values()					)
	if num_same == 0:
		return 0
	lowerCAmelCase       :     List[Any]   				=			1.0 * num_same / len(_A					)
	lowerCAmelCase       :     int   				=			1.0 * num_same / len(_A					)
	lowerCAmelCase       :     Dict   				=			(2 * precision * recall) / (precision + recall)
	return fa

def       __UpperCamelCase     (     _A     :					Tuple       , _A     :					Union[str, Any]					)     ->   Any:




	"""simple docstring"""





	return normalize_answer(_A					) == normalize_answer(_A					)

def       __UpperCamelCase     (     _A     :					List[Any]       , _A     :					List[str]       , _A     :					str					)     ->   Dict:




	"""simple docstring"""





	lowerCAmelCase       :     Optional[int]   				=			[]
	for ground_truth in ground_truths:
		lowerCAmelCase       :     int   				=			metric_fn(_A       , _A					)
		scores_for_ground_truths.append(_A					)
	return max(_A					)

def       __UpperCamelCase     (     _A     :					Optional[Any]       , _A     :					Optional[int]					)     ->   str:




	"""simple docstring"""





	lowerCAmelCase       :     Any   				=			0
	lowerCAmelCase       :     Optional[Any]   				=			[]
	for passage in dataset:
		for qa in passage["qas"]:
			total += 1
			if qa["id"] not in predictions:
				lowerCAmelCase       :     str   				=			F"Unanswered question {qa['id']} will receive score 0."
				print(_A       , file=sys.stderr					)
				continue

			lowerCAmelCase       :     Dict   				=			[x['text'] for x in qa['answers']]
			lowerCAmelCase       :     str   				=			predictions[qa['id']]

			lowerCAmelCase       :     Union[str, Any]   				=			metric_max_over_ground_truths(_A       , _A       , _A					)
			if int(_exact_match					) == 1:
				correct_ids.append(qa['id']					)
			exact_match += _exact_match

			fa += metric_max_over_ground_truths(_A       , _A       , _A					)

	lowerCAmelCase       :     List[Any]   				=			exact_match / total
	lowerCAmelCase       :     Dict   				=			fa / total

	return {"exact_match": exact_match, "f1": fa}, correct_ids


if __name__ == "__main__":
				_lowerCAmelCase	:		Optional[int]		  =						'1.0'
				_lowerCAmelCase	:		List[Any]		  =						argparse.ArgumentParser('Official evaluation script for ReCoRD v1.0.')
				parser.add_argument('data_file', help='The dataset file in JSON format.')
				parser.add_argument('pred_file', help='The model prediction file in JSON format.')
				parser.add_argument('--output_correct_ids', action='store_true', help='Output the correctly answered query IDs.')
				_lowerCAmelCase	:		Any		  =						parser.parse_args()

				with open(args.data_file) as data_file:
								_lowerCAmelCase	:		str		  =						json.load(data_file)
								if dataset_json["version"] != expected_version:
												print(
												    f"""Evaluation expects v-{expected_version}, but got dataset with v-{dataset_json['version']}""",
												    file=sys.stderr,
												)
								_lowerCAmelCase	:		Optional[int]		  =						dataset_json['data']

				with open(args.pred_file) as pred_file:
								_lowerCAmelCase	:		Dict		  =						json.load(pred_file)

				_lowerCAmelCase  ,   _lowerCAmelCase	:		Tuple		  =						evaluate(dataset, predictions)

				if args.output_correct_ids:
								print(f"""Output {len(correct_ids)} correctly answered question IDs.""")
								with open('correct_ids.json', 'w') as f:
												json.dump(correct_ids, f)




'''simple docstring'''




from itertools import combinations, product

def       __UpperCamelCase     (     _A     :					int       , _A     :					int       , _A     :					int       , _A     :					int					)     ->   bool:




	"""simple docstring"""





	if xa == ya == 0 or xa == ya == 0:
		return False
	lowerCAmelCase       :     Optional[Any]   				=			xa * xa + ya * ya
	lowerCAmelCase       :     Tuple   				=			xa * xa + ya * ya
	lowerCAmelCase       :     List[str]   				=			(xa - xa) * (xa - xa) + (ya - ya) * (ya - ya)
	return (
	    a_square + b_square == c_square
	    or a_square + c_square == b_square
	    or b_square + c_square == a_square
	)

def       __UpperCamelCase     (     _A     :					int = 50					)     ->   int:




	"""simple docstring"""





	return sum(
	    1
	    for pta, pta in combinations(product(range(limit + 1					)       , repeat=2					)       , 2					)
	    if is_right(*_A       , *_A					)					)


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