
"""simple docstring"""





import argparse
import os
import re


# All paths are set with the intent you should run this script from the root of the repo with the command
# python utils/check_dummies.py
_a														=		"""src/diffusers"""

# Matches is_xxx_available()
_a														=		re.compile(R"""is\_([a-z_]*)_available\(\)""")
# Matches from xxx import bla
_a														=		re.compile(R"""\s+from\s+\S*\s+import\s+([^\(\s].*)\n""")


_a														=		"""
{0} = None
"""

_a														=		"""
class {0}(metaclass=DummyObject):
    _backends = {1}

    def __init__(self, *args, **kwargs):
        requires_backends(self, {1})

    @classmethod
    def from_config(cls, *args, **kwargs):
        requires_backends(cls, {1})

    @classmethod
    def from_pretrained(cls, *args, **kwargs):
        requires_backends(cls, {1})
"""


_a														=		"""
def {0}(*args, **kwargs):
    requires_backends({0}, {1})
"""



def       lowerCamelCase__		(			__snake_case	)							->		Any:


					"""simple docstring"""





					_UpperCamelCase							 =  _re_backend.findall(__snake_case	)
					if len(__snake_case	) == 0:
										return None

					return "_and_".join(__snake_case	)



def       lowerCamelCase__		(			)							->		List[Any]:


					"""simple docstring"""





					with open(os.path.join(__snake_case,     '''__init__.py'''	),     '''r''',     encoding='''utf-8''',     newline='''\n'''	) as f:
										_UpperCamelCase							 =  f.readlines()

					# Get to the point we do the actual imports for type checking
					_UpperCamelCase							 =  0
					_UpperCamelCase							 =  {}
					# Go through the end of the file
					while line_index < len(__snake_case	):
										# If the line contains is_backend_available, we grab all objects associated with the `else` block
										_UpperCamelCase							 =  find_backend(lines[line_index]	)
										if backend is not None:
															while not lines[line_index].startswith('''else:'''	):
																				line_index += 1
															line_index += 1
															_UpperCamelCase							 =  []
															# Until we unindent, add backend objects to the list
															while line_index < len(__snake_case	) and len(lines[line_index]	) > 1:
																				_UpperCamelCase							 =  lines[line_index]
																				_UpperCamelCase							 =  _re_single_line_import.search(__snake_case	)
																				if single_line_import_search is not None:
																									objects.extend(single_line_import_search.groups()[0].split(''', '''	)	)
																				elif line.startswith(''' ''' * 8	):
																									objects.append(line[8:-2]	)
																				line_index += 1

															if len(__snake_case	) > 0:
																				_UpperCamelCase							 =  objects
										else:
															line_index += 1

					return backend_specific_objects



def       lowerCamelCase__		(			__snake_case,     __snake_case	)							->		List[Any]:


					"""simple docstring"""





					if name.isupper():
										return DUMMY_CONSTANT.format(__snake_case	)
					elif name.islower():
										return DUMMY_FUNCTION.format(__snake_case,     __snake_case	)
					else:
										return DUMMY_CLASS.format(__snake_case,     __snake_case	)



def       lowerCamelCase__		(			__snake_case=None	)							->		Dict:


					"""simple docstring"""





					if backend_specific_objects is None:
										_UpperCamelCase							 =  read_init()
					# For special correspondence backend to module name as used in the function requires_modulename
					_UpperCamelCase							 =  {}

					for backend, objects in backend_specific_objects.items():
										_UpperCamelCase							 =  '''[''' + ''', '''.join(F'''"{b}"''' for b in backend.split('''_and_'''	)	) + ''']'''
										_UpperCamelCase							 =  '''# This file is autogenerated by the command `make fix-copies`, do not edit.\n'''
										dummy_file += "from ..utils import DummyObject, requires_backends\n\n"
										dummy_file += "\n".join([create_dummy_object(__snake_case,     __snake_case	) for o in objects]	)
										_UpperCamelCase							 =  dummy_file

					return dummy_files



def       lowerCamelCase__		(			__snake_case=False	)							->		Any:


					"""simple docstring"""





					_UpperCamelCase							 =  create_dummy_files()
					# For special correspondence backend to shortcut as used in utils/dummy_xxx_objects.py
					_UpperCamelCase							 =  {'''torch''': '''pt'''}

					# Locate actual dummy modules and read their content.
					_UpperCamelCase							 =  os.path.join(__snake_case,     '''utils'''	)
					_UpperCamelCase							 =  {
					    backend: os.path.join(__snake_case,     F'''dummy_{short_names.get(__snake_case,     __snake_case	)}_objects.py'''	)
					    for backend in dummy_files.keys()
					}

					_UpperCamelCase							 =  {}
					for backend, file_path in dummy_file_paths.items():
										if os.path.isfile(__snake_case	):
															with open(__snake_case,     '''r''',     encoding='''utf-8''',     newline='''\n'''	) as f:
																				_UpperCamelCase							 =  f.read()
										else:
															_UpperCamelCase							 =  ''''''

					for backend in dummy_files.keys():
										if dummy_files[backend] != actual_dummies[backend]:
															if overwrite:
																				print(
																				    F'''Updating diffusers.utils.dummy_{short_names.get(__snake_case,     __snake_case	)}_objects.py as the main '''
																				    '''__init__ has new objects.'''	)
																				with open(dummy_file_paths[backend],     '''w''',     encoding='''utf-8''',     newline='''\n'''	) as f:
																									f.write(dummy_files[backend]	)
															else:
																				raise ValueError(
																				    '''The main __init__ has objects that are not present in '''
																				    F'''diffusers.utils.dummy_{short_names.get(__snake_case,     __snake_case	)}_objects.py. Run `make fix-copies` '''
																				    '''to fix this.'''	)


if __name__ == "__main__":
				_a														=		argparse.ArgumentParser()
				parser.add_argument("""--fix_and_overwrite""", action="""store_true""", help="""Whether to fix inconsistencies.""")
				_a														=		parser.parse_args()

				check_dummies(args.fix_and_overwrite)








"""simple docstring"""





from collections import defaultdict






class     _UpperCAmelCase:



		def __init__(					self				,		__a				,		__a)       ->       Union[str, Any]:






							'''simple docstring'''
							_UpperCamelCase							 =  total  # total no of tasks (N)

							# DP table will have a dimension of (2^M)*N
							# initially all values are set to -1
							_UpperCamelCase							 =  [
							    [-1 for i in range(total + 1)] for j in range(2 ** len(__a))
							]

							_UpperCamelCase							 =  defaultdict(__a)  # stores the list of persons for each task

							# final_mask is used to check if all persons are included by setting all bits
							# to 1
							_UpperCamelCase							 =  (1 << len(__a)) - 1



		def 						UpperCAmelCase							(					self				,		__a				,		__a)       ->       Dict:






							'''simple docstring'''
							# if mask == self.finalmask all persons are distributed tasks, return 1
							if mask == self.final_mask:
												return 1

							# if not everyone gets the task and no more tasks are available, return 0
							if task_no > self.total_tasks:
												return 0

							# if case already considered
							if self.dp[mask][task_no] != -1:
												return self.dp[mask][task_no]

							# Number of ways when we don't this task in the arrangement
							_UpperCamelCase							 =  self.count_ways_until(__a				,		task_no + 1)

							# now assign the tasks one by one to all possible persons and recursively
							# assign for the remaining tasks.
							if task_no in self.task:
												for p in self.task[task_no]:
																	# if p is already given a task
																	if mask & (1 << p):
																						continue

																	# assign this task to p and change the mask value. And recursively
																	# assign tasks with the new mask value.
																	total_ways_util += self.count_ways_until(mask | (1 << p)				,		task_no + 1)

        # save the value.
							_UpperCamelCase							 =  total_ways_util

							return self.dp[mask][task_no]




		def 						UpperCAmelCase							(					self				,		__a)       ->       int:






							'''simple docstring'''
							# Store the list of persons for each task
							for i in range(len(__a)):
												for j in task_performed[i]:
																	self.task[j].append(__a)

        # call the function to fill the DP table, final answer is stored in dp[0][1]
							return self.count_ways_until(0				,		1)


if __name__ == "__main__":
				_a														=		5  # total no of tasks (the value of N)

				# the list of tasks that can be done by M persons.
				_a														=		[[1, 3, 4], [1, 2, 5], [3, 4]]
				print(
				    AssignmentUsingBitmask(task_performed, total_tasks).count_no_of_ways(
				        task_performed
				    )
				)






