
from collections import defaultdict




class 					_lowerCamelCase			:





     """simple docstring"""







     def __init__(				self    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE	)	-> Dict:




           """simple docstring"""







           UpperCamelCase__     : int											=					total  # total no of tasks (N)

           # DP table will have a dimension of (2^M)*N
           # initially all values are set to -1
           UpperCamelCase__     : List[str]											=					[
               [-1 for i in range(total + 1	)] for j in range(2 ** len(__SCREAMING_SNAKE_CASE	)	)
           ]

           UpperCamelCase__     : Tuple											=					defaultdict(__SCREAMING_SNAKE_CASE	)  # stores the list of persons for each task

           # final_mask is used to check if all persons are included by setting all bits
           # to 1
           UpperCamelCase__     : Optional[Any]											=					(1 << len(__SCREAMING_SNAKE_CASE	)) - 1






     def  __SCREAMING_SNAKE_CASE      (				self    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE	)	-> Optional[int]:




           """simple docstring"""







           if mask == self.final_mask:
                 return 1

           # if not everyone gets the task and no more tasks are available, return 0
           if task_no > self.total_tasks:
                 return 0

           # if case already considered
           if self.dp[mask][task_no] != -1:
                 return self.dp[mask][task_no]

           # Number of ways when we don't this task in the arrangement
           UpperCamelCase__     : Dict											=					self.count_ways_until(__SCREAMING_SNAKE_CASE    ,    task_no + 1	)

           # now assign the tasks one by one to all possible persons and recursively
           # assign for the remaining tasks.
           if task_no in self.task:
                 for p in self.task[task_no]:
                       # if p is already given a task
                       if mask & (1 << p):
                             continue

                       # assign this task to p and change the mask value. And recursively
                       # assign tasks with the new mask value.
                       total_ways_util += self.count_ways_until(mask | (1 << p)    ,    task_no + 1	)

        # save the value.
           UpperCamelCase__     : List[Any]											=					total_ways_util

           return self.dp[mask][task_no]






     def  __SCREAMING_SNAKE_CASE      (				self    ,    __SCREAMING_SNAKE_CASE	)	-> int:




           """simple docstring"""







           for i in range(len(__SCREAMING_SNAKE_CASE	)	):
                 for j in task_performed[i]:
                       self.task[j].append(__SCREAMING_SNAKE_CASE	)

        # call the function to fill the DP table, final answer is stored in dp[0][1]
           return self.count_ways_until(0    ,    1	)


if __name__ == "__main__":
    lowerCamelCase  =5  # total no of tasks (the value of N)

    # the list of tasks that can be done by M persons.
    lowerCamelCase  =[[1, 3, 4], [1, 2, 5], [3, 4]]
    print(
        AssignmentUsingBitmask(task_performed, total_tasks).count_no_of_ways(
            task_performed
        )
    )




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  ="▁"

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

lowerCamelCase  ={
    "vocab_file": {
        "google/reformer-crime-and-punishment": (
            "https://huggingface.co/google/reformer-crime-and-punishment/resolve/main/spiece.model"
        )
    }
}

lowerCamelCase  ={
    "google/reformer-crime-and-punishment": 5_2_4_2_8_8,
}




class 					_lowerCamelCase			(   UpperCamelCase_			):





     """simple docstring"""







     SCREAMING_SNAKE_CASE_		 =	VOCAB_FILES_NAMES
     SCREAMING_SNAKE_CASE_		 =	PRETRAINED_VOCAB_FILES_MAP
     SCREAMING_SNAKE_CASE_		 =	PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
     SCREAMING_SNAKE_CASE_		 =	['''input_ids''', '''attention_mask''']






     def __init__(				self    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE="</s>"    ,    __SCREAMING_SNAKE_CASE="<unk>"    ,    __SCREAMING_SNAKE_CASE=[]    ,    __SCREAMING_SNAKE_CASE = None    ,    **__SCREAMING_SNAKE_CASE    ,    )	-> None:




           """simple docstring"""







           UpperCamelCase__     : int											=					{} if sp_model_kwargs is None else sp_model_kwargs

           super().__init__(
               eos_token=__SCREAMING_SNAKE_CASE    ,    unk_token=__SCREAMING_SNAKE_CASE    ,    additional_special_tokens=__SCREAMING_SNAKE_CASE    ,    sp_model_kwargs=self.sp_model_kwargs    ,    **__SCREAMING_SNAKE_CASE    ,    )

           UpperCamelCase__     : Dict											=					vocab_file
           UpperCamelCase__     : Any											=					spm.SentencePieceProcessor(**self.sp_model_kwargs	)
           self.sp_model.Load(__SCREAMING_SNAKE_CASE	)






     @property
     def  __SCREAMING_SNAKE_CASE      (				self	)	-> List[Any]:




           """simple docstring"""







           return self.sp_model.get_piece_size()






     def  __SCREAMING_SNAKE_CASE      (				self	)	-> Dict[str, int]:




           """simple docstring"""







           UpperCamelCase__     : Tuple											=					{self.convert_ids_to_tokens(__SCREAMING_SNAKE_CASE	): i for i in range(self.vocab_size	)}
           vocab.update(self.added_tokens_encoder	)
           return vocab






     def __getstate__(				self	)	-> Any:




           """simple docstring"""







           UpperCamelCase__     : Dict											=					self.__dict__.copy()
           UpperCamelCase__     : int											=					None
           return state






     def __setstate__(				self    ,    __SCREAMING_SNAKE_CASE	)	-> str:




           """simple docstring"""







           UpperCamelCase__     : int											=					d

           # for backward compatibility
           if not hasattr(self    ,    '''sp_model_kwargs'''	):
                 UpperCamelCase__     : int											=					{}

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






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




           """simple docstring"""







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






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




           """simple docstring"""







           return self.sp_model.piece_to_id(__SCREAMING_SNAKE_CASE	)






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




           """simple docstring"""







           if index < self.sp_model.get_piece_size():
                 UpperCamelCase__     : str											=					self.sp_model.IdToPiece(__SCREAMING_SNAKE_CASE	)
           return token






     def  __SCREAMING_SNAKE_CASE      (				self    ,    __SCREAMING_SNAKE_CASE	)	-> Dict:




           """simple docstring"""







           UpperCamelCase__     : List[str]											=					[]
           UpperCamelCase__     : Union[str, 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(__SCREAMING_SNAKE_CASE	) + token
                       UpperCamelCase__     : str											=					[]
                 else:
                       current_sub_tokens.append(__SCREAMING_SNAKE_CASE	)
           out_string += self.sp_model.decode(__SCREAMING_SNAKE_CASE	)
           return out_string.strip()






     def  __SCREAMING_SNAKE_CASE      (				self    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE = None	)	-> Tuple[str]:




           """simple docstring"""







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

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

           return (out_vocab_file,)


