



'''simple docstring'''





lowercase_	 =						256
# Modulus to hash a string
lowercase_	 =						1_000_003




def lowerCAmelCase						(__A						,			__A):



     """simple docstring"""



     _a											=						len(__A)
     _a											=						len(__A)
     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(__A):
          _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(__A						,			__A) and not rabin_karp(__A						,			__A)

     # Test 2)
     _a											=						'''ABABX'''
     _a											=						'''ABABZABABYABABX'''
     assert rabin_karp(__A						,			__A)

     # Test 3)
     _a											=						'''AAAB'''
     _a											=						'''ABAAAAAB'''
     assert rabin_karp(__A						,			__A)

     # Test 4)
     _a											=						'''abcdabcy'''
     _a											=						'''abcxabcdabxabcdabcdabcy'''
     assert rabin_karp(__A						,			__A)

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


if __name__ == "__main__":
  test_rabin_karp()








'''simple docstring'''





import PIL.Image
import PIL.ImageOps
from packaging import version
from PIL import Image


if version.parse(version.parse(PIL.__version__).base_version) >= version.parse("9.1.0"):
  lowercase_	 =						{
      "linear": PIL.Image.Resampling.BILINEAR,
      "bilinear": PIL.Image.Resampling.BILINEAR,
      "bicubic": PIL.Image.Resampling.BICUBIC,
      "lanczos": PIL.Image.Resampling.LANCZOS,
      "nearest": PIL.Image.Resampling.NEAREST,
  }
else:
  lowercase_	 =						{
      "linear": PIL.Image.LINEAR,
      "bilinear": PIL.Image.BILINEAR,
      "bicubic": PIL.Image.BICUBIC,
      "lanczos": PIL.Image.LANCZOS,
      "nearest": PIL.Image.NEAREST,
  }




def lowerCAmelCase						(__A):



     """simple docstring"""



     _a											=						(images / 2 + 0.5).clamp(0						,			1)
     _a											=						images.cpu().permute(0						,			2						,			3						,			1).float().numpy()
     _a											=						numpy_to_pil(__A)
     return images




def lowerCAmelCase						(__A):



     """simple docstring"""



     if images.ndim == 3:
          _a											=						images[None, ...]
     _a											=						(images * 255).round().astype('''uint8''')
     if images.shape[-1] == 1:
          # special case for grayscale (single channel) images
          _a											=						[Image.fromarray(image.squeeze()						,			mode='''L''') for image in images]
     else:
          _a											=						[Image.fromarray(__A) for image in images]

     return pil_images



