





"""simple docstring"""






import itertools
import string
from collections.abc import Generator, Iterable

def      __A   (      a_    :Iterable[str] ,							a_    :int)		->		Generator[tuple[str, ...], None, None]:
				__a			:    List[str]      							=	iter(a_)
				while True:
								__a			:    List[Any]      							=	tuple(itertools.islice(a_ ,							a_))
								if not chunk:
												return
								yield chunk

def      __A   (      a_    :str)		->		str:
				__a			:    int      							=	''''''.join([c.upper() for c in dirty if c in string.ascii_letters])
				__a			:    Tuple      							=	''''''

				if len(a_) < 2:
								return dirty

				for i in range(len(a_) - 1):
								clean += dirty[i]

								if dirty[i] == dirty[i + 1]:
												clean += "X"

				clean += dirty[-1]

				if len(a_) & 1:
								clean += "X"

				return clean

def      __A   (      a_    :str)		->		list[str]:
				# I and J are used interchangeably to allow
				# us to use a 5x5 table (25 letters)
				__a			:    Optional[Any]      							=	'''ABCDEFGHIKLMNOPQRSTUVWXYZ'''
				# we're using a list instead of a '2d' array because it makes the math
				# for setting up the table and doing the actual encoding/decoding simpler
				__a			:    Tuple      							=	[]

				# copy key chars into the table if they are in `alphabet` ignoring duplicates
				for char in key.upper():
								if char not in table and char in alphabet:
												table.append(a_)

    # fill the rest of the table in with the remaining alphabet chars
				for char in alphabet:
								if char not in table:
												table.append(a_)

				return table

def      __A   (      a_    :str ,							a_    :str)		->		str:
				__a			:    Optional[Any]      							=	generate_table(a_)
				__a			:    Optional[int]      							=	prepare_input(a_)
				__a			:    List[str]      							=	''''''

				# https://en.wikipedia.org/wiki/Playfair_cipher#Description
				for chara, chara in chunker(a_ ,							2):
								__a							,    __a			:    Optional[Any]      							=	divmod(table.index(a_) ,							5)
								__a							,    __a			:    Tuple      							=	divmod(table.index(a_) ,							5)

								if rowa == rowa:
												ciphertext += table[rowa * 5 + (cola + 1) % 5]
												ciphertext += table[rowa * 5 + (cola + 1) % 5]
								elif cola == cola:
												ciphertext += table[((rowa + 1) % 5) * 5 + cola]
												ciphertext += table[((rowa + 1) % 5) * 5 + cola]
								else:  # rectangle
												ciphertext += table[rowa * 5 + cola]
												ciphertext += table[rowa * 5 + cola]

				return ciphertext






def      __A   (      a_    :str ,							a_    :str)		->		str:
				__a			:    Any      							=	generate_table(a_)
				__a			:    Any      							=	''''''

				# https://en.wikipedia.org/wiki/Playfair_cipher#Description
				for chara, chara in chunker(a_ ,							2):
								__a							,    __a			:    Any      							=	divmod(table.index(a_) ,							5)
								__a							,    __a			:    Union[str, Any]      							=	divmod(table.index(a_) ,							5)

								if rowa == rowa:
												plaintext += table[rowa * 5 + (cola - 1) % 5]
												plaintext += table[rowa * 5 + (cola - 1) % 5]
								elif cola == cola:
												plaintext += table[((rowa - 1) % 5) * 5 + cola]
												plaintext += table[((rowa - 1) % 5) * 5 + cola]
								else:  # rectangle
												plaintext += table[rowa * 5 + cola]
												plaintext += table[rowa * 5 + cola]

				return plaintext







from __future__ import annotations



def  a__ (__lowercase							:list					,  __lowercase							:int | None = None					,  __lowercase							:int | None = None   )		-> None:
				if start is None:
								_A	:				Optional[int]   =      0

				if end is None:
								_A	:				Union[str, Any]   =      len(__lowercase   ) - 1

				if start >= end:
								return

				_A	:				Union[str, Any]   =      (start + end) // 2

				slowsort(__lowercase					,  __lowercase					,  __lowercase   )
				slowsort(__lowercase					,  mid + 1					,  __lowercase   )

				if sequence[end] < sequence[mid]:
								_A  ,				_A	:				Optional[int]   =      sequence[mid], sequence[end]

				slowsort(__lowercase					,  __lowercase					,  end - 1   )


if __name__ == "__main__":
	from doctest import testmod

	testmod()



