






from collections import defaultdict



class   lowerCamelCase				:







		'''simple docstring'''



		def __init__(							self    ,		_UpperCamelCase    ,		_UpperCamelCase       )     ->							int:
							UpperCAmelCase_   :				List[Any]						=						total  # total no of tasks (N)

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

							UpperCAmelCase_   :				Optional[int]						=						defaultdict(SCREAMING_SNAKE_CASE_       )  # 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_   :				Dict						=						(1 << len(SCREAMING_SNAKE_CASE_       )) - 1



		def  __UpperCAmelCase      (							self    ,		_UpperCamelCase    ,		_UpperCamelCase       )     ->							List[Any]:
							# 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_   :				str						=						self.count_ways_until(SCREAMING_SNAKE_CASE_    ,		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_   :				List[str]						=						total_ways_util

							return self.dp[mask][task_no]



		def  __UpperCAmelCase      (							self    ,		_UpperCamelCase       )     ->							Any:
							# Store the list of persons for each task
							for i in range(len(SCREAMING_SNAKE_CASE_       )       ):
												for j in task_performed[i]:
																	self.task[j].append(SCREAMING_SNAKE_CASE_       )

        # 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__":
		__UpperCAmelCase     							=						5  # total no of tasks (the value of N)

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














from __future__ import annotations

from collections.abc import Callable

__UpperCAmelCase     							=						list[list[float | int]]




def 					lowercase__				(					__snake_case   :							Matrix					,	__snake_case   :							Matrix  ):


					'''simple docstring'''


					UpperCAmelCase_   :				int						=						len(__snake_case  )
					UpperCAmelCase_   :				Matrix						=						[[0 for _ in range(size + 1  )] for _ in range(__snake_case  )]
					UpperCAmelCase_   :				int
					UpperCAmelCase_   :				int
					UpperCAmelCase_   :				int
					UpperCAmelCase_   :				int
					UpperCAmelCase_   :				int
					UpperCAmelCase_   :				float

					for row in range(__snake_case  ):
										for col in range(__snake_case  ):
															UpperCAmelCase_   :				Dict						=						matrix[row][col]

										UpperCAmelCase_   :				Union[str, Any]						=						vector[row][0]

					UpperCAmelCase_   :				Union[str, Any]						=						0
					UpperCAmelCase_   :				Union[str, Any]						=						0
					while row < size and col < size:
										# pivoting
										UpperCAmelCase_   :				Optional[Any]						=						max((abs(augmented[rowa][col]  ), rowa) for rowa in range(__snake_case					,	__snake_case  )  )[
										    1
										]
										if augmented[pivot_row][col] == 0:
															col += 1
															continue
										else:
															UpperCAmelCase_	,  UpperCAmelCase_   :				Tuple						=						augmented[pivot_row], augmented[row]

										for rowa in range(row + 1					,	__snake_case  ):
															UpperCAmelCase_   :				Optional[int]						=						augmented[rowa][col] / augmented[row][col]
															UpperCAmelCase_   :				List[str]						=						0
															for cola in range(col + 1					,	size + 1  ):
																				augmented[rowa][cola] -= augmented[row][cola] * ratio

										row += 1
										col += 1

					# back substitution
					for col in range(1					,	__snake_case  ):
										for row in range(__snake_case  ):
															UpperCAmelCase_   :				Union[str, Any]						=						augmented[row][col] / augmented[col][col]
															for cola in range(__snake_case					,	size + 1  ):
																				augmented[row][cola] -= augmented[col][cola] * ratio

    # round to get rid of numbers like 2.000000000000004
					return [
					    [round(augmented[row][size] / augmented[row][row]					,	10  )] for row in range(__snake_case  )
					]




def 					lowercase__				(					__snake_case   :							list[int]  ):


					'''simple docstring'''


					UpperCAmelCase_   :				int						=						len(__snake_case  )
					UpperCAmelCase_   :				Matrix						=						[[0 for _ in range(__snake_case  )] for _ in range(__snake_case  )]
					UpperCAmelCase_   :				Matrix						=						[[0] for _ in range(__snake_case  )]
					UpperCAmelCase_   :				Matrix
					UpperCAmelCase_   :				int
					UpperCAmelCase_   :				int
					UpperCAmelCase_   :				int

					for x_val, y_val in enumerate(__snake_case  ):
										for col in range(__snake_case  ):
															UpperCAmelCase_   :				int						=						(x_val + 1) ** (size - col - 1)
										UpperCAmelCase_   :				int						=						y_val

					UpperCAmelCase_   :				List[str]						=						solve(__snake_case					,	__snake_case  )

					def interpolated_func(__snake_case   :							int  ) -> int:
										return sum(
										    round(coeffs[x_val][0]  ) * (var ** (size - x_val - 1))
										    for x_val in range(__snake_case  )  )

					return interpolated_func




def 					lowercase__				(					__snake_case   :							int  ):


					'''simple docstring'''


					return (
					    1
					    - variable
					    + variable**2
					    - variable**3
					    + variable**4
					    - variable**5
					    + variable**6
					    - variable**7
					    + variable**8
					    - variable**9
					    + variable**10
					)




def 					lowercase__				(					__snake_case   :							Callable[[int], int] = question_function					,	__snake_case   :							int = 10  ):


					'''simple docstring'''


					UpperCAmelCase_   :				list[int]						=						[func(__snake_case  ) for x_val in range(1					,	order + 1  )]

					UpperCAmelCase_   :				list[Callable[[int], int]]						=						[
					    interpolate(data_points[:max_coeff]  ) for max_coeff in range(1					,	order + 1  )
					]

					UpperCAmelCase_   :				int						=						0
					UpperCAmelCase_   :				Callable[[int], int]
					UpperCAmelCase_   :				int

					for poly in polynomials:
										UpperCAmelCase_   :				Optional[int]						=						1
										while func(__snake_case  ) == poly(__snake_case  ):
															x_val += 1

										ret += poly(__snake_case  )

					return ret


if __name__ == "__main__":
		print(F'{solution() = }')






