
'''simple docstring'''





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





def 							_lowerCamelCase			(					lowerCamelCase_:  Union[str, Any]		):



				'''simple docstring'''







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

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

				def remove_punc(lowerCamelCase_:  str		):
								A     :  List[str]   =				set(string.punctuation		)
								return "".join(ch for ch in text if ch not in exclude		)

				def lower(lowerCamelCase_:  Optional[int]		):
								return text.lower()

				return white_space_fix(remove_articles(remove_punc(lower(lowerCamelCase_		)		)		)		)





def 							_lowerCamelCase			(					lowerCamelCase_:  Optional[int]				,	lowerCamelCase_:  List[str]		):



				'''simple docstring'''







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





def 							_lowerCamelCase			(					lowerCamelCase_:  Optional[Any]				,	lowerCamelCase_:  List[Any]		):



				'''simple docstring'''







				return normalize_answer(lowerCamelCase_		) == normalize_answer(lowerCamelCase_		)





def 							_lowerCamelCase			(					lowerCamelCase_:  Optional[Any]				,	lowerCamelCase_:  Any				,	lowerCamelCase_:  List[str]		):



				'''simple docstring'''







				A     :  Optional[int]   =				[]
				for ground_truth in ground_truths:
								A     :  List[str]   =				metric_fn(lowerCamelCase_				,	lowerCamelCase_		)
								scores_for_ground_truths.append(lowerCamelCase_		)
				return max(lowerCamelCase_		)





def 							_lowerCamelCase			(					lowerCamelCase_:  Tuple				,	lowerCamelCase_:  int		):



				'''simple docstring'''







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

												A     :  int   =				[x['''text'''] for x in qa['''answers''']]
												A     :  Optional[int]   =				predictions[qa['''id''']]

												A     :  Dict   =				metric_max_over_ground_truths(lowerCamelCase_				,	lowerCamelCase_				,	lowerCamelCase_		)
												if int(_exact_match		) == 1:
																correct_ids.append(qa['''id''']		)
												exact_match += _exact_match

												fa += metric_max_over_ground_truths(lowerCamelCase_				,	lowerCamelCase_				,	lowerCamelCase_		)

				A     :  str   =				exact_match / total
				A     :  str   =				fa / total

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


if __name__ == "__main__":
					UpperCamelCase_  =	"1.0"
					UpperCamelCase_  =	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.")
					UpperCamelCase_  =	parser.parse_args()

					with open(args.data_file) as data_file:
										UpperCamelCase_  =	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,
															)
										UpperCamelCase_  =	dataset_json["data"]

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

					UpperCamelCase_ ,		UpperCamelCase_  =	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)

UpperCamelCase_  =	{
    "0": 1,
    "1": 1,
    "2": 2,
    "3": 6,
    "4": 24,
    "5": 1_20,
    "6": 7_20,
    "7": 50_40,
    "8": 4_03_20,
    "9": 36_28_80,
}

UpperCamelCase_  =	{1_45: 1_45}

UpperCamelCase_  =	{
    1_45: 0,
    1_69: 3,
    3_63_01: 3,
    14_54: 3,
    8_71: 2,
    4_53_61: 2,
    8_72: 2,
}





def 							_lowerCamelCase			(					lowerCamelCase_:  int		):



				'''simple docstring'''







				if n in CACHE_SUM_DIGIT_FACTORIALS:
								return CACHE_SUM_DIGIT_FACTORIALS[n]
				A     :  Tuple   =				sum(DIGIT_FACTORIALS[let] for let in str(lowerCamelCase_		)		)
				A     :  Dict   =				ret
				return ret





def 							_lowerCamelCase			(					lowerCamelCase_:  int				,	lowerCamelCase_:  set | None = None		):



				'''simple docstring'''







				A     :  Optional[int]   =				previous or set()
				if n in CHAIN_LENGTH_CACHE:
								return CHAIN_LENGTH_CACHE[n]
				A     :  Dict   =				sum_digit_factorials(lowerCamelCase_		)
				if next_number in previous:
								A     :  Optional[int]   =				0
								return 0
				else:
								previous.add(lowerCamelCase_		)
								A     :  str   =				1 + chain_length(lowerCamelCase_				,	lowerCamelCase_		)
								A     :  Any   =				ret
								return ret





def 							_lowerCamelCase			(					lowerCamelCase_:  int = 60				,	lowerCamelCase_:  int = 100_0000		):



				'''simple docstring'''







				return sum(1 for i in range(1				,	lowerCamelCase_		) if chain_length(lowerCamelCase_		) == num_terms		)


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