




'''simple docstring'''
import unittest

import numpy as np
import timeout_decorator  # noqa

from transformers import MarianConfig, is_flax_available
from transformers.testing_utils import require_flax, require_sentencepiece, require_tokenizers, slow
from transformers.utils import cached_property

from ...generation.test_flax_utils import FlaxGenerationTesterMixin
from ...test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor


if is_flax_available():
  import os

  # The slow tests are often failing with OOM error on GPU
  # This makes JAX allocate exactly what is needed on demand, and deallocate memory that is no longer needed
  # but will be slower as stated here https://jax.readthedocs.io/en/latest/gpu_memory_allocation.html
  A							:      int 	=       """platform"""

  import jax
  import jax.numpy as jnp

  from transformers import MarianTokenizer
  from transformers.models.marian.modeling_flax_marian import FlaxMarianModel, FlaxMarianMTModel, shift_tokens_right
def 				snake_case_  (   a__		:	Optional[int]    ,a__		:	List[str]    ,a__		:	List[Any]=None    ,a__		:	int=None    ,a__		:	Optional[Any]=None    ,a__		:	Dict=None    ,a__		:	List[str]=None    ,a__		:	str=None    ,):



    """simple docstring"""




    if attention_mask is None:
        __lowercase							=						np.where(input_ids != config.pad_token_id    ,1    ,0			)
    if decoder_attention_mask is None:
        __lowercase							=						np.where(decoder_input_ids != config.pad_token_id    ,1    ,0			)
    if head_mask is None:
        __lowercase							=						np.ones((config.encoder_layers, config.encoder_attention_heads)			)
    if decoder_head_mask is None:
        __lowercase							=						np.ones((config.decoder_layers, config.decoder_attention_heads)			)
    if cross_attn_head_mask is None:
        __lowercase							=						np.ones((config.decoder_layers, config.decoder_attention_heads)			)
    return {
        "input_ids": input_ids,
        "decoder_input_ids": decoder_input_ids,
        "attention_mask": attention_mask,
        "decoder_attention_mask": attention_mask,
    }






class        SCREAMING_SNAKE_CASE:

       def __init__(    self					,		lowerCamelCase__					,		lowerCamelCase__=13					,		lowerCamelCase__=7					,		lowerCamelCase__=True					,		lowerCamelCase__=False					,		lowerCamelCase__=99					,		lowerCamelCase__=16					,		lowerCamelCase__=2					,		lowerCamelCase__=4					,		lowerCamelCase__=4					,		lowerCamelCase__="gelu"					,		lowerCamelCase__=0.1					,		lowerCamelCase__=0.1					,		lowerCamelCase__=32					,		lowerCamelCase__=2					,		lowerCamelCase__=1					,		lowerCamelCase__=0					,		lowerCamelCase__=0.02					,		)    ->					int:

           """simple docstring"""



           __lowercase							=						parent
           __lowercase							=						batch_size
           __lowercase							=						seq_length
           __lowercase							=						is_training
           __lowercase							=						use_labels
           __lowercase							=						vocab_size
           __lowercase							=						hidden_size
           __lowercase							=						num_hidden_layers
           __lowercase							=						num_attention_heads
           __lowercase							=						intermediate_size
           __lowercase							=						hidden_act
           __lowercase							=						hidden_dropout_prob
           __lowercase							=						attention_probs_dropout_prob
           __lowercase							=						max_position_embeddings
           __lowercase							=						eos_token_id
           __lowercase							=						pad_token_id
           __lowercase							=						bos_token_id
           __lowercase							=						initializer_range

       def     snake_case__			(    self     )    ->					Union[str, Any]:

           """simple docstring"""



           __lowercase							=						np.clip(ids_tensor([self.batch_size, self.seq_length - 1]					,		self.vocab_size     )					,		3					,		self.vocab_size     )
           __lowercase							=						np.concatenate((input_ids, 2 * np.ones((self.batch_size, 1)					,		dtype=np.intaa     ))					,		-1     )

           __lowercase							=						shift_tokens_right(lowerCamelCase__					,		1					,		2     )

           __lowercase							=						MarianConfig(
               vocab_size=self.vocab_size					,		d_model=self.hidden_size					,		encoder_layers=self.num_hidden_layers					,		decoder_layers=self.num_hidden_layers					,		encoder_attention_heads=self.num_attention_heads					,		decoder_attention_heads=self.num_attention_heads					,		encoder_ffn_dim=self.intermediate_size					,		decoder_ffn_dim=self.intermediate_size					,		dropout=self.hidden_dropout_prob					,		attention_dropout=self.attention_probs_dropout_prob					,		max_position_embeddings=self.max_position_embeddings					,		eos_token_id=self.eos_token_id					,		bos_token_id=self.bos_token_id					,		pad_token_id=self.pad_token_id					,		initializer_range=self.initializer_range					,		use_cache=lowerCamelCase__					,		)
           __lowercase							=						prepare_marian_inputs_dict(lowerCamelCase__					,		lowerCamelCase__					,		lowerCamelCase__     )
           return config, inputs_dict

       def     snake_case__			(    self     )    ->					Tuple:

           """simple docstring"""



           __lowercase							=						self.prepare_config_and_inputs()
           return config, inputs_dict

       def     snake_case__			(    self					,		lowerCamelCase__					,		lowerCamelCase__					,		lowerCamelCase__     )    ->					Optional[Any]:

           """simple docstring"""



           __lowercase							=						20
           __lowercase							=						model_class_name(lowerCamelCase__     )

           __lowercase							=						model.encode(inputs_dict["""input_ids"""]     )

           __lowercase							=						(
               inputs_dict["""decoder_input_ids"""],
               inputs_dict["""decoder_attention_mask"""],
           )

           __lowercase							=						model.init_cache(decoder_input_ids.shape[0]					,		lowerCamelCase__					,		lowerCamelCase__     )
           __lowercase							=						jnp.ones((decoder_input_ids.shape[0], max_decoder_length)					,		dtype="""i4"""     )

           __lowercase							=						jnp.broadcast_to(
               jnp.arange(decoder_input_ids.shape[-1] - 1     )[None, :]					,		(decoder_input_ids.shape[0], decoder_input_ids.shape[-1] - 1)					,		)
           __lowercase							=						model.decode(
               decoder_input_ids[:, :-1]					,		lowerCamelCase__					,		decoder_attention_mask=lowerCamelCase__					,		past_key_values=lowerCamelCase__					,		decoder_position_ids=lowerCamelCase__					,		)

           __lowercase							=						jnp.array(decoder_input_ids.shape[0] * [[decoder_input_ids.shape[-1] - 1]]					,		dtype="""i4"""     )
           __lowercase							=						model.decode(
               decoder_input_ids[:, -1:]					,		lowerCamelCase__					,		decoder_attention_mask=lowerCamelCase__					,		past_key_values=outputs_cache.past_key_values					,		decoder_position_ids=lowerCamelCase__					,		)

           __lowercase							=						model.decode(lowerCamelCase__					,		lowerCamelCase__     )

           __lowercase							=						np.max(np.abs((outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5])     )     )
           self.parent.assertTrue(diff < 1E-3					,		msg=F'Max diff is {diff}'     )




       def     snake_case__			(    self					,		lowerCamelCase__					,		lowerCamelCase__					,		lowerCamelCase__     )    ->					Any:

           """simple docstring"""



           __lowercase							=						20
           __lowercase							=						model_class_name(lowerCamelCase__     )

           __lowercase							=						model.encode(inputs_dict["""input_ids"""]     )

           __lowercase							=						(
               inputs_dict["""decoder_input_ids"""],
               inputs_dict["""decoder_attention_mask"""],
           )

           __lowercase							=						jnp.concatenate(
               [
                   decoder_attention_mask,
                   jnp.zeros((decoder_attention_mask.shape[0], max_decoder_length - decoder_attention_mask.shape[1])     ),
               ]					,		axis=-1					,		)

           __lowercase							=						model.init_cache(decoder_input_ids.shape[0]					,		lowerCamelCase__					,		lowerCamelCase__     )
           __lowercase							=						jnp.broadcast_to(
               jnp.arange(decoder_input_ids.shape[-1] - 1     )[None, :]					,		(decoder_input_ids.shape[0], decoder_input_ids.shape[-1] - 1)					,		)

           __lowercase							=						model.decode(
               decoder_input_ids[:, :-1]					,		lowerCamelCase__					,		decoder_attention_mask=lowerCamelCase__					,		past_key_values=lowerCamelCase__					,		decoder_position_ids=lowerCamelCase__					,		)
           __lowercase							=						jnp.array(decoder_input_ids.shape[0] * [[decoder_input_ids.shape[-1] - 1]]					,		dtype="""i4"""     )
           __lowercase							=						model.decode(
               decoder_input_ids[:, -1:]					,		lowerCamelCase__					,		past_key_values=outputs_cache.past_key_values					,		decoder_attention_mask=lowerCamelCase__					,		decoder_position_ids=lowerCamelCase__					,		)

           __lowercase							=						model.decode(lowerCamelCase__					,		lowerCamelCase__					,		decoder_attention_mask=lowerCamelCase__     )

           __lowercase							=						np.max(np.abs((outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5])     )     )
           self.parent.assertTrue(diff < 1E-3					,		msg=F'Max diff is {diff}'     )






@require_flax
class        SCREAMING_SNAKE_CASE(				a_   ,      unittest.TestCase   ,      a_     ):
       snake_case_ :     List[Any]    =					True
       snake_case_ :     Any    =					(FlaxMarianModel, FlaxMarianMTModel) if is_flax_available() else ()
       snake_case_ :     List[Any]    =					(FlaxMarianMTModel,) if is_flax_available() else ()

       def     snake_case__			(    self     )    ->					int:

           """simple docstring"""



           __lowercase							=						FlaxMarianModelTester(self     )

       def     snake_case__			(    self     )    ->					Union[str, Any]:

           """simple docstring"""



           __lowercase							=						self.model_tester.prepare_config_and_inputs()
           for model_class in self.all_model_classes:
               self.model_tester.check_use_cache_forward(lowerCamelCase__					,		lowerCamelCase__					,		lowerCamelCase__     )

       def     snake_case__			(    self     )    ->					Dict:

           """simple docstring"""



           __lowercase							=						self.model_tester.prepare_config_and_inputs()
           for model_class in self.all_model_classes:
               self.model_tester.check_use_cache_forward_with_attn_mask(lowerCamelCase__					,		lowerCamelCase__					,		lowerCamelCase__     )

       def     snake_case__			(    self     )    ->					Tuple:

           """simple docstring"""



           __lowercase							=						self.model_tester.prepare_config_and_inputs_for_common()

           for model_class in self.all_model_classes:
               with self.subTest(model_class.__name__     ):
                   __lowercase							=						self._prepare_for_class(lowerCamelCase__					,		lowerCamelCase__     )
                   __lowercase							=						model_class(lowerCamelCase__     )

                   @jax.jit
                   def encode_jitted(lowerCamelCase__					,		lowerCamelCase__=None					,		**lowerCamelCase__     ):
                       return model.encode(input_ids=lowerCamelCase__					,		attention_mask=lowerCamelCase__     )

                   with self.subTest("""JIT Enabled"""     ):
                       __lowercase							=						encode_jitted(**lowerCamelCase__     ).to_tuple()

                   with self.subTest("""JIT Disabled"""     ):
                       with jax.disable_jit():
                           __lowercase							=						encode_jitted(**lowerCamelCase__     ).to_tuple()

                   self.assertEqual(len(lowerCamelCase__     )					,		len(lowerCamelCase__     )     )
                   for jitted_output, output in zip(lowerCamelCase__					,		lowerCamelCase__     ):
                       self.assertEqual(jitted_output.shape					,		output.shape     )

       def     snake_case__			(    self     )    ->					Dict:

           """simple docstring"""



           __lowercase							=						self.model_tester.prepare_config_and_inputs_for_common()

           for model_class in self.all_model_classes:
               with self.subTest(model_class.__name__     ):
                   __lowercase							=						model_class(lowerCamelCase__     )
                   __lowercase							=						model.encode(inputs_dict["""input_ids"""]					,		inputs_dict["""attention_mask"""]     )

                   __lowercase							=						{
                       """decoder_input_ids""": inputs_dict["""decoder_input_ids"""],
                       """decoder_attention_mask""": inputs_dict["""decoder_attention_mask"""],
                       """encoder_outputs""": encoder_outputs,
                   }

                   @jax.jit
                   def decode_jitted(lowerCamelCase__					,		lowerCamelCase__					,		lowerCamelCase__     ):
                       return model.decode(
                           decoder_input_ids=lowerCamelCase__					,		decoder_attention_mask=lowerCamelCase__					,		encoder_outputs=lowerCamelCase__					,		)

                   with self.subTest("""JIT Enabled"""     ):
                       __lowercase							=						decode_jitted(**lowerCamelCase__     ).to_tuple()

                   with self.subTest("""JIT Disabled"""     ):
                       with jax.disable_jit():
                           __lowercase							=						decode_jitted(**lowerCamelCase__     ).to_tuple()

                   self.assertEqual(len(lowerCamelCase__     )					,		len(lowerCamelCase__     )     )
                   for jitted_output, output in zip(lowerCamelCase__					,		lowerCamelCase__     ):
                       self.assertEqual(jitted_output.shape					,		output.shape     )




       @slow
       def     snake_case__			(    self     )    ->					Any:

           """simple docstring"""



           for model_class_name in self.all_model_classes:
               __lowercase							=						model_class_name.from_pretrained("""Helsinki-NLP/opus-mt-en-de"""     )
               # FlaxMarianForSequenceClassification expects eos token in input_ids
               __lowercase							=						np.ones((1, 1)     ) * model.config.eos_token_id
               __lowercase							=						model(lowerCamelCase__     )
               self.assertIsNotNone(lowerCamelCase__     )






@require_flax
@require_sentencepiece
@require_tokenizers
class        SCREAMING_SNAKE_CASE(				unittest.TestCase     ):
       snake_case_ :     List[str]    =					None
       snake_case_ :     str    =					None

       @classmethod
       def     snake_case__			(    cls     )    ->					None:

           """simple docstring"""



           __lowercase							=						F'Helsinki-NLP/opus-mt-{cls.src}-{cls.tgt}'
           return cls

       @cached_property
       def     snake_case__			(    self     )    ->					Any:

           """simple docstring"""



           return MarianTokenizer.from_pretrained(self.model_name     )

       @property
       def     snake_case__			(    self     )    ->					int:

           """simple docstring"""



           return self.tokenizer.eos_token_id

       @cached_property
       def     snake_case__			(    self     )    ->					Union[str, Any]:

           """simple docstring"""



           __lowercase							=						FlaxMarianMTModel.from_pretrained(self.model_name     )
           self.assertEqual(model.config.decoder_start_token_id					,		model.config.pad_token_id     )
           return model

       def     snake_case__			(    self					,		**lowerCamelCase__     )    ->					Tuple:

           """simple docstring"""



           __lowercase							=						self.translate_src_text(**lowerCamelCase__     )
           self.assertListEqual(self.expected_text					,		lowerCamelCase__     )




       def     snake_case__			(    self					,		**lowerCamelCase__     )    ->					int:

           """simple docstring"""



           __lowercase							=						self.tokenizer(self.src_text					,		padding=lowerCamelCase__					,		return_tensors="""np"""					,		**lowerCamelCase__     )
           __lowercase							=						self.model.generate(
               model_inputs.input_ids					,		attention_mask=model_inputs.attention_mask					,		num_beams=2					,		max_length=128					,		).sequences
           __lowercase							=						self.tokenizer.batch_decode(lowerCamelCase__					,		skip_special_tokens=lowerCamelCase__     )
           return generated_words






@require_flax
@require_sentencepiece
@require_tokenizers
class        SCREAMING_SNAKE_CASE(				a_     ):
       snake_case_ :     int    =					"en"
       snake_case_ :     Optional[Any]    =					"fr"
       snake_case_ :     List[str]    =					[
           "I am a small frog.",
           "Now I can forget the 100 words of german that I know.",
       ]
       snake_case_ :     int    =					[
           "Je suis une petite grenouille.",
           "Maintenant, je peux oublier les 100 mots d'allemand que je connais.",
       ]

       @slow
       def     snake_case__			(    self     )    ->					Dict:

           """simple docstring"""



           self._assert_generated_batch_equal_expected()






@require_flax
@require_sentencepiece
@require_tokenizers
class        SCREAMING_SNAKE_CASE(				a_     ):
       snake_case_ :     Tuple    =					"fr"
       snake_case_ :     Union[str, Any]    =					"en"
       snake_case_ :     Union[str, Any]    =					[
           "Donnez moi le micro.",
           "Tom et Mary étaient assis à une table.",  # Accents
       ]
       snake_case_ :     Union[str, Any]    =					[
           "Give me the microphone.",
           "Tom and Mary were sitting at a table.",
       ]

       @slow
       def     snake_case__			(    self     )    ->					Optional[Any]:

           """simple docstring"""



           self._assert_generated_batch_equal_expected()






@require_flax
@require_sentencepiece
@require_tokenizers
class        SCREAMING_SNAKE_CASE(				a_     ):
       snake_case_ :     Any    =					"mt"
       snake_case_ :     int    =					"en"
       snake_case_ :     Union[str, Any]    =					["Billi messu b'mod ġentili, Ġesù fejjaq raġel li kien milqut bil - marda kerha tal - ġdiem."]
       snake_case_ :     Tuple    =					["Touching gently, Jesus healed a man who was affected by the sad disease of leprosy."]

       @slow
       def     snake_case__			(    self     )    ->					Any:

           """simple docstring"""



           self._assert_generated_batch_equal_expected()






@require_flax
@require_sentencepiece
@require_tokenizers
class        SCREAMING_SNAKE_CASE(				a_     ):
       snake_case_ :     Union[str, Any]    =					"en"
       snake_case_ :     Tuple    =					"de"
       snake_case_ :     Optional[int]    =					[
           "I am a small frog.",
           "Now I can forget the 100 words of german that I know.",
           "Tom asked his teacher for advice.",
           "That's how I would do it.",
           "Tom really admired Mary's courage.",
           "Turn around and close your eyes.",
       ]
       snake_case_ :     Optional[int]    =					[
           "Ich bin ein kleiner Frosch.",
           "Jetzt kann ich die 100 Wörter des Deutschen vergessen, die ich kenne.",
           "Tom bat seinen Lehrer um Rat.",
           "So würde ich das machen.",
           "Tom bewunderte Marias Mut wirklich.",
           "Drehen Sie sich um und schließen Sie die Augen.",
       ]

       @slow
       def     snake_case__			(    self     )    ->					Optional[int]:

           """simple docstring"""



           self._assert_generated_batch_equal_expected()






@require_flax
@require_sentencepiece
@require_tokenizers
class        SCREAMING_SNAKE_CASE(				a_     ):
       snake_case_ :     int    =					"en"
       snake_case_ :     str    =					"zh"
       snake_case_ :     Tuple    =					["My name is Wolfgang and I live in Berlin"]
       snake_case_ :     str    =					["我叫沃尔夫冈 我住在柏林"]

       @slow
       def     snake_case__			(    self     )    ->					Any:

           """simple docstring"""



           self._assert_generated_batch_equal_expected()






@require_flax
@require_sentencepiece
@require_tokenizers
class        SCREAMING_SNAKE_CASE(				a_     ):
       snake_case_ :     str    =					"ru"
       snake_case_ :     Optional[int]    =					"fr"
       snake_case_ :     Dict    =					["Он показал мне рукопись своей новой пьесы."]
       snake_case_ :     int    =					["Il m'a montré le manuscrit de sa nouvelle pièce."]

       @slow
       def     snake_case__			(    self     )    ->					Union[str, Any]:

           """simple docstring"""



           self._assert_generated_batch_equal_expected()






@require_flax
@require_sentencepiece
@require_tokenizers
class        SCREAMING_SNAKE_CASE(				a_     ):
       snake_case_ :     Tuple    =					"en"
       snake_case_ :     Union[str, Any]    =					"ROMANCE"
       snake_case_ :     Tuple    =					[
           ">>fr<< Don't spend so much time watching TV.",
           ">>pt<< Your message has been sent.",
           ">>es<< He's two years older than me.",
       ]
       snake_case_ :     Optional[Any]    =					[
           "Ne passez pas autant de temps à regarder la télé.",
           "A sua mensagem foi enviada.",
           "Es dos años más viejo que yo.",
       ]

       @slow
       def     snake_case__			(    self     )    ->					Any:

           """simple docstring"""



           self._assert_generated_batch_equal_expected()







from __future__ import annotations

import os



class SCREAMING_SNAKE_CASE	:
  """simple docstring"""






  lowerCamelCase    :			Union[str, Any]						      =(
      "High card",
      "One pair",
      "Two pairs",
      "Three of a kind",
      "Straight",
      "Flush",
      "Full house",
      "Four of a kind",
      "Straight flush",
      "Royal flush",
  )

  lowerCamelCase    :			Dict						      =(
      "",  # placeholder as tuples are zero-indexed
      "One",
      "Two",
      "Three",
      "Four",
      "Five",
      "Six",
      "Seven",
      "Eight",
      "Nine",
      "Ten",
      "Jack",
      "Queen",
      "King",
      "Ace",
  )







  def __init__(			self :    Tuple       ,							lowerCAmelCase :    str    )							->	None:






     """simple docstring"""







     if not isinstance(lowerCAmelCase       ,							lowerCAmelCase    ):
        __lowerCAmelCase  :			Tuple					    =						f'''Hand should be of type \'str\': {hand!r}'''
        raise TypeError(lowerCAmelCase    )
     # split removes duplicate whitespaces so no need of strip
     if len(hand.split(""" """    )    ) != 5:
        __lowerCAmelCase  :			Any					    =						f'''Hand should contain only 5 cards: {hand!r}'''
        raise ValueError(lowerCAmelCase    )
     __lowerCAmelCase  :			int					    =						hand
     __lowerCAmelCase  :			Any					    =						0
     __lowerCAmelCase  :			str					    =						0
     __lowerCAmelCase    ,__lowerCAmelCase  :			List[str]					    =						self._internal_state()
     __lowerCAmelCase  :			int					    =						self._get_hand_type()
     __lowerCAmelCase  :			Any					    =						self._card_values[0]







  @property
  def        SCREAMING_SNAKE_CASE    (			self :    Union[str, Any]    )							->	Optional[int]:






     """simple docstring"""







     return self._hand







  def        SCREAMING_SNAKE_CASE    (			self :    Dict       ,							lowerCAmelCase :    PokerHand    )							->	str:






     """simple docstring"""







     if self._hand_type > other._hand_type:
        return "Win"
     elif self._hand_type < other._hand_type:
        return "Loss"
     elif self._first_pair == other._first_pair:
        if self._second_pair == other._second_pair:
           return self._compare_cards(lowerCAmelCase    )
        else:
           return "Win" if self._second_pair > other._second_pair else "Loss"
     return "Win" if self._first_pair > other._first_pair else "Loss"







  def        SCREAMING_SNAKE_CASE    (			self :    int    )							->	str:






     """simple docstring"""







     __lowerCAmelCase  :			Optional[int]					    =						PokerHand._HAND_NAME[self._hand_type - 14]
     __lowerCAmelCase  :			str					    =						PokerHand._CARD_NAME[self._high_card]
     __lowerCAmelCase  :			Optional[Any]					    =						PokerHand._CARD_NAME[self._first_pair]
     __lowerCAmelCase  :			Any					    =						PokerHand._CARD_NAME[self._second_pair]
     if self._hand_type in [22, 19, 18]:
        return name + f''', {high}-high'''
     elif self._hand_type in [21, 17, 15]:
        return name + f''', {paira}s'''
     elif self._hand_type in [20, 16]:
        __lowerCAmelCase  :			List[str]					    =						"""over""" if self._hand_type == 20 else """and"""
        return name + f''', {paira}s {join} {paira}s'''
     elif self._hand_type == 23:
        return name
     else:
        return name + f''', {high}'''







  def        SCREAMING_SNAKE_CASE    (			self :    Dict       ,							lowerCAmelCase :    PokerHand    )							->	str:






     """simple docstring"""







     for index, card_value in enumerate(self._card_values    ):
        if card_value != other._card_values[index]:
           return "Win" if card_value > other._card_values[index] else "Loss"
     return "Tie"







  def        SCREAMING_SNAKE_CASE    (			self :    Optional[int]    )							->	int:






     """simple docstring"""







     if self._is_flush():
        if self._is_five_high_straight() or self._is_straight():
           return 23 if sum(self._card_values    ) == 60 else 22
        return 19
     elif self._is_five_high_straight() or self._is_straight():
        return 18
     return 14 + self._is_same_kind()







  def        SCREAMING_SNAKE_CASE    (			self :    List[Any]    )							->	bool:






     """simple docstring"""







     return len(self._card_suit    ) == 1







  def        SCREAMING_SNAKE_CASE    (			self :    List[str]    )							->	bool:






     """simple docstring"""







     if sorted(self._card_values    ) == [2, 3, 4, 5, 14]:
        if self._card_values[0] == 14:
           # Remember, our list is sorted in reverse order
           __lowerCAmelCase  :			Optional[Any]					    =						self._card_values.pop(0    )
           self._card_values.append(lowerCAmelCase    )
        return True
     return False







  def        SCREAMING_SNAKE_CASE    (			self :    List[str]    )							->	bool:






     """simple docstring"""







     for i in range(4    ):
        if self._card_values[i] - self._card_values[i + 1] != 1:
           return False
     return True







  def        SCREAMING_SNAKE_CASE    (			self :    Optional[int]    )							->	int:






     """simple docstring"""







     __lowerCAmelCase  :			str					    =						0
     for i in range(4    ):
        # Compare two cards at a time, if they are same increase 'kind',
        # add the value of the card to val1, if it is repeating again we
        # will add 2 to 'kind' as there are now 3 cards with same value.
        # If we get card of different value than val1, we will do the same
        # thing with val2
        if self._card_values[i] == self._card_values[i + 1]:
           if not vala:
              __lowerCAmelCase  :			List[str]					    =						self._card_values[i]
              kind += 1
           elif vala == self._card_values[i]:
              kind += 2
           elif not vala:
              __lowerCAmelCase  :			Optional[Any]					    =						self._card_values[i]
              kind += 1
           elif vala == self._card_values[i]:
              kind += 2
        # For consistency in hand type (look at note in _get_hand_type function)
     __lowerCAmelCase  :			List[Any]					    =						kind + 2 if kind in [4, 5] else kind
     # first meaning first pair to compare in 'compare_with'
     __lowerCAmelCase  :			Optional[int]					    =						max(lowerCAmelCase       ,							lowerCAmelCase    )
     __lowerCAmelCase  :			Optional[Any]					    =						min(lowerCAmelCase       ,							lowerCAmelCase    )
     # If it's full house (three count pair + two count pair), make sure
     # first pair is three count and if not then switch them both.
     if kind == 6 and self._card_values.count(lowerCAmelCase    ) != 3:
        __lowerCAmelCase    ,__lowerCAmelCase  :			Tuple					    =						second, first
     __lowerCAmelCase  :			Optional[Any]					    =						first
     __lowerCAmelCase  :			Union[str, Any]					    =						second
     return kind







  def        SCREAMING_SNAKE_CASE    (			self :    List[Any]    )							->	tuple[list[int], set[str]]:






     """simple docstring"""







     __lowerCAmelCase  :			dict					    =						{"T": "10", "J": "11", "Q": "12", "K": "13", "A": "14"}
     __lowerCAmelCase  :			Optional[Any]					    =						self._hand.translate(str.maketrans(lowerCAmelCase    )    ).split()
     __lowerCAmelCase  :			List[str]					    =						[int(card[:-1]    ) for card in new_hand]
     __lowerCAmelCase  :			str					    =						{card[-1] for card in new_hand}
     return sorted(lowerCAmelCase       ,							reverse=lowerCAmelCase    ), card_suit







  def __repr__(			self :    List[str]    )							->	Any:






     """simple docstring"""







     return f'''{self.__class__}("{self._hand}")'''







  def __str__(			self :    Any    )							->	Any:






     """simple docstring"""







     return self._hand







  def __eq__(			self :    Union[str, Any]       ,							lowerCAmelCase :    List[Any]    )							->	Union[str, Any]:






     """simple docstring"""







     if isinstance(lowerCAmelCase       ,							lowerCAmelCase    ):
        return self.compare_with(lowerCAmelCase    ) == "Tie"
     return NotImplemented







  def __lt__(			self :    Dict       ,							lowerCAmelCase :    str    )							->	List[str]:






     """simple docstring"""







     if isinstance(lowerCAmelCase       ,							lowerCAmelCase    ):
        return self.compare_with(lowerCAmelCase    ) == "Loss"
     return NotImplemented







  def __le__(			self :    str       ,							lowerCAmelCase :    int    )							->	Union[str, Any]:






     """simple docstring"""







     if isinstance(lowerCAmelCase       ,							lowerCAmelCase    ):
        return self < other or self == other
     return NotImplemented







  def __gt__(			self :    Dict       ,							lowerCAmelCase :    str    )							->	Optional[Any]:






     """simple docstring"""







     if isinstance(lowerCAmelCase       ,							lowerCAmelCase    ):
        return not self < other and self != other
     return NotImplemented







  def __ge__(			self :    Tuple       ,							lowerCAmelCase :    Tuple    )							->	Dict:






     """simple docstring"""







     if isinstance(lowerCAmelCase       ,							lowerCAmelCase    ):
        return not self < other
     return NotImplemented







  def __hash__(			self :    List[str]    )							->	str:






     """simple docstring"""







     return object.__hash__(self    )






def 	snake_case_      ()			->	int:
   # Solution for problem number 54 from Project Euler
   # Input from poker_hands.txt file
   __lowerCAmelCase  :			str					    =						0
   __lowerCAmelCase  :			List[str]					    =						os.path.abspath(os.path.dirname(__A     )     )
   __lowerCAmelCase  :			Optional[Any]					    =						os.path.join(__A					,   """poker_hands.txt"""     )
   with open(__A     ) as file_hand:
      for line in file_hand:
         __lowerCAmelCase  :			Union[str, Any]					    =						line[:1_4].strip()
         __lowerCAmelCase  :			Optional[int]					    =						line[1_5:].strip()
         __lowerCAmelCase    ,__lowerCAmelCase  :			List[str]					    =						PokerHand(__A     ), PokerHand(__A     )
         __lowerCAmelCase  :			List[str]					    =						player.compare_with(__A     )
         if output == "Win":
            answer += 1
   return answer


if __name__ == "__main__":
   solution()


