



import argparse
import collections
import json
import os
import re
import string
import sys

import numpy as np


__snake_case    :		List[str]  =re.compile(R'\b(a|an|the)\b', re.UNICODE)

__snake_case    :		Optional[Any]  =None






def      lowerCAmelCase__		(   ):





				'''simple docstring'''

				lowerCAmelCase__					:    Union[str, Any]												=					argparse.ArgumentParser('''Official evaluation script for SQuAD version 2.0.''')
				parser.add_argument('''data_file'''	,metavar='''data.json'''	,help='''Input data JSON file.''')
				parser.add_argument('''pred_file'''	,metavar='''pred.json'''	,help='''Model predictions.''')
				parser.add_argument(
				    '''--out-file'''	,'''-o'''	,metavar='''eval.json'''	,help='''Write accuracy metrics to file (default is stdout).''')
				parser.add_argument(
				    '''--na-prob-file'''	,'''-n'''	,metavar='''na_prob.json'''	,help='''Model estimates of probability of no answer.''')
				parser.add_argument(
				    '''--na-prob-thresh'''	,'''-t'''	,type=lowerCamelCase_	,default=1.0	,help='''Predict "" if no-answer probability exceeds this (default = 1.0).'''	,)
				parser.add_argument(
				    '''--out-image-dir'''	,'''-p'''	,metavar='''out_images'''	,default=lowerCamelCase_	,help='''Save precision-recall curves to directory.''')
				parser.add_argument('''--verbose'''	,'''-v'''	,action='''store_true''')
				if len(sys.argv) == 1:
								parser.print_help()
								sys.exit(1)
				return parser.parse_args()






def      lowerCAmelCase__		(   lowerCamelCase_		:		Optional[int]):





				'''simple docstring'''

				lowerCAmelCase__					:    Dict												=					{}
				for article in dataset:
								for p in article["paragraphs"]:
												for qa in p["qas"]:
																lowerCAmelCase__					:    int												=					bool(qa['''answers''']['''text'''])
				return qid_to_has_ans






def      lowerCAmelCase__		(   lowerCamelCase_		:		Optional[Any]):





				'''simple docstring'''

				def remove_articles(lowerCamelCase_		:		Tuple):
								return ARTICLES_REGEX.sub(''' '''	,lowerCamelCase_)

				def white_space_fix(lowerCamelCase_		:		Optional[int]):
								return " ".join(text.split())

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

				def lower(lowerCamelCase_		:		Dict):
								return text.lower()

				return white_space_fix(remove_articles(remove_punc(lower(lowerCamelCase_))))






def      lowerCAmelCase__		(   lowerCamelCase_		:		Union[str, Any]):





				'''simple docstring'''

				if not s:
								return []
				return normalize_answer(lowerCamelCase_).split()






def      lowerCAmelCase__		(   lowerCamelCase_		:		Dict	,lowerCamelCase_		:		List[Any]):





				'''simple docstring'''

				return int(normalize_answer(lowerCamelCase_) == normalize_answer(lowerCamelCase_))






def      lowerCAmelCase__		(   lowerCamelCase_		:		Tuple	,lowerCamelCase_		:		Optional[Any]):





				'''simple docstring'''

				lowerCAmelCase__					:    List[str]												=					get_tokens(lowerCamelCase_)
				lowerCAmelCase__					:    Optional[Any]												=					get_tokens(lowerCamelCase_)
				lowerCAmelCase__					:    Dict												=					collections.Counter(lowerCamelCase_) & collections.Counter(lowerCamelCase_)
				lowerCAmelCase__					:    Dict												=					sum(common.values())
				if len(lowerCamelCase_) == 0 or len(lowerCamelCase_) == 0:
								# If either is no-answer, then F1 is 1 if they agree, 0 otherwise
								return int(gold_toks == pred_toks)
				if num_same == 0:
								return 0
				lowerCAmelCase__					:    List[str]												=					1.0 * num_same / len(lowerCamelCase_)
				lowerCAmelCase__					:    Optional[Any]												=					1.0 * num_same / len(lowerCamelCase_)
				lowerCAmelCase__					:    List[Any]												=					(2 * precision * recall) / (precision + recall)
				return fa






def      lowerCAmelCase__		(   lowerCamelCase_		:		List[str]	,lowerCamelCase_		:		Tuple):





				'''simple docstring'''

				lowerCAmelCase__					:    Union[str, Any]												=					{}
				lowerCAmelCase__					:    List[str]												=					{}
				for article in dataset:
								for p in article["paragraphs"]:
												for qa in p["qas"]:
																lowerCAmelCase__					:    Dict												=					qa['''id''']
																lowerCAmelCase__					:    str												=					[t for t in qa['''answers''']['''text'''] if normalize_answer(lowerCamelCase_)]
																if not gold_answers:
																				# For unanswerable questions, only correct answer is empty string
																				lowerCAmelCase__					:    Dict												=					['''''']
																if qid not in preds:
																				print(f"""Missing prediction for {qid}""")
																				continue
																lowerCAmelCase__					:    List[Any]												=					preds[qid]
																# Take max over all gold answers
																lowerCAmelCase__					:    Optional[int]												=					max(compute_exact(lowerCamelCase_	,lowerCamelCase_) for a in gold_answers)
																lowerCAmelCase__					:    Any												=					max(compute_fa(lowerCamelCase_	,lowerCamelCase_) for a in gold_answers)
				return exact_scores, fa_scores






def      lowerCAmelCase__		(   lowerCamelCase_		:		str	,lowerCamelCase_		:		Union[str, Any]	,lowerCamelCase_		:		str	,lowerCamelCase_		:		Optional[int]):





				'''simple docstring'''

				lowerCAmelCase__					:    List[Any]												=					{}
				for qid, s in scores.items():
								lowerCAmelCase__					:    List[str]												=					na_probs[qid] > na_prob_thresh
								if pred_na:
												lowerCAmelCase__					:    List[Any]												=					float(not qid_to_has_ans[qid])
								else:
												lowerCAmelCase__					:    Optional[Any]												=					s
				return new_scores






def      lowerCAmelCase__		(   lowerCamelCase_		:		int	,lowerCamelCase_		:		Optional[int]	,lowerCamelCase_		:		Tuple=None):





				'''simple docstring'''

				if not qid_list:
								lowerCAmelCase__					:    Union[str, Any]												=					len(lowerCamelCase_)
								return collections.OrderedDict(
								    [
								        ('''exact''', 100.0 * sum(exact_scores.values()) / total),
								        ('''f1''', 100.0 * sum(fa_scores.values()) / total),
								        ('''total''', total),
								    ])
				else:
								lowerCAmelCase__					:    Optional[Any]												=					len(lowerCamelCase_)
								return collections.OrderedDict(
								    [
								        ('''exact''', 100.0 * sum(exact_scores[k] for k in qid_list) / total),
								        ('''f1''', 100.0 * sum(fa_scores[k] for k in qid_list) / total),
								        ('''total''', total),
								    ])






def      lowerCAmelCase__		(   lowerCamelCase_		:		List[Any]	,lowerCamelCase_		:		Optional[Any]	,lowerCamelCase_		:		int):





				'''simple docstring'''

				for k in new_eval:
								lowerCAmelCase__					:    Tuple												=					new_eval[k]






def      lowerCAmelCase__		(   lowerCamelCase_		:		Union[str, Any]	,lowerCamelCase_		:		List[Any]	,lowerCamelCase_		:		Any	,lowerCamelCase_		:		Optional[int]):





				'''simple docstring'''

				plt.step(lowerCamelCase_	,lowerCamelCase_	,color='''b'''	,alpha=0.2	,where='''post''')
				plt.fill_between(lowerCamelCase_	,lowerCamelCase_	,step='''post'''	,alpha=0.2	,color='''b''')
				plt.xlabel('''Recall''')
				plt.ylabel('''Precision''')
				plt.xlim([0.0, 1.05])
				plt.ylim([0.0, 1.05])
				plt.title(lowerCamelCase_)
				plt.savefig(lowerCamelCase_)
				plt.clf()






def      lowerCAmelCase__		(   lowerCamelCase_		:		Any	,lowerCamelCase_		:		Dict	,lowerCamelCase_		:		List[str]	,lowerCamelCase_		:		Tuple	,lowerCamelCase_		:		Tuple=None	,lowerCamelCase_		:		Optional[int]=None):





				'''simple docstring'''

				lowerCAmelCase__					:    str												=					sorted(lowerCamelCase_	,key=lambda lowerCamelCase_: na_probs[k])
				lowerCAmelCase__					:    List[str]												=					0.0
				lowerCAmelCase__					:    Optional[Any]												=					1.0
				lowerCAmelCase__					:    Optional[Any]												=					0.0
				lowerCAmelCase__					:    Optional[Any]												=					[1.0]
				lowerCAmelCase__					:    Tuple												=					[0.0]
				lowerCAmelCase__					:    List[str]												=					0.0
				for i, qid in enumerate(lowerCamelCase_):
								if qid_to_has_ans[qid]:
												true_pos += scores[qid]
								lowerCAmelCase__					:    List[Any]												=					true_pos / float(i + 1)
								lowerCAmelCase__					:    Any												=					true_pos / float(lowerCamelCase_)
								if i == len(lowerCamelCase_) - 1 or na_probs[qid] != na_probs[qid_list[i + 1]]:
												# i.e., if we can put a threshold after this point
												avg_prec += cur_p * (cur_r - recalls[-1])
												precisions.append(lowerCamelCase_)
												recalls.append(lowerCamelCase_)
				if out_image:
								plot_pr_curve(lowerCamelCase_	,lowerCamelCase_	,lowerCamelCase_	,lowerCamelCase_)
				return {"ap": 100.0 * avg_prec}






def      lowerCAmelCase__		(   lowerCamelCase_		:		List[str]	,lowerCamelCase_		:		int	,lowerCamelCase_		:		str	,lowerCamelCase_		:		Tuple	,lowerCamelCase_		:		Any	,lowerCamelCase_		:		List[str]):





				'''simple docstring'''

				if out_image_dir and not os.path.exists(lowerCamelCase_):
								os.makedirs(lowerCamelCase_)
				lowerCAmelCase__					:    Optional[int]												=					sum(1 for v in qid_to_has_ans.values() if v)
				if num_true_pos == 0:
								return
				lowerCAmelCase__					:    Optional[Any]												=					make_precision_recall_eval(
				    lowerCamelCase_	,lowerCamelCase_	,lowerCamelCase_	,lowerCamelCase_	,out_image=os.path.join(lowerCamelCase_	,'''pr_exact.png''')	,title='''Precision-Recall curve for Exact Match score'''	,)
				lowerCAmelCase__					:    Any												=					make_precision_recall_eval(
				    lowerCamelCase_	,lowerCamelCase_	,lowerCamelCase_	,lowerCamelCase_	,out_image=os.path.join(lowerCamelCase_	,'''pr_f1.png''')	,title='''Precision-Recall curve for F1 score'''	,)
				lowerCAmelCase__					:    Optional[Any]												=					{k: float(lowerCamelCase_) for k, v in qid_to_has_ans.items()}
				lowerCAmelCase__					:    List[Any]												=					make_precision_recall_eval(
				    lowerCamelCase_	,lowerCamelCase_	,lowerCamelCase_	,lowerCamelCase_	,out_image=os.path.join(lowerCamelCase_	,'''pr_oracle.png''')	,title='''Oracle Precision-Recall curve (binary task of HasAns vs. NoAns)'''	,)
				merge_eval(lowerCamelCase_	,lowerCamelCase_	,'''pr_exact''')
				merge_eval(lowerCamelCase_	,lowerCamelCase_	,'''pr_f1''')
				merge_eval(lowerCamelCase_	,lowerCamelCase_	,'''pr_oracle''')






def      lowerCAmelCase__		(   lowerCamelCase_		:		Union[str, Any]	,lowerCamelCase_		:		Dict	,lowerCamelCase_		:		List[Any]	,lowerCamelCase_		:		Optional[int]):





				'''simple docstring'''

				if not qid_list:
								return
				lowerCAmelCase__					:    List[str]												=					[na_probs[k] for k in qid_list]
				lowerCAmelCase__					:    Optional[Any]												=					np.ones_like(lowerCamelCase_) / float(len(lowerCamelCase_))
				plt.hist(lowerCamelCase_	,weights=lowerCamelCase_	,bins=20	,range=(0.0, 1.0))
				plt.xlabel('''Model probability of no-answer''')
				plt.ylabel('''Proportion of dataset''')
				plt.title(f"""Histogram of no-answer probability: {name}""")
				plt.savefig(os.path.join(lowerCamelCase_	,f"""na_prob_hist_{name}.png"""))
				plt.clf()






def      lowerCAmelCase__		(   lowerCamelCase_		:		Union[str, Any]	,lowerCamelCase_		:		Optional[int]	,lowerCamelCase_		:		Optional[Any]	,lowerCamelCase_		:		Optional[Any]):





				'''simple docstring'''

				lowerCAmelCase__					:    List[str]												=					sum(1 for k in qid_to_has_ans if not qid_to_has_ans[k])
				lowerCAmelCase__					:    int												=					num_no_ans
				lowerCAmelCase__					:    str												=					cur_score
				lowerCAmelCase__					:    Tuple												=					0.0
				lowerCAmelCase__					:    Tuple												=					sorted(lowerCamelCase_	,key=lambda lowerCamelCase_: na_probs[k])
				for i, qid in enumerate(lowerCamelCase_):
								if qid not in scores:
												continue
								if qid_to_has_ans[qid]:
												lowerCAmelCase__					:    Any												=					scores[qid]
								else:
												if preds[qid]:
																lowerCAmelCase__					:    str												=					-1
												else:
																lowerCAmelCase__					:    int												=					0
								cur_score += diff
								if cur_score > best_score:
												lowerCAmelCase__					:    Any												=					cur_score
												lowerCAmelCase__					:    Any												=					na_probs[qid]
				return 100.0 * best_score / len(lowerCamelCase_), best_thresh






def      lowerCAmelCase__		(   lowerCamelCase_		:		Union[str, Any]	,lowerCamelCase_		:		List[str]	,lowerCamelCase_		:		List[str]	,lowerCamelCase_		:		Dict	,lowerCamelCase_		:		Optional[Any]	,lowerCamelCase_		:		Optional[int]):





				'''simple docstring'''

				lowerCAmelCase__						,		lowerCAmelCase__					:    Union[str, Any]												=					find_best_thresh(lowerCamelCase_	,lowerCamelCase_	,lowerCamelCase_	,lowerCamelCase_)
				lowerCAmelCase__						,		lowerCAmelCase__					:    Optional[Any]												=					find_best_thresh(lowerCamelCase_	,lowerCamelCase_	,lowerCamelCase_	,lowerCamelCase_)
				lowerCAmelCase__					:    Any												=					best_exact
				lowerCAmelCase__					:    str												=					exact_thresh
				lowerCAmelCase__					:    Dict												=					best_fa
				lowerCAmelCase__					:    Optional[Any]												=					fa_thresh






def      lowerCAmelCase__		(   ):





				'''simple docstring'''

				with open(OPTS.data_file) as f:
								lowerCAmelCase__					:    List[Any]												=					json.load(lowerCamelCase_)
								lowerCAmelCase__					:    int												=					dataset_json['''data''']
				with open(OPTS.pred_file) as f:
								lowerCAmelCase__					:    Any												=					json.load(lowerCamelCase_)
				if OPTS.na_prob_file:
								with open(OPTS.na_prob_file) as f:
												lowerCAmelCase__					:    List[Any]												=					json.load(lowerCamelCase_)
				else:
								lowerCAmelCase__					:    str												=					{k: 0.0 for k in preds}
				lowerCAmelCase__					:    Union[str, Any]												=					make_qid_to_has_ans(lowerCamelCase_)  # maps qid to True/False
				lowerCAmelCase__					:    List[Any]												=					[k for k, v in qid_to_has_ans.items() if v]
				lowerCAmelCase__					:    Optional[int]												=					[k for k, v in qid_to_has_ans.items() if not v]
				lowerCAmelCase__						,		lowerCAmelCase__					:    Union[str, Any]												=					get_raw_scores(lowerCamelCase_	,lowerCamelCase_)
				lowerCAmelCase__					:    Dict												=					apply_no_ans_threshold(lowerCamelCase_	,lowerCamelCase_	,lowerCamelCase_	,OPTS.na_prob_thresh)
				lowerCAmelCase__					:    Tuple												=					apply_no_ans_threshold(lowerCamelCase_	,lowerCamelCase_	,lowerCamelCase_	,OPTS.na_prob_thresh)
				lowerCAmelCase__					:    Any												=					make_eval_dict(lowerCamelCase_	,lowerCamelCase_)
				if has_ans_qids:
								lowerCAmelCase__					:    Optional[int]												=					make_eval_dict(lowerCamelCase_	,lowerCamelCase_	,qid_list=lowerCamelCase_)
								merge_eval(lowerCamelCase_	,lowerCamelCase_	,'''HasAns''')
				if no_ans_qids:
								lowerCAmelCase__					:    List[Any]												=					make_eval_dict(lowerCamelCase_	,lowerCamelCase_	,qid_list=lowerCamelCase_)
								merge_eval(lowerCamelCase_	,lowerCamelCase_	,'''NoAns''')
				if OPTS.na_prob_file:
								find_all_best_thresh(lowerCamelCase_	,lowerCamelCase_	,lowerCamelCase_	,lowerCamelCase_	,lowerCamelCase_	,lowerCamelCase_)
				if OPTS.na_prob_file and OPTS.out_image_dir:
								run_precision_recall_analysis(lowerCamelCase_	,lowerCamelCase_	,lowerCamelCase_	,lowerCamelCase_	,lowerCamelCase_	,OPTS.out_image_dir)
								histogram_na_prob(lowerCamelCase_	,lowerCamelCase_	,OPTS.out_image_dir	,'''hasAns''')
								histogram_na_prob(lowerCamelCase_	,lowerCamelCase_	,OPTS.out_image_dir	,'''noAns''')
				if OPTS.out_file:
								with open(OPTS.out_file	,'''w''') as f:
												json.dump(lowerCamelCase_	,lowerCamelCase_)
				else:
								print(json.dumps(lowerCamelCase_	,indent=2))


if __name__ == "__main__":
							__snake_case    :		List[str]  =parse_args()
							if OPTS.out_image_dir:
														import matplotlib

														matplotlib.use('Agg')
														import matplotlib.pyplot as plt
							main()






def      lowerCAmelCase__		(   lowerCamelCase_		:		int = 1000):





				'''simple docstring'''

				lowerCAmelCase__						,		lowerCAmelCase__					:    int												=					1, 1
				lowerCAmelCase__					:    Any												=					2
				while True:
								lowerCAmelCase__					:    Optional[Any]												=					0
								lowerCAmelCase__					:    Any												=					fa + fa
								lowerCAmelCase__						,		lowerCAmelCase__					:    Optional[Any]												=					fa, f
								index += 1
								for _ in str(lowerCamelCase_):
												i += 1
								if i == n:
												break
				return index


if __name__ == "__main__":
							print(solution(int(str(input()).strip())))

