

import json
import os
from functools import lru_cache
from typing import List, Optional, Tuple

import regex as re

from ...tokenization_utils import AddedToken, PreTrainedTokenizer
from ...utils import logging


_SCREAMING_SNAKE_CASE          = logging.get_logger(__name__)

_SCREAMING_SNAKE_CASE          = {
    '''vocab_file''': '''vocab.json''',
    '''merges_file''': '''merges.txt''',
}

_SCREAMING_SNAKE_CASE          = {
    '''vocab_file''': {
        '''roberta-base''': '''https://huggingface.co/roberta-base/resolve/main/vocab.json''',
        '''roberta-large''': '''https://huggingface.co/roberta-large/resolve/main/vocab.json''',
        '''roberta-large-mnli''': '''https://huggingface.co/roberta-large-mnli/resolve/main/vocab.json''',
        '''distilroberta-base''': '''https://huggingface.co/distilroberta-base/resolve/main/vocab.json''',
        '''roberta-base-openai-detector''': '''https://huggingface.co/roberta-base-openai-detector/resolve/main/vocab.json''',
        '''roberta-large-openai-detector''': (
            '''https://huggingface.co/roberta-large-openai-detector/resolve/main/vocab.json'''
        ),
    },
    '''merges_file''': {
        '''roberta-base''': '''https://huggingface.co/roberta-base/resolve/main/merges.txt''',
        '''roberta-large''': '''https://huggingface.co/roberta-large/resolve/main/merges.txt''',
        '''roberta-large-mnli''': '''https://huggingface.co/roberta-large-mnli/resolve/main/merges.txt''',
        '''distilroberta-base''': '''https://huggingface.co/distilroberta-base/resolve/main/merges.txt''',
        '''roberta-base-openai-detector''': '''https://huggingface.co/roberta-base-openai-detector/resolve/main/merges.txt''',
        '''roberta-large-openai-detector''': (
            '''https://huggingface.co/roberta-large-openai-detector/resolve/main/merges.txt'''
        ),
    },
}

_SCREAMING_SNAKE_CASE          = {
    '''roberta-base''': 5_1_2,
    '''roberta-large''': 5_1_2,
    '''roberta-large-mnli''': 5_1_2,
    '''distilroberta-base''': 5_1_2,
    '''roberta-base-openai-detector''': 5_1_2,
    '''roberta-large-openai-detector''': 5_1_2,
}





@lru_cache()
def    _snake_case		()       ->		Optional[Any]:
  __UpperCAmelCase  :     Union[str, Any]		=    (
      list(range(ord('!'     )						,					ord('~'     ) + 1     )     ) + list(range(ord('¡'     )						,					ord('¬'     ) + 1     )     ) + list(range(ord('®'     )						,					ord('ÿ'     ) + 1     )     )
  )
  __UpperCAmelCase  :     Union[str, Any]		=    bs[:]
  __UpperCAmelCase  :     Union[str, Any]		=    0
  for b in range(2**8     ):
    if b not in bs:
      bs.append(snake_case_     )
      cs.append(2**8 + n     )
      n += 1
  __UpperCAmelCase  :     Optional[Any]		=    [chr(snake_case_     ) for n in cs]
  return dict(zip(snake_case_						,					snake_case_     )     )





def    _snake_case		(snake_case_				:    str     )       ->		Optional[int]:
  __UpperCAmelCase  :     Optional[int]		=    set()
  __UpperCAmelCase  :     Tuple		=    word[0]
  for char in word[1:]:
    pairs.add((prev_char, char)     )
    __UpperCAmelCase  :     Any		=    char
  return pairs







class     lowerCamelCase_   ( _lowerCAmelCase):
 _lowerCAmelCase       		=  VOCAB_FILES_NAMES
 _lowerCAmelCase       		=  PRETRAINED_VOCAB_FILES_MAP
 _lowerCAmelCase       		=  PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
 _lowerCAmelCase       		=  ['''input_ids''', '''attention_mask''']




 def __init__( self     ,     _UpperCAmelCase     ,     _UpperCAmelCase     ,     _UpperCAmelCase="replace"     ,     _UpperCAmelCase="<s>"     ,     _UpperCAmelCase="</s>"     ,     _UpperCAmelCase="</s>"     ,     _UpperCAmelCase="<s>"     ,     _UpperCAmelCase="<unk>"     ,     _UpperCAmelCase="<pad>"     ,     _UpperCAmelCase="<mask>"     ,     _UpperCAmelCase=False     ,     **_UpperCAmelCase     ,     ):
   __UpperCAmelCase  :     Dict		=    AddedToken(_UpperCAmelCase     ,     lstrip=_UpperCAmelCase     ,     rstrip=_UpperCAmelCase       ) if isinstance(_UpperCAmelCase     ,     _UpperCAmelCase       ) else bos_token
   __UpperCAmelCase  :     int		=    AddedToken(_UpperCAmelCase     ,     lstrip=_UpperCAmelCase     ,     rstrip=_UpperCAmelCase       ) if isinstance(_UpperCAmelCase     ,     _UpperCAmelCase       ) else eos_token
   __UpperCAmelCase  :     Tuple		=    AddedToken(_UpperCAmelCase     ,     lstrip=_UpperCAmelCase     ,     rstrip=_UpperCAmelCase       ) if isinstance(_UpperCAmelCase     ,     _UpperCAmelCase       ) else sep_token
   __UpperCAmelCase  :     Tuple		=    AddedToken(_UpperCAmelCase     ,     lstrip=_UpperCAmelCase     ,     rstrip=_UpperCAmelCase       ) if isinstance(_UpperCAmelCase     ,     _UpperCAmelCase       ) else cls_token
   __UpperCAmelCase  :     List[Any]		=    AddedToken(_UpperCAmelCase     ,     lstrip=_UpperCAmelCase     ,     rstrip=_UpperCAmelCase       ) if isinstance(_UpperCAmelCase     ,     _UpperCAmelCase       ) else unk_token
   __UpperCAmelCase  :     Optional[int]		=    AddedToken(_UpperCAmelCase     ,     lstrip=_UpperCAmelCase     ,     rstrip=_UpperCAmelCase       ) if isinstance(_UpperCAmelCase     ,     _UpperCAmelCase       ) else pad_token

   # Mask token behave like a normal word, i.e. include the space before it
   __UpperCAmelCase  :     str		=    AddedToken(_UpperCAmelCase     ,     lstrip=_UpperCAmelCase     ,     rstrip=_UpperCAmelCase       ) if isinstance(_UpperCAmelCase     ,     _UpperCAmelCase       ) else mask_token

   super().__init__(
       errors=_UpperCAmelCase     ,     bos_token=_UpperCAmelCase     ,     eos_token=_UpperCAmelCase     ,     unk_token=_UpperCAmelCase     ,     sep_token=_UpperCAmelCase     ,     cls_token=_UpperCAmelCase     ,     pad_token=_UpperCAmelCase     ,     mask_token=_UpperCAmelCase     ,     add_prefix_space=_UpperCAmelCase     ,     **_UpperCAmelCase     ,     )

   with open(_UpperCAmelCase     ,     encoding='utf-8'       ) as vocab_handle:
     __UpperCAmelCase  :     int		=    json.load(_UpperCAmelCase       )
   __UpperCAmelCase  :     int		=    {v: k for k, v in self.encoder.items()}
   __UpperCAmelCase  :     List[str]		=    errors  # how to handle errors in decoding
   __UpperCAmelCase  :     Dict		=    bytes_to_unicode()
   __UpperCAmelCase  :     Tuple		=    {v: k for k, v in self.byte_encoder.items()}
   with open(_UpperCAmelCase     ,     encoding='utf-8'       ) as merges_handle:
     __UpperCAmelCase  :     List[Any]		=    merges_handle.read().split('\n'       )[1:-1]
   __UpperCAmelCase  :     Optional[Any]		=    [tuple(merge.split()       ) for merge in bpe_merges]
   __UpperCAmelCase  :     Dict		=    dict(zip(_UpperCAmelCase     ,     range(len(_UpperCAmelCase       )       )       )       )
   __UpperCAmelCase  :     Tuple		=    {}
   __UpperCAmelCase  :     Tuple		=    add_prefix_space

   # Should have added re.IGNORECASE so BPE merges can happen for capitalized versions of contractions
   __UpperCAmelCase  :     Optional[int]		=    re.compile(R'\'s|\'t|\'re|\'ve|\'m|\'ll|\'d| ?\p{L}+| ?\p{N}+| ?[^\s\p{L}\p{N}]+|\s+(?!\S)|\s+'       )




 @property
 def 						a					( self       ):
   return len(self.encoder       )




 def 						a					( self       ):
   return dict(self.encoder     ,     **self.added_tokens_encoder       )




 def 						a					( self     ,     _UpperCAmelCase       ):
   if token in self.cache:
     return self.cache[token]
   __UpperCAmelCase  :     int		=    tuple(_UpperCAmelCase       )
   __UpperCAmelCase  :     Optional[Any]		=    get_pairs(_UpperCAmelCase       )

   if not pairs:
     return token

   while True:
     __UpperCAmelCase  :     Tuple		=    min(_UpperCAmelCase     ,     key=lambda _UpperCAmelCase       : self.bpe_ranks.get(_UpperCAmelCase     ,     float('inf'       )       )       )
     if bigram not in self.bpe_ranks:
       break
     __UpperCAmelCase, __UpperCAmelCase  :     List[Any]		=    bigram
     __UpperCAmelCase  :     Any		=    []
     __UpperCAmelCase  :     Any		=    0
     while i < len(_UpperCAmelCase       ):
       try:
         __UpperCAmelCase  :     List[Any]		=    word.index(_UpperCAmelCase     ,     _UpperCAmelCase       )
       except ValueError:
         new_word.extend(word[i:]       )
         break
       else:
         new_word.extend(word[i:j]       )
         __UpperCAmelCase  :     Tuple		=    j

       if word[i] == first and i < len(_UpperCAmelCase       ) - 1 and word[i + 1] == second:
         new_word.append(first + second       )
         i += 2
       else:
         new_word.append(word[i]       )
         i += 1
     __UpperCAmelCase  :     str		=    tuple(_UpperCAmelCase       )
     __UpperCAmelCase  :     str		=    new_word
     if len(_UpperCAmelCase       ) == 1:
       break
     else:
       __UpperCAmelCase  :     Union[str, Any]		=    get_pairs(_UpperCAmelCase       )
   __UpperCAmelCase  :     int		=    ' '.join(_UpperCAmelCase       )
   __UpperCAmelCase  :     Optional[Any]		=    word
   return word




 def 						a					( self     ,     _UpperCAmelCase       ):
   __UpperCAmelCase  :     Dict		=    []
   for token in re.findall(self.pat     ,     _UpperCAmelCase       ):
     __UpperCAmelCase  :     List[str]		=    ''.join(
         self.byte_encoder[b] for b in token.encode('utf-8'       )       )  # Maps all our bytes to unicode strings, avoiding control tokens of the BPE (spaces in our case)
     bpe_tokens.extend(bpe_token for bpe_token in self.bpe(_UpperCAmelCase       ).split(' '       )       )
   return bpe_tokens




 def 						a					( self     ,     _UpperCAmelCase       ):
   return self.encoder.get(_UpperCAmelCase     ,     self.encoder.get(self.unk_token       )       )




 def 						a					( self     ,     _UpperCAmelCase       ):
   return self.decoder.get(_UpperCAmelCase       )




 def 						a					( self     ,     _UpperCAmelCase       ):
   __UpperCAmelCase  :     Optional[int]		=    ''.join(_UpperCAmelCase       )
   __UpperCAmelCase  :     str		=    bytearray([self.byte_decoder[c] for c in text]       ).decode('utf-8'     ,     errors=self.errors       )
   return text




 def 						a					( self     ,     _UpperCAmelCase     ,     _UpperCAmelCase = None       ):
   if not os.path.isdir(_UpperCAmelCase       ):
     logger.error(F"Vocabulary path ({save_directory}) should be a directory"       )
     return
   __UpperCAmelCase  :     Optional[int]		=    os.path.join(
       _UpperCAmelCase     ,     (filename_prefix + '-' if filename_prefix else '') + VOCAB_FILES_NAMES['vocab_file']       )
   __UpperCAmelCase  :     str		=    os.path.join(
       _UpperCAmelCase     ,     (filename_prefix + '-' if filename_prefix else '') + VOCAB_FILES_NAMES['merges_file']       )

   with open(_UpperCAmelCase     ,     'w'     ,     encoding='utf-8'       ) as f:
     f.write(json.dumps(self.encoder     ,     indent=2     ,     sort_keys=_UpperCAmelCase     ,     ensure_ascii=_UpperCAmelCase       ) + '\n'       )

   __UpperCAmelCase  :     int		=    0
   with open(_UpperCAmelCase     ,     'w'     ,     encoding='utf-8'       ) as writer:
     writer.write('#version: 0.2\n'       )
     for bpe_tokens, token_index in sorted(self.bpe_ranks.items()     ,     key=lambda _UpperCAmelCase       : kv[1]       ):
       if index != token_index:
         logger.warning(
             F"Saving vocabulary to {merge_file}: BPE merge indices are not consecutive."
             ' Please check that the tokenizer is not corrupted!'       )
         __UpperCAmelCase  :     List[Any]		=    token_index
       writer.write(' '.join(_UpperCAmelCase       ) + '\n'       )
       index += 1

   return vocab_file, merge_file




 def 						a					( self     ,     _UpperCAmelCase     ,     _UpperCAmelCase = None       ):
   if token_ids_a is None:
     return [self.cls_token_id] + token_ids_a + [self.sep_token_id]
   __UpperCAmelCase  :     Dict		=    [self.cls_token_id]
   __UpperCAmelCase  :     Dict		=    [self.sep_token_id]
   return cls + token_ids_a + sep + sep + token_ids_a + sep




 def 						a					( self     ,     _UpperCAmelCase     ,     _UpperCAmelCase = None     ,     _UpperCAmelCase = False       ):
   if already_has_special_tokens:
     return super().get_special_tokens_mask(
         token_ids_a=_UpperCAmelCase     ,     token_ids_a=_UpperCAmelCase     ,     already_has_special_tokens=_UpperCAmelCase       )

   if token_ids_a is None:
     return [1] + ([0] * len(_UpperCAmelCase       )) + [1]
   return [1] + ([0] * len(_UpperCAmelCase       )) + [1, 1] + ([0] * len(_UpperCAmelCase       )) + [1]




 def 						a					( self     ,     _UpperCAmelCase     ,     _UpperCAmelCase = None       ):
   __UpperCAmelCase  :     Dict		=    [self.sep_token_id]
   __UpperCAmelCase  :     Tuple		=    [self.cls_token_id]

   if token_ids_a is None:
     return len(cls + token_ids_a + sep       ) * [0]
   return len(cls + token_ids_a + sep + sep + token_ids_a + sep       ) * [0]




 def 						a					( self     ,     _UpperCAmelCase     ,     _UpperCAmelCase=False     ,     **_UpperCAmelCase       ):
   __UpperCAmelCase  :     Dict		=    kwargs.pop('add_prefix_space'     ,     self.add_prefix_space       )
   if (is_split_into_words or add_prefix_space) and (len(_UpperCAmelCase       ) > 0 and not text[0].isspace()):
     __UpperCAmelCase  :     str		=    ' ' + text
   return (text, kwargs)








import math
from itertools import permutations





def    _snake_case		(snake_case_				:    int     )       ->		bool:

  if 1 < number < 4:
    # 2 and 3 are primes
    return True
  elif number < 2 or number % 2 == 0 or number % 3 == 0:
    # Negatives, 0, 1, all even numbers, all multiples of 3 are not primes
    return False

  # All primes number are in format of 6k +/- 1
  for i in range(5						,					int(math.sqrt(snake_case_     ) + 1     )						,					6     ):
    if number % i == 0 or number % (i + 2) == 0:
      return False
  return True





def    _snake_case		(snake_case_				:    int						,					snake_case_				:    list     )       ->		bool:
  __UpperCAmelCase, __UpperCAmelCase  :     Any		=    0, len(snake_case_     ) - 1
  while left <= right:
    __UpperCAmelCase  :     List[str]		=    (left + right) // 2
    if prime_list[middle] == target:
      return True
    elif prime_list[middle] < target:
      __UpperCAmelCase  :     Tuple		=    middle + 1
    else:
      __UpperCAmelCase  :     Tuple		=    middle - 1

  return False





def    _snake_case		()       ->		str:
  __UpperCAmelCase  :     List[Any]		=    [n for n in range(1001						,					1_0000						,					2     ) if is_prime(snake_case_     )]
  __UpperCAmelCase  :     Tuple		=    []

  for number in prime_list:
    __UpperCAmelCase  :     List[str]		=    []

    for prime_member in permutations(list(str(snake_case_     )     )     ):
      __UpperCAmelCase  :     Dict		=    int(''.join(snake_case_     )     )

      if prime % 2 == 0:
        continue

      if search(snake_case_						,					snake_case_     ):
        tmp_numbers.append(snake_case_     )

    tmp_numbers.sort()
    if len(snake_case_     ) >= 3:
      candidates.append(snake_case_     )

  __UpperCAmelCase  :     Optional[int]		=    []
  for candidate in candidates:
    __UpperCAmelCase  :     int		=    len(snake_case_     )
    __UpperCAmelCase  :     List[Any]		=    False

    for i in range(snake_case_     ):
      for j in range(i + 1						,					snake_case_     ):
        for k in range(j + 1						,					snake_case_     ):
          if (
              abs(candidate[i] - candidate[j]     )
              == abs(candidate[j] - candidate[k]     )
              and len({candidate[i], candidate[j], candidate[k]}     ) == 3
          ):
            passed.append(
                sorted([candidate[i], candidate[j], candidate[k]]     )     )
            __UpperCAmelCase  :     Any		=    True

          if found:
            break
        if found:
          break
      if found:
        break

  __UpperCAmelCase  :     Dict		=    set()
  for seq in passed:
    answer.add(''.join([str(snake_case_     ) for i in seq]     )     )

  return max(int(snake_case_     ) for x in answer     )


if __name__ == "__main__":
      print(solution())





