

'''simple docstring'''

import json
import os
import re
import unicodedata
from typing import Dict, List, Optional, Tuple

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


UpperCAmelCase				   =  logging.get_logger(__name__)

UpperCAmelCase				   =  {
    '''src_vocab_file''': '''vocab-src.json''',
    '''tgt_vocab_file''': '''vocab-tgt.json''',
    '''merges_file''': '''merges.txt''',
}

UpperCAmelCase				   =  {
    '''src_vocab_file''': {
        '''stas/tiny-wmt19-en-de''': '''https://huggingface.co/stas/tiny-wmt19-en-de/resolve/main/vocab-src.json'''
    },
    '''tgt_vocab_file''': {
        '''stas/tiny-wmt19-en-de''': '''https://huggingface.co/stas/tiny-wmt19-en-de/resolve/main/vocab-tgt.json'''
    },
    '''merges_file''': {'''stas/tiny-wmt19-en-de''': '''https://huggingface.co/stas/tiny-wmt19-en-de/resolve/main/merges.txt'''},
}

UpperCAmelCase				   =  {'''stas/tiny-wmt19-en-de''': 1024}
UpperCAmelCase				   =  {
    '''stas/tiny-wmt19-en-de''': {
        '''langs''': ['''en''', '''de'''],
        '''model_max_length''': 1024,
        '''special_tokens_map_file''': None,
        '''full_tokenizer_file''': None,
    }
}

def 				__UpperCamelCase							(	lowercase__						:  Optional[Any] ):






     '''simple docstring'''





     __lowercase					=set()
     __lowercase					=word[0]
     for char in word[1:]:
          pairs.add((prev_char, char) )
          __lowercase					=char
     return pairs

def 				__UpperCamelCase							(	lowercase__						:  Optional[int] ):






     '''simple docstring'''





     __lowercase					=text.replace('，',					',' )
     __lowercase					=re.sub(R'。\s*',					'. ',					lowercase__ )
     __lowercase					=text.replace('、',					',' )
     __lowercase					=text.replace('”',					'"' )
     __lowercase					=text.replace('“',					'"' )
     __lowercase					=text.replace('∶',					':' )
     __lowercase					=text.replace('：',					':' )
     __lowercase					=text.replace('？',					'?' )
     __lowercase					=text.replace('《',					'"' )
     __lowercase					=text.replace('》',					'"' )
     __lowercase					=text.replace('）',					')' )
     __lowercase					=text.replace('！',					'!' )
     __lowercase					=text.replace('（',					'(' )
     __lowercase					=text.replace('；',					';' )
     __lowercase					=text.replace('１',					'1' )
     __lowercase					=text.replace('」',					'"' )
     __lowercase					=text.replace('「',					'"' )
     __lowercase					=text.replace('０',					'0' )
     __lowercase					=text.replace('３',					'3' )
     __lowercase					=text.replace('２',					'2' )
     __lowercase					=text.replace('５',					'5' )
     __lowercase					=text.replace('６',					'6' )
     __lowercase					=text.replace('９',					'9' )
     __lowercase					=text.replace('７',					'7' )
     __lowercase					=text.replace('８',					'8' )
     __lowercase					=text.replace('４',					'4' )
     __lowercase					=re.sub(R'．\s*',					'. ',					lowercase__ )
     __lowercase					=text.replace('～',					'~' )
     __lowercase					=text.replace('’',					'\'' )
     __lowercase					=text.replace('…',					'...' )
     __lowercase					=text.replace('━',					'-' )
     __lowercase					=text.replace('〈',					'<' )
     __lowercase					=text.replace('〉',					'>' )
     __lowercase					=text.replace('【',					'[' )
     __lowercase					=text.replace('】',					']' )
     __lowercase					=text.replace('％',					'%' )
     return text

def 				__UpperCamelCase							(	lowercase__						:  Dict ):






     '''simple docstring'''





     __lowercase					=[]
     for char in text:
          __lowercase					=unicodedata.category(lowercase__ )
          if cat.startswith('C' ):
               continue
          output.append(lowercase__ )
     return "".join(lowercase__ )







class   lowerCAmelCase     (      A   ):
       lowerCAmelCase_		= VOCAB_FILES_NAMES
       lowerCAmelCase_		= PRETRAINED_VOCAB_FILES_MAP
       lowerCAmelCase_		= PRETRAINED_INIT_CONFIGURATION
       lowerCAmelCase_		= PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
       lowerCAmelCase_		= ["input_ids", "attention_mask"]







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







            """simple docstring"""







            super().__init__(
                langs=__lowercase						,      src_vocab_file=__lowercase						,      tgt_vocab_file=__lowercase						,      merges_file=__lowercase						,      do_lower_case=__lowercase						,      unk_token=__lowercase						,      bos_token=__lowercase						,      sep_token=__lowercase						,      pad_token=__lowercase						,      **__lowercase						,      )

            try:
                 import sacremoses
            except ImportError:
                 raise ImportError(
                     'You need to install sacremoses to use XLMTokenizer. '
                     'See https://pypi.org/project/sacremoses/ for installation.'      )

            __lowercase					=sacremoses

            __lowercase					=src_vocab_file
            __lowercase					=tgt_vocab_file
            __lowercase					=merges_file
            __lowercase					=do_lower_case

            # cache of sm.MosesPunctNormalizer instance
            __lowercase					={}
            # cache of sm.MosesTokenizer instance
            __lowercase					={}
            __lowercase					={}

            if langs and len(__lowercase      ) == 2:
                 __lowercase		,     __lowercase					=langs
            else:
                 raise ValueError(
                     f'''arg `langs` needs to be a list of 2 langs, e.g. [\'en\', \'ru\'], but got {langs}. '''
                     'Usually that means that tokenizer can\'t find a mapping for the given model path '
                     'in PRETRAINED_VOCAB_FILES_MAP, and other maps of this tokenizer.'      )

            with open(__lowercase						,      encoding='utf-8'      ) as src_vocab_handle:
                 __lowercase					=json.load(__lowercase      )
            with open(__lowercase						,      encoding='utf-8'      ) as tgt_vocab_handle:
                 __lowercase					=json.load(__lowercase      )
                 __lowercase					={v: k for k, v in tgt_vocab.items()}
            with open(__lowercase						,      encoding='utf-8'      ) as merges_handle:
                 __lowercase					=merges_handle.read().split('\n'      )[:-1]
            __lowercase					=[tuple(merge.split()[:2]      ) for merge in merges]
            __lowercase					=dict(zip(__lowercase						,      range(len(__lowercase      )      )      )      )
            __lowercase					={}







       def 			snake_case   (							self			: Tuple      ):







            """simple docstring"""







            return self.get_src_vocab()







       @property
       def 			snake_case   (							self			: Optional[int]      ):







            """simple docstring"""







            return self.src_vocab_size







       def 			snake_case   (							self			: Optional[int]						,      __lowercase			: Any						,      __lowercase			: List[str]      ):







            """simple docstring"""







            if lang not in self.cache_moses_punct_normalizer:
                 __lowercase					=self.sm.MosesPunctNormalizer(lang=__lowercase      )
                 __lowercase					=punct_normalizer
            return self.cache_moses_punct_normalizer[lang].normalize(__lowercase      )







       def 			snake_case   (							self			: Optional[int]						,      __lowercase			: Tuple						,      __lowercase			: Tuple      ):







            """simple docstring"""







            if lang not in self.cache_moses_tokenizer:
                 __lowercase					=self.sm.MosesTokenizer(lang=__lowercase      )
                 __lowercase					=moses_tokenizer
            return self.cache_moses_tokenizer[lang].tokenize(
                __lowercase						,      aggressive_dash_splits=__lowercase						,      return_str=__lowercase						,      escape=__lowercase      )







       def 			snake_case   (							self			: Optional[int]						,      __lowercase			: Optional[int]						,      __lowercase			: Dict      ):







            """simple docstring"""







            if lang not in self.cache_moses_detokenizer:
                 __lowercase					=self.sm.MosesDetokenizer(lang=__lowercase      )
                 __lowercase					=moses_detokenizer
            return self.cache_moses_detokenizer[lang].detokenize(__lowercase      )







       def 			snake_case   (							self			: Union[str, Any]						,      __lowercase			: Optional[Any]						,      __lowercase			: Tuple      ):







            """simple docstring"""







            __lowercase					=replace_unicode_punct(__lowercase      )
            __lowercase					=self.moses_punct_norm(__lowercase						,      __lowercase      )
            __lowercase					=remove_non_printing_char(__lowercase      )
            return text







       @property
       def 			snake_case   (							self			: List[str]      ):







            """simple docstring"""







            return len(self.encoder      )







       @property
       def 			snake_case   (							self			: int      ):







            """simple docstring"""







            return len(self.decoder      )







       def 			snake_case   (							self			: int      ):







            """simple docstring"""







            return dict(self.encoder						,      **self.added_tokens_encoder      )







       def 			snake_case   (							self			: Optional[Any]      ):







            """simple docstring"""







            return dict(self.decoder						,      **self.added_tokens_decoder      )







       def 			snake_case   (							self			: Dict						,      __lowercase			: Optional[Any]      ):







            """simple docstring"""







            __lowercase					=tuple(token[:-1]      ) + (token[-1] + '</w>',)
            if token in self.cache:
                 return self.cache[token]
            __lowercase					=get_pairs(__lowercase      )

            if not pairs:
                 return token + "</w>"

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

                      if word[i] == first and i < len(__lowercase      ) - 1 and word[i + 1] == second:
                           new_word.append(first + second      )
                           i += 2
                      else:
                           new_word.append(word[i]      )
                           i += 1
                 __lowercase					=tuple(__lowercase      )
                 __lowercase					=new_word
                 if len(__lowercase      ) == 1:
                      break
                 else:
                      __lowercase					=get_pairs(__lowercase      )
            __lowercase					=' '.join(__lowercase      )
            if word == "\n  </w>":
                 __lowercase					='\n</w>'
            __lowercase					=word
            return word







       def 			snake_case   (							self			: int						,      __lowercase			: Union[str, Any]						,      __lowercase			: List[str]="en"						,      __lowercase			: Tuple=False      ):







            """simple docstring"""







            __lowercase					=self.src_lang

            if self.do_lower_case:
                 __lowercase					=text.lower()

            if bypass_tokenizer:
                 __lowercase					=text.split()
            else:
                 __lowercase					=self.moses_pipeline(__lowercase						,      lang=__lowercase      )
                 __lowercase					=self.moses_tokenize(__lowercase						,      lang=__lowercase      )

            __lowercase					=[]
            for token in text:
                 if token:
                      split_tokens.extend(list(self.bpe(__lowercase      ).split(' '      )      )      )

            return split_tokens







       def 			snake_case   (							self			: Any						,      __lowercase			: Optional[Any]      ):







            """simple docstring"""







            return self.encoder.get(__lowercase						,      self.encoder.get(self.unk_token      )      )







       def 			snake_case   (							self			: List[str]						,      __lowercase			: Dict      ):







            """simple docstring"""







            return self.decoder.get(__lowercase						,      self.unk_token      )







       def 			snake_case   (							self			: Dict						,      __lowercase			: Union[str, Any]      ):







            """simple docstring"""







            __lowercase					=[t.replace(' '						,      ''      ).replace('</w>'						,      ' '      ) for t in tokens]
            __lowercase					=''.join(__lowercase      ).split()
            # detokenize
            __lowercase					=self.moses_detokenize(__lowercase						,      self.tgt_lang      )
            return text







       def 			snake_case   (							self			: Optional[Any]						,      __lowercase			: List[int]						,      __lowercase			: Optional[List[int]] = None      ):







            """simple docstring"""







            __lowercase					=[self.sep_token_id]

            # no bos used in fairseq
            if token_ids_a is None:
                 return token_ids_a + sep
            return token_ids_a + sep + token_ids_a + sep







       def 			snake_case   (							self			: Dict						,      __lowercase			: List[int]						,      __lowercase			: Optional[List[int]] = None						,      __lowercase			: bool = False      ):







            """simple docstring"""







            if already_has_special_tokens:
                 return super().get_special_tokens_mask(
                     token_ids_a=__lowercase						,      token_ids_a=__lowercase						,      already_has_special_tokens=__lowercase      )
            # no bos used in fairseq
            if token_ids_a is not None:
                 return ([0] * len(__lowercase      )) + [1] + ([0] * len(__lowercase      )) + [1]
            return ([0] * len(__lowercase      )) + [1]







       def 			snake_case   (							self			: Union[str, Any]						,      __lowercase			: List[int]						,      __lowercase			: Optional[List[int]] = None      ):







            """simple docstring"""







            __lowercase					=[self.sep_token_id]

            # no bos used in fairseq
            if token_ids_a is None:
                 return len(token_ids_a + sep      ) * [0]
            return len(token_ids_a + sep      ) * [0] + len(token_ids_a + sep      ) * [1]







       def 			snake_case   (							self			: List[Any]						,      __lowercase			: str						,      __lowercase			: Optional[str] = None      ):







            """simple docstring"""







            if not os.path.isdir(__lowercase      ):
                 logger.error(f'''Vocabulary path ({save_directory}) should be a directory'''      )
                 return

            __lowercase					=os.path.join(
                __lowercase						,      (filename_prefix + '-' if filename_prefix else '') + VOCAB_FILES_NAMES['src_vocab_file']      )
            __lowercase					=os.path.join(
                __lowercase						,      (filename_prefix + '-' if filename_prefix else '') + VOCAB_FILES_NAMES['tgt_vocab_file']      )
            __lowercase					=os.path.join(
                __lowercase						,      (filename_prefix + '-' if filename_prefix else '') + VOCAB_FILES_NAMES['merges_file']      )

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

            with open(__lowercase						,      'w'						,      encoding='utf-8'      ) as f:
                 __lowercase					={v: k for k, v in self.decoder.items()}
                 f.write(json.dumps(__lowercase						,      indent=2						,      sort_keys=__lowercase						,      ensure_ascii=__lowercase      ) + '\n'      )

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

            return src_vocab_file, tgt_vocab_file, merges_file







       def __getstate__(							self			: Dict      ):







            """simple docstring"""







            __lowercase					=self.__dict__.copy()
            __lowercase					=None
            return state







       def __setstate__(							self			: Any						,      __lowercase			: int      ):







            """simple docstring"""







            __lowercase					=d

            try:
                 import sacremoses
            except ImportError:
                 raise ImportError(
                     'You need to install sacremoses to use XLMTokenizer. '
                     'See https://pypi.org/project/sacremoses/ for installation.'      )

            __lowercase					=sacremoses





'''simple docstring'''

from __future__ import annotations

from pathlib import Path

def 				__UpperCamelCase							(	lowercase__						:  tuple[int, int],					lowercase__						:  tuple[int, int] ):






     '''simple docstring'''





     return pointa[0] * pointa[1] - pointa[1] * pointa[0]

def 				__UpperCamelCase							(	lowercase__						:  int,					lowercase__						:  int,					lowercase__						:  int,					lowercase__						:  int,					lowercase__						:  int,					lowercase__						:  int ):






     '''simple docstring'''





     __lowercase					=(xa, ya)
     __lowercase					=(xa - xa, ya - ya)
     __lowercase					=(xa - xa, ya - ya)
     __lowercase					=-vector_product(lowercase__,					lowercase__ ) / vector_product(
         lowercase__,					lowercase__ )
     __lowercase					=+vector_product(lowercase__,					lowercase__ ) / vector_product(
         lowercase__,					lowercase__ )

     return a > 0 and b > 0 and a + b < 1

def 				__UpperCamelCase							(	lowercase__						:  str = "p102_triangles.txt" ):






     '''simple docstring'''





     __lowercase					=Path(lowercase__ ).parent.joinpath(lowercase__ ).read_text(encoding='utf-8' )

     __lowercase					=[]
     for line in data.strip().split('\n' ):
          triangles.append([int(lowercase__ ) for number in line.split(',' )] )

     __lowercase					=0
     __lowercase					=42

     for triangle in triangles:
          ret += contains_origin(*lowercase__ )

     return ret


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


