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







def 					UpperCamelCase_						( snake_case_	:	Union[str, Any]				) ->					Optional[int]:






 '''simple docstring'''

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

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

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

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

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







def 					UpperCamelCase_						( snake_case_	:	str						,		snake_case_	:	Optional[int]				) ->					Any:






 '''simple docstring'''

 __lowerCAmelCase    							=						normalize_answer(snake_case_				).split()
 __lowerCAmelCase    							=						normalize_answer(snake_case_				).split()
 __lowerCAmelCase    							=						Counter(snake_case_				) & Counter(snake_case_				)
 __lowerCAmelCase    							=						sum(common.values()				)
 if num_same == 0:
  return 0
 __lowerCAmelCase    							=						1.0 * num_same / len(snake_case_				)
 __lowerCAmelCase    							=						1.0 * num_same / len(snake_case_				)
 __lowerCAmelCase    							=						(2 * precision * recall) / (precision + recall)
 return fa







def 					UpperCamelCase_						( snake_case_	:	Optional[Any]						,		snake_case_	:	str				) ->					List[str]:






 '''simple docstring'''

 return normalize_answer(snake_case_				) == normalize_answer(snake_case_				)







def 					UpperCamelCase_						( snake_case_	:	str						,		snake_case_	:	str						,		snake_case_	:	Optional[int]				) ->					Any:






 '''simple docstring'''

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







def 					UpperCamelCase_						( snake_case_	:	int						,		snake_case_	:	List[str]				) ->					List[str]:






 '''simple docstring'''

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

   __lowerCAmelCase    							=						[x["""text"""] for x in qa["""answers"""]]
   __lowerCAmelCase    							=						predictions[qa["""id"""]]

   __lowerCAmelCase    							=						metric_max_over_ground_truths(snake_case_						,		snake_case_						,		snake_case_				)
   if int(_exact_match				) == 1:
    correct_ids.append(qa["""id"""]				)
   exact_match += _exact_match

   fa += metric_max_over_ground_truths(snake_case_						,		snake_case_						,		snake_case_				)

 __lowerCAmelCase    							=						exact_match / total
 __lowerCAmelCase    							=						fa / total

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


if __name__ == "__main__":
 _A      :				Optional[int] 				=    '''1.0'''
 _A      :				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.''')
 _A      :				Optional[int] 				=    parser.parse_args()

 with open(args.data_file) as data_file:
  _A      :				List[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,
   )
  _A      :				int 				=    dataset_json['''data''']

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

 _A      :				Dict 				=    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'''

import functools
from math import sqrt
from time import time







def 					UpperCamelCase_						( snake_case_	:	Dict						,		*snake_case_	:	Union[str, Any]						,		**snake_case_	:	List[str]				) ->					List[str]:






 '''simple docstring'''

 __lowerCAmelCase    							=						time()
 __lowerCAmelCase    							=						func(*snake_case_						,		**snake_case_				)
 __lowerCAmelCase    							=						time()
 if int(end - start				) > 0:
  print(f"""{func.__name__} runtime: {(end - start):0.4f} s"""				)
 else:
  print(f"""{func.__name__} runtime: {(end - start) * 10_00:0.4f} ms"""				)
 return output







def 					UpperCamelCase_						( snake_case_	:	int				) ->					list[int]:






 '''simple docstring'''

 if n < 0:
  raise Exception("""n is negative"""				)
 if n == 0:
  return [0]
 __lowerCAmelCase    							=						[0, 1]
 for _ in range(n - 1				):
  fib.append(fib[-1] + fib[-2]				)
 return fib







def 					UpperCamelCase_						( snake_case_	:	int				) ->					list[int]:






 '''simple docstring'''

 def fib_recursive_term(snake_case_	:	int				) -> int:
  if i < 0:
   raise Exception("""n is negative"""				)
  if i < 2:
   return i
  return fib_recursive_term(i - 1				) + fib_recursive_term(i - 2				)

 if n < 0:
  raise Exception("""n is negative"""				)
 return [fib_recursive_term(snake_case_				) for i in range(n + 1				)]







def 					UpperCamelCase_						( snake_case_	:	int				) ->					list[int]:






 '''simple docstring'''

 @functools.cache
 def fib_recursive_term(snake_case_	:	int				) -> int:
  if i < 0:
   raise Exception("""n is negative"""				)
  if i < 2:
   return i
  return fib_recursive_term(i - 1				) + fib_recursive_term(i - 2				)

 if n < 0:
  raise Exception("""n is negative"""				)
 return [fib_recursive_term(snake_case_				) for i in range(n + 1				)]







def 					UpperCamelCase_						( snake_case_	:	int				) ->					list[int]:






 '''simple docstring'''

 if n < 0:
  raise Exception("""n is negative"""				)
 # Cache must be outside recursuive function
 # other it will reset every time it calls itself.
 __lowerCAmelCase    							=						{0: 0, 1: 1, 2: 1}  # Prefilled cache

 def rec_fn_memoized(snake_case_	:	int				) -> int:
  if num in cache:
   return cache[num]

  __lowerCAmelCase    							=						rec_fn_memoized(num - 1				) + rec_fn_memoized(num - 2				)
  __lowerCAmelCase    							=						value
  return value

 return [rec_fn_memoized(snake_case_				) for i in range(n + 1				)]







def 					UpperCamelCase_						( snake_case_	:	int				) ->					list[int]:






 '''simple docstring'''

 if n < 0:
  raise Exception("""n is negative"""				)
 if n >= 14_75:
  raise Exception("""n is too large"""				)
 __lowerCAmelCase    							=						sqrt(5				)
 __lowerCAmelCase    							=						(1 + sqrt_a) / 2
 return [round(phi**i / sqrt_a				) for i in range(n + 1				)]


if __name__ == "__main__":
 _A      :				Optional[Any] 				=    30
 time_func(fib_iterative, num)
 time_func(fib_recursive, num)  # Around 3s runtime
 time_func(fib_recursive_cached, num)  # Around 0ms runtime
 time_func(fib_memoization, num)
 time_func(fib_binet, num)






