

'''simple docstring'''

import os
from typing import List, Union

import tensorflow as tf
from tensorflow_text import BertTokenizer as BertTokenizerLayer
from tensorflow_text import FastBertTokenizer, ShrinkLongestTrimmer, case_fold_utfa, combine_segments, pad_model_inputs

from .tokenization_bert import BertTokenizer





class 							_snake_case	(    tf.keras.layers.Layer  ):
   def __init__(	self     : int       ,SCREAMING_SNAKE_CASE__     : List       ,SCREAMING_SNAKE_CASE__     : bool       ,SCREAMING_SNAKE_CASE__     : int = None       ,SCREAMING_SNAKE_CASE__     : int = None       ,SCREAMING_SNAKE_CASE__     : int = None       ,SCREAMING_SNAKE_CASE__     : str = "longest"       ,SCREAMING_SNAKE_CASE__     : bool = True       ,SCREAMING_SNAKE_CASE__     : int = 512       ,SCREAMING_SNAKE_CASE__     : int = None       ,SCREAMING_SNAKE_CASE__     : bool = True       ,SCREAMING_SNAKE_CASE__     : bool = True       ,SCREAMING_SNAKE_CASE__     : bool = True       ,**SCREAMING_SNAKE_CASE__     : Optional[int]       ,):
     super().__init__()
     if use_fast_bert_tokenizer:
       SCREAMING_SNAKE_CASE:List[str]   =   FastBertTokenizer(
           SCREAMING_SNAKE_CASE__       ,token_out_type=tf.intaa       ,lower_case_nfd_strip_accents=SCREAMING_SNAKE_CASE__       ,**SCREAMING_SNAKE_CASE__							)
     else:
       SCREAMING_SNAKE_CASE:str   =   tf.lookup.StaticVocabularyTable(
           tf.lookup.KeyValueTensorInitializer(
               keys=SCREAMING_SNAKE_CASE__       ,key_dtype=tf.string       ,values=tf.range(tf.size(SCREAMING_SNAKE_CASE__       ,out_type=tf.intaa							)       ,dtype=tf.intaa							)       ,value_dtype=tf.intaa       ,)       ,num_oov_buckets=1       ,)
       SCREAMING_SNAKE_CASE:List[Any]   =   BertTokenizerLayer(
           SCREAMING_SNAKE_CASE__       ,token_out_type=tf.intaa       ,lower_case=SCREAMING_SNAKE_CASE__       ,**SCREAMING_SNAKE_CASE__							)

     SCREAMING_SNAKE_CASE:List[str]   =   vocab_list
     SCREAMING_SNAKE_CASE:str   =   do_lower_case
     SCREAMING_SNAKE_CASE:Optional[Any]   =   cls_token_id or vocab_list.index("[CLS]"							)
     SCREAMING_SNAKE_CASE:Dict   =   sep_token_id or vocab_list.index("[SEP]"							)
     SCREAMING_SNAKE_CASE:List[Any]   =   pad_token_id or vocab_list.index("[PAD]"							)
     SCREAMING_SNAKE_CASE:Dict   =   ShrinkLongestTrimmer(max_length - 3       ,axis=1							)  # Allow room for special tokens
     SCREAMING_SNAKE_CASE:Tuple   =   max_length
     SCREAMING_SNAKE_CASE:List[Any]   =   padding
     SCREAMING_SNAKE_CASE:Union[str, Any]   =   truncation
     SCREAMING_SNAKE_CASE:List[Any]   =   pad_to_multiple_of
     SCREAMING_SNAKE_CASE:Optional[Any]   =   return_token_type_ids
     SCREAMING_SNAKE_CASE:Tuple   =   return_attention_mask
   @classmethod
   def       __UpperCamelCase  (	cls     : Any       ,SCREAMING_SNAKE_CASE__     : "PreTrainedTokenizerBase"       ,**SCREAMING_SNAKE_CASE__     : Dict							):  # noqa: F821
     SCREAMING_SNAKE_CASE:Union[str, Any]   =   kwargs.pop("do_lower_case"       ,SCREAMING_SNAKE_CASE__							)
     SCREAMING_SNAKE_CASE:str   =   tokenizer.do_lower_case if do_lower_case is None else do_lower_case
     SCREAMING_SNAKE_CASE:str   =   kwargs.pop("cls_token_id"       ,SCREAMING_SNAKE_CASE__							)
     SCREAMING_SNAKE_CASE:Optional[int]   =   tokenizer.cls_token_id if cls_token_id is None else cls_token_id
     SCREAMING_SNAKE_CASE:Dict   =   kwargs.pop("sep_token_id"       ,SCREAMING_SNAKE_CASE__							)
     SCREAMING_SNAKE_CASE:List[Any]   =   tokenizer.sep_token_id if sep_token_id is None else sep_token_id
     SCREAMING_SNAKE_CASE:Tuple   =   kwargs.pop("pad_token_id"       ,SCREAMING_SNAKE_CASE__							)
     SCREAMING_SNAKE_CASE:int   =   tokenizer.pad_token_id if pad_token_id is None else pad_token_id

     SCREAMING_SNAKE_CASE:List[str]   =   tokenizer.get_vocab()
     SCREAMING_SNAKE_CASE:Dict   =   sorted([(wordpiece, idx) for wordpiece, idx in vocab.items()]       ,key=lambda SCREAMING_SNAKE_CASE__							: x[1]							)
     SCREAMING_SNAKE_CASE:Optional[Any]   =   [entry[0] for entry in vocab]
     return cls(
         vocab_list=SCREAMING_SNAKE_CASE__       ,do_lower_case=SCREAMING_SNAKE_CASE__       ,cls_token_id=SCREAMING_SNAKE_CASE__       ,sep_token_id=SCREAMING_SNAKE_CASE__       ,pad_token_id=SCREAMING_SNAKE_CASE__       ,**SCREAMING_SNAKE_CASE__       ,)
   @classmethod
   def       __UpperCamelCase  (	cls     : Optional[int]       ,SCREAMING_SNAKE_CASE__     : Union[str, os.PathLike]       ,*SCREAMING_SNAKE_CASE__     : List[Any]       ,**SCREAMING_SNAKE_CASE__     : Any							):
     try:
       SCREAMING_SNAKE_CASE:int   =   BertTokenizer.from_pretrained(SCREAMING_SNAKE_CASE__       ,*SCREAMING_SNAKE_CASE__       ,**SCREAMING_SNAKE_CASE__							)
     except:  # noqa: E722
       from .tokenization_bert_fast import BertTokenizerFast

       SCREAMING_SNAKE_CASE:Any   =   BertTokenizerFast.from_pretrained(SCREAMING_SNAKE_CASE__       ,*SCREAMING_SNAKE_CASE__       ,**SCREAMING_SNAKE_CASE__							)
     return cls.from_tokenizer(SCREAMING_SNAKE_CASE__       ,**SCREAMING_SNAKE_CASE__							)
   def       __UpperCamelCase  (	self     : Dict       ,SCREAMING_SNAKE_CASE__     : Any							):
     if self.do_lower_case:
       SCREAMING_SNAKE_CASE:str   =   case_fold_utfa(SCREAMING_SNAKE_CASE__							)
     SCREAMING_SNAKE_CASE:Optional[int]   =   self.tf_tokenizer.tokenize(SCREAMING_SNAKE_CASE__							)
     return tokens.merge_dims(1       ,-1							)
   def       __UpperCamelCase  (	self     : Any       ,SCREAMING_SNAKE_CASE__     : str       ,SCREAMING_SNAKE_CASE__     : str=None       ,SCREAMING_SNAKE_CASE__     : List[str]=None       ,SCREAMING_SNAKE_CASE__     : Tuple=None       ,SCREAMING_SNAKE_CASE__     : List[Any]=None       ,SCREAMING_SNAKE_CASE__     : Any=None       ,SCREAMING_SNAKE_CASE__     : Dict=None       ,SCREAMING_SNAKE_CASE__     : Optional[Any]=None       ,):
     if padding is None:
       SCREAMING_SNAKE_CASE:str   =   self.padding
     if padding not in ("longest", "max_length"):
       raise ValueError("Padding must be either 'longest' or 'max_length'!"							)
     if max_length is not None and text_pair is not None:
       # Because we have to instantiate a Trimmer to do it properly
       raise ValueError("max_length cannot be overridden at call time when truncating paired texts!"							)
     if max_length is None:
       SCREAMING_SNAKE_CASE:Any   =   self.max_length
     if truncation is None:
       SCREAMING_SNAKE_CASE:str   =   self.truncation
     if pad_to_multiple_of is None:
       SCREAMING_SNAKE_CASE:Any   =   self.pad_to_multiple_of
     if return_token_type_ids is None:
       SCREAMING_SNAKE_CASE:List[Any]   =   self.return_token_type_ids
     if return_attention_mask is None:
       SCREAMING_SNAKE_CASE:Any   =   self.return_attention_mask
     if not isinstance(SCREAMING_SNAKE_CASE__       ,tf.Tensor							):
       SCREAMING_SNAKE_CASE:Union[str, Any]   =   tf.convert_to_tensor(SCREAMING_SNAKE_CASE__							)
     if text_pair is not None and not isinstance(SCREAMING_SNAKE_CASE__       ,tf.Tensor							):
       SCREAMING_SNAKE_CASE:Any   =   tf.convert_to_tensor(SCREAMING_SNAKE_CASE__							)
     if text_pair is not None:
       if text.shape.rank > 1:
         raise ValueError("text argument should not be multidimensional when a text pair is supplied!"							)
       if text_pair.shape.rank > 1:
         raise ValueError("text_pair should not be multidimensional!"							)
     if text.shape.rank == 2:
       SCREAMING_SNAKE_CASE ,      SCREAMING_SNAKE_CASE:int   =   text[:, 0], text[:, 1]
     SCREAMING_SNAKE_CASE:Dict   =   self.unpaired_tokenize(SCREAMING_SNAKE_CASE__							)
     if text_pair is None:  # Unpaired text
       if truncation:
         SCREAMING_SNAKE_CASE:Dict   =   text[:, : max_length - 2]  # Allow room for special tokens
       SCREAMING_SNAKE_CASE ,      SCREAMING_SNAKE_CASE:Union[str, Any]   =   combine_segments(
           (text,)       ,start_of_sequence_id=self.cls_token_id       ,end_of_segment_id=self.sep_token_id							)
     else:  # Paired text
       SCREAMING_SNAKE_CASE:Dict   =   self.unpaired_tokenize(SCREAMING_SNAKE_CASE__							)
       if truncation:
         SCREAMING_SNAKE_CASE ,      SCREAMING_SNAKE_CASE:Optional[int]   =   self.paired_trimmer.trim([text, text_pair]							)
       SCREAMING_SNAKE_CASE ,      SCREAMING_SNAKE_CASE:Any   =   combine_segments(
           (text, text_pair)       ,start_of_sequence_id=self.cls_token_id       ,end_of_segment_id=self.sep_token_id							)
     if padding == "longest":
       SCREAMING_SNAKE_CASE:Any   =   input_ids.bounding_shape(axis=1							)
       if pad_to_multiple_of is not None:
         # No ceiling division in tensorflow, so we negate floordiv instead
         SCREAMING_SNAKE_CASE:List[Any]   =   pad_to_multiple_of * (-tf.math.floordiv(-pad_length       ,SCREAMING_SNAKE_CASE__							))
     else:
       SCREAMING_SNAKE_CASE:int   =   max_length

     SCREAMING_SNAKE_CASE ,      SCREAMING_SNAKE_CASE:Union[str, Any]   =   pad_model_inputs(SCREAMING_SNAKE_CASE__       ,max_seq_length=SCREAMING_SNAKE_CASE__       ,pad_value=self.pad_token_id							)
     SCREAMING_SNAKE_CASE:List[Any]   =   {"input_ids": input_ids}
     if return_attention_mask:
       SCREAMING_SNAKE_CASE:List[str]   =   attention_mask
     if return_token_type_ids:
       SCREAMING_SNAKE_CASE ,      SCREAMING_SNAKE_CASE:List[Any]   =   pad_model_inputs(
           SCREAMING_SNAKE_CASE__       ,max_seq_length=SCREAMING_SNAKE_CASE__       ,pad_value=self.pad_token_id							)
       SCREAMING_SNAKE_CASE:int   =   token_type_ids
     return output







   def       __UpperCamelCase  (	self     : Tuple							):
     return {
         "vocab_list": self.vocab_list,
         "do_lower_case": self.do_lower_case,
         "cls_token_id": self.cls_token_id,
         "sep_token_id": self.sep_token_id,
         "pad_token_id": self.pad_token_id,
     }









'''simple docstring'''

from collections import Counter





def 				A_					(	snake_case	):
  return sum(socks_by_color // 2 for socks_by_color in Counter(snake_case	).values()	)


if __name__ == "__main__":
    import doctest

    doctest.testmod()

    A_      =							[int(x) for x in input("Enter socks by color :").rstrip().split()]
    print(f'''sock_merchant({colors}) = {sock_merchant(colors)}''')






