

__lowercase				      =						256
# Modulus to hash a string
__lowercase				      =						1000003







def 							_lowerCamelCase   (			SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE   ):
      '''simple docstring'''







      A_							       =		len(SCREAMING_SNAKE_CASE   )
      A_							       =		len(SCREAMING_SNAKE_CASE   )
      if p_len > t_len:
            return False

      A_							       =		0
      A_							       =		0
      A_							       =		1

      # Calculating the hash of pattern and substring of text
      for i in range(SCREAMING_SNAKE_CASE   ):
            A_							       =		(ord(pattern[i]   ) + p_hash * alphabet_size) % modulus
            A_							       =		(ord(text[i]   ) + text_hash * alphabet_size) % modulus
            if i == p_len - 1:
                  continue
            A_							       =		(modulus_power * alphabet_size) % modulus

      for i in range(0		,				t_len - p_len + 1   ):
            if text_hash == p_hash and text[i : i + p_len] == pattern:
                  return True
            if i == t_len - p_len:
                  continue
            # Calculate the https://en.wikipedia.org/wiki/Rolling_hash
            A_							       =		(
                (text_hash - ord(text[i]   ) * modulus_power) * alphabet_size
                + ord(text[i + p_len]   )
            ) % modulus
      return False







def 							_lowerCamelCase   (			):
      '''simple docstring'''







      A_							       =		'''abc1abc12'''
      A_							       =		'''alskfjaldsabc1abc1abc12k23adsfabcabc'''
      A_							       =		'''alskfjaldsk23adsfabcabc'''
      assert rabin_karp(SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE   ) and not rabin_karp(SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE   )

      # Test 2)
      A_							       =		'''ABABX'''
      A_							       =		'''ABABZABABYABABX'''
      assert rabin_karp(SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE   )

      # Test 3)
      A_							       =		'''AAAB'''
      A_							       =		'''ABAAAAAB'''
      assert rabin_karp(SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE   )

      # Test 4)
      A_							       =		'''abcdabcy'''
      A_							       =		'''abcxabcdabxabcdabcdabcy'''
      assert rabin_karp(SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE   )

      # Test 5)
      A_							       =		'''Lü'''
      A_							       =		'''Lüsai'''
      assert rabin_karp(SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE   )
      A_							       =		'''Lue'''
      assert not rabin_karp(SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE   )
      print('''Success.'''   )


if __name__ == "__main__":
      test_rabin_karp()








import logging
import os
from logging import (
    CRITICAL,  # NOQA
    DEBUG,  # NOQA
    ERROR,  # NOQA
    FATAL,  # NOQA
    INFO,  # NOQA
    NOTSET,  # NOQA
    WARN,  # NOQA
    WARNING,  # NOQA
)
from typing import Optional

from tqdm import auto as tqdm_lib


__lowercase				      =						{
    """debug""": logging.DEBUG,
    """info""": logging.INFO,
    """warning""": logging.WARNING,
    """error""": logging.ERROR,
    """critical""": logging.CRITICAL,
}

__lowercase				      =						logging.WARNING







def 							_lowerCamelCase   (			):
      '''simple docstring'''







      A_							       =		os.getenv('''DATASETS_VERBOSITY'''		,				SCREAMING_SNAKE_CASE   )
      if env_level_str:
            if env_level_str in log_levels:
                  return log_levels[env_level_str]
            else:
                  logging.getLogger().warning(
                      f"Unknown option DATASETS_VERBOSITY={env_level_str}, "
                      f"has to be one of: { ', '.join(log_levels.keys()   ) }"   )
      return _default_log_level







def 							_lowerCamelCase   (			):
      '''simple docstring'''







      return __name__.split('''.'''   )[0]







def 							_lowerCamelCase   (			):
      '''simple docstring'''







      return logging.getLogger(_get_library_name()   )







def 							_lowerCamelCase   (			):
      '''simple docstring'''







      A_							       =		_get_library_root_logger()
      library_root_logger.setLevel(_get_default_logging_level()   )







def 							_lowerCamelCase   (			):
      '''simple docstring'''







      A_							       =		_get_library_root_logger()
      library_root_logger.setLevel(logging.NOTSET   )







def 							_lowerCamelCase   (			SCREAMING_SNAKE_CASE = None   ):
      '''simple docstring'''







      if name is None:
            A_							       =		_get_library_name()
      return logging.getLogger(SCREAMING_SNAKE_CASE   )







def 							_lowerCamelCase   (			):
      '''simple docstring'''







      return _get_library_root_logger().getEffectiveLevel()







def 							_lowerCamelCase   (			SCREAMING_SNAKE_CASE   ):
      '''simple docstring'''







      _get_library_root_logger().setLevel(SCREAMING_SNAKE_CASE   )







def 							_lowerCamelCase   (			):
      '''simple docstring'''







      return set_verbosity(SCREAMING_SNAKE_CASE   )







def 							_lowerCamelCase   (			):
      '''simple docstring'''







      return set_verbosity(SCREAMING_SNAKE_CASE   )







def 							_lowerCamelCase   (			):
      '''simple docstring'''







      return set_verbosity(SCREAMING_SNAKE_CASE   )







def 							_lowerCamelCase   (			):
      '''simple docstring'''







      return set_verbosity(SCREAMING_SNAKE_CASE   )







def 							_lowerCamelCase   (			):
      '''simple docstring'''







      A_							       =		False







def 							_lowerCamelCase   (			):
      '''simple docstring'''







      A_							       =		True


# Configure the library root logger at the module level (singleton-like)
_configure_library_root_logger()

class    _lowercase				:

   def __init__(				self	:    Optional[int]			,						*lowerCamelCase__	:    int			,						**lowerCamelCase__	:    Tuple       ) ->			Dict:  # pylint: disable=unused-argument
         """simple docstring"""





         A_							       =		args[0] if args else None

   def __iter__(				self	:    Optional[int]       ) ->			List[str]:
         """simple docstring"""





         return iter(self._iterator       )

   def __getattr__(				self	:    int			,						lowerCamelCase__	:    List[str]       ) ->			List[str]:
         """simple docstring"""





         def empty_fn(*lowerCamelCase__	:    Optional[Any]			,						**lowerCamelCase__	:    str       ):  # pylint: disable=unused-argument
               return

         return empty_fn

   def __enter__(				self	:    Tuple       ) ->			Tuple:
         """simple docstring"""





         return self





   def __exit__(				self	:    Tuple			,						lowerCamelCase__	:    List[Any]			,						lowerCamelCase__	:    List[str]			,						lowerCamelCase__	:    Optional[Any]       ) ->			Optional[int]:
         """simple docstring"""





         return



__lowercase				      =						True

class    _lowercase				:

   def __call__(				self	:    Optional[int]			,						*lowerCamelCase__	:    Optional[int]			,						lowerCamelCase__	:    List[str]=False			,						**lowerCamelCase__	:    Optional[Any]       ) ->			Optional[Any]:
         """simple docstring"""





         if _tqdm_active and not disable:
               return tqdm_lib.tqdm(*lowerCamelCase__			,						**lowerCamelCase__       )
         else:
               return EmptyTqdm(*lowerCamelCase__			,						**lowerCamelCase__       )

   def     UpperCamelCase					(				self	:    Optional[Any]			,						*lowerCamelCase__	:    Any			,						**lowerCamelCase__	:    int       ) ->			str:
         """simple docstring"""





         A_							       =		None
         if _tqdm_active:
               return tqdm_lib.tqdm.set_lock(*lowerCamelCase__			,						**lowerCamelCase__       )





   def     UpperCamelCase					(				self	:    Optional[Any]       ) ->			int:
         """simple docstring"""





         if _tqdm_active:
               return tqdm_lib.tqdm.get_lock()



__lowercase				      =						_tqdm_cls()







def 							_lowerCamelCase   (			):
      '''simple docstring'''







      global _tqdm_active
      return bool(_tqdm_active   )







def 							_lowerCamelCase   (			):
      '''simple docstring'''







      global _tqdm_active
      A_							       =		True







def 							_lowerCamelCase   (			):
      '''simple docstring'''







      global _tqdm_active
      A_							       =		False





