






"""simple docstring"""



from __future__ import annotations

_UpperCamelCase						:    Optional[int]		=						[2, 1, 4, 5, 6, 0, 8, 9, 1, 2, 0, 6, 4, 2, 0, 6, 5, 3, 2, 7]

class 			a	:







    def __init__(     self				,						_lowerCamelCase			):
      lowercase				       =			-1
      lowercase				       =			-1
      lowercase				       =			[-1] * length
      lowercase				       =			None
      lowercase				       =			None







    def __repr__(     self			):
      return F'Node(min_value={self.minn} max_value={self.maxx})'


def 		_SCREAMING_SNAKE_CASE					(       __snake_case     :    list[int]       ):





  '''simple docstring'''





  lowercase				       =			Node(len(__snake_case       )       )
  lowercase       ,	lowercase				       =			min(__snake_case       ), max(__snake_case       )
  # Leaf node case where the node contains only one unique value
  if root.minn == root.maxx:
    return root
  lowercase				       =			(root.minn + root.maxx) // 2

  lowercase				       =			[]
  lowercase				       =			[]

  for index, num in enumerate(__snake_case       ):
    if num <= pivot:
      left_arr.append(__snake_case       )
    else:
      right_arr.append(__snake_case       )
    lowercase				       =			len(__snake_case       )
  lowercase				       =			build_tree(__snake_case       )
  lowercase				       =			build_tree(__snake_case       )
  return root
def 		_SCREAMING_SNAKE_CASE					(       __snake_case     :    Node | None						,   __snake_case     :    int						,   __snake_case     :    int       ):





  '''simple docstring'''





  if index < 0 or node is None:
    return 0
  # Leaf node cases
  if node.minn == node.maxx:
    return index + 1 if node.minn == num else 0
  lowercase				       =			(node.minn + node.maxx) // 2
  if num <= pivot:
    # go the left subtree and map index to the left subtree
    return rank_till_index(node.left						,   __snake_case						,   node.map_left[index] - 1       )
  else:
    # go to the right subtree and map index to the right subtree
    return rank_till_index(node.right						,   __snake_case						,   index - node.map_left[index]       )
def 		_SCREAMING_SNAKE_CASE					(       __snake_case     :    Node | None						,   __snake_case     :    int						,   __snake_case     :    int						,   __snake_case     :    int       ):





  '''simple docstring'''





  if start > end:
    return 0
  lowercase				       =			rank_till_index(__snake_case						,   __snake_case						,   __snake_case       )
  lowercase				       =			rank_till_index(__snake_case						,   __snake_case						,   start - 1       )
  return rank_till_end - rank_before_start
def 		_SCREAMING_SNAKE_CASE					(       __snake_case     :    Node | None						,   __snake_case     :    int						,   __snake_case     :    int						,   __snake_case     :    int       ):





  '''simple docstring'''





  if index > (end - start) or start > end or node is None:
    return -1
  # Leaf node case
  if node.minn == node.maxx:
    return node.minn
  # Number of elements in the left subtree in interval [start, end]
  lowercase				       =			node.map_left[end] - (
      node.map_left[start - 1] if start else 0
  )
  if num_elements_in_left_tree > index:
    return quantile(
        node.left						,   __snake_case						,   (node.map_left[start - 1] if start else 0)						,   node.map_left[end] - 1						,   )
  else:
    return quantile(
        node.right						,   index - num_elements_in_left_tree						,   start - (node.map_left[start - 1] if start else 0)						,   end - node.map_left[end]						,   )
def 		_SCREAMING_SNAKE_CASE					(       __snake_case     :    Node | None						,   __snake_case     :    int						,   __snake_case     :    int						,   __snake_case     :    int						,   __snake_case     :    int       ):





  '''simple docstring'''





  if (
      start > end
      or node is None
      or start_num > end_num
      or node.minn > end_num
      or node.maxx < start_num
  ):
    return 0
  if start_num <= node.minn and node.maxx <= end_num:
    return end - start + 1
  lowercase				       =			range_counting(
      node.left						,   (node.map_left[start - 1] if start else 0)						,   node.map_left[end] - 1						,   __snake_case						,   __snake_case						,   )
  lowercase				       =			range_counting(
      node.right						,   start - (node.map_left[start - 1] if start else 0)						,   end - node.map_left[end]						,   __snake_case						,   __snake_case						,   )
  return left + right


if __name__ == "__main__":
    import doctest

    doctest.testmod()










"""simple docstring"""





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






def 							A(    snake_case_						):
       """simple docstring"""





       def remove_articles(snake_case_						):
              return re.sub(r"\b(a|an|the)\b"		,  " "		,  snake_case_						)

       def white_space_fix(snake_case_						):
              return " ".join(text.split()						)

       def remove_punc(snake_case_						):
              lowercase__:							str         =     set(string.punctuation						)
              return "".join(ch for ch in text if ch not in exclude						)

       def lower(snake_case_						):
              return text.lower()

       return white_space_fix(remove_articles(remove_punc(lower(snake_case_						)						)						)						)






def 							A(    snake_case_		,  snake_case_						):
       """simple docstring"""





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






def 							A(    snake_case_		,  snake_case_						):
       """simple docstring"""





       return normalize_answer(snake_case_						) == normalize_answer(snake_case_						)






def 							A(    snake_case_		,  snake_case_		,  snake_case_						):
       """simple docstring"""





       lowercase__:							int         =     []
       for ground_truth in ground_truths:
              lowercase__:							str         =     metric_fn(snake_case_		,  snake_case_						)
              scores_for_ground_truths.append(snake_case_						)
       return max(snake_case_						)






def 							A(    snake_case_		,  snake_case_						):
       """simple docstring"""





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

       lowercase__:							Union[str, Any]         =     1_00.0 * exact_match / total
       lowercase__:							str         =     1_00.0 * fa / total

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


if __name__ == "__main__":
  UpperCamelCase					=     """1.1"""
  UpperCamelCase					=     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					=     parser.parse_args()
  with open(args.dataset_file) as dataset_file:
    UpperCamelCase					=     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					=     dataset_json["""data"""]
  with open(args.prediction_file) as prediction_file:
    UpperCamelCase					=     json.load(prediction_file)
  print(json.dumps(evaluate(dataset, predictions)))






