


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


def   a						(				SCREAMING_SNAKE_CASE_   :		Union[str, Any]							):






       """simple docstring"""





       def remove_articles(SCREAMING_SNAKE_CASE_   :		Optional[Any]							):
              return re.sub(R'''\b(a|an|the)\b'''				,      ''' '''				,      SCREAMING_SNAKE_CASE_							)

       def white_space_fix(SCREAMING_SNAKE_CASE_   :		Union[str, Any]							):
              return " ".join(text.split()							)

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

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

       return white_space_fix(remove_articles(remove_punc(lower(SCREAMING_SNAKE_CASE_							)							)							)							)


def   a						(				SCREAMING_SNAKE_CASE_   :		List[Any]				,      SCREAMING_SNAKE_CASE_   :		Optional[int]							):






       """simple docstring"""





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


def   a						(				SCREAMING_SNAKE_CASE_   :		Dict				,      SCREAMING_SNAKE_CASE_   :		List[Any]							):






       """simple docstring"""





       return normalize_answer(SCREAMING_SNAKE_CASE_							) == normalize_answer(SCREAMING_SNAKE_CASE_							)


def   a						(				SCREAMING_SNAKE_CASE_   :		Dict				,      SCREAMING_SNAKE_CASE_   :		Tuple				,      SCREAMING_SNAKE_CASE_   :		List[Any]							):






       """simple docstring"""





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


def   a						(				SCREAMING_SNAKE_CASE_   :		Optional[int]				,      SCREAMING_SNAKE_CASE_   :		Any							):






       """simple docstring"""





       UpperCamelCase     :						List[str] 						=		0
       for article in dataset:
              for paragraph in article["paragraphs"]:
                     for qa in paragraph["qas"]:
                            total += 1
                            if qa["id"] not in predictions:
                                   UpperCamelCase     :						List[Any] 						=		'''Unanswered question ''' + qa['''id'''] + ''' will receive score 0.'''
                                   print(SCREAMING_SNAKE_CASE_				,      file=sys.stderr							)
                                   continue
                            UpperCamelCase     :						List[Any] 						=		[x['''text'''] for x in qa['''answers''']]
                            UpperCamelCase     :						Any 						=		predictions[qa['''id''']]
                            exact_match += metric_max_over_ground_truths(SCREAMING_SNAKE_CASE_				,      SCREAMING_SNAKE_CASE_				,      SCREAMING_SNAKE_CASE_							)
                            fa += metric_max_over_ground_truths(SCREAMING_SNAKE_CASE_				,      SCREAMING_SNAKE_CASE_				,      SCREAMING_SNAKE_CASE_							)

       UpperCamelCase     :						str 						=		100.0 * exact_match / total
       UpperCamelCase     :						List[Any] 						=		100.0 * fa / total

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


if __name__ == "__main__":
  __UpperCAmelCase			:			str			      =					"1.1"
  __UpperCAmelCase			:			Union[str, Any]			      =					argparse.ArgumentParser(description="Evaluation for SQuAD " + expected_version)
  parser.add_argument("dataset_file", help="Dataset file")
  parser.add_argument("prediction_file", help="Prediction File")
  __UpperCAmelCase			:			Any			      =					parser.parse_args()
  with open(args.dataset_file) as dataset_file:
    __UpperCAmelCase			:			List[Any]			      =					json.load(dataset_file)
    if dataset_json["version"] != expected_version:
      print(
          "Evaluation expects v-" + expected_version + ", but got dataset with v-" + dataset_json["version"],
          file=sys.stderr,
      )
    __UpperCAmelCase			:			Optional[int]			      =					dataset_json["data"]
  with open(args.prediction_file) as prediction_file:
    __UpperCAmelCase			:			Dict			      =					json.load(prediction_file)
  print(json.dumps(evaluate(dataset, predictions)))





def   a						(				SCREAMING_SNAKE_CASE_   :		int							):






       """simple docstring"""





       UpperCamelCase     :						Tuple 						=		[True for i in range(n + 1							)]
       UpperCamelCase     :						Tuple 						=		[i - 1 for i in range(n + 1							)]
       UpperCamelCase     :						Optional[Any] 						=		[]
       for i in range(2				,      n + 1							):
              if is_prime[i]:
                     primes.append(SCREAMING_SNAKE_CASE_							)
              for j in range(0				,      len(SCREAMING_SNAKE_CASE_							)							):
                     if i * primes[j] >= n:
                            break
                     UpperCamelCase     :						Any 						=		False

                     if i % primes[j] == 0:
                            UpperCamelCase     :						int 						=		totients[i] * primes[j]
                            break

                     UpperCamelCase     :						Dict 						=		totients[i] * (primes[j] - 1)

       return totients


if __name__ == "__main__":
  import doctest

  doctest.testmod()

