






'''simple docstring'''

import os
import sys
from contextlib import contextmanager


# Windows only
if os.name == "nt":
   import ctypes
   import msvcrt  # noqa







   class 	SCREAMING_SNAKE_CASE	(      ctypes.Structure  ):
          # _fields is a specific attr expected by ctypes
          snake_case__    :     Any   		=			[('size', ctypes.c_int), ('visible', ctypes.c_byte)]
def     __lowercase  ()   ->     str:


     """simple docstring"""
     if os.name == "nt":
          __lowerCamelCase						:       Tuple				   =				CursorInfo()
          __lowerCamelCase						:       Dict				   =				ctypes.windll.kernelaa.GetStdHandle(-11     )
          ctypes.windll.kernelaa.GetConsoleCursorInfo(_lowercase,						ctypes.byref(_lowercase     )     )
          __lowerCamelCase						:       Any				   =				False
          ctypes.windll.kernelaa.SetConsoleCursorInfo(_lowercase,						ctypes.byref(_lowercase     )     )
     elif os.name == "posix":
          sys.stdout.write("""\033[?25l"""     )
          sys.stdout.flush()
def     __lowercase  ()   ->     int:


     """simple docstring"""
     if os.name == "nt":
          __lowerCamelCase						:       int				   =				CursorInfo()
          __lowerCamelCase						:       Tuple				   =				ctypes.windll.kernelaa.GetStdHandle(-11     )
          ctypes.windll.kernelaa.GetConsoleCursorInfo(_lowercase,						ctypes.byref(_lowercase     )     )
          __lowerCamelCase						:       str				   =				True
          ctypes.windll.kernelaa.SetConsoleCursorInfo(_lowercase,						ctypes.byref(_lowercase     )     )
     elif os.name == "posix":
          sys.stdout.write("""\033[?25h"""     )
          sys.stdout.flush()
@contextmanager
def     __lowercase  ()   ->     List[Any]:


     """simple docstring"""
     try:
          hide_cursor()
          yield
     finally:
          show_cursor()











'''simple docstring'''

UpperCAmelCase__						:List[Any]          =			256
# Modulus to hash a string
UpperCAmelCase__						:str          =			1_000_003
def     __lowercase  (_lowercase,						_lowercase     )   ->     bool:


     """simple docstring"""
     __lowerCamelCase						:       str				   =				len(_lowercase     )
     __lowerCamelCase						:       List[str]				   =				len(_lowercase     )
     if p_len > t_len:
          return False

     __lowerCamelCase						:       Optional[Any]				   =				0
     __lowerCamelCase						:       Tuple				   =				0
     __lowerCamelCase						:       Dict				   =				1

     # Calculating the hash of pattern and substring of text
     for i in range(_lowercase     ):
          __lowerCamelCase						:       Optional[int]				   =				(ord(pattern[i]     ) + p_hash * alphabet_size) % modulus
          __lowerCamelCase						:       Dict				   =				(ord(text[i]     ) + text_hash * alphabet_size) % modulus
          if i == p_len - 1:
               continue
          __lowerCamelCase						:       Dict				   =				(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
          __lowerCamelCase						:       Dict				   =				(
              (text_hash - ord(text[i]     ) * modulus_power) * alphabet_size
              + ord(text[i + p_len]     )
          ) % modulus
     return False
def     __lowercase  ()   ->     None:


     """simple docstring"""
     __lowerCamelCase						:       List[Any]				   =				"""abc1abc12"""
     __lowerCamelCase						:       Optional[Any]				   =				"""alskfjaldsabc1abc1abc12k23adsfabcabc"""
     __lowerCamelCase						:       List[Any]				   =				"""alskfjaldsk23adsfabcabc"""
     assert rabin_karp(_lowercase,						_lowercase     ) and not rabin_karp(_lowercase,						_lowercase     )

     # Test 2)
     __lowerCamelCase						:       Optional[int]				   =				"""ABABX"""
     __lowerCamelCase						:       Dict				   =				"""ABABZABABYABABX"""
     assert rabin_karp(_lowercase,						_lowercase     )

     # Test 3)
     __lowerCamelCase						:       Any				   =				"""AAAB"""
     __lowerCamelCase						:       int				   =				"""ABAAAAAB"""
     assert rabin_karp(_lowercase,						_lowercase     )

     # Test 4)
     __lowerCamelCase						:       Any				   =				"""abcdabcy"""
     __lowerCamelCase						:       Dict				   =				"""abcxabcdabxabcdabcdabcy"""
     assert rabin_karp(_lowercase,						_lowercase     )

     # Test 5)
     __lowerCamelCase						:       str				   =				"""Lü"""
     __lowerCamelCase						:       str				   =				"""Lüsai"""
     assert rabin_karp(_lowercase,						_lowercase     )
     __lowerCamelCase						:       Tuple				   =				"""Lue"""
     assert not rabin_karp(_lowercase,						_lowercase     )
     print("""Success."""     )


if __name__ == "__main__":
   test_rabin_karp()



