

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







def 			A_      (    _UpperCAmelCase				,	_UpperCAmelCase    ):
						SCREAMING_SNAKE_CASE_: str  		=       iter(_UpperCAmelCase    )
						while True:
												SCREAMING_SNAKE_CASE_: Dict  		=       tuple(itertools.islice(_UpperCAmelCase				,	_UpperCAmelCase    )    )
												if not chunk:
																		return
												yield chunk







def 			A_      (    _UpperCAmelCase    ):
						SCREAMING_SNAKE_CASE_: Any  		=       "".join([c.upper() for c in dirty if c in string.ascii_letters]    )
						SCREAMING_SNAKE_CASE_: Any  		=       ""

						if len(_UpperCAmelCase    ) < 2:
												return dirty

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

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

						clean += dirty[-1]

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

						return clean







def 			A_      (    _UpperCAmelCase    ):
						# I and J are used interchangeably to allow
						# us to use a 5x5 table (25 letters)
						SCREAMING_SNAKE_CASE_: Tuple  		=       "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
						SCREAMING_SNAKE_CASE_: List[str]  		=       []

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

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

						return table







def 			A_      (    _UpperCAmelCase				,	_UpperCAmelCase    ):
						SCREAMING_SNAKE_CASE_: str  		=       generate_table(_UpperCAmelCase    )
						SCREAMING_SNAKE_CASE_: Optional[Any]  		=       prepare_input(_UpperCAmelCase    )
						SCREAMING_SNAKE_CASE_: Dict  		=       ""

						# https://en.wikipedia.org/wiki/Playfair_cipher#Description
						for chara, chara in chunker(_UpperCAmelCase				,	2    ):
												SCREAMING_SNAKE_CASE_		,    SCREAMING_SNAKE_CASE_: List[Any]  		=       divmod(table.index(_UpperCAmelCase    )				,	5    )
												SCREAMING_SNAKE_CASE_		,    SCREAMING_SNAKE_CASE_: int  		=       divmod(table.index(_UpperCAmelCase    )				,	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_      (    _UpperCAmelCase				,	_UpperCAmelCase    ):
						SCREAMING_SNAKE_CASE_: Any  		=       generate_table(_UpperCAmelCase    )
						SCREAMING_SNAKE_CASE_: int  		=       ""

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









def 			A_      (    _UpperCAmelCase    ):
						SCREAMING_SNAKE_CASE_: List[str]  		=       [0] * len(_UpperCAmelCase    )
						SCREAMING_SNAKE_CASE_: List[Any]  		=       []
						SCREAMING_SNAKE_CASE_: str  		=       []
						SCREAMING_SNAKE_CASE_: List[str]  		=       0

						for values in graph.values():
												for i in values:
																		indegree[i] += 1

						for i in range(len(_UpperCAmelCase    )    ):
												if indegree[i] == 0:
																		queue.append(_UpperCAmelCase    )

						while queue:
												SCREAMING_SNAKE_CASE_: Optional[int]  		=       queue.pop(0    )
												cnt += 1
												topo.append(_UpperCAmelCase    )
												for x in graph[vertex]:
																		indegree[x] -= 1
																		if indegree[x] == 0:
																								queue.append(_UpperCAmelCase    )

						if cnt != len(_UpperCAmelCase    ):
												print("Cycle exists"    )
						else:
												print(_UpperCAmelCase    )


# Adjacency List of Graph
lowerCAmelCase							:  Any   	=						{0: [1, 2], 1: [3], 2: [3], 3: [4, 5], 4: [], 5: []}



topological_sort(graph)






