"""simple docstring"""






import html

from ...feature_extraction_utils import BatchFeature, FeatureExtractionMixin
from ...utils import is_bsa_available, logging, requires_backends


if is_bsa_available():
       import bsa
       from bsa import BeautifulSoup


__lowerCAmelCase					: Tuple        =logging.get_logger(__name__)







class 				_A		( __UpperCAmelCase			):

      def __init__(		self	, **__lowerCAmelCase		):







            """simple docstring"""



            requires_backends(self	, ["""bs4"""]		)
            super().__init__(**_lowerCamelCase		)

      def        A__ (		self	, __lowerCAmelCase		):







            """simple docstring"""



            lowercase														=			[]
            lowercase														=			[]
            lowercase														=			element if element.name else element.parent
            for parent in child.parents:  # type: bs4.element.Tag
                  lowercase														=			parent.find_all(child.name	, recursive=_lowerCamelCase		)
                  xpath_tags.append(child.name		)
                  xpath_subscripts.append(
                      0 if 1 == len(_lowerCamelCase		) else next(i for i, s in enumerate(_lowerCamelCase	, 1		) if s is child		)		)
                  lowercase														=			parent
            xpath_tags.reverse()
            xpath_subscripts.reverse()
            return xpath_tags, xpath_subscripts

      def        A__ (		self	, __lowerCAmelCase		):







            """simple docstring"""



            lowercase														=			BeautifulSoup(_lowerCamelCase	, """html.parser"""		)

            lowercase														=			[]
            lowercase														=			[]
            lowercase														=			[]

            for element in html_code.descendants:
                  if type(_lowerCamelCase		) == bsa.element.NavigableString:
                        if type(element.parent		) != bsa.element.Tag:
                              continue

                        lowercase														=			html.unescape(_lowerCamelCase		).strip()
                        if not text_in_this_tag:
                              continue

                        all_doc_strings.append(_lowerCamelCase		)

                        lowercase							,							lowercase														=			self.xpath_soup(_lowerCamelCase		)
                        stringaxtag_seq.append(_lowerCamelCase		)
                        stringaxsubs_seq.append(_lowerCamelCase		)

            if len(_lowerCamelCase		) != len(_lowerCamelCase		):
                  raise ValueError("""Number of doc strings and xtags does not correspond"""		)
            if len(_lowerCamelCase		) != len(_lowerCamelCase		):
                  raise ValueError("""Number of doc strings and xsubs does not correspond"""		)

            return all_doc_strings, stringaxtag_seq, stringaxsubs_seq

      def        A__ (		self	, __lowerCAmelCase	, __lowerCAmelCase		):







            """simple docstring"""



            lowercase														=			""""""
            for tagname, subs in zip(_lowerCamelCase	, _lowerCamelCase		):
                  xpath += f'/{tagname}'
                  if subs != 0:
                        xpath += f'[{subs}]'
            return xpath







      def __call__(		self	, __lowerCAmelCase		):







            """simple docstring"""



            lowercase														=			False

            # Check that strings has a valid type
            if isinstance(_lowerCamelCase	, _lowerCamelCase		):
                  lowercase														=			True
            elif isinstance(_lowerCamelCase	, (list, tuple)		):
                  if len(_lowerCamelCase		) == 0 or isinstance(html_strings[0]	, _lowerCamelCase		):
                        lowercase														=			True

            if not valid_strings:
                  raise ValueError(
                      """HTML strings must of type `str`, `List[str]` (batch of examples), """
                      f'but is of type {type(_lowerCamelCase		)}.'		)

            lowercase														=			bool(isinstance(_lowerCamelCase	, (list, tuple)		) and (isinstance(html_strings[0]	, _lowerCamelCase		))		)

            if not is_batched:
                  lowercase														=			[html_strings]

            # Get nodes + xpaths
            lowercase														=			[]
            lowercase														=			[]
            for html_string in html_strings:
                  lowercase							,							lowercase							,							lowercase														=			self.get_three_from_single(_lowerCamelCase		)
                  nodes.append(_lowerCamelCase		)
                  lowercase														=			[]
                  for node, tag_list, sub_list in zip(_lowerCamelCase	, _lowerCamelCase	, _lowerCamelCase		):
                        lowercase														=			self.construct_xpath(_lowerCamelCase	, _lowerCamelCase		)
                        xpath_strings.append(_lowerCamelCase		)
                  xpaths.append(_lowerCamelCase		)

            # return as Dict
            lowercase														=			{"""nodes""": nodes, """xpaths""": xpaths}
            lowercase														=			BatchFeature(data=_lowerCamelCase	, tensor_type=_lowerCamelCase		)

            return encoded_inputs




"""simple docstring"""






def     UpperCAmelCase__ (       lowerCAmelCase__  :int	)				->					bool:
      '''simple docstring'''


      lowercase														=			(1 + 2_4 * n) ** 0.5
      return ((1 + root) / 6) % 1 == 0


def     UpperCAmelCase__ (       lowerCAmelCase__  :int = 5_0_0_0	)				->					int:
      '''simple docstring'''


      lowercase														=			[(i * (3 * i - 1)) // 2 for i in range(1      ,	lowerCAmelCase__	)]
      for i, pentagonal_i in enumerate(lowerCAmelCase__	):
            for j in range(lowerCAmelCase__      ,	len(lowerCAmelCase__	)	):
                  lowercase														=			pentagonal_nums[j]
                  lowercase														=			pentagonal_i + pentagonal_j
                  lowercase														=			pentagonal_j - pentagonal_i
                  if is_pentagonal(lowerCAmelCase__	) and is_pentagonal(lowerCAmelCase__	):
                        return b

      return -1


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



