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


def       UpperCAmelCase_					(  __lowerCAmelCase		)	->  Union[str, Any]:




    def remove_articles(__lowerCAmelCase		):
        return re.sub(R'''\b(a|an|the)\b'''		,   ''' '''		,   _UpperCamelCase		)

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

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

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

    return white_space_fix(remove_articles(remove_punc(lower(_UpperCamelCase		)		)		)		)


def       UpperCAmelCase_					(  __lowerCAmelCase		,   __lowerCAmelCase		)	->  Any:
    __lowercase						:     str		      =    normalize_answer(_UpperCamelCase		).split()
    __lowercase						:     int		      =    normalize_answer(_UpperCamelCase		).split()
    __lowercase						:     List[Any]		      =    Counter(_UpperCamelCase		) & Counter(_UpperCamelCase		)
    __lowercase						:     Dict		      =    sum(common.values()		)
    if num_same == 0:
        return 0
    __lowercase						:     Union[str, Any]		      =    1.0 * num_same / len(_UpperCamelCase		)
    __lowercase						:     str		      =    1.0 * num_same / len(_UpperCamelCase		)
    __lowercase						:     List[Any]		      =    (2 * precision * recall) / (precision + recall)
    return fa


def       UpperCAmelCase_					(  __lowerCAmelCase		,   __lowerCAmelCase		)	->  Any:
    return normalize_answer(_UpperCamelCase		) == normalize_answer(_UpperCamelCase		)


def       UpperCAmelCase_					(  __lowerCAmelCase		,   __lowerCAmelCase		,   __lowerCAmelCase		)	->  List[str]:
    __lowercase						:     Optional[int]		      =    []
    for ground_truth in ground_truths:
        __lowercase						:     Tuple		      =    metric_fn(_UpperCamelCase		,   _UpperCamelCase		)
        scores_for_ground_truths.append(_UpperCamelCase		)
    return max(_UpperCamelCase		)


def       UpperCAmelCase_					(  __lowerCAmelCase		,   __lowerCAmelCase		)	->  Any:
    __lowercase						:     List[Any]		      =    0
    __lowercase						:     Union[str, Any]		      =    []
    for passage in dataset:
        for qa in passage["qas"]:
            total += 1
            if qa["id"] not in predictions:
                __lowercase						:     str		      =    F'Unanswered question {qa["id"]} will receive score 0.'
                print(_UpperCamelCase		,   file=sys.stderr		)
                continue

            __lowercase						:     int		      =    [x["text"] for x in qa["answers"]]
            __lowercase						:     Tuple		      =    predictions[qa["id"]]

            __lowercase						:     List[str]		      =    metric_max_over_ground_truths(_UpperCamelCase		,   _UpperCamelCase		,   _UpperCamelCase		)
            if int(_exact_match		) == 1:
                correct_ids.append(qa['''id''']		)
            exact_match += _exact_match

            fa += metric_max_over_ground_truths(_UpperCamelCase		,   _UpperCamelCase		,   _UpperCamelCase		)

    __lowercase						:     Optional[int]		      =    exact_match / total
    __lowercase						:     str		      =    fa / total

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


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

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

    with open(args.pred_file) as pred_file:
        __lowerCAmelCase   :     Optional[int]      =						json.load(pred_file)

    __lowerCAmelCase ,				__lowerCAmelCase   :     List[str]      =						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)




from __future__ import annotations

from collections import Counter


def       UpperCAmelCase_					(  __lowerCAmelCase		)	->  list[int]:
    __lowercase						:     Any		      =    [True] * n
    __lowercase						:     str		      =    False
    __lowercase						:     int		      =    False
    __lowercase						:     List[Any]		      =    True

    for i in range(3		,   int(n**0.5 + 1		)		,   2		):
        __lowercase						:     List[str]		      =    i * 2
        while index < n:
            __lowercase						:     List[Any]		      =    False
            __lowercase						:     Dict		      =    index + i

    __lowercase						:     Tuple		      =    [2]

    for i in range(3		,   __lowerCAmelCase		,   2		):
        if is_prime[i]:
            primes.append(__lowerCAmelCase		)

    return primes


def       UpperCAmelCase_					(  __lowerCAmelCase		)	->  list[list[int]]:
    __lowercase						:     Optional[int]		      =    str(__lowerCAmelCase		)
    __lowercase						:     List[str]		      =    []
    __lowercase						:     int		      =    ['''0''', '''1''', '''2''', '''3''', '''4''', '''5''', '''6''', '''7''', '''8''', '''9''']

    for duplicate in Counter(__lowerCAmelCase		) - Counter(set(__lowerCAmelCase		)		):
        __lowercase						:     Union[str, Any]		      =    [int(number_str.replace(__lowerCAmelCase		,   __lowerCAmelCase		)		) for digit in digits]
        replacements.append(__lowerCAmelCase		)

    return replacements


def       UpperCAmelCase_					(  __lowerCAmelCase = 8		)	->  int:
    __lowercase						:     Tuple		      =    set()

    # Filter primes with less than 3 replaceable digits
    __lowercase						:     int		      =    {
        x for x in set(prime_sieve(1_000_000		)		) if len(str(__lowerCAmelCase		)		) - len(set(str(__lowerCAmelCase		)		)		) >= 3
    }

    for prime in primes:
        if prime in numbers_checked:
            continue

        __lowercase						:     str		      =    digit_replacements(__lowerCAmelCase		)

        for family in replacements:
            numbers_checked.update(__lowerCAmelCase		)
            __lowercase						:     List[Any]		      =    primes.intersection(__lowerCAmelCase		)

            if len(__lowerCAmelCase		) != family_length:
                continue

            return min(__lowerCAmelCase		)

    return -1


if __name__ == "__main__":
 print(solution())


