



from math import isclose, sqrt
def 							__SCREAMING_SNAKE_CASE		(				_SCREAMING_SNAKE_CASE   :	List[str]     ,				_SCREAMING_SNAKE_CASE   :	Optional[int]     ,				_SCREAMING_SNAKE_CASE   :	str				)->Tuple:
      _lowerCAmelCase 			=  point_y / 4 / point_x
      _lowerCAmelCase 			=  2 * normal_gradient / (1 + normal_gradient * normal_gradient)
      _lowerCAmelCase 			=  (1 - normal_gradient * normal_gradient) / (
          1 + normal_gradient * normal_gradient
      )
      _lowerCAmelCase 			=  (sa - ca * incoming_gradient) / (ca + sa * incoming_gradient)

      # to find the next point, solve the simultaeneous equations:
      # y^2 + 4x^2 = 100
      # y - b = m * (x - a)
      # ==> A x^2 + B x + C = 0
      _lowerCAmelCase 			=  outgoing_gradient**2 + 4
      _lowerCAmelCase 			=  2 * outgoing_gradient * (point_y - outgoing_gradient * point_x)
      _lowerCAmelCase 			=  (point_y - outgoing_gradient * point_x) ** 2 - 1_0_0

      _lowerCAmelCase 			=  (
          -linear_term - sqrt(linear_term**2 - 4 * quadratic_term * constant_term				)
      ) / (2 * quadratic_term)
      _lowerCAmelCase 			=  (
          -linear_term + sqrt(linear_term**2 - 4 * quadratic_term * constant_term				)
      ) / (2 * quadratic_term)

      # two solutions, one of which is our input point
      _lowerCAmelCase 			=  x_minus if isclose(_lowerCamelCase     ,				_lowerCamelCase				) else x_plus
      _lowerCAmelCase 			=  point_y + outgoing_gradient * (next_x - point_x)

      return next_x, next_y, outgoing_gradient
def 							__SCREAMING_SNAKE_CASE		(				_SCREAMING_SNAKE_CASE   :	str = 1.4     ,				_SCREAMING_SNAKE_CASE   :	Optional[Any] = -9.6				)->Optional[Any]:
      _lowerCAmelCase 			=  0
      _lowerCAmelCase 			=  first_x_coord
      _lowerCAmelCase 			=  first_y_coord
      _lowerCAmelCase 			=  (10.1 - point_y) / (0.0 - point_x)

      while not (-0.01 <= point_x <= 0.01 and point_y > 0):
            _lowerCAmelCase 			=  next_point(_lowerCamelCase     ,				_lowerCamelCase     ,				_lowerCamelCase				)
            num_reflections += 1

      return num_reflections


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




import re
import string
from collections import Counter

import sacrebleu
import sacremoses
from packaging import version

import datasets


UpperCAmelCase_									=							"\n@inproceedings{xu-etal-2016-optimizing,\n    title = {Optimizing Statistical Machine Translation for Text Simplification},\n    authors={Xu, Wei and Napoles, Courtney and Pavlick, Ellie and Chen, Quanze and Callison-Burch, Chris},\n    journal = {Transactions of the Association for Computational Linguistics},\n    volume = {4},\n    year={2016},\n    url = {https://www.aclweb.org/anthology/Q16-1029},\n    pages = {401--415\n},\n@inproceedings{post-2018-call,\n    title = \"A Call for Clarity in Reporting {BLEU} Scores\",\n    author = \"Post, Matt\",\n    booktitle = \"Proceedings of the Third Conference on Machine Translation: Research Papers\",\n    month = oct,\n    year = \"2018\",\n    address = \"Belgium, Brussels\",\n    publisher = \"Association for Computational Linguistics\",\n    url = \"https://www.aclweb.org/anthology/W18-6319\",\n    pages = \"186--191\",\n}\n"

UpperCAmelCase_									=							"\\nWIKI_SPLIT is the combination of three metrics SARI, EXACT and SACREBLEU\nIt can be used to evaluate the quality of machine-generated texts.\n"


UpperCAmelCase_									=							"\nCalculates sari score (between 0 and 100) given a list of source and predicted\nsentences, and a list of lists of reference sentences. It also computes the BLEU score as well as the exact match score.\nArgs:\n    sources: list of source sentences where each sentence should be a string.\n    predictions: list of predicted sentences where each sentence should be a string.\n    references: list of lists of reference sentences where each sentence should be a string.\nReturns:\n    sari: sari score\n    sacrebleu: sacrebleu score\n    exact: exact score\n\nExamples:\n    >>> sources=[\"About 95 species are currently accepted .\"]\n    >>> predictions=[\"About 95 you now get in .\"]\n    >>> references=[[\"About 95 species are currently known .\"]]\n    >>> wiki_split = datasets.load_metric(\"wiki_split\")\n    >>> results = wiki_split.compute(sources=sources, predictions=predictions, references=references)\n    >>> print(results)\n    {'sari': 21.805555555555557, 'sacrebleu': 14.535768424205482, 'exact': 0.0}\n"
def 							UpperCAmelCase__		(				_SCREAMING_SNAKE_CASE   :	List[Any]				)->Optional[Any]:

      def remove_articles(_SCREAMING_SNAKE_CASE   :	List[str]				):
            _lowerCAmelCase 			=  re.compile(r'''\b(a|an|the)\b'''     ,				re.UNICODE				)
            return re.sub(_SCREAMING_SNAKE_CASE     ,				''' '''     ,				_SCREAMING_SNAKE_CASE				)

      def white_space_fix(_SCREAMING_SNAKE_CASE   :	List[Any]				):
            return " ".join(text.split()				)

      def remove_punc(_SCREAMING_SNAKE_CASE   :	Optional[Any]				):
            _lowerCAmelCase 			=  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 							UpperCAmelCase__		(				_SCREAMING_SNAKE_CASE   :	Optional[Any]     ,				_SCREAMING_SNAKE_CASE   :	List[Any]				)->Any:
      return int(normalize_answer(_SCREAMING_SNAKE_CASE				) == normalize_answer(_SCREAMING_SNAKE_CASE				)				)
def 							UpperCAmelCase__		(				_SCREAMING_SNAKE_CASE   :	Union[str, Any]     ,				_SCREAMING_SNAKE_CASE   :	str				)->int:
      _lowerCAmelCase 			=  [any(compute_exact(_SCREAMING_SNAKE_CASE     ,				_SCREAMING_SNAKE_CASE				) for ref in refs				) for pred, refs in zip(_SCREAMING_SNAKE_CASE     ,				_SCREAMING_SNAKE_CASE				)]
      return (sum(_SCREAMING_SNAKE_CASE				) / len(_SCREAMING_SNAKE_CASE				)) * 1_0_0
def 							UpperCAmelCase__		(				_SCREAMING_SNAKE_CASE   :	List[str]     ,				_SCREAMING_SNAKE_CASE   :	Union[str, Any]     ,				_SCREAMING_SNAKE_CASE   :	Union[str, Any]     ,				_SCREAMING_SNAKE_CASE   :	List[str]				)->Optional[int]:
      _lowerCAmelCase 			=  [rgram for rgrams in rgramslist for rgram in rgrams]
      _lowerCAmelCase 			=  Counter(_SCREAMING_SNAKE_CASE				)

      _lowerCAmelCase 			=  Counter(_SCREAMING_SNAKE_CASE				)
      _lowerCAmelCase 			=  Counter()
      for sgram, scount in sgramcounter.items():
            _lowerCAmelCase 			=  scount * numref

      _lowerCAmelCase 			=  Counter(_SCREAMING_SNAKE_CASE				)
      _lowerCAmelCase 			=  Counter()
      for cgram, ccount in cgramcounter.items():
            _lowerCAmelCase 			=  ccount * numref

      # KEEP
      _lowerCAmelCase 			=  sgramcounter_rep & cgramcounter_rep
      _lowerCAmelCase 			=  keepgramcounter_rep & rgramcounter
      _lowerCAmelCase 			=  sgramcounter_rep & rgramcounter

      _lowerCAmelCase 			=  0
      _lowerCAmelCase 			=  0
      for keepgram in keepgramcountergood_rep:
            keeptmpscorea += keepgramcountergood_rep[keepgram] / keepgramcounter_rep[keepgram]
            # Fix an alleged bug [2] in the keep score computation.
            # keeptmpscore2 += keepgramcountergood_rep[keepgram] / keepgramcounterall_rep[keepgram]
            keeptmpscorea += keepgramcountergood_rep[keepgram]
      # Define 0/0=1 instead of 0 to give higher scores for predictions that match
      #      a target exactly.
      _lowerCAmelCase 			=  1
      _lowerCAmelCase 			=  1
      if len(_SCREAMING_SNAKE_CASE				) > 0:
            _lowerCAmelCase 			=  keeptmpscorea / len(_SCREAMING_SNAKE_CASE				)
      if len(_SCREAMING_SNAKE_CASE				) > 0:
            # Fix an alleged bug [2] in the keep score computation.
            # keepscore_recall = keeptmpscore2 / len(keepgramcounterall_rep)
            _lowerCAmelCase 			=  keeptmpscorea / sum(keepgramcounterall_rep.values()				)
      _lowerCAmelCase 			=  0
      if keepscore_precision > 0 or keepscore_recall > 0:
            _lowerCAmelCase 			=  2 * keepscore_precision * keepscore_recall / (keepscore_precision + keepscore_recall)

      # DELETION
      _lowerCAmelCase 			=  sgramcounter_rep - cgramcounter_rep
      _lowerCAmelCase 			=  delgramcounter_rep - rgramcounter
      _lowerCAmelCase 			=  sgramcounter_rep - rgramcounter
      _lowerCAmelCase 			=  0
      _lowerCAmelCase 			=  0
      for delgram in delgramcountergood_rep:
            deltmpscorea += delgramcountergood_rep[delgram] / delgramcounter_rep[delgram]
            deltmpscorea += delgramcountergood_rep[delgram] / delgramcounterall_rep[delgram]
      # Define 0/0=1 instead of 0 to give higher scores for predictions that match
      # a target exactly.
      _lowerCAmelCase 			=  1
      if len(_SCREAMING_SNAKE_CASE				) > 0:
            _lowerCAmelCase 			=  deltmpscorea / len(_SCREAMING_SNAKE_CASE				)

      # ADDITION
      _lowerCAmelCase 			=  set(_SCREAMING_SNAKE_CASE				) - set(_SCREAMING_SNAKE_CASE				)
      _lowerCAmelCase 			=  set(_SCREAMING_SNAKE_CASE				) & set(_SCREAMING_SNAKE_CASE				)
      _lowerCAmelCase 			=  set(_SCREAMING_SNAKE_CASE				) - set(_SCREAMING_SNAKE_CASE				)

      _lowerCAmelCase 			=  0
      for addgram in addgramcountergood:
            addtmpscore += 1

      # Define 0/0=1 instead of 0 to give higher scores for predictions that match
      # a target exactly.
      _lowerCAmelCase 			=  1
      _lowerCAmelCase 			=  1
      if len(_SCREAMING_SNAKE_CASE				) > 0:
            _lowerCAmelCase 			=  addtmpscore / len(_SCREAMING_SNAKE_CASE				)
      if len(_SCREAMING_SNAKE_CASE				) > 0:
            _lowerCAmelCase 			=  addtmpscore / len(_SCREAMING_SNAKE_CASE				)
      _lowerCAmelCase 			=  0
      if addscore_precision > 0 or addscore_recall > 0:
            _lowerCAmelCase 			=  2 * addscore_precision * addscore_recall / (addscore_precision + addscore_recall)

      return (keepscore, delscore_precision, addscore)
def 							UpperCAmelCase__		(				_SCREAMING_SNAKE_CASE   :	Any     ,				_SCREAMING_SNAKE_CASE   :	int     ,				_SCREAMING_SNAKE_CASE   :	str				)->List[Any]:
      _lowerCAmelCase 			=  len(_SCREAMING_SNAKE_CASE				)

      _lowerCAmelCase 			=  ssent.split(''' '''				)
      _lowerCAmelCase 			=  csent.split(''' '''				)
      _lowerCAmelCase 			=  []
      _lowerCAmelCase 			=  []
      _lowerCAmelCase 			=  []
      _lowerCAmelCase 			=  []
      _lowerCAmelCase 			=  []
      _lowerCAmelCase 			=  []

      _lowerCAmelCase 			=  []
      _lowerCAmelCase 			=  []
      _lowerCAmelCase 			=  []
      _lowerCAmelCase 			=  []
      for rsent in rsents:
            _lowerCAmelCase 			=  rsent.split(''' '''				)
            _lowerCAmelCase 			=  []
            _lowerCAmelCase 			=  []
            _lowerCAmelCase 			=  []
            ragramslist.append(_SCREAMING_SNAKE_CASE				)
            for i in range(0     ,				len(_SCREAMING_SNAKE_CASE				) - 1				):
                  if i < len(_SCREAMING_SNAKE_CASE				) - 1:
                        _lowerCAmelCase 			=  ragrams[i] + ''' ''' + ragrams[i + 1]
                        ragrams.append(_SCREAMING_SNAKE_CASE				)
                  if i < len(_SCREAMING_SNAKE_CASE				) - 2:
                        _lowerCAmelCase 			=  ragrams[i] + ''' ''' + ragrams[i + 1] + ''' ''' + ragrams[i + 2]
                        ragrams.append(_SCREAMING_SNAKE_CASE				)
                  if i < len(_SCREAMING_SNAKE_CASE				) - 3:
                        _lowerCAmelCase 			=  ragrams[i] + ''' ''' + ragrams[i + 1] + ''' ''' + ragrams[i + 2] + ''' ''' + ragrams[i + 3]
                        ragrams.append(_SCREAMING_SNAKE_CASE				)
            ragramslist.append(_SCREAMING_SNAKE_CASE				)
            ragramslist.append(_SCREAMING_SNAKE_CASE				)
            ragramslist.append(_SCREAMING_SNAKE_CASE				)

      for i in range(0     ,				len(_SCREAMING_SNAKE_CASE				) - 1				):
            if i < len(_SCREAMING_SNAKE_CASE				) - 1:
                  _lowerCAmelCase 			=  sagrams[i] + ''' ''' + sagrams[i + 1]
                  sagrams.append(_SCREAMING_SNAKE_CASE				)
            if i < len(_SCREAMING_SNAKE_CASE				) - 2:
                  _lowerCAmelCase 			=  sagrams[i] + ''' ''' + sagrams[i + 1] + ''' ''' + sagrams[i + 2]
                  sagrams.append(_SCREAMING_SNAKE_CASE				)
            if i < len(_SCREAMING_SNAKE_CASE				) - 3:
                  _lowerCAmelCase 			=  sagrams[i] + ''' ''' + sagrams[i + 1] + ''' ''' + sagrams[i + 2] + ''' ''' + sagrams[i + 3]
                  sagrams.append(_SCREAMING_SNAKE_CASE				)

      for i in range(0     ,				len(_SCREAMING_SNAKE_CASE				) - 1				):
            if i < len(_SCREAMING_SNAKE_CASE				) - 1:
                  _lowerCAmelCase 			=  cagrams[i] + ''' ''' + cagrams[i + 1]
                  cagrams.append(_SCREAMING_SNAKE_CASE				)
            if i < len(_SCREAMING_SNAKE_CASE				) - 2:
                  _lowerCAmelCase 			=  cagrams[i] + ''' ''' + cagrams[i + 1] + ''' ''' + cagrams[i + 2]
                  cagrams.append(_SCREAMING_SNAKE_CASE				)
            if i < len(_SCREAMING_SNAKE_CASE				) - 3:
                  _lowerCAmelCase 			=  cagrams[i] + ''' ''' + cagrams[i + 1] + ''' ''' + cagrams[i + 2] + ''' ''' + cagrams[i + 3]
                  cagrams.append(_SCREAMING_SNAKE_CASE				)

      ((_lowerCAmelCase)			,   (_lowerCAmelCase)			,   (_lowerCAmelCase)) 			=  SARIngram(_SCREAMING_SNAKE_CASE     ,				_SCREAMING_SNAKE_CASE     ,				_SCREAMING_SNAKE_CASE     ,				_SCREAMING_SNAKE_CASE				)
      ((_lowerCAmelCase)			,   (_lowerCAmelCase)			,   (_lowerCAmelCase)) 			=  SARIngram(_SCREAMING_SNAKE_CASE     ,				_SCREAMING_SNAKE_CASE     ,				_SCREAMING_SNAKE_CASE     ,				_SCREAMING_SNAKE_CASE				)
      ((_lowerCAmelCase)			,   (_lowerCAmelCase)			,   (_lowerCAmelCase)) 			=  SARIngram(_SCREAMING_SNAKE_CASE     ,				_SCREAMING_SNAKE_CASE     ,				_SCREAMING_SNAKE_CASE     ,				_SCREAMING_SNAKE_CASE				)
      ((_lowerCAmelCase)			,   (_lowerCAmelCase)			,   (_lowerCAmelCase)) 			=  SARIngram(_SCREAMING_SNAKE_CASE     ,				_SCREAMING_SNAKE_CASE     ,				_SCREAMING_SNAKE_CASE     ,				_SCREAMING_SNAKE_CASE				)
      _lowerCAmelCase 			=  sum([keepascore, keepascore, keepascore, keepascore]				) / 4
      _lowerCAmelCase 			=  sum([delascore, delascore, delascore, delascore]				) / 4
      _lowerCAmelCase 			=  sum([addascore, addascore, addascore, addascore]				) / 4
      _lowerCAmelCase 			=  (avgkeepscore + avgdelscore + avgaddscore) / 3
      return finalscore
def 							UpperCAmelCase__		(				_SCREAMING_SNAKE_CASE   :	int     ,				_SCREAMING_SNAKE_CASE   :	bool = True     ,				_SCREAMING_SNAKE_CASE   :	str = "13a"     ,				_SCREAMING_SNAKE_CASE   :	bool = True				)->int:
      # Normalization is requried for the ASSET dataset (one of the primary
      # datasets in sentence simplification) to allow using space
      # to split the sentence. Even though Wiki-Auto and TURK datasets,
      # do not require normalization, we do it for consistency.
      # Code adapted from the EASSE library [1] written by the authors of the ASSET dataset.
      # [1] https://github.com/feralvam/easse/blob/580bba7e1378fc8289c663f864e0487188fe8067/easse/utils/preprocessing.py#L7

      if lowercase:
            _lowerCAmelCase 			=  sentence.lower()

      if tokenizer in ["13a", "intl"]:
            if version.parse(sacrebleu.__version__				).major >= 2:
                  _lowerCAmelCase 			=  sacrebleu.metrics.bleu._get_tokenizer(_SCREAMING_SNAKE_CASE				)()(_SCREAMING_SNAKE_CASE				)
            else:
                  _lowerCAmelCase 			=  sacrebleu.TOKENIZERS[tokenizer]()(_SCREAMING_SNAKE_CASE				)
      elif tokenizer == "moses":
            _lowerCAmelCase 			=  sacremoses.MosesTokenizer().tokenize(_SCREAMING_SNAKE_CASE     ,				return_str=_SCREAMING_SNAKE_CASE     ,				escape=_SCREAMING_SNAKE_CASE				)
      elif tokenizer == "penn":
            _lowerCAmelCase 			=  sacremoses.MosesTokenizer().penn_tokenize(_SCREAMING_SNAKE_CASE     ,				return_str=_SCREAMING_SNAKE_CASE				)
      else:
            _lowerCAmelCase 			=  sentence

      if not return_str:
            _lowerCAmelCase 			=  normalized_sent.split()

      return normalized_sent
def 							UpperCAmelCase__		(				_SCREAMING_SNAKE_CASE   :	int     ,				_SCREAMING_SNAKE_CASE   :	List[Any]     ,				_SCREAMING_SNAKE_CASE   :	List[str]				)->str:
      if not (len(_SCREAMING_SNAKE_CASE				) == len(_SCREAMING_SNAKE_CASE				) == len(_SCREAMING_SNAKE_CASE				)):
            raise ValueError('''Sources length must match predictions and references lengths.'''				)
      _lowerCAmelCase 			=  0
      for src, pred, refs in zip(_SCREAMING_SNAKE_CASE     ,				_SCREAMING_SNAKE_CASE     ,				_SCREAMING_SNAKE_CASE				):
            sari_score += SARIsent(normalize(_SCREAMING_SNAKE_CASE				)     ,				normalize(_SCREAMING_SNAKE_CASE				)     ,				[normalize(_SCREAMING_SNAKE_CASE				) for sent in refs]				)
      _lowerCAmelCase 			=  sari_score / len(_SCREAMING_SNAKE_CASE				)
      return 1_0_0 * sari_score
def 							UpperCAmelCase__		(				_SCREAMING_SNAKE_CASE   :	str     ,				_SCREAMING_SNAKE_CASE   :	List[str]     ,				_SCREAMING_SNAKE_CASE   :	Optional[Any]="exp"     ,				_SCREAMING_SNAKE_CASE   :	Optional[int]=None     ,				_SCREAMING_SNAKE_CASE   :	Optional[int]=False     ,				_SCREAMING_SNAKE_CASE   :	str=False     ,				_SCREAMING_SNAKE_CASE   :	int=False     ,				)->str:
      _lowerCAmelCase 			=  len(references[0]				)
      if any(len(_SCREAMING_SNAKE_CASE				) != references_per_prediction for refs in references				):
            raise ValueError('''Sacrebleu requires the same number of references for each prediction'''				)
      _lowerCAmelCase 			=  [[refs[i] for refs in references] for i in range(_SCREAMING_SNAKE_CASE				)]
      _lowerCAmelCase 			=  sacrebleu.corpus_bleu(
          _SCREAMING_SNAKE_CASE     ,				_SCREAMING_SNAKE_CASE     ,				smooth_method=_SCREAMING_SNAKE_CASE     ,				smooth_value=_SCREAMING_SNAKE_CASE     ,				force=_SCREAMING_SNAKE_CASE     ,				lowercase=_SCREAMING_SNAKE_CASE     ,				use_effective_order=_SCREAMING_SNAKE_CASE     ,				)
      return output.score





@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION       ,_KWARGS_DESCRIPTION				)
class 		UpperCAmelCase						(						datasets.Metric				):





   def 	__lowerCAmelCase							(	self			):
         return datasets.MetricInfo(
             description=_DESCRIPTION       ,     citation=_CITATION       ,     inputs_description=_KWARGS_DESCRIPTION       ,     features=datasets.Features(
                 {
                     '''predictions''': datasets.Value('''string'''       ,     id='''sequence'''			),
                     '''references''': datasets.Sequence(datasets.Value('''string'''       ,     id='''sequence'''			)       ,     id='''references'''			),
                 }			)       ,     codebase_urls=[
                 '''https://github.com/huggingface/transformers/blob/master/src/transformers/data/metrics/squad_metrics.py''',
                 '''https://github.com/cocoxu/simplification/blob/master/SARI.py''',
                 '''https://github.com/tensorflow/tensor2tensor/blob/master/tensor2tensor/utils/sari_hook.py''',
                 '''https://github.com/mjpost/sacreBLEU''',
             ]       ,     reference_urls=[
                 '''https://www.aclweb.org/anthology/Q16-1029.pdf''',
                 '''https://github.com/mjpost/sacreBLEU''',
                 '''https://en.wikipedia.org/wiki/BLEU''',
                 '''https://towardsdatascience.com/evaluating-text-output-in-nlp-bleu-at-your-own-risk-e8609665a213''',
             ]       ,     )





   def 	__lowerCAmelCase							(	self       ,     _lowerCAmelCase       ,     _lowerCAmelCase       ,     _lowerCAmelCase			):
         _lowerCAmelCase 			=  {}
         result.update({'''sari''': compute_sari(sources=_lowerCAmelCase       ,     predictions=_lowerCAmelCase       ,     references=_lowerCAmelCase			)}			)
         result.update({'''sacrebleu''': compute_sacrebleu(predictions=_lowerCAmelCase       ,     references=_lowerCAmelCase			)}			)
         result.update({'''exact''': compute_em(predictions=_lowerCAmelCase       ,     references=_lowerCAmelCase			)}			)
         return result