






from __future__ import annotations

from typing import Any





class 						SCREAMING_SNAKE_CASE				:





							"""simple docstring"""

							def __init__(  self:   List[str]		,     __A:   int = 6   )    ->				None:
												_A								= None
												_A								= None
												self.create_linked_list(__A   )

							def       __A (  self:   Union[str, Any]		,     __A:   int   )    ->				None:
												_A								= Node()
												_A								= current_node
												_A								= current_node
												_A								= current_node
												for _ in range(1		,     __A   ):
																	_A								= Node()
																	_A								= current_node
																	_A								= previous_node
																	_A								= current_node
												_A								= self.front
												_A								= previous_node

							def       __A (  self:   int   )    ->				bool:
												return (
												    self.front == self.rear
												    and self.front is not None
												    and self.front.data is None
												)

							def       __A (  self:   Dict   )    ->				Any | None:
												self.check_can_perform_operation()
												return self.front.data if self.front else None

							def       __A (  self:   Dict		,     __A:   Any   )    ->				None:
												if self.rear is None:
																	return

												self.check_is_full()
												if not self.is_empty():
																	_A								= self.rear.next
												if self.rear:
																	_A								= data

							def       __A (  self:   List[str]   )    ->				Any:
												self.check_can_perform_operation()
												if self.rear is None or self.front is None:
																	return None
												if self.front == self.rear:
																	_A								= self.front.data
																	_A								= None
																	return data

												_A								= self.front
												_A								= old_front.next
												_A								= old_front.data
												_A								= None
												return data

							def       __A (  self:   Any   )    ->				None:
												if self.is_empty():
																	raise Exception('''Empty Queue'''   )



							def       __A (  self:   List[str]   )    ->				None:
												if self.rear and self.rear.next == self.front:
																	raise Exception('''Full Queue'''   )





class 						SCREAMING_SNAKE_CASE				:





							"""simple docstring"""

							def __init__(  self:   Dict   )    ->				None:
												_A								= None
												_A								= None
												_A								= None


if __name__ == "__main__":
				import doctest

				doctest.testmod()











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




def      __A					(     _lowercase					,			_lowercase ):

					'''simple docstring'''







					_A								= iter(_lowercase )
					while True:
										_A								= tuple(itertools.islice(_lowercase					,			_lowercase ) )
										if not chunk:
															return
										yield chunk




def      __A					(     _lowercase ):

					'''simple docstring'''







					_A								= ''''''.join([c.upper() for c in dirty if c in string.ascii_letters] )
					_A								= ''''''

					if len(_lowercase ) < 2:
										return dirty

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

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

					clean += dirty[-1]

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

					return clean




def      __A					(     _lowercase ):

					'''simple docstring'''







					_A								= '''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								= []

					# 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(_lowercase )

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

					return table




def      __A					(     _lowercase					,			_lowercase ):

					'''simple docstring'''







					_A								= generate_table(_lowercase )
					_A								= prepare_input(_lowercase )
					_A								= ''''''

					# https://en.wikipedia.org/wiki/Playfair_cipher#Description
					for chara, chara in chunker(_lowercase					,			2 ):
										_A							,_A								= divmod(table.index(_lowercase )					,			5 )
										_A							,_A								= divmod(table.index(_lowercase )					,			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					(     _lowercase					,			_lowercase ):

					'''simple docstring'''







					_A								= generate_table(_lowercase )
					_A								= ''''''

					# https://en.wikipedia.org/wiki/Playfair_cipher#Description
					for chara, chara in chunker(_lowercase					,			2 ):
										_A							,_A								= divmod(table.index(_lowercase )					,			5 )
										_A							,_A								= divmod(table.index(_lowercase )					,			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



