"""simple docstring"""






from collections import deque



def     a_		(   lowerCamelCase			):
				return input(lowerCamelCase			).strip().split(' '			)



def     a_		(   lowerCamelCase   ,     lowerCamelCase			):
				UpperCAmelCase__			 =				{}
				for i in range(lowerCamelCase			):
								UpperCAmelCase__			 =				[]

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



def     a_		(   lowerCamelCase   ,     lowerCamelCase			):
				UpperCAmelCase__			 =				{}
				for i in range(lowerCamelCase			):
								UpperCAmelCase__			 =				[]

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



def     a_		(   lowerCamelCase   ,     lowerCamelCase			):
				UpperCAmelCase__			 =				{}
				for i in range(lowerCamelCase			):
								UpperCAmelCase__			 =				[]

				for e in range(lowerCamelCase			):
								UpperCAmelCase__ ,      UpperCAmelCase__ ,      UpperCAmelCase__			 =				(int(lowerCamelCase			) 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__":
						lowerCAmelCase__	,      lowerCAmelCase__    :    int			=      (int(i) for i in _input('Number of nodes and edges: '))

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

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



def     a_		(   lowerCamelCase   ,     lowerCamelCase			):
				UpperCAmelCase__ ,      UpperCAmelCase__			 =				{s}, [s]
				print(lowerCamelCase			)
				while _s:
								UpperCAmelCase__			 =				0
								for i in g[_s[-1]]:
												if i not in vis:
																_s.append(lowerCamelCase			)
																vis.add(lowerCamelCase			)
																UpperCAmelCase__			 =				1
																print(lowerCamelCase			)
																break
								if not flag:
												_s.pop()



def     a_		(   lowerCamelCase   ,     lowerCamelCase			):
				UpperCAmelCase__ ,      UpperCAmelCase__			 =				{s}, deque([s]			)
				print(lowerCamelCase			)
				while q:
								UpperCAmelCase__			 =				q.popleft()
								for v in g[u]:
												if v not in vis:
																vis.add(lowerCamelCase			)
																q.append(lowerCamelCase			)
																print(lowerCamelCase			)



def     a_		(   lowerCamelCase   ,     lowerCamelCase			):
				UpperCAmelCase__ ,      UpperCAmelCase__ ,      UpperCAmelCase__			 =				{s: 0}, set(), {s: 0}
				while True:
								if len(lowerCamelCase			) == len(lowerCamelCase			) - 1:
												break
								UpperCAmelCase__			 =				1_0_0_0_0_0
								for i in dist:
												if i not in known and dist[i] < mini:
																UpperCAmelCase__			 =				dist[i]
																UpperCAmelCase__			 =				i
								known.add(lowerCamelCase			)
								for v in g[u]:
												if v[0] not in known and dist[u] + v[1] < dist.get(v[0]   ,     1_0_0_0_0_0			):
																UpperCAmelCase__			 =				dist[u] + v[1]
																UpperCAmelCase__			 =				u
				for i in dist:
								if i != s:
												print(dist[i]			)



def     a_		(   lowerCamelCase   ,     lowerCamelCase=None   ,     lowerCamelCase=None			):
				if q is None:
								UpperCAmelCase__			 =				[1]
				if ind is None:
								UpperCAmelCase__			 =				[0] * (len(lowerCamelCase			) + 1)  # SInce oth Index is ignored
								for u in g:
												for v in g[u]:
																ind[v] += 1
								UpperCAmelCase__			 =				deque()
								for i in g:
												if ind[i] == 0:
																q.append(lowerCamelCase			)
				if len(lowerCamelCase			) == 0:
								return
				UpperCAmelCase__			 =				q.popleft()
				print(lowerCamelCase			)
				for w in g[v]:
								ind[w] -= 1
								if ind[w] == 0:
												q.append(lowerCamelCase			)
				topo(lowerCamelCase   ,     lowerCamelCase   ,     lowerCamelCase			)



def     a_		(   ):
				UpperCAmelCase__			 =				input().strip()
				UpperCAmelCase__			 =				[]
				for _ in range(lowerCamelCase			):
								a.append(map(lowerCamelCase   ,     input().strip().split()			)			)
				return a, n



def     a_		(   lowerCamelCase			):
				((UpperCAmelCase__) ,      (UpperCAmelCase__))			 =				a_and_n
				UpperCAmelCase__			 =				list(lowerCamelCase			)
				UpperCAmelCase__			 =				[[0] * n for i in range(lowerCamelCase			)]
				for k in range(lowerCamelCase			):
								for i in range(lowerCamelCase			):
												for j in range(lowerCamelCase			):
																if dist[i][j] > dist[i][k] + dist[k][j]:
																				UpperCAmelCase__			 =				dist[i][k] + dist[k][j]
																				UpperCAmelCase__			 =				k
				print(lowerCamelCase			)



def     a_		(   lowerCamelCase   ,     lowerCamelCase			):
				UpperCAmelCase__ ,      UpperCAmelCase__ ,      UpperCAmelCase__			 =				{s: 0}, set(), {s: 0}
				while True:
								if len(lowerCamelCase			) == len(lowerCamelCase			) - 1:
												break
								UpperCAmelCase__			 =				1_0_0_0_0_0
								for i in dist:
												if i not in known and dist[i] < mini:
																UpperCAmelCase__			 =				dist[i]
																UpperCAmelCase__			 =				i
								known.add(lowerCamelCase			)
								for v in g[u]:
												if v[0] not in known and v[1] < dist.get(v[0]   ,     1_0_0_0_0_0			):
																UpperCAmelCase__			 =				v[1]
																UpperCAmelCase__			 =				u
				return dist



def     a_		(   ):
				UpperCAmelCase__ ,      UpperCAmelCase__			 =				map(lowerCamelCase   ,     input().split(' '			)			)
				UpperCAmelCase__			 =				[]
				for _ in range(lowerCamelCase			):
								edges.append(map(lowerCamelCase   ,     input().split(' '			)			)			)
				return edges, n



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







def     a_		(   lowerCamelCase			):
				UpperCAmelCase__			 =				[]
				for node in graph:
								if not graph[node]:
												isolated.append(lowerCamelCase			)
				return isolated




"""simple docstring"""






import numpy as np



def     a_		(   lowerCamelCase   ,     lowerCamelCase="utf-8"   ,     lowerCamelCase="surrogatepass"			):
				UpperCAmelCase__			 =				bin(int.from_bytes(text.encode(lowerCamelCase   ,     lowerCamelCase			)   ,     'big'			)			)[2:]
				return bits.zfill(8 * ((len(lowerCamelCase			) + 7) // 8)			)



def     a_		(   lowerCamelCase   ,     lowerCamelCase="utf-8"   ,     lowerCamelCase="surrogatepass"			):
				UpperCAmelCase__			 =				int(lowerCamelCase   ,     2			)
				return n.to_bytes((n.bit_length() + 7) // 8   ,     'big'			).decode(lowerCamelCase   ,     lowerCamelCase			) or "\0"



def     a_		(   lowerCamelCase   ,     lowerCamelCase			):
				if size_par + len(lowerCamelCase			) <= 2**size_par - (len(lowerCamelCase			) - 1):
								raise ValueError('size of parity don\'t match with size of data'			)

				UpperCAmelCase__			 =				[]
				UpperCAmelCase__			 =				[]
				UpperCAmelCase__			 =				[bin(lowerCamelCase			)[2:] for x in range(1   ,     size_par + len(lowerCamelCase			) + 1			)]

				# sorted information data for the size of the output data
				UpperCAmelCase__			 =				[]
				# data position template + parity
				UpperCAmelCase__			 =				[]
				# parity bit counter
				UpperCAmelCase__			 =				0
				# counter position of data bits
				UpperCAmelCase__			 =				0

				for x in range(1   ,     size_par + len(lowerCamelCase			) + 1			):
								# Performs a template of bit positions - who should be given,
								# and who should be parity
								if qtd_bp < size_par:
												if (np.log(lowerCamelCase			) / np.log(2			)).is_integer():
																data_out_gab.append('P'			)
																UpperCAmelCase__			 =				qtd_bp + 1
												else:
																data_out_gab.append('D'			)
								else:
												data_out_gab.append('D'			)

								# Sorts the data to the new output size
								if data_out_gab[-1] == "D":
												data_ord.append(data[cont_data]			)
												cont_data += 1
								else:
												data_ord.append(lowerCamelCase			)

    # Calculates parity
				UpperCAmelCase__			 =				0  # parity bit counter
				for bp in range(1   ,     size_par + 1			):
								# Bit counter one for a given parity
								UpperCAmelCase__			 =				0
								# counter to control the loop reading
								UpperCAmelCase__			 =				0
								for x in data_ord:
												if x is not None:
																try:
																				UpperCAmelCase__			 =				(bin_pos[cont_loop])[-1 * (bp)]
																except IndexError:
																				UpperCAmelCase__			 =				'0'
																if aux == "1" and x == "1":
																				cont_bo += 1
												cont_loop += 1
								parity.append(cont_bo % 2			)

								qtd_bp += 1

				# Mount the message
				UpperCAmelCase__			 =				0  # parity bit counter
				for x in range(0   ,     size_par + len(lowerCamelCase			)			):
								if data_ord[x] is None:
												data_out.append(str(parity[cont_bp]			)			)
												cont_bp += 1
								else:
												data_out.append(data_ord[x]			)

				return data_out



def     a_		(   lowerCamelCase   ,     lowerCamelCase			):
				UpperCAmelCase__			 =				[]
				# Parity bit counter
				UpperCAmelCase__			 =				0
				# Counter p data bit reading
				UpperCAmelCase__			 =				0
				# list of parity received
				UpperCAmelCase__			 =				[]
				UpperCAmelCase__			 =				[]

				for x in range(1   ,     len(lowerCamelCase			) + 1			):
								# Performs a template of bit positions - who should be given,
								#  and who should be parity
								if qtd_bp < size_par and (np.log(lowerCamelCase			) / np.log(2			)).is_integer():
												data_out_gab.append('P'			)
												UpperCAmelCase__			 =				qtd_bp + 1
								else:
												data_out_gab.append('D'			)

								# Sorts the data to the new output size
								if data_out_gab[-1] == "D":
												data_output.append(data[cont_data]			)
								else:
												parity_received.append(data[cont_data]			)
								cont_data += 1

				# -----------calculates the parity with the data
				UpperCAmelCase__			 =				[]
				UpperCAmelCase__			 =				[]
				UpperCAmelCase__			 =				[bin(lowerCamelCase			)[2:] for x in range(1   ,     size_par + len(lowerCamelCase			) + 1			)]

				#  sorted information data for the size of the output data
				UpperCAmelCase__			 =				[]
				# Data position feedback + parity
				UpperCAmelCase__			 =				[]
				# Parity bit counter
				UpperCAmelCase__			 =				0
				# Counter p data bit reading
				UpperCAmelCase__			 =				0

				for x in range(1   ,     size_par + len(lowerCamelCase			) + 1			):
								# Performs a template position of bits - who should be given,
								# and who should be parity
								if qtd_bp < size_par and (np.log(lowerCamelCase			) / np.log(2			)).is_integer():
												data_out_gab.append('P'			)
												UpperCAmelCase__			 =				qtd_bp + 1
								else:
												data_out_gab.append('D'			)

								# Sorts the data to the new output size
								if data_out_gab[-1] == "D":
												data_ord.append(data_output[cont_data]			)
												cont_data += 1
								else:
												data_ord.append(lowerCamelCase			)

    # Calculates parity
				UpperCAmelCase__			 =				0  # parity bit counter
				for bp in range(1   ,     size_par + 1			):
								# Bit counter one for a certain parity
								UpperCAmelCase__			 =				0
								# Counter to control loop reading
								UpperCAmelCase__			 =				0
								for x in data_ord:
												if x is not None:
																try:
																				UpperCAmelCase__			 =				(bin_pos[cont_loop])[-1 * (bp)]
																except IndexError:
																				UpperCAmelCase__			 =				'0'
																if aux == "1" and x == "1":
																				cont_bo += 1
												cont_loop += 1
								parity.append(str(cont_bo % 2			)			)

								qtd_bp += 1

				# Mount the message
				UpperCAmelCase__			 =				0  # Parity bit counter
				for x in range(0   ,     size_par + len(lowerCamelCase			)			):
								if data_ord[x] is None:
												data_out.append(str(parity[cont_bp]			)			)
												cont_bp += 1
								else:
												data_out.append(data_ord[x]			)

				UpperCAmelCase__			 =				parity_received == parity
				return data_output, ack



