






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




def       _a   (							lowerCamelCase__				)  ->      List[Any]:

 def remove_articles(lowerCamelCase__				):
  return re.sub(r'\b(a|an|the)\b' ,			' ' ,			lowerCamelCase__				)

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

 def remove_punc(lowerCamelCase__				):
  lowerCamelCase_							:    Any							=     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(lowerCamelCase__				)				)				)				)




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




def       _a   (							lowerCamelCase__ ,			lowerCamelCase__				)  ->      List[Any]:
 return normalize_answer(lowerCamelCase__				) == normalize_answer(lowerCamelCase__				)




def       _a   (							lowerCamelCase__ ,			lowerCamelCase__ ,			lowerCamelCase__				)  ->      Optional[int]:
 lowerCamelCase_							:    Optional[Any]							=     []
 for ground_truth in ground_truths:
  lowerCamelCase_							:    Any							=     metric_fn(lowerCamelCase__ ,			lowerCamelCase__				)
  scores_for_ground_truths.append(lowerCamelCase__				)
 return max(lowerCamelCase__				)




def       _a   (							lowerCamelCase__ ,			lowerCamelCase__				)  ->      Optional[int]:
 lowerCamelCase_							:    List[Any]							=     0
 lowerCamelCase_							:    Optional[Any]							=     []
 for passage in dataset:
  for qa in passage["qas"]:
   total += 1
   if qa["id"] not in predictions:
    lowerCamelCase_							:    int							=     F'Unanswered question {qa["id"]} will receive score 0.'
    print(lowerCamelCase__ ,			file=sys.stderr				)
    continue

   lowerCamelCase_							:    Dict							=     [x['text'] for x in qa['answers']]
   lowerCamelCase_							:    Optional[int]							=     predictions[qa['id']]

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

   fa += metric_max_over_ground_truths(lowerCamelCase__ ,			lowerCamelCase__ ,			lowerCamelCase__				)

 lowerCamelCase_							:    int							=     exact_match / total
 lowerCamelCase_							:    str							=     fa / total

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


if __name__ == "__main__":
       UpperCamelCase											=      '''1.0'''
       UpperCamelCase											=      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											=      parser.parse_args()

       with open(args.data_file) as data_file:
              UpperCamelCase											=      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											=      dataset_json['''data''']

       with open(args.pred_file) as pred_file:
              UpperCamelCase											=      json.load(pred_file)

       UpperCamelCase						,  UpperCamelCase											=      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)








UpperCamelCase											=      [
    [0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0],
    [0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0],
    [0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0],
]




def       _a   (							lowerCamelCase__ ,			lowerCamelCase__ ,			lowerCamelCase__ ,			lowerCamelCase__				)  ->      bool:
 return 0 <= row < rows and 0 <= col < cols




def       _a   (							lowerCamelCase__ ,			lowerCamelCase__ ,			lowerCamelCase__ ,			lowerCamelCase__				)  ->      int:
 lowerCamelCase_							:    Tuple							=     len(lowerCamelCase__				)
 lowerCamelCase_							:    Tuple							=     len(mat[0]				)
 if is_safe(lowerCamelCase__ ,			lowerCamelCase__ ,			lowerCamelCase__ ,			lowerCamelCase__				) and (row, col) not in seen and mat[row][col] == 1:
  seen.add((row, col)				)
  return (
      1
      + depth_first_search(row + 1 ,			lowerCamelCase__ ,			lowerCamelCase__ ,			lowerCamelCase__				)
      + depth_first_search(row - 1 ,			lowerCamelCase__ ,			lowerCamelCase__ ,			lowerCamelCase__				)
      + depth_first_search(lowerCamelCase__ ,			col + 1 ,			lowerCamelCase__ ,			lowerCamelCase__				)
      + depth_first_search(lowerCamelCase__ ,			col - 1 ,			lowerCamelCase__ ,			lowerCamelCase__				)
  )
 else:
  return 0




def       _a   (							lowerCamelCase__				)  ->      int:
 lowerCamelCase_							:    set							=     set()

 lowerCamelCase_							:    int							=     0
 for row, line in enumerate(lowerCamelCase__				):
  for col, item in enumerate(lowerCamelCase__				):
   if item == 1 and (row, col) not in seen:
    # Maximizing the area
    lowerCamelCase_							:    str							=     max(lowerCamelCase__ ,			depth_first_search(lowerCamelCase__ ,			lowerCamelCase__ ,			lowerCamelCase__ ,			lowerCamelCase__				)				)
 return max_area


if __name__ == "__main__":
       import doctest

       print(find_max_area(matrix))  # Output -> 6
       doctest.testmod()
