





"""simple docstring"""
from collections import deque

def 						_SCREAMING_SNAKE_CASE       (_UpperCAmelCase :  Optional[int]       ):
 return input(_UpperCAmelCase       ).strip().split(' '       )

def 						_SCREAMING_SNAKE_CASE       (_UpperCAmelCase :  int   ,			_UpperCAmelCase :  int       ):
 lowerCAmelCase  							=      {}
 for i in range(_UpperCAmelCase       ):
  lowerCAmelCase  							=      []

 for e in range(_UpperCAmelCase       ):
  lowerCAmelCase							,lowerCAmelCase  							=      (int(_UpperCAmelCase       ) for i in _input(F'Edge {e + 1}: <node1> <node2> '       ))
  graph[x].append(_UpperCAmelCase       )
 return graph

def 						_SCREAMING_SNAKE_CASE       (_UpperCAmelCase :  int   ,			_UpperCAmelCase :  int       ):
 lowerCAmelCase  							=      {}
 for i in range(_UpperCAmelCase       ):
  lowerCAmelCase  							=      []

 for e in range(_UpperCAmelCase       ):
  lowerCAmelCase							,lowerCAmelCase  							=      (int(_UpperCAmelCase       ) for i in _input(F'Edge {e + 1}: <node1> <node2> '       ))
  graph[x].append(_UpperCAmelCase       )
  graph[y].append(_UpperCAmelCase       )
 return graph

def 						_SCREAMING_SNAKE_CASE       (_UpperCAmelCase :  int   ,			_UpperCAmelCase :  int       ):
 lowerCAmelCase  							=      {}
 for i in range(_UpperCAmelCase       ):
  lowerCAmelCase  							=      []

 for e in range(_UpperCAmelCase       ):
  lowerCAmelCase							,lowerCAmelCase							,lowerCAmelCase  							=      (int(_UpperCAmelCase       ) for i in _input(F'Edge {e + 1}: <node1> <node2> <weight> '       ))
  graph[x].append((y, w)       )
  graph[y].append((x, w)       )
 return graph


if __name__ == "__main__":
       __UpperCamelCase    ,__UpperCamelCase			:		Tuple		    =   (int(i) for i in _input('''Number of nodes and edges: '''))

       __UpperCamelCase			:		Any		    =   int(
           _input(
               '''Press 1 or 2 or 3 \n'''
               '''1. Unweighted directed \n'''
               '''2. Unweighted undirected \n'''
               '''3. Weighted undirected \n'''
           )[0]
       )

       __UpperCamelCase			:		Any		    =   {
           1: initialize_unweighted_directed_graph,
           2: initialize_unweighted_undirected_graph,
           3: initialize_weighted_undirected_graph,
       }[graph_choice](n, m)

def 						_SCREAMING_SNAKE_CASE       (_UpperCAmelCase :  List[Any]   ,			_UpperCAmelCase :  List[str]       ):
 lowerCAmelCase							,lowerCAmelCase  							=      {s}, [s]
 print(_UpperCAmelCase       )
 while _s:
  lowerCAmelCase  							=      0
  for i in g[_s[-1]]:
   if i not in vis:
    _s.append(_UpperCAmelCase       )
    vis.add(_UpperCAmelCase       )
    lowerCAmelCase  							=      1
    print(_UpperCAmelCase       )
    break
  if not flag:
   _s.pop()

def 						_SCREAMING_SNAKE_CASE       (_UpperCAmelCase :  Any   ,			_UpperCAmelCase :  Union[str, Any]       ):
 lowerCAmelCase							,lowerCAmelCase  							=      {s}, deque([s]       )
 print(_UpperCAmelCase       )
 while q:
  lowerCAmelCase  							=      q.popleft()
  for v in g[u]:
   if v not in vis:
    vis.add(_UpperCAmelCase       )
    q.append(_UpperCAmelCase       )
    print(_UpperCAmelCase       )

def 						_SCREAMING_SNAKE_CASE       (_UpperCAmelCase :  List[str]   ,			_UpperCAmelCase :  List[Any]       ):
 lowerCAmelCase							,lowerCAmelCase							,lowerCAmelCase  							=      {s: 0}, set(), {s: 0}
 while True:
  if len(_UpperCAmelCase       ) == len(_UpperCAmelCase       ) - 1:
   break
  lowerCAmelCase  							=      10_0000
  for i in dist:
   if i not in known and dist[i] < mini:
    lowerCAmelCase  							=      dist[i]
    lowerCAmelCase  							=      i
  known.add(_UpperCAmelCase       )
  for v in g[u]:
   if v[0] not in known and dist[u] + v[1] < dist.get(v[0]   ,			10_0000       ):
    lowerCAmelCase  							=      dist[u] + v[1]
    lowerCAmelCase  							=      u
 for i in dist:
  if i != s:
   print(dist[i]       )

def 						_SCREAMING_SNAKE_CASE       (_UpperCAmelCase :  Optional[int]   ,			_UpperCAmelCase :  List[str]=None   ,			_UpperCAmelCase :  str=None       ):
 if q is None:
  lowerCAmelCase  							=      [1]
 if ind is None:
  lowerCAmelCase  							=      [0] * (len(_UpperCAmelCase       ) + 1)  # SInce oth Index is ignored
  for u in g:
   for v in g[u]:
    ind[v] += 1
  lowerCAmelCase  							=      deque()
  for i in g:
   if ind[i] == 0:
    q.append(_UpperCAmelCase       )
 if len(_UpperCAmelCase       ) == 0:
  return
 lowerCAmelCase  							=      q.popleft()
 print(_UpperCAmelCase       )
 for w in g[v]:
  ind[w] -= 1
  if ind[w] == 0:
   q.append(_UpperCAmelCase       )
 topo(_UpperCAmelCase   ,			_UpperCAmelCase   ,			_UpperCAmelCase       )

def 						_SCREAMING_SNAKE_CASE       ():
 lowerCAmelCase  							=      input().strip()
 lowerCAmelCase  							=      []
 for _ in range(_UpperCAmelCase       ):
  a.append(map(_UpperCAmelCase   ,			input().strip().split()       )       )
 return a, n

def 						_SCREAMING_SNAKE_CASE       (_UpperCAmelCase :  List[str]       ):
 ((lowerCAmelCase)							,(lowerCAmelCase))  							=      a_and_n
 lowerCAmelCase  							=      list(_UpperCAmelCase       )
 lowerCAmelCase  							=      [[0] * n for i in range(_UpperCAmelCase       )]
 for k in range(_UpperCAmelCase       ):
  for i in range(_UpperCAmelCase       ):
   for j in range(_UpperCAmelCase       ):
    if dist[i][j] > dist[i][k] + dist[k][j]:
     lowerCAmelCase  							=      dist[i][k] + dist[k][j]
     lowerCAmelCase  							=      k
 print(_UpperCAmelCase       )

def 						_SCREAMING_SNAKE_CASE       (_UpperCAmelCase :  Tuple   ,			_UpperCAmelCase :  Tuple       ):
 lowerCAmelCase							,lowerCAmelCase							,lowerCAmelCase  							=      {s: 0}, set(), {s: 0}
 while True:
  if len(_UpperCAmelCase       ) == len(_UpperCAmelCase       ) - 1:
   break
  lowerCAmelCase  							=      10_0000
  for i in dist:
   if i not in known and dist[i] < mini:
    lowerCAmelCase  							=      dist[i]
    lowerCAmelCase  							=      i
  known.add(_UpperCAmelCase       )
  for v in g[u]:
   if v[0] not in known and v[1] < dist.get(v[0]   ,			10_0000       ):
    lowerCAmelCase  							=      v[1]
    lowerCAmelCase  							=      u
 return dist

def 						_SCREAMING_SNAKE_CASE       ():
 lowerCAmelCase							,lowerCAmelCase  							=      map(_UpperCAmelCase   ,			input().split(' '       )       )
 lowerCAmelCase  							=      []
 for _ in range(_UpperCAmelCase       ):
  edges.append(map(_UpperCAmelCase   ,			input().split(' '       )       )       )
 return edges, n

def 						_SCREAMING_SNAKE_CASE       (_UpperCAmelCase :  Optional[Any]       ):
 # Sort edges on the basis of distance
 ((lowerCAmelCase)							,(lowerCAmelCase))  							=      e_and_n
 e.sort(reverse=_UpperCAmelCase   ,			key=lambda _UpperCAmelCase       : x[2]       )
 lowerCAmelCase  							=      [{i} for i in range(1   ,			n + 1       )]
 while True:
  if len(_UpperCAmelCase       ) == 1:
   break
  print(_UpperCAmelCase       )
  lowerCAmelCase  							=      e.pop()
  for i in range(len(_UpperCAmelCase       )       ):
   if x[0] in s[i]:
    break
  for j in range(len(_UpperCAmelCase       )       ):
   if x[1] in s[j]:
    if i == j:
     break
    s[j].update(s[i]       )
    s.pop(_UpperCAmelCase       )
    break




def 						_SCREAMING_SNAKE_CASE       (_UpperCAmelCase :  Optional[int]       ):
 lowerCAmelCase  							=      []
 for node in graph:
  if not graph[node]:
   isolated.append(_UpperCAmelCase       )
 return isolated












"""simple docstring"""
import os
import sys
import time

from . import transposition_cipher as trans_cipher

def 						_SCREAMING_SNAKE_CASE       ():
 lowerCAmelCase  							=      'Prehistoric Men.txt'
 lowerCAmelCase  							=      'Output.txt'
 lowerCAmelCase  							=      int(input('Enter key: '       )       )
 lowerCAmelCase  							=      input('Encrypt/Decrypt [e/d]: '       )

 if not os.path.exists(_UpperCAmelCase       ):
  print(F'File {input_file} does not exist. Quitting...'       )
  sys.exit()
 if os.path.exists(_UpperCAmelCase       ):
  print(F'Overwrite {output_file}? [y/n]'       )
  lowerCAmelCase  							=      input('> '       )
  if not response.lower().startswith('y'       ):
   sys.exit()

 lowerCAmelCase  							=      time.time()
 if mode.lower().startswith('e'       ):
  with open(_UpperCAmelCase       ) as f:
   lowerCAmelCase  							=      f.read()
  lowerCAmelCase  							=      trans_cipher.encrypt_message(_UpperCAmelCase   ,			_UpperCAmelCase       )
 elif mode.lower().startswith('d'       ):
  with open(_UpperCAmelCase       ) as f:
   lowerCAmelCase  							=      f.read()
  lowerCAmelCase  							=      trans_cipher.decrypt_message(_UpperCAmelCase   ,			_UpperCAmelCase       )

 with open(_UpperCAmelCase   ,			'w'       ) as output_obj:
  output_obj.write(_UpperCAmelCase       )

 lowerCAmelCase  							=      round(time.time() - start_time   ,			2       )
 print(('Done (', total_time, 'seconds )')       )


if __name__ == "__main__":
       main()





