



'''simple docstring'''





import timeit


class 							_lowerCAmelCase	:


 """simple docstring"""

 def __init__(      self					,    _lowerCamelCase  )    ->    Any:







    if isinstance(__lowercase					,    __lowercase  ):  # Initializes a matrix identical to the one provided.
       A_  :		Dict						=					arg
       A_  :		Optional[Any]						=					len(__lowercase  )
    else:  # Initializes a square matrix of the given size and set values to zero.
       A_  :		List[str]						=					arg
       A_  :		List[Any]						=					[[0 for _ in range(self.n  )] for _ in range(self.n  )]







 def __mul__(      self					,    _lowerCamelCase  )    ->    Union[str, Any]:
    A_  :		Tuple						=					Matrix(self.n  )
    for i in range(self.n  ):
       for j in range(self.n  ):
          for k in range(self.n  ):
             matrix.t[i][j] += self.t[i][k] * b.t[k][j]
    return matrix



def     UpperCAmelCase     (    a_      ,		a_		)   ->       int:



   """simple docstring"""






   A_  :		Tuple						=					Matrix([[1, 0], [0, 1]]		)
   while b > 0:
      if b & 1:
         matrix *= a
      a *= a
      b >>= 1
   return matrix



def     UpperCAmelCase     (    a_      ,		a_      ,		a_		)   ->       List[str]:



   """simple docstring"""






   if n == 1:
      return fa
   elif n == 2:
      return fa
   A_  :		int						=					Matrix([[1, 1], [1, 0]]		)
   A_  :		Any						=					modular_exponentiation(a_      ,		n - 2		)
   return fa * matrix.t[0][0] + fa * matrix.t[0][1]



def     UpperCAmelCase     (    a_      ,		a_      ,		a_		)   ->       List[Any]:



   """simple docstring"""






   if n == 1:
      return fa
   elif n == 2:
      return fa

   A_  :		Any						=					fa
   A_  :		Optional[Any]						=					fa
   n -= 2

   while n > 0:
      A_						,  A_  :		Optional[Any]						=					fn_a + fn_a, fn_a
      n -= 1

   return fn_a



def     UpperCAmelCase     (    )   ->       List[str]:



   """simple docstring"""






   A_  :		Any						=					"""
from random import randint
from __main__ import fibonacci_with_matrix_exponentiation
"""
   A_  :		Tuple						=					"""fibonacci_with_matrix_exponentiation(randint(1,70000), 1, 1)"""
   A_  :		Optional[int]						=					timeit.timeit(setup=a_      ,		stmt=a_      ,		number=1_0_0		)
   print("""With matrix exponentiation the average execution time is """      ,		exec_time / 1_0_0		)
   return exec_time



def     UpperCAmelCase     (    )   ->       List[str]:



   """simple docstring"""






   A_  :		Dict						=					"""
from random import randint
from __main__ import simple_fibonacci
"""
   A_  :		Optional[int]						=					"""simple_fibonacci(randint(1,70000), 1, 1)"""
   A_  :		Optional[Any]						=					timeit.timeit(setup=a_      ,		stmt=a_      ,		number=1_0_0		)
   print(
       """Without matrix exponentiation the average execution time is """      ,		exec_time / 1_0_0		)
   return exec_time



def     UpperCAmelCase     (    )   ->       List[str]:



   """simple docstring"""






   matrix_exponentiation_time()
   simple_fibonacci_time()


if __name__ == "__main__":
  main()







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




def  A_(      A ):

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

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

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

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

	return white_space_fix(remove_articles(remove_punc(lower(A ) ) ) )




def  A_(      A					,   A ):
	UpperCAmelCase_		    =  normalize_answer(A ).split()
	UpperCAmelCase_		    =  normalize_answer(A ).split()
	UpperCAmelCase_		    =  Counter(A ) & Counter(A )
	UpperCAmelCase_		    =  sum(common.values() )
	if num_same == 0:
		return 0
	UpperCAmelCase_		    =  1.0 * num_same / len(A )
	UpperCAmelCase_		    =  1.0 * num_same / len(A )
	UpperCAmelCase_		    =  (2 * precision * recall) / (precision + recall)
	return fa




def  A_(      A					,   A ):
	return normalize_answer(A ) == normalize_answer(A )




def  A_(      A					,   A					,   A ):
	UpperCAmelCase_		    =  []
	for ground_truth in ground_truths:
		UpperCAmelCase_		    =  metric_fn(A					,   A )
		scores_for_ground_truths.append(A )
	return max(A )




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

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

			UpperCAmelCase_		    =  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 )

	UpperCAmelCase_		    =  exact_match / total
	UpperCAmelCase_		    =  fa / total

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


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

				with open(args.data_file) as data_file:
								UpperCamelCase__ :			int       	=			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__ :			str       	=			dataset_json["""data"""]

				with open(args.pred_file) as pred_file:
								UpperCamelCase__ :			List[Any]       	=			json.load(pred_file)

				UpperCamelCase__	,      UpperCamelCase__ :			Optional[int]       	=			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)


