




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      :						Optional[int]							=  logging.get_logger(__name__)


class 							UpperCamelCase_       (					UpperCAmelCase__	):

    '''simple docstring'''






    def __init__(     self :      Union[str, Any]   ,					**UpperCAmelCase__ :      Optional[int])		->Optional[int]:





           '''simple docstring'''

           requires_backends(self   ,					['''bs4'''])
           super().__init__(**UpperCAmelCase__)


    def 			SCREAMING_SNAKE_CASE				(     self :      Union[str, Any]   ,					UpperCAmelCase__ :      Dict)		->Optional[Any]:





           '''simple docstring'''

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


    def 			SCREAMING_SNAKE_CASE				(     self :      Dict   ,					UpperCAmelCase__ :      Dict)		->Optional[int]:





           '''simple docstring'''

           A__ 					=       BeautifulSoup(UpperCAmelCase__   ,					'''html.parser''')

           A__ 					=       []
           A__ 					=       []
           A__ 					=       []

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

                         A__ 					=       html.unescape(UpperCAmelCase__).strip()
                         if not text_in_this_tag:
                                continue

                         all_doc_strings.append(UpperCAmelCase__)

                         A__					,				A__ 					=       self.xpath_soup(UpperCAmelCase__)
                         stringaxtag_seq.append(UpperCAmelCase__)
                         stringaxsubs_seq.append(UpperCAmelCase__)

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

           return all_doc_strings, stringaxtag_seq, stringaxsubs_seq


    def 			SCREAMING_SNAKE_CASE				(     self :      List[str]   ,					UpperCAmelCase__ :      Any   ,					UpperCAmelCase__ :      Optional[int])		->Optional[Any]:





           '''simple docstring'''

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





    def __call__(     self :      Optional[Any]   ,					UpperCAmelCase__ :      Tuple)		->BatchFeature:





           '''simple docstring'''

           A__ 					=       False

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

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

           A__ 					=       bool(isinstance(UpperCAmelCase__   ,					(list, tuple)) and (isinstance(html_strings[0]   ,					UpperCAmelCase__)))

           if not is_batched:
                  A__ 					=       [html_strings]

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

           # return as Dict
           A__ 					=       {'''nodes''': nodes, '''xpaths''': xpaths}
           A__ 					=       BatchFeature(data=UpperCAmelCase__   ,					tensor_type=UpperCAmelCase__)

           return encoded_inputs






'''simple docstring'''
def 	_A  (       A							)  ->				list:

	if len(A							) <= 1:
		return [tuple(A							)]

	lowercase						:		Dict   					=		[]

	def generate(A							,A							):
		lowercase						:		List[Any]   					=		[0] * n
		res.append(tuple(A							)							)

		lowercase						:		Tuple   					=		0
		while i < n:
			if c[i] < i:
				if i % 2 == 0:
					lowercase					,		lowercase						:		List[Any]   					=		arr[i], arr[0]
				else:
					lowercase					,		lowercase						:		Optional[Any]   					=		arr[i], arr[c[i]]
				res.append(tuple(A							)							)
				c[i] += 1
				lowercase						:		Optional[Any]   					=		0
			else:
				lowercase						:		Any   					=		0
				i += 1

	generate(len(A							)							,A							)
	return res


if __name__ == "__main__":
					lowerCAmelCase   : Any             =				input("""Enter numbers separated by a comma:\n""").strip()
					lowerCAmelCase   : List[str]             =				[int(item) for item in user_input.split(""",""")]
					print(heaps(arr))


