
import os
from shutil import copyfile
from typing import Any, Dict, List, Optional, Tuple

import sentencepiece as spm

from ...tokenization_utils import PreTrainedTokenizer
from ...utils import logging


lowerCamelCase__          =		logging.get_logger(__name__)

lowerCamelCase__          =		{"""vocab_file""": """spiece.model"""}

lowerCamelCase__          =		{
    """vocab_file""": {
        """bert_for_seq_generation""": (
            """https://huggingface.co/google/bert_for_seq_generation_L-24_bbc_encoder/resolve/main/spiece.model"""
        ),
    }
}

lowerCamelCase__          =		{"""bert_for_seq_generation""": 512}







class      A__							(     __magic_name__	):
				lowercase			    =  VOCAB_FILES_NAMES
				lowercase			    =  PRETRAINED_VOCAB_FILES_MAP
				lowercase			    =  PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
				lowercase			    =  []
				lowercase			    =  ['input_ids', 'attention_mask']






				def __init__(						self					:      Union[str, Any]    ,     a					:      Optional[Any]    ,     a					:      List[str]="<s>"    ,     a					:      Any="</s>"    ,     a					:      int="<unk>"    ,     a					:      int="<pad>"    ,     a					:      int="<::::>"    ,     a					:      Optional[Dict[str, Any]] = None    ,     **a					:      Any    ,     ):






							'''simple docstring'''







							lowerCAmelCase__      :      List[str]         =		{} if sp_model_kwargs is None else sp_model_kwargs

							# Add extra_ids to the special token list
							super().__init__(
							    bos_token=a    ,     eos_token=a    ,     unk_token=a    ,     pad_token=a    ,     sep_token=a    ,     sp_model_kwargs=self.sp_model_kwargs    ,     **a    ,     )

							lowerCAmelCase__      :      Dict         =		vocab_file

							lowerCAmelCase__      :      int         =		spm.SentencePieceProcessor(**self.sp_model_kwargs   )
							self.sp_model.Load(a   )






				@property
				def 							_lowerCamelCase		(						self					:      Union[str, Any]   ):






							'''simple docstring'''







							return self.sp_model.get_piece_size()






				def 							_lowerCamelCase		(						self					:      Tuple   ):






							'''simple docstring'''







							lowerCAmelCase__      :      str         =		{self.convert_ids_to_tokens(a   ): i for i in range(self.vocab_size   )}
							vocab.update(self.added_tokens_encoder   )
							return vocab






				def __getstate__(						self					:      List[str]   ):






							'''simple docstring'''







							lowerCAmelCase__      :      str         =		self.__dict__.copy()
							lowerCAmelCase__      :      str         =		None
							return state






				def __setstate__(						self					:      List[Any]    ,     a					:      Any   ):






							'''simple docstring'''







							lowerCAmelCase__      :      Dict         =		d

							# for backward compatibility
							if not hasattr(self    ,     'sp_model_kwargs'   ):
										lowerCAmelCase__      :      Optional[Any]         =		{}

							lowerCAmelCase__      :      Optional[int]         =		spm.SentencePieceProcessor(**self.sp_model_kwargs   )
							self.sp_model.Load(self.vocab_file   )






				def 							_lowerCamelCase		(						self					:      Union[str, Any]    ,     a					:      str   ):






							'''simple docstring'''







							return self.sp_model.encode(a    ,     out_type=a   )






				def 							_lowerCamelCase		(						self					:      Dict    ,     a					:      Any   ):






							'''simple docstring'''







							return self.sp_model.piece_to_id(a   )






				def 							_lowerCamelCase		(						self					:      Any    ,     a					:      Any   ):






							'''simple docstring'''







							lowerCAmelCase__      :      Optional[int]         =		self.sp_model.IdToPiece(a   )
							return token






				def 							_lowerCamelCase		(						self					:      Dict    ,     a					:      Any   ):






							'''simple docstring'''







							lowerCAmelCase__      :      List[str]         =		[]
							lowerCAmelCase__      :      Any         =		''
							for token in tokens:
										# make sure that special tokens are not decoded using sentencepiece model
										if token in self.all_special_tokens:
													out_string += self.sp_model.decode(a   ) + token
													lowerCAmelCase__      :      int         =		[]
										else:
													current_sub_tokens.append(a   )
							out_string += self.sp_model.decode(a   )
							return out_string.strip()






				def 							_lowerCamelCase		(						self					:      List[Any]    ,     a					:      str    ,     a					:      Optional[str] = None   ):






							'''simple docstring'''







							if not os.path.isdir(a   ):
										logger.error(f'''Vocabulary path ({save_directory}) should be a directory'''   )
										return
							lowerCAmelCase__      :      Any         =		os.path.join(
							    a    ,     (filename_prefix + '-' if filename_prefix else '') + VOCAB_FILES_NAMES['vocab_file']   )

							if os.path.abspath(self.vocab_file   ) != os.path.abspath(a   ) and os.path.isfile(self.vocab_file   ):
										copyfile(self.vocab_file    ,     a   )
							elif not os.path.isfile(self.vocab_file   ):
										with open(a    ,     'wb'   ) as fi:
													lowerCAmelCase__      :      Tuple         =		self.sp_model.serialized_model_proto()
													fi.write(a   )

							return (out_vocab_file,)

def  lowerCAmelCase__			(  SCREAMING_SNAKE_CASE_     )				->		list:

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

			lowerCAmelCase__      :      Optional[Any]         =		[]

			def generate(SCREAMING_SNAKE_CASE_       ,							SCREAMING_SNAKE_CASE_     ):
						if k == 1:
									res.append(tuple(arr[:]     )     )
									return

						generate(k - 1       ,							SCREAMING_SNAKE_CASE_     )

						for i in range(k - 1     ):
									if k % 2 == 0:  # k is even
												lowerCAmelCase__      ,				lowerCAmelCase__      :      str         =		arr[k - 1], arr[i]
									else:  # k is odd
												lowerCAmelCase__      ,				lowerCAmelCase__      :      Union[str, Any]         =		arr[k - 1], arr[0]
									generate(k - 1       ,							SCREAMING_SNAKE_CASE_     )

			generate(len(SCREAMING_SNAKE_CASE_     )       ,							SCREAMING_SNAKE_CASE_     )
			return res


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