





import itertools
import string
from collections.abc import Generator, Iterable
def      _A       (		SCREAMING_SNAKE_CASE     :   Iterable[str]       ,       SCREAMING_SNAKE_CASE     :   int						):





  """simple docstring"""



  a__	:					Dict										=iter(SCREAMING_SNAKE_CASE						)
  while True:
    a__	:					int										=tuple(itertools.islice(SCREAMING_SNAKE_CASE       ,       SCREAMING_SNAKE_CASE						)						)
    if not chunk:
      return
    yield chunk
def      _A       (		SCREAMING_SNAKE_CASE     :   str						):





  """simple docstring"""



  a__	:					Tuple										="".join([c.upper() for c in dirty if c in string.ascii_letters]						)
  a__	:					List[str]										=""

  if len(SCREAMING_SNAKE_CASE						) < 2:
    return dirty

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

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

  clean += dirty[-1]

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

  return clean
def      _A       (		SCREAMING_SNAKE_CASE     :   str						):





  """simple docstring"""



  a__	:					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
  a__	:					Optional[int]										=[]

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

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

  return table
def      _A       (		SCREAMING_SNAKE_CASE     :   str       ,       SCREAMING_SNAKE_CASE     :   str						):





  """simple docstring"""



  a__	:					Tuple										=generate_table(SCREAMING_SNAKE_CASE						)
  a__	:					Optional[int]										=prepare_input(SCREAMING_SNAKE_CASE						)
  a__	:					Any										=""

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





  """simple docstring"""



  a__	:					Tuple										=generate_table(SCREAMING_SNAKE_CASE						)
  a__	:					Union[str, Any]										=""

  # https://en.wikipedia.org/wiki/Playfair_cipher#Description
  for chara, chara in chunker(SCREAMING_SNAKE_CASE       ,       2						):
    a__					,							a__	:					List[str]										=divmod(table.index(SCREAMING_SNAKE_CASE						)       ,       5						)
    a__					,							a__	:					Tuple										=divmod(table.index(SCREAMING_SNAKE_CASE						)       ,       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				(	lowerCamelCase:   list[float]					,				lowerCamelCase:   Tuple )	->						List[str]:







      '''simple docstring'''






      print(F"""Vertex\tShortest Distance from vertex {src}""" )
      for i, d in enumerate(lowerCamelCase ):
            print(F"""{i}\t\t{d}""" )



def _a				(	lowerCamelCase:   list[dict[str, int]]					,				lowerCamelCase:   list[float]					,				lowerCamelCase:   int )	->						Union[str, Any]:







      '''simple docstring'''






      for j in range(lowerCamelCase ):
            __A   ,						__A   ,						__A          =				(graph[j][k] for k in ['''src''', '''dst''', '''weight'''])
            if distance[u] != float('''inf''' ) and distance[u] + w < distance[v]:
                  return True
      return False



def _a				(	lowerCamelCase:   list[dict[str, int]]					,				lowerCamelCase:   int					,				lowerCamelCase:   int					,				lowerCamelCase:   int )	->						list[float]:







      '''simple docstring'''






      __A          =				[float('''inf''' )] * vertex_count
      __A          =				0.0

      for _ in range(vertex_count - 1 ):
            for j in range(lowerCamelCase ):
                  __A   ,						__A   ,						__A          =				(graph[j][k] for k in ['''src''', '''dst''', '''weight'''])

                  if distance[u] != float('''inf''' ) and distance[u] + w < distance[v]:
                        __A          =				distance[u] + w

      __A          =				check_negative_cycle(lowerCamelCase					,				lowerCamelCase					,				lowerCamelCase )
      if negative_cycle_exists:
            raise Exception('''Negative cycle found''' )

      return distance


if __name__ == "__main__":
       import doctest

       doctest.testmod()

       snake_case__					:							Dict													=     int(input('Enter number of vertices: ').strip())
       snake_case__					:							Optional[int]													=     int(input('Enter number of edges: ').strip())

       snake_case__					:							list[dict[str, int]]													=     [{} for _ in range(E)]

       for i in range(E):
              print('Edge ', i + 1)
              snake_case__						,    snake_case__						,    snake_case__					:							Dict													=     (
                  int(x)
                  for x in input('Enter source, destination, weight: ').strip().split(' ')
              )
              snake_case__					:							List[Any]													=     {'src': src, 'dst': dest, 'weight': weight}

       snake_case__					:							Union[str, Any]													=     int(input('\nEnter shortest path source:').strip())
       snake_case__					:							List[Any]													=     bellman_ford(graph, V, E, source)
       print_distance(shortest_distance, 0)





