




__a  :		List[Any]			=    float('''inf''')







class       UpperCAmelCase:



	"""simple docstring"""






	def __init__(     self       ,      lowerCamelCase				)					->			Tuple:





								"""simple docstring"""


								lowercase__  :       Optional[int]   					=							[0] * n
								lowercase__  :       Any   					=							[0] * n
								lowercase__  :       str   					=							[0] * n
								lowercase__  :       Any   					=							[[] for _ in range(__SCREAMING_SNAKE_CASE				)]

	def     __a	(     self       ,      lowerCamelCase       ,      lowerCamelCase       ,      lowerCamelCase       ,      lowerCamelCase=0				)					->			Union[str, Any]:





								"""simple docstring"""


								self.adj[a].append([b, len(self.adj[b]				), c, 0]				)
								self.adj[b].append([a, len(self.adj[a]				) - 1, rcap, 0]				)

	def     __a	(     self       ,      lowerCamelCase       ,      lowerCamelCase       ,      lowerCamelCase				)					->			str:





								"""simple docstring"""


								if vertex == sink or not flow:
															return flow

								for i in range(self.ptr[vertex]       ,      len(self.adj[vertex]				)				):
															lowercase__  :       Tuple   					=							self.adj[vertex][i]
															if self.lvl[e[0]] == self.lvl[vertex] + 1:
																						lowercase__  :       Union[str, Any]   					=							self.depth_first_search(e[0]       ,      __SCREAMING_SNAKE_CASE       ,      min(__SCREAMING_SNAKE_CASE       ,      e[2] - e[3]				)				)
																						if p:
																													self.adj[vertex][i][3] += p
																													self.adj[e[0]][e[1]][3] -= p
																													return p
															lowercase__  :       str   					=							self.ptr[vertex] + 1
								return 0







	def     __a	(     self       ,      lowerCamelCase       ,      lowerCamelCase				)					->			List[str]:





								"""simple docstring"""


								lowercase__					,   lowercase__  :       Any   					=							0, source
								for l in range(31				):  # noqa: E741  l = 30 maybe faster for random data
															while True:
																						lowercase__					,   lowercase__  :       Optional[Any]   					=							[0] * len(self.q				), [0] * len(self.q				)
																						lowercase__					,   lowercase__					,   lowercase__  :       str   					=							0, 1, 1
																						while qi < qe and not self.lvl[sink]:
																													lowercase__  :       Optional[int]   					=							self.q[qi]
																													qi += 1
																													for e in self.adj[v]:
																																				if not self.lvl[e[0]] and (e[2] - e[3]) >> (30 - l):
																																											lowercase__  :       Optional[int]   					=							e[0]
																																											qe += 1
																																											lowercase__  :       List[str]   					=							self.lvl[v] + 1

																						lowercase__  :       Dict   					=							self.depth_first_search(__SCREAMING_SNAKE_CASE       ,      __SCREAMING_SNAKE_CASE       ,      __SCREAMING_SNAKE_CASE				)
																						while p:
																													flow += p
																													lowercase__  :       int   					=							self.depth_first_search(__SCREAMING_SNAKE_CASE       ,      __SCREAMING_SNAKE_CASE       ,      __SCREAMING_SNAKE_CASE				)

																						if not self.lvl[sink]:
																													break

								return flow

__a  :		List[str]			=    Dinic(1_0)
__a  :		List[str]			=    0
__a  :		Optional[Any]			=    9
for vertex in range(1, 5):
						graph.add_edge(source, vertex, 1)
for vertex in range(5, 9):
						graph.add_edge(vertex, sink, 1)
for vertex in range(1, 5):
						graph.add_edge(vertex, vertex + 4, 1)

# Now we can know that is the maximum flow(source -> sink)
print(graph.max_flow(source, sink))






"""simple docstring"""


import random
import sys

from . import cryptomath_module as cryptomath

a__    :   int    						= (
    r""" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`"""
    r"""abcdefghijklmnopqrstuvwxyz{|}~"""
)





def 							a__	(     _UpperCAmelCase		,   _UpperCAmelCase		,   _UpperCAmelCase		)			->     None:

 '''simple docstring'''






 if mode == "encrypt":
  if key_a == 1:
   sys.exit(
       "The affine cipher becomes weak when key "
       "A is set to 1. Choose different key"		)
  if key_b == 0:
   sys.exit(
       "The affine cipher becomes weak when key "
       "B is set to 0. Choose different key"		)
 if key_a < 0 or key_b < 0 or key_b > len(_UpperCAmelCase		) - 1:
  sys.exit(
      "Key A must be greater than 0 and key B must "
      f"be between 0 and {len(_UpperCAmelCase		) - 1}."		)
 if cryptomath.gcd(_UpperCAmelCase		,   len(_UpperCAmelCase		)		) != 1:
  sys.exit(
      f"Key A {key_a} and the symbol set size {len(_UpperCAmelCase		)} "
      "are not relatively prime. Choose a different key."		)





def 							a__	(     _UpperCAmelCase		,   _UpperCAmelCase		)			->     str:

 '''simple docstring'''






 snake_case__							,      snake_case__										= divmod(_UpperCAmelCase		,   len(_UpperCAmelCase		)		)
 check_keys(_UpperCAmelCase		,   _UpperCAmelCase		,   "encrypt"		)
 snake_case__										= ""
 for symbol in message:
  if symbol in SYMBOLS:
   snake_case__										= SYMBOLS.find(_UpperCAmelCase		)
   cipher_text += SYMBOLS[(sym_index * key_a + key_b) % len(_UpperCAmelCase		)]
  else:
   cipher_text += symbol
 return cipher_text





def 							a__	(     _UpperCAmelCase		,   _UpperCAmelCase		)			->     str:

 '''simple docstring'''






 snake_case__							,      snake_case__										= divmod(_UpperCAmelCase		,   len(_UpperCAmelCase		)		)
 check_keys(_UpperCAmelCase		,   _UpperCAmelCase		,   "decrypt"		)
 snake_case__										= ""
 snake_case__										= cryptomath.find_mod_inverse(_UpperCAmelCase		,   len(_UpperCAmelCase		)		)
 for symbol in message:
  if symbol in SYMBOLS:
   snake_case__										= SYMBOLS.find(_UpperCAmelCase		)
   plain_text += SYMBOLS[
       (sym_index - key_b) * mod_inverse_of_key_a % len(_UpperCAmelCase		)
   ]
  else:
   plain_text += symbol
 return plain_text





def 							a__	(     )			->     int:

 '''simple docstring'''






 while True:
  snake_case__										= random.randint(2		,   len(_UpperCAmelCase		)		)
  snake_case__										= random.randint(2		,   len(_UpperCAmelCase		)		)
  if cryptomath.gcd(_UpperCAmelCase		,   len(_UpperCAmelCase		)		) == 1 and key_b % len(_UpperCAmelCase		) != 0:
   return key_b * len(_UpperCAmelCase		) + key_b





def 							a__	(     )			->     None:

 '''simple docstring'''






 snake_case__										= input("Enter message: "		).strip()
 snake_case__										= int(input("Enter key [2000 - 9000]: "		).strip()		)
 snake_case__										= input("Encrypt/Decrypt [E/D]: "		).strip().lower()

 if mode.startswith("e"		):
  snake_case__										= "encrypt"
  snake_case__										= encrypt_message(_UpperCAmelCase		,   _UpperCAmelCase		)
 elif mode.startswith("d"		):
  snake_case__										= "decrypt"
  snake_case__										= decrypt_message(_UpperCAmelCase		,   _UpperCAmelCase		)
 print(f"\n{mode.title()}ed text: \n{translated}"		)


if __name__ == "__main__":
   import doctest

   doctest.testmod()
   # main()

