






import os
from collections.abc import Iterator




def      __A					(     _lowercase = "." ):

					'''simple docstring'''







					for dir_path, dir_names, filenames in os.walk(__lowerCAmelCase ):
										_A								= [d for d in dir_names if d != '''scripts''' and d[0] not in '''._''']
										for filename in filenames:
															if filename == "__init__.py":
																				continue
															if os.path.splitext(__lowerCAmelCase )[1] in (".py", ".ipynb"):
																				yield os.path.join(__lowerCAmelCase					,			__lowerCAmelCase ).lstrip('''./''' )




def      __A					(     _lowercase ):

					'''simple docstring'''







					return f"""{i * "  "}*""" if i else "\n##"




def      __A					(     _lowercase					,			_lowercase ):

					'''simple docstring'''







					_A								= old_path.split(os.sep )
					for i, new_part in enumerate(new_path.split(os.sep ) ):
										if (i + 1 > len(__lowerCAmelCase ) or old_parts[i] != new_part) and new_part:
															print(f"""{md_prefix(__lowerCAmelCase )} {new_part.replace("_"					,			" " ).title()}""" )
					return new_path




def      __A					(     _lowercase = "." ):

					'''simple docstring'''







					_A								= ''''''
					for filepath in sorted(good_file_paths(__lowerCAmelCase ) ):
										_A							,_A								= os.path.split(__lowerCAmelCase )
										if filepath != old_path:
															_A								= print_path(__lowerCAmelCase					,			__lowerCAmelCase )
										_A								= (filepath.count(os.sep ) + 1) if filepath else 0
										_A								= f"""{filepath}/{filename}""".replace(''' '''					,			'''%20''' )
										_A								= os.path.splitext(filename.replace('''_'''					,			''' ''' ).title() )[0]
										print(f"""{md_prefix(__lowerCAmelCase )} [{filename}]({url})""" )


if __name__ == "__main__":
				print_directory_md('.')











def      __A					(     _lowercase					,			_lowercase					,			_lowercase					,			_lowercase ):

					'''simple docstring'''







					global f  # a global dp table for knapsack
					if f[i][j] < 0:
										if j < wt[i - 1]:
															_A								= mf_knapsack(i - 1					,			_lowercase					,			_lowercase					,			_lowercase )
										else:
															_A								= max(
															    mf_knapsack(i - 1					,			_lowercase					,			_lowercase					,			_lowercase )					,			mf_knapsack(i - 1					,			_lowercase					,			_lowercase					,			j - wt[i - 1] ) + val[i - 1]					,			)
										_A								= val
					return f[i][j]




def      __A					(     _lowercase					,			_lowercase					,			_lowercase					,			_lowercase ):

					'''simple docstring'''







					_A								= [[0] * (w + 1) for _ in range(n + 1 )]

					for i in range(1					,			n + 1 ):
										for w_ in range(1					,			w + 1 ):
															if wt[i - 1] <= w_:
																				_A								= max(val[i - 1] + dp[i - 1][w_ - wt[i - 1]]					,			dp[i - 1][w_] )
															else:
																				_A								= dp[i - 1][w_]

					return dp[n][w_], dp




def      __A					(     _lowercase					,			_lowercase					,			_lowercase ):

					'''simple docstring'''







					if not (isinstance(_lowercase					,			(list, tuple) ) and isinstance(_lowercase					,			(list, tuple) )):
										raise ValueError(
										    '''Both the weights and values vectors must be either lists or tuples''' )

					_A								= len(_lowercase )
					if num_items != len(_lowercase ):
										_A								= (
										    '''The number of weights must be the same as the number of values.\n'''
										    f"""But got {num_items} weights and {len(_lowercase )} values"""
										)
										raise ValueError(_lowercase )
					for i in range(_lowercase ):
										if not isinstance(wt[i]					,			_lowercase ):
															_A								= (
															    '''All weights must be integers but got weight of '''
															    f"""type {type(wt[i] )} at index {i}"""
															)
															raise TypeError(_lowercase )

					_A							,_A								= knapsack(_lowercase					,			_lowercase					,			_lowercase					,			_lowercase )
					_A								= set()
					_construct_solution(_lowercase					,			_lowercase					,			_lowercase					,			_lowercase					,			_lowercase )

					return optimal_val, example_optional_set




def      __A					(     _lowercase					,			_lowercase					,			_lowercase					,			_lowercase					,			_lowercase ):

					'''simple docstring'''







					if i > 0 and j > 0:
										if dp[i - 1][j] == dp[i][j]:
															_construct_solution(_lowercase					,			_lowercase					,			i - 1					,			_lowercase					,			_lowercase )
										else:
															optimal_set.add(_lowercase )
															_construct_solution(_lowercase					,			_lowercase					,			i - 1					,			j - wt[i - 1]					,			_lowercase )


if __name__ == "__main__":
				__A      =				[3, 2, 4, 4]
				__A      =				[4, 3, 2, 3]
				__A      =				4
				__A      =				6
				__A      =				[[0] * (w + 1)] + [[0] + [-1] * (w + 1) for _ in range(n + 1)]
				__A ,  __A      =				knapsack(w, wt, val, n)
				print(optimal_solution)
				print(mf_knapsack(n, wt, val, w))  # switched the n and w

				# testing the dynamic programming problem with example
				# the optimal subset for the above example are items 3 and 4
				__A ,  __A      =				knapsack_with_example_solution(w, wt, val)
				assert optimal_solution == 8
				assert optimal_subset == {3, 4}
				print('optimal_value = ', optimal_solution)
				print('An optimal subset corresponding to the optimal value', optimal_subset)



