
from collections import deque
from math import floor
from random import random
from time import time


class 				lowercase					:



		def __init__( self       )  ->					Tuple:
				"""simple docstring"""
				UpperCamelCase		=     {}



		def __UpperCamelCase ( self				,      A_				,      A_				,      A_=1       )  ->					str:
				"""simple docstring"""
				if self.graph.get(A_       ):
						if self.graph[u].count([w, v]       ) == 0:
								self.graph[u].append([w, v]       )
				else:
						UpperCamelCase		=     [[w, v]]
				if not self.graph.get(A_       ):
						UpperCamelCase		=     []



		def __UpperCamelCase ( self       )  ->					Union[str, Any]:
				"""simple docstring"""
				return list(self.graph       )



		def __UpperCamelCase ( self				,      A_				,      A_       )  ->					Union[str, Any]:
				"""simple docstring"""
				if self.graph.get(A_       ):
						for _ in self.graph[u]:
								if _[1] == v:
										self.graph[u].remove(A_       )



		def __UpperCamelCase ( self				,      A_=-2				,      A_=-1       )  ->					Tuple:
				"""simple docstring"""
				if s == d:
						return []
				UpperCamelCase		=     []
				UpperCamelCase		=     []
				if s == -2:
						UpperCamelCase		=     list(self.graph       )[0]
				stack.append(A_       )
				visited.append(A_       )
				UpperCamelCase		=     s

				while True:
						# check if there is any non isolated nodes
						if len(self.graph[s]       ) != 0:
								UpperCamelCase		=     s
								for node in self.graph[s]:
										if visited.count(node[1]       ) < 1:
												if node[1] == d:
														visited.append(A_       )
														return visited
												else:
														stack.append(node[1]       )
														visited.append(node[1]       )
														UpperCamelCase		=     node[1]
														break

            # check if all the children are visited
						if s == ss:
								stack.pop()
								if len(A_       ) != 0:
										UpperCamelCase		=     stack[len(A_       ) - 1]
						else:
								UpperCamelCase		=     ss

						# check if se have reached the starting point
						if len(A_       ) == 0:
								return visited



		def __UpperCamelCase ( self				,      A_=-1       )  ->					int:
				"""simple docstring"""
				if c == -1:
						UpperCamelCase		=     floor(random() * 10_000       ) + 10
				for i in range(A_       ):
						# every vertex has max 100 edges
						for _ in range(floor(random() * 102       ) + 1       ):
								UpperCamelCase		=     floor(random() * c       ) + 1
								if n != i:
										self.add_pair(A_				,      A_				,      1       )



		def __UpperCamelCase ( self				,      A_=-2       )  ->					List[Any]:
				"""simple docstring"""
				UpperCamelCase		=     deque()
				UpperCamelCase		=     []
				if s == -2:
						UpperCamelCase		=     list(self.graph       )[0]
				d.append(A_       )
				visited.append(A_       )
				while d:
						UpperCamelCase		=     d.popleft()
						if len(self.graph[s]       ) != 0:
								for node in self.graph[s]:
										if visited.count(node[1]       ) < 1:
												d.append(node[1]       )
												visited.append(node[1]       )
				return visited



		def __UpperCamelCase ( self				,      A_       )  ->					Optional[int]:
				"""simple docstring"""
				UpperCamelCase		=     0
				for x in self.graph:
						for y in self.graph[x]:
								if y[1] == u:
										count += 1
				return count



		def __UpperCamelCase ( self				,      A_       )  ->					Optional[int]:
				"""simple docstring"""
				return len(self.graph[u]       )



		def __UpperCamelCase ( self				,      A_=-2       )  ->					Optional[Any]:
				"""simple docstring"""
				UpperCamelCase		=     []
				UpperCamelCase		=     []
				if s == -2:
						UpperCamelCase		=     list(self.graph       )[0]
				stack.append(A_       )
				visited.append(A_       )
				UpperCamelCase		=     s
				UpperCamelCase		=     []

				while True:
						# check if there is any non isolated nodes
						if len(self.graph[s]       ) != 0:
								UpperCamelCase		=     s
								for node in self.graph[s]:
										if visited.count(node[1]       ) < 1:
												stack.append(node[1]       )
												visited.append(node[1]       )
												UpperCamelCase		=     node[1]
												break

            # check if all the children are visited
						if s == ss:
								sorted_nodes.append(stack.pop()       )
								if len(A_       ) != 0:
										UpperCamelCase		=     stack[len(A_       ) - 1]
						else:
								UpperCamelCase		=     ss

						# check if se have reached the starting point
						if len(A_       ) == 0:
								return sorted_nodes



		def __UpperCamelCase ( self       )  ->					str:
				"""simple docstring"""
				UpperCamelCase		=     []
				UpperCamelCase		=     []
				UpperCamelCase		=     list(self.graph       )[0]
				stack.append(A_       )
				visited.append(A_       )
				UpperCamelCase		=     -2
				UpperCamelCase		=     []
				UpperCamelCase		=     s
				UpperCamelCase		=     False
				UpperCamelCase		=     set()

				while True:
						# check if there is any non isolated nodes
						if len(self.graph[s]       ) != 0:
								UpperCamelCase		=     s
								for node in self.graph[s]:
										if (
										    visited.count(node[1]       ) > 0
										    and node[1] != parent
										    and indirect_parents.count(node[1]       ) > 0
										    and not on_the_way_back
										):
												UpperCamelCase		=     len(A_       ) - 1
												while len_stack >= 0:
														if stack[len_stack] == node[1]:
																anticipating_nodes.add(node[1]       )
																break
														else:
																anticipating_nodes.add(stack[len_stack]       )
																len_stack -= 1
										if visited.count(node[1]       ) < 1:
												stack.append(node[1]       )
												visited.append(node[1]       )
												UpperCamelCase		=     node[1]
												break

            # check if all the children are visited
						if s == ss:
								stack.pop()
								UpperCamelCase		=     True
								if len(A_       ) != 0:
										UpperCamelCase		=     stack[len(A_       ) - 1]
						else:
								UpperCamelCase		=     False
								indirect_parents.append(A_       )
								UpperCamelCase		=     s
								UpperCamelCase		=     ss

						# check if se have reached the starting point
						if len(A_       ) == 0:
								return list(A_       )



		def __UpperCamelCase ( self       )  ->					Union[str, Any]:
				"""simple docstring"""
				UpperCamelCase		=     []
				UpperCamelCase		=     []
				UpperCamelCase		=     list(self.graph       )[0]
				stack.append(A_       )
				visited.append(A_       )
				UpperCamelCase		=     -2
				UpperCamelCase		=     []
				UpperCamelCase		=     s
				UpperCamelCase		=     False
				UpperCamelCase		=     set()

				while True:
						# check if there is any non isolated nodes
						if len(self.graph[s]       ) != 0:
								UpperCamelCase		=     s
								for node in self.graph[s]:
										if (
										    visited.count(node[1]       ) > 0
										    and node[1] != parent
										    and indirect_parents.count(node[1]       ) > 0
										    and not on_the_way_back
										):
												UpperCamelCase		=     len(A_       ) - 1
												while len_stack_minus_one >= 0:
														if stack[len_stack_minus_one] == node[1]:
																anticipating_nodes.add(node[1]       )
																break
														else:
																return True
										if visited.count(node[1]       ) < 1:
												stack.append(node[1]       )
												visited.append(node[1]       )
												UpperCamelCase		=     node[1]
												break

            # check if all the children are visited
						if s == ss:
								stack.pop()
								UpperCamelCase		=     True
								if len(A_       ) != 0:
										UpperCamelCase		=     stack[len(A_       ) - 1]
						else:
								UpperCamelCase		=     False
								indirect_parents.append(A_       )
								UpperCamelCase		=     s
								UpperCamelCase		=     ss

						# check if se have reached the starting point
						if len(A_       ) == 0:
								return False



		def __UpperCamelCase ( self				,      A_=-2				,      A_=-1       )  ->					int:
				"""simple docstring"""
				UpperCamelCase		=     time()
				self.dfs(A_				,      A_       )
				UpperCamelCase		=     time()
				return end - begin



		def __UpperCamelCase ( self				,      A_=-2       )  ->					Optional[Any]:
				"""simple docstring"""
				UpperCamelCase		=     time()
				self.bfs(A_       )
				UpperCamelCase		=     time()
				return end - begin






class 				lowercase					:



		def __init__( self       )  ->					Tuple:
				"""simple docstring"""
				UpperCamelCase		=     {}



		def __UpperCamelCase ( self				,      A_				,      A_				,      A_=1       )  ->					int:
				"""simple docstring"""
				# check if the u exists
				if self.graph.get(A_       ):
						# if there already is a edge
						if self.graph[u].count([w, v]       ) == 0:
								self.graph[u].append([w, v]       )
				else:
						# if u does not exist
						UpperCamelCase		=     [[w, v]]
				# add the other way
				if self.graph.get(A_       ):
						# if there already is a edge
						if self.graph[v].count([w, u]       ) == 0:
								self.graph[v].append([w, u]       )
				else:
						# if u does not exist
						UpperCamelCase		=     [[w, u]]



		def __UpperCamelCase ( self				,      A_				,      A_       )  ->					Union[str, Any]:
				"""simple docstring"""
				if self.graph.get(A_       ):
						for _ in self.graph[u]:
								if _[1] == v:
										self.graph[u].remove(A_       )
        # the other way round
				if self.graph.get(A_       ):
						for _ in self.graph[v]:
								if _[1] == u:
										self.graph[v].remove(A_       )



		def __UpperCamelCase ( self				,      A_=-2				,      A_=-1       )  ->					Optional[Any]:
				"""simple docstring"""
				if s == d:
						return []
				UpperCamelCase		=     []
				UpperCamelCase		=     []
				if s == -2:
						UpperCamelCase		=     list(self.graph       )[0]
				stack.append(A_       )
				visited.append(A_       )
				UpperCamelCase		=     s

				while True:
						# check if there is any non isolated nodes
						if len(self.graph[s]       ) != 0:
								UpperCamelCase		=     s
								for node in self.graph[s]:
										if visited.count(node[1]       ) < 1:
												if node[1] == d:
														visited.append(A_       )
														return visited
												else:
														stack.append(node[1]       )
														visited.append(node[1]       )
														UpperCamelCase		=     node[1]
														break

            # check if all the children are visited
						if s == ss:
								stack.pop()
								if len(A_       ) != 0:
										UpperCamelCase		=     stack[len(A_       ) - 1]
						else:
								UpperCamelCase		=     ss

						# check if se have reached the starting point
						if len(A_       ) == 0:
								return visited



		def __UpperCamelCase ( self				,      A_=-1       )  ->					str:
				"""simple docstring"""
				if c == -1:
						UpperCamelCase		=     floor(random() * 10_000       ) + 10
				for i in range(A_       ):
						# every vertex has max 100 edges
						for _ in range(floor(random() * 102       ) + 1       ):
								UpperCamelCase		=     floor(random() * c       ) + 1
								if n != i:
										self.add_pair(A_				,      A_				,      1       )



		def __UpperCamelCase ( self				,      A_=-2       )  ->					Optional[int]:
				"""simple docstring"""
				UpperCamelCase		=     deque()
				UpperCamelCase		=     []
				if s == -2:
						UpperCamelCase		=     list(self.graph       )[0]
				d.append(A_       )
				visited.append(A_       )
				while d:
						UpperCamelCase		=     d.popleft()
						if len(self.graph[s]       ) != 0:
								for node in self.graph[s]:
										if visited.count(node[1]       ) < 1:
												d.append(node[1]       )
												visited.append(node[1]       )
				return visited



		def __UpperCamelCase ( self				,      A_       )  ->					int:
				"""simple docstring"""
				return len(self.graph[u]       )



		def __UpperCamelCase ( self       )  ->					str:
				"""simple docstring"""
				UpperCamelCase		=     []
				UpperCamelCase		=     []
				UpperCamelCase		=     list(self.graph       )[0]
				stack.append(A_       )
				visited.append(A_       )
				UpperCamelCase		=     -2
				UpperCamelCase		=     []
				UpperCamelCase		=     s
				UpperCamelCase		=     False
				UpperCamelCase		=     set()

				while True:
						# check if there is any non isolated nodes
						if len(self.graph[s]       ) != 0:
								UpperCamelCase		=     s
								for node in self.graph[s]:
										if (
										    visited.count(node[1]       ) > 0
										    and node[1] != parent
										    and indirect_parents.count(node[1]       ) > 0
										    and not on_the_way_back
										):
												UpperCamelCase		=     len(A_       ) - 1
												while len_stack >= 0:
														if stack[len_stack] == node[1]:
																anticipating_nodes.add(node[1]       )
																break
														else:
																anticipating_nodes.add(stack[len_stack]       )
																len_stack -= 1
										if visited.count(node[1]       ) < 1:
												stack.append(node[1]       )
												visited.append(node[1]       )
												UpperCamelCase		=     node[1]
												break

            # check if all the children are visited
						if s == ss:
								stack.pop()
								UpperCamelCase		=     True
								if len(A_       ) != 0:
										UpperCamelCase		=     stack[len(A_       ) - 1]
						else:
								UpperCamelCase		=     False
								indirect_parents.append(A_       )
								UpperCamelCase		=     s
								UpperCamelCase		=     ss

						# check if se have reached the starting point
						if len(A_       ) == 0:
								return list(A_       )



		def __UpperCamelCase ( self       )  ->					Optional[Any]:
				"""simple docstring"""
				UpperCamelCase		=     []
				UpperCamelCase		=     []
				UpperCamelCase		=     list(self.graph       )[0]
				stack.append(A_       )
				visited.append(A_       )
				UpperCamelCase		=     -2
				UpperCamelCase		=     []
				UpperCamelCase		=     s
				UpperCamelCase		=     False
				UpperCamelCase		=     set()

				while True:
						# check if there is any non isolated nodes
						if len(self.graph[s]       ) != 0:
								UpperCamelCase		=     s
								for node in self.graph[s]:
										if (
										    visited.count(node[1]       ) > 0
										    and node[1] != parent
										    and indirect_parents.count(node[1]       ) > 0
										    and not on_the_way_back
										):
												UpperCamelCase		=     len(A_       ) - 1
												while len_stack_minus_one >= 0:
														if stack[len_stack_minus_one] == node[1]:
																anticipating_nodes.add(node[1]       )
																break
														else:
																return True
										if visited.count(node[1]       ) < 1:
												stack.append(node[1]       )
												visited.append(node[1]       )
												UpperCamelCase		=     node[1]
												break

            # check if all the children are visited
						if s == ss:
								stack.pop()
								UpperCamelCase		=     True
								if len(A_       ) != 0:
										UpperCamelCase		=     stack[len(A_       ) - 1]
						else:
								UpperCamelCase		=     False
								indirect_parents.append(A_       )
								UpperCamelCase		=     s
								UpperCamelCase		=     ss

						# check if se have reached the starting point
						if len(A_       ) == 0:
								return False



		def __UpperCamelCase ( self       )  ->					Optional[Any]:
				"""simple docstring"""
				return list(self.graph       )



		def __UpperCamelCase ( self				,      A_=-2				,      A_=-1       )  ->					List[str]:
				"""simple docstring"""
				UpperCamelCase		=     time()
				self.dfs(A_				,      A_       )
				UpperCamelCase		=     time()
				return end - begin



		def __UpperCamelCase ( self				,      A_=-2       )  ->					Union[str, Any]:
				"""simple docstring"""
				UpperCamelCase		=     time()
				self.bfs(A_       )
				UpperCamelCase		=     time()
				return end - begin


def       A       (					lowercase    ,       lowercase    ,       lowercase    ,       lowercase    ,       lowercase )   ->  int:
		'''simple docstring'''

		if index == number_of_items:
				return 0
		UpperCamelCase		=     0
		UpperCamelCase		=     0
		UpperCamelCase		=     knapsack(lowercase    ,       lowercase    ,       lowercase    ,       lowercase    ,       index + 1 )
		if weights[index] <= max_weight:
				UpperCamelCase		=     values[index] + knapsack(
				    lowercase    ,       lowercase    ,       lowercase    ,       max_weight - weights[index]    ,       index + 1 )
		return max(lowercase    ,       lowercase )


if __name__ == "__main__":
					import doctest

					doctest.testmod()
