

'''simple docstring'''







from collections import Counter
from pathlib import Path
from typing import Optional, Tuple

import yaml


class 					A__      (      yaml.SafeLoader			):



    def 					snake_case_			(					self		,				UpperCamelCase__       )						->      List[Any]:





           '''simple docstring'''
           A_						=      [self.constructed_objects[key_node] for key_node, _ in node.value]
           A_						=      [tuple(UpperCamelCase__       ) if isinstance(UpperCamelCase__		,				UpperCamelCase__       ) else key for key in keys]
           A_						=      Counter(UpperCamelCase__       )
           A_						=      [key for key in counter if counter[key] > 1]
           if duplicate_keys:
                  raise TypeError(f'''Got duplicate yaml keys: {duplicate_keys}'''       )







    def 					snake_case_			(					self		,				UpperCamelCase__		,				UpperCamelCase__=False       )						->      Tuple:





           '''simple docstring'''
           A_						=      super().construct_mapping(UpperCamelCase__		,				deep=UpperCamelCase__       )
           self._check_no_duplicates_on_constructed_node(UpperCamelCase__       )
           return mapping

def       UpperCAmelCase__    (      UpperCAmelCase__				)			->			Tuple[Optional[str], str]:
       A_						=      list(readme_content.splitlines()				)
       if full_content and full_content[0] == "---" and "---" in full_content[1:]:
              A_						=      full_content[1:].index("""---"""				) + 1
              A_						=      """\n""".join(full_content[1:sep_idx]				)
              return yamlblock, "\n".join(full_content[sep_idx + 1 :]				)

       return None, "\n".join(UpperCAmelCase__				)


class 					A__      (      _snake_case			):
    # class attributes
    lowercase						=		{"train_eval_index"}  # train-eval-index in the YAML metadata



    @classmethod
    def 					snake_case_			(					cls		,				UpperCamelCase__       )						->      "DatasetMetadata":





           '''simple docstring'''
           with open(UpperCamelCase__		,				encoding="""utf-8"""       ) as readme_file:
                  A_					,			A_						=      _split_yaml_from_readme(readme_file.read()       )
           if yaml_string is not None:
                  return cls.from_yaml_string(UpperCamelCase__       )
           else:
                  return cls()



    def 					snake_case_			(					self		,				UpperCamelCase__       )						->      List[str]:





           '''simple docstring'''
           if path.exists():
                  with open(UpperCamelCase__		,				encoding="""utf-8"""       ) as readme_file:
                         A_						=      readme_file.read()
           else:
                  A_						=      None
           A_						=      self._to_readme(UpperCamelCase__       )
           with open(UpperCamelCase__		,				"""w"""		,				encoding="""utf-8"""       ) as readme_file:
                  readme_file.write(UpperCamelCase__       )



    def 					snake_case_			(					self		,				UpperCamelCase__ = None       )						->      str:





           '''simple docstring'''
           if readme_content is not None:
                  A_					,			A_						=      _split_yaml_from_readme(UpperCamelCase__       )
                  A_						=      """---\n""" + self.to_yaml_string() + """---\n""" + content
           else:
                  A_						=      """---\n""" + self.to_yaml_string() + """---\n"""
           return full_content



    @classmethod
    def 					snake_case_			(					cls		,				UpperCamelCase__       )						->      "DatasetMetadata":





           '''simple docstring'''
           A_						=      yaml.load(UpperCamelCase__		,				Loader=_NoDuplicateSafeLoader       ) or {}

           # Convert the YAML keys to DatasetMetadata fields
           A_						=      {
               (key.replace("""-"""		,				"""_"""       ) if key.replace("""-"""		,				"""_"""       ) in cls._FIELDS_WITH_DASHES else key): value
               for key, value in metadata_dict.items()
           }
           return cls(**UpperCamelCase__       )







    def 					snake_case_			(					self       )						->      str:





           '''simple docstring'''
           return yaml.safe_dump(
               {
                   (key.replace("""_"""		,				"""-"""       ) if key in self._FIELDS_WITH_DASHES else key): value
                   for key, value in self.items()
               }		,				sort_keys=UpperCamelCase__		,				allow_unicode=UpperCamelCase__		,				encoding="""utf-8"""		,				).decode("""utf-8"""       )

__lowerCamelCase		       =    {
    '''image-classification''': [],
    '''translation''': [],
    '''image-segmentation''': [],
    '''fill-mask''': [],
    '''automatic-speech-recognition''': [],
    '''token-classification''': [],
    '''sentence-similarity''': [],
    '''audio-classification''': [],
    '''question-answering''': [],
    '''summarization''': [],
    '''zero-shot-classification''': [],
    '''table-to-text''': [],
    '''feature-extraction''': [],
    '''other''': [],
    '''multiple-choice''': [],
    '''text-classification''': [],
    '''text-to-image''': [],
    '''text2text-generation''': [],
    '''zero-shot-image-classification''': [],
    '''tabular-classification''': [],
    '''tabular-regression''': [],
    '''image-to-image''': [],
    '''tabular-to-text''': [],
    '''unconditional-image-generation''': [],
    '''text-retrieval''': [],
    '''text-to-speech''': [],
    '''object-detection''': [],
    '''audio-to-audio''': [],
    '''text-generation''': [],
    '''conversational''': [],
    '''table-question-answering''': [],
    '''visual-question-answering''': [],
    '''image-to-text''': [],
    '''reinforcement-learning''': [],
    '''voice-activity-detection''': [],
    '''time-series-forecasting''': [],
    '''document-question-answering''': [],
}


if __name__ == "__main__":
      from argparse import ArgumentParser

      __lowerCamelCase		       =    ArgumentParser(usage='''Validate the yaml metadata block of a README.md file.''')
      ap.add_argument('''readme_filepath''')
      __lowerCamelCase		       =    ap.parse_args()

      __lowerCamelCase		       =    Path(args.readme_filepath)
      __lowerCamelCase		       =    DatasetMetadata.from_readme(readme_filepath)
      print(dataset_metadata)
      dataset_metadata.to_readme(readme_filepath)



'''simple docstring'''







__lowerCamelCase		       =    range(2, 20 + 1)
__lowerCamelCase		       =    [10**k for k in range(ks[-1] + 1)]
__lowerCamelCase		       =    {}
def       UpperCAmelCase__    (      UpperCAmelCase__,       UpperCAmelCase__,       UpperCAmelCase__,       UpperCAmelCase__				)			->			Tuple:
       A_						=      sum(a_i[j] for j in range(UpperCAmelCase__,       len(UpperCAmelCase__				)				)				)
       A_						=      sum(a_i[j] * base[j] for j in range(min(len(UpperCAmelCase__				),       UpperCAmelCase__				)				)				)

       A_					,			A_						=      0, 0
       A_						=      n - i

       A_						=      memo.get(UpperCAmelCase__				)

       if sub_memo is not None:
              A_						=      sub_memo.get(UpperCAmelCase__				)

              if jumps is not None and len(UpperCAmelCase__				) > 0:
                     # find and make the largest jump without going over
                     A_						=      -1
                     for _k in range(len(UpperCAmelCase__				) - 1,       -1,       -1				):
                            if jumps[_k][2] <= k and jumps[_k][1] <= max_dn:
                                   A_						=      _k
                                   break

                     if max_jump >= 0:
                            A_					,			A_					,			A_						=      jumps[max_jump]
                            # since the difference between jumps is cached, add c
                            A_						=      diff + c
                            for j in range(min(UpperCAmelCase__,       len(UpperCAmelCase__				)				)				):
                                   A_					,			A_						=      divmod(UpperCAmelCase__,       10				)
                            if new_c > 0:
                                   add(UpperCAmelCase__,       UpperCAmelCase__,       UpperCAmelCase__				)

              else:
                     A_						=      []
       else:
              A_						=      {c: []}
              A_						=      sub_memo

       if dn >= max_dn or c + diff >= base[k]:
              return diff, dn

       if k > ks[0]:
              while True:
                     # keep doing smaller jumps
                     A_					,			A_						=      next_term(UpperCAmelCase__,       k - 1,       i + dn,       UpperCAmelCase__				)
                     diff += _diff
                     dn += terms_jumped

                     if dn >= max_dn or c + diff >= base[k]:
                            break
       else:
              # would be too small a jump, just compute sequential terms instead
              A_					,			A_						=      compute(UpperCAmelCase__,       UpperCAmelCase__,       i + dn,       UpperCAmelCase__				)
              diff += _diff
              dn += terms_jumped

       A_						=      sub_memo[c]

       # keep jumps sorted by # of terms skipped
       A_						=      0
       while j < len(UpperCAmelCase__				):
              if jumps[j][1] > dn:
                     break
              j += 1

       # cache the jump for this value digitsum(b) and c
       sub_memo[c].insert(UpperCAmelCase__,       (diff, dn, k)				)
       return (diff, dn)
def       UpperCAmelCase__    (      UpperCAmelCase__,       UpperCAmelCase__,       UpperCAmelCase__,       UpperCAmelCase__				)			->			int:
       if i >= n:
              return 0, i
       if k > len(UpperCAmelCase__				):
              a_i.extend([0 for _ in range(k - len(UpperCAmelCase__				)				)]				)

       # note: a_i -> b * 10^k + c
       # ds_b -> digitsum(b)
       # ds_c -> digitsum(c)
       A_						=      i
       A_					,			A_					,			A_						=      0, 0, 0
       for j in range(len(UpperCAmelCase__				)				):
              if j >= k:
                     ds_b += a_i[j]
              else:
                     ds_c += a_i[j]

       while i < n:
              i += 1
              A_						=      ds_c + ds_b
              diff += addend
              A_						=      0
              for j in range(UpperCAmelCase__				):
                     A_						=      a_i[j] + addend
                     A_					,			A_						=      divmod(UpperCAmelCase__,       10				)

                     ds_c += a_i[j]

              if addend > 0:
                     break

       if addend > 0:
              add(UpperCAmelCase__,       UpperCAmelCase__,       UpperCAmelCase__				)
       return diff, i - start_i
def       UpperCAmelCase__    (      UpperCAmelCase__,       UpperCAmelCase__,       UpperCAmelCase__				)			->			str:
       for j in range(UpperCAmelCase__,       len(UpperCAmelCase__				)				):
              A_						=      digits[j] + addend
              if s >= 10:
                     A_					,			A_						=      divmod(UpperCAmelCase__,       10				)
                     A_						=      addend // 10 + quotient
              else:
                     A_						=      s
                     A_						=      addend // 10

              if addend == 0:
                     break

       while addend > 0:
              A_					,			A_						=      divmod(UpperCAmelCase__,       10				)
              digits.append(UpperCAmelCase__				)
def       UpperCAmelCase__    (      UpperCAmelCase__ = 10**15				)			->			int:
       A_						=      [1]
       A_						=      1
       A_						=      0
       while True:
              A_					,			A_						=      next_term(UpperCAmelCase__,       20,       i + dn,       UpperCAmelCase__				)
              dn += terms_jumped
              if dn == n - i:
                     break

       A_						=      0
       for j in range(len(UpperCAmelCase__				)				):
              a_n += digits[j] * 10**j
       return a_n


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