'''simple docstring'''




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







def 			A_   ( _lowerCamelCase			:							Tuple    ):

      def remove_articles(_lowerCamelCase			:							Optional[int]    ):
            return re.sub(r'\b(a|an|the)\b'  ,  ' '  ,  _lowerCamelCase    )

      def white_space_fix(_lowerCamelCase			:							str    ):
            return " ".join(text.split()    )

      def remove_punc(_lowerCamelCase			:							Union[str, Any]    ):
            _lowerCAmelCase		   =   set(string.punctuation    )
            return "".join(ch for ch in text if ch not in exclude    )

      def lower(_lowerCamelCase			:							List[Any]    ):
            return text.lower()

      return white_space_fix(remove_articles(remove_punc(lower(_lowerCamelCase    )    )    )    )







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







def 			A_   ( _lowerCamelCase			:							int  ,  _lowerCamelCase			:							Tuple    ):
      return normalize_answer(_lowerCamelCase    ) == normalize_answer(_lowerCamelCase    )







def 			A_   ( _lowerCamelCase			:							List[str]  ,  _lowerCamelCase			:							Any  ,  _lowerCamelCase			:							Dict    ):
      _lowerCAmelCase		   =   []
      for ground_truth in ground_truths:
            _lowerCAmelCase		   =   metric_fn(_lowerCamelCase  ,  _lowerCamelCase    )
            scores_for_ground_truths.append(_lowerCamelCase    )
      return max(_lowerCamelCase    )







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

      _lowerCAmelCase		   =   100.0 * exact_match / total
      _lowerCAmelCase		   =   100.0 * fa / total

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


if __name__ == "__main__":
 snake_case  =			'''1.1'''
 snake_case  =			argparse.ArgumentParser(description='''Evaluation for SQuAD ''' + expected_version)
 parser.add_argument('''dataset_file''', help='''Dataset file''')
 parser.add_argument('''prediction_file''', help='''Prediction File''')
 snake_case  =			parser.parse_args()
 with open(args.dataset_file) as dataset_file:
  snake_case  =			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,
   )
  snake_case  =			dataset_json['''data''']
 with open(args.prediction_file) as prediction_file:
  snake_case  =			json.load(prediction_file)
 print(json.dumps(evaluate(dataset, predictions)))






'''simple docstring'''




from __future__ import annotations







def 			A_   ( _lowerCamelCase			:							str  ,  _lowerCamelCase			:							dict[str, str]    ):
      _lowerCAmelCase   ,  _lowerCAmelCase   ,  _lowerCAmelCase		   =   '', '', ''
      _lowerCAmelCase		   =   []

      for character in message_part:
            tmp.append(character_to_number[character]    )

      for each in tmp:
            one += each[0]
            two += each[1]
            three += each[2]

      return one + two + three







def 			A_   ( _lowerCamelCase			:							str  ,  _lowerCamelCase			:							dict[str, str]    ):
      _lowerCAmelCase   ,  _lowerCAmelCase		   =   '', ''
      _lowerCAmelCase		   =   []

      for character in message_part:
            this_part += character_to_number[character]

      for digit in this_part:
            tmp += digit
            if len(_lowerCamelCase    ) == len(_lowerCamelCase    ):
                  result.append(_lowerCamelCase    )
                  _lowerCAmelCase		   =   ''

      return result[0], result[1], result[2]







def 			A_   ( _lowerCamelCase			:							str  ,  _lowerCamelCase			:							str    ):
      # Validate message and alphabet, set to upper and remove spaces
      _lowerCAmelCase		   =   alphabet.replace(' '  ,  ''    ).upper()
      _lowerCAmelCase		   =   message.replace(' '  ,  ''    ).upper()

      # Check length and characters
      if len(_lowerCamelCase    ) != 27:
            raise KeyError('Length of alphabet has to be 27.'    )
      for each in message:
            if each not in alphabet:
                  raise ValueError('Each message character has to be included in alphabet!'    )

    # Generate dictionares
      _lowerCAmelCase		   =   (
          '111',
          '112',
          '113',
          '121',
          '122',
          '123',
          '131',
          '132',
          '133',
          '211',
          '212',
          '213',
          '221',
          '222',
          '223',
          '231',
          '232',
          '233',
          '311',
          '312',
          '313',
          '321',
          '322',
          '323',
          '331',
          '332',
          '333',
      )
      _lowerCAmelCase		   =   {}
      _lowerCAmelCase		   =   {}
      for letter, number in zip(_lowerCamelCase  ,  _lowerCamelCase    ):
            _lowerCAmelCase		   =   number
            _lowerCAmelCase		   =   letter

      return message, alphabet, character_to_number, number_to_character







def 			A_   ( _lowerCamelCase			:							str  ,  _lowerCamelCase			:							str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ."  ,  _lowerCamelCase			:							int = 5    ):
      _lowerCAmelCase   ,  _lowerCAmelCase   ,  _lowerCAmelCase   ,  _lowerCAmelCase		   =   __prepare(
          _lowerCamelCase  ,  _lowerCamelCase    )
      _lowerCAmelCase   ,  _lowerCAmelCase		   =   '', ''

      for i in range(0  ,  len(_lowerCamelCase    ) + 1  ,  _lowerCamelCase    ):
            encrypted_numeric += __encrypt_part(
                message[i : i + period]  ,  _lowerCamelCase    )

      for i in range(0  ,  len(_lowerCamelCase    )  ,  3    ):
            encrypted += number_to_character[encrypted_numeric[i : i + 3]]

      return encrypted







def 			A_   ( _lowerCamelCase			:							str  ,  _lowerCamelCase			:							str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ."  ,  _lowerCamelCase			:							int = 5    ):
      _lowerCAmelCase   ,  _lowerCAmelCase   ,  _lowerCAmelCase   ,  _lowerCAmelCase		   =   __prepare(
          _lowerCamelCase  ,  _lowerCamelCase    )
      _lowerCAmelCase		   =   []
      _lowerCAmelCase		   =   ''

      for i in range(0  ,  len(_lowerCamelCase    ) + 1  ,  _lowerCamelCase    ):
            _lowerCAmelCase   ,  _lowerCAmelCase   ,  _lowerCAmelCase		   =   __decrypt_part(message[i : i + period]  ,  _lowerCamelCase    )

            for j in range(0  ,  len(_lowerCamelCase    )    ):
                  decrypted_numeric.append(a[j] + b[j] + c[j]    )

      for each in decrypted_numeric:
            decrypted += number_to_character[each]

      return decrypted


if __name__ == "__main__":
 snake_case  =			'''DEFEND THE EAST WALL OF THE CASTLE.'''
 snake_case  =			encrypt_message(msg, '''EPSDUCVWYM.ZLKXNBTFGORIJHAQ''')
 snake_case  =			decrypt_message(encrypted, '''EPSDUCVWYM.ZLKXNBTFGORIJHAQ''')
 print(f'''Encrypted: {encrypted}\nDecrypted: {decrypted}''')





