






from math import sqrt



def 					_lowerCamelCase(			lowerCAmelCase__				:		int      ):





				'''simple docstring'''







				assert isinstance(lowerCAmelCase__    ,    lowerCAmelCase__      ) and (
				    number >= 0
				), "'number' must been an int and positive"

				SCREAMING_SNAKE_CASE_   :	Dict													=   True

				# 0 and 1 are none primes.
				if number <= 1:
								SCREAMING_SNAKE_CASE_   :	Optional[int]													=   False

				for divisor in range(2    ,    int(round(sqrt(lowerCAmelCase__      )      )      ) + 1      ):
								# if 'number' divisible by 'divisor' then sets 'status'
								# of false and break up the loop.
								if number % divisor == 0:
												SCREAMING_SNAKE_CASE_   :	Dict													=   False
												break

    # precondition
				assert isinstance(lowerCAmelCase__    ,    lowerCAmelCase__      ), "'status' must been from type bool"

				return status



def 					_lowerCamelCase(			lowerCAmelCase__				:		int      ):





				'''simple docstring'''







				assert isinstance(lowerCAmelCase__    ,    lowerCAmelCase__      ) and (n > 2), "'N' must been an int and > 2"

				# beginList: contains all natural numbers from 2 up to N
				SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   list(range(2    ,    n + 1      )      )

				SCREAMING_SNAKE_CASE_   :	Any													=   []  # this list will be returns.

				# actual sieve of erathostenes
				for i in range(len(lowerCAmelCase__      )      ):
								for j in range(i + 1    ,    len(lowerCAmelCase__      )      ):
												if (begin_list[i] != 0) and (begin_list[j] % begin_list[i] == 0):
																SCREAMING_SNAKE_CASE_   :	str													=   0

    # filters actual prime numbers.
				SCREAMING_SNAKE_CASE_   :	int													=   [x for x in begin_list if x != 0]

				# precondition
				assert isinstance(lowerCAmelCase__    ,    lowerCAmelCase__      ), "'ans' must been from type list"

				return ans



def 					_lowerCamelCase(			lowerCAmelCase__				:		List[str]      ):





				'''simple docstring'''







				assert isinstance(lowerCAmelCase__    ,    lowerCAmelCase__      ) and (n > 2), "'N' must been an int and > 2"

				SCREAMING_SNAKE_CASE_   :	int													=   []

				# iterates over all numbers between 2 up to N+1
				# if a number is prime then appends to list 'ans'
				for number in range(2    ,    n + 1      ):
								if is_prime(lowerCAmelCase__      ):
												ans.append(lowerCAmelCase__      )

    # precondition
				assert isinstance(lowerCAmelCase__    ,    lowerCAmelCase__      ), "'ans' must been from type list"

				return ans



def 					_lowerCamelCase(			lowerCAmelCase__				:		Union[str, Any]      ):





				'''simple docstring'''







				assert isinstance(lowerCAmelCase__    ,    lowerCAmelCase__      ) and number >= 0, "'number' must been an int and >= 0"

				SCREAMING_SNAKE_CASE_   :	Optional[int]													=   []  # this list will be returns of the function.

				# potential prime number factors.

				SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   2

				SCREAMING_SNAKE_CASE_   :	List[Any]													=   number

				if number == 0 or number == 1:
								ans.append(lowerCAmelCase__      )

				# if 'number' not prime then builds the prime factorization of 'number'
				elif not is_prime(lowerCAmelCase__      ):
								while quotient != 1:
												if is_prime(lowerCAmelCase__      ) and (quotient % factor == 0):
																ans.append(lowerCAmelCase__      )
																quotient /= factor
												else:
																factor += 1

				else:
								ans.append(lowerCAmelCase__      )

				# precondition
				assert isinstance(lowerCAmelCase__    ,    lowerCAmelCase__      ), "'ans' must been from type list"

				return ans



def 					_lowerCamelCase(			lowerCAmelCase__				:		Any      ):





				'''simple docstring'''







				assert isinstance(lowerCAmelCase__    ,    lowerCAmelCase__      ) and (
				    number >= 0
				), "'number' bust been an int and >= 0"

				SCREAMING_SNAKE_CASE_   :	int													=   0

				# prime factorization of 'number'
				SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   prime_factorization(lowerCAmelCase__      )

				SCREAMING_SNAKE_CASE_   :	Dict													=   max(lowerCAmelCase__      )

				# precondition
				assert isinstance(lowerCAmelCase__    ,    lowerCAmelCase__      ), "'ans' must been from type int"

				return ans



def 					_lowerCamelCase(			lowerCAmelCase__				:		Optional[Any]      ):





				'''simple docstring'''







				assert isinstance(lowerCAmelCase__    ,    lowerCAmelCase__      ) and (
				    number >= 0
				), "'number' bust been an int and >= 0"

				SCREAMING_SNAKE_CASE_   :	Optional[int]													=   0

				# prime factorization of 'number'
				SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   prime_factorization(lowerCAmelCase__      )

				SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   min(lowerCAmelCase__      )

				# precondition
				assert isinstance(lowerCAmelCase__    ,    lowerCAmelCase__      ), "'ans' must been from type int"

				return ans



def 					_lowerCamelCase(			lowerCAmelCase__				:		Optional[int]      ):





				'''simple docstring'''







				assert isinstance(lowerCAmelCase__    ,    lowerCAmelCase__      ), "'number' must been an int"
				assert isinstance(number % 2 == 0    ,    lowerCAmelCase__      ), "compare bust been from type bool"

				return number % 2 == 0



def 					_lowerCamelCase(			lowerCAmelCase__				:		Optional[int]      ):





				'''simple docstring'''







				assert isinstance(lowerCAmelCase__    ,    lowerCAmelCase__      ), "'number' must been an int"
				assert isinstance(number % 2 != 0    ,    lowerCAmelCase__      ), "compare bust been from type bool"

				return number % 2 != 0



def 					_lowerCamelCase(			lowerCAmelCase__				:		Optional[Any]      ):





				'''simple docstring'''







				assert (
				    isinstance(lowerCAmelCase__    ,    lowerCAmelCase__      ) and (number > 2) and is_even(lowerCAmelCase__      )
				), "'number' must been an int, even and > 2"

				SCREAMING_SNAKE_CASE_   :	Any													=   []  # this list will returned

				# creates a list of prime numbers between 2 up to 'number'
				SCREAMING_SNAKE_CASE_   :	int													=   get_prime_numbers(lowerCAmelCase__      )
				SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   len(lowerCAmelCase__      )

				# run variable for while-loops.
				SCREAMING_SNAKE_CASE_   :	Any													=   0
				SCREAMING_SNAKE_CASE_   :	List[str]													=   None

				# exit variable. for break up the loops
				SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   True

				while i < len_pn and loop:
								SCREAMING_SNAKE_CASE_   :	Optional[int]													=   i + 1

								while j < len_pn and loop:
												if prime_numbers[i] + prime_numbers[j] == number:
																SCREAMING_SNAKE_CASE_   :	List[str]													=   False
																ans.append(prime_numbers[i]      )
																ans.append(prime_numbers[j]      )

												j += 1

								i += 1

				# precondition
				assert (
				    isinstance(lowerCAmelCase__    ,    lowerCAmelCase__      )
				    and (len(lowerCAmelCase__      ) == 2)
				    and (ans[0] + ans[1] == number)
				    and is_prime(ans[0]      )
				    and is_prime(ans[1]      )
				), "'ans' must contains two primes. And sum of elements must been eq 'number'"

				return ans



def 					_lowerCamelCase(			lowerCAmelCase__				:		str    ,    lowerCAmelCase__				:		List[Any]      ):





				'''simple docstring'''







				assert (
				    isinstance(lowerCAmelCase__    ,    lowerCAmelCase__      )
				    and isinstance(lowerCAmelCase__    ,    lowerCAmelCase__      )
				    and (numbera >= 0)
				    and (numbera >= 0)
				), "'number1' and 'number2' must been positive integer."

				SCREAMING_SNAKE_CASE_   :	int													=   0

				while numbera != 0:
								SCREAMING_SNAKE_CASE_   :	List[str]													=   numbera % numbera
								SCREAMING_SNAKE_CASE_   :	Optional[int]													=   numbera
								SCREAMING_SNAKE_CASE_   :	List[Any]													=   rest

				# precondition
				assert isinstance(lowerCAmelCase__    ,    lowerCAmelCase__      ) and (
				    numbera >= 0
				), "'number' must been from type int and positive"

				return numbera



def 					_lowerCamelCase(			lowerCAmelCase__				:		int    ,    lowerCAmelCase__				:		Optional[Any]      ):





				'''simple docstring'''







				assert (
				    isinstance(lowerCAmelCase__    ,    lowerCAmelCase__      )
				    and isinstance(lowerCAmelCase__    ,    lowerCAmelCase__      )
				    and (numbera >= 1)
				    and (numbera >= 1)
				), "'number1' and 'number2' must been positive integer."

				SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   1  # actual answer that will be return.

				# for kgV (x,1)
				if numbera > 1 and numbera > 1:
								# builds the prime factorization of 'number1' and 'number2'
								SCREAMING_SNAKE_CASE_   :	Tuple													=   prime_factorization(lowerCAmelCase__      )
								SCREAMING_SNAKE_CASE_   :	List[Any]													=   prime_factorization(lowerCAmelCase__      )

				elif numbera == 1 or numbera == 1:
								SCREAMING_SNAKE_CASE_   :	List[Any]													=   []
								SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   []
								SCREAMING_SNAKE_CASE_   :	int													=   max(lowerCAmelCase__    ,    lowerCAmelCase__      )

				SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   0
				SCREAMING_SNAKE_CASE_   :	Any													=   0

				SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   []  # captured numbers int both 'primeFac1' and 'primeFac2'

				# iterates through primeFac1
				for n in prime_fac_a:
								if n not in done:
												if n in prime_fac_a:
																SCREAMING_SNAKE_CASE_   :	int													=   prime_fac_a.count(lowerCAmelCase__      )
																SCREAMING_SNAKE_CASE_   :	Tuple													=   prime_fac_a.count(lowerCAmelCase__      )

																for _ in range(max(lowerCAmelCase__    ,    lowerCAmelCase__      )      ):
																				ans *= n

												else:
																SCREAMING_SNAKE_CASE_   :	List[Any]													=   prime_fac_a.count(lowerCAmelCase__      )

																for _ in range(lowerCAmelCase__      ):
																				ans *= n

												done.append(lowerCAmelCase__      )

    # iterates through primeFac2
				for n in prime_fac_a:
								if n not in done:
												SCREAMING_SNAKE_CASE_   :	int													=   prime_fac_a.count(lowerCAmelCase__      )

												for _ in range(lowerCAmelCase__      ):
																ans *= n

												done.append(lowerCAmelCase__      )

    # precondition
				assert isinstance(lowerCAmelCase__    ,    lowerCAmelCase__      ) and (
				    ans >= 0
				), "'ans' must been from type int and positive"

				return ans



def 					_lowerCamelCase(			lowerCAmelCase__				:		Any      ):





				'''simple docstring'''







				assert isinstance(lowerCAmelCase__    ,    lowerCAmelCase__      ) and (n >= 0), "'number' must been a positive int"

				SCREAMING_SNAKE_CASE_   :	Optional[int]													=   0
				SCREAMING_SNAKE_CASE_   :	Optional[int]													=   2  # this variable holds the answer

				while index < n:
								index += 1

								ans += 1  # counts to the next number

								# if ans not prime then
								# runs to the next prime number.
								while not is_prime(lowerCAmelCase__      ):
												ans += 1

    # precondition
				assert isinstance(lowerCAmelCase__    ,    lowerCAmelCase__      ) and is_prime(
				    lowerCAmelCase__      ), "'ans' must been a prime number and from type int"

				return ans



def 					_lowerCamelCase(			lowerCAmelCase__				:		List[str]    ,    lowerCAmelCase__				:		Optional[int]      ):





				'''simple docstring'''







				assert (
				    is_prime(lowerCAmelCase__      ) and is_prime(lowerCAmelCase__      ) and (p_number_a < p_number_a)
				), "The arguments must been prime numbers and 'pNumber1' < 'pNumber2'"

				SCREAMING_SNAKE_CASE_   :	str													=   p_number_a + 1  # jump to the next number

				SCREAMING_SNAKE_CASE_   :	List[Any]													=   []  # this list will be returns.

				# if number is not prime then
				# fetch the next prime number.
				while not is_prime(lowerCAmelCase__      ):
								number += 1

				while number < p_number_a:
								ans.append(lowerCAmelCase__      )

								number += 1

								# fetch the next prime number.
								while not is_prime(lowerCAmelCase__      ):
												number += 1

    # precondition
				assert (
				    isinstance(lowerCAmelCase__    ,    lowerCAmelCase__      )
				    and ans[0] != p_number_a
				    and ans[len(lowerCAmelCase__      ) - 1] != p_number_a
				), "'ans' must been a list without the arguments"

				# 'ans' contains not 'pNumber1' and 'pNumber2' !
				return ans



def 					_lowerCamelCase(			lowerCAmelCase__				:		Optional[Any]      ):





				'''simple docstring'''







				assert isinstance(lowerCAmelCase__    ,    lowerCAmelCase__      ) and (n >= 1), "'n' must been int and >= 1"

				SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   []  # will be returned.

				for divisor in range(1    ,    n + 1      ):
								if n % divisor == 0:
												ans.append(lowerCAmelCase__      )

    # precondition
				assert ans[0] == 1 and ans[len(lowerCAmelCase__      ) - 1] == n, "Error in function getDivisiors(...)"

				return ans



def 					_lowerCamelCase(			lowerCAmelCase__				:		int      ):





				'''simple docstring'''







				assert isinstance(lowerCAmelCase__    ,    lowerCAmelCase__      ) and (
				    number > 1
				), "'number' must been an int and >= 1"

				SCREAMING_SNAKE_CASE_   :	int													=   get_divisors(lowerCAmelCase__      )

				# precondition
				assert (
				    isinstance(lowerCAmelCase__    ,    lowerCAmelCase__      )
				    and (divisors[0] == 1)
				    and (divisors[len(lowerCAmelCase__      ) - 1] == number)
				), "Error in help-function getDivisiors(...)"

				# summed all divisors up to 'number' (exclusive), hence [:-1]
				return sum(divisors[:-1]      ) == number



def 					_lowerCamelCase(			lowerCAmelCase__				:		Dict    ,    lowerCAmelCase__				:		str      ):





				'''simple docstring'''







				assert (
				    isinstance(lowerCAmelCase__    ,    lowerCAmelCase__      )
				    and isinstance(lowerCAmelCase__    ,    lowerCAmelCase__      )
				    and (denominator != 0)
				), "The arguments must been from type int and 'denominator' != 0"

				# build the greatest common divisor of numerator and denominator.
				SCREAMING_SNAKE_CASE_   :	str													=   gcd(abs(lowerCAmelCase__      )    ,    abs(lowerCAmelCase__      )      )

				# precondition
				assert (
				    isinstance(lowerCAmelCase__    ,    lowerCAmelCase__      )
				    and (numerator % gcd_of_fraction == 0)
				    and (denominator % gcd_of_fraction == 0)
				), "Error in function gcd(...,...)"

				return (numerator // gcd_of_fraction, denominator // gcd_of_fraction)



def 					_lowerCamelCase(			lowerCAmelCase__				:		Tuple      ):





				'''simple docstring'''







				assert isinstance(lowerCAmelCase__    ,    lowerCAmelCase__      ) and (n >= 0), "'n' must been a int and >= 0"

				SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   1  # this will be return.

				for factor in range(1    ,    n + 1      ):
								ans *= factor

				return ans



def 					_lowerCamelCase(			lowerCAmelCase__				:		Tuple      ):





				'''simple docstring'''







				assert isinstance(lowerCAmelCase__    ,    lowerCAmelCase__      ) and (n >= 0), "'n' must been an int and >= 0"

				SCREAMING_SNAKE_CASE_   :	List[Any]													=   0
				SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   1
				SCREAMING_SNAKE_CASE_   :	int													=   1  # this will be return

				for _ in range(n - 1      ):
								SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   ans
								ans += fiba
								SCREAMING_SNAKE_CASE_   :	List[str]													=   tmp

				return ans







from abc import ABC, abstractmethod
from typing import List, Optional


class 							__a							(  __A						):





		'''simple docstring'''



		def __init__(						self       ):
						# test for the above condition
						self.test()


		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	Tuple													=   0
						SCREAMING_SNAKE_CASE_   :	Dict													=   False
						while not completed:
										if counter == 1:
														self.reset()
										SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   self.advance()
										if not self.does_advance(UpperCamelCase__       ):
														raise Exception(
														    'Custom Constraint is not defined correctly. self.does_advance(self.advance()) must be true.'       )

										SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_   :	Any													=   self.update(UpperCamelCase__       )
										counter += 1

										if counter > 10000:
														raise Exception('update() does not fulfill the constraint.'       )

						if self.remaining() != 0:
										raise Exception('Custom Constraint is not defined correctly.'       )


		@abstractmethod
		def   __snake_case			(						self       ):
						raise NotImplementedError(
						    F'''{self.__class__} is an abstract class. Only classes inheriting this class can be called.'''       )


		@abstractmethod
		def   __snake_case			(						self ,    UpperCamelCase__       ):
						raise NotImplementedError(
						    F'''{self.__class__} is an abstract class. Only classes inheriting this class can be called.'''       )


		@abstractmethod
		def   __snake_case			(						self ,    UpperCamelCase__       ):
						raise NotImplementedError(
						    F'''{self.__class__} is an abstract class. Only classes inheriting this class can be called.'''       )


		@abstractmethod
		def   __snake_case			(						self       ):
						raise NotImplementedError(
						    F'''{self.__class__} is an abstract class. Only classes inheriting this class can be called.'''       )


		@abstractmethod
		def   __snake_case			(						self       ):
						raise NotImplementedError(
						    F'''{self.__class__} is an abstract class. Only classes inheriting this class can be called.'''       )






		@abstractmethod
		def   __snake_case			(						self ,    UpperCamelCase__=False       ):
						raise NotImplementedError(
						    F'''{self.__class__} is an abstract class. Only classes inheriting this class can be called.'''       )






class 							__a							(  __A						):





		'''simple docstring'''



		def __init__(						self ,    UpperCamelCase__       ):
						super(UpperCamelCase__ ,    self       ).__init__()

						if not isinstance(UpperCamelCase__ ,    UpperCamelCase__       ) or len(UpperCamelCase__       ) == 0:
										raise ValueError(F'''`token_ids` has to be a non-empty list, but is {token_ids}.'''       )
						if any((not isinstance(UpperCamelCase__ ,    UpperCamelCase__       ) or token_id < 0) for token_id in token_ids       ):
										raise ValueError(F'''Each list in `token_ids` has to be a list of positive integers, but is {token_ids}.'''       )

						SCREAMING_SNAKE_CASE_   :	List[str]													=   token_ids

						SCREAMING_SNAKE_CASE_   :	Tuple													=   len(self.token_ids       )
						SCREAMING_SNAKE_CASE_   :	Any													=   -1  # the index of the currently fulfilled step
						SCREAMING_SNAKE_CASE_   :	Any													=   False


		def   __snake_case			(						self       ):
						if self.completed:
										return None
						return self.token_ids[self.fulfilled_idx + 1]


		def   __snake_case			(						self ,    UpperCamelCase__       ):
						if not isinstance(UpperCamelCase__ ,    UpperCamelCase__       ):
										raise ValueError(F'''`token_id` has to be an `int`, but is {token_id} of type {type(UpperCamelCase__       )}'''       )

						if self.completed:
										return False

						return token_id == self.token_ids[self.fulfilled_idx + 1]


		def   __snake_case			(						self ,    UpperCamelCase__       ):
						if not isinstance(UpperCamelCase__ ,    UpperCamelCase__       ):
										raise ValueError(F'''`token_id` has to be an `int`, but is {token_id} of type {type(UpperCamelCase__       )}'''       )

						SCREAMING_SNAKE_CASE_   :	Optional[int]													=   False
						SCREAMING_SNAKE_CASE_   :	Optional[int]													=   False
						SCREAMING_SNAKE_CASE_   :	List[Any]													=   False

						if self.does_advance(UpperCamelCase__       ):
										self.fulfilled_idx += 1
										SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   True
										if self.fulfilled_idx == (self.seqlen - 1):
														SCREAMING_SNAKE_CASE_   :	Dict													=   True
										SCREAMING_SNAKE_CASE_   :	List[str]													=   completed
						else:
										# failed to make progress.
										SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   True
										self.reset()
						return stepped, completed, reset


		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	Optional[int]													=   False
						SCREAMING_SNAKE_CASE_   :	List[str]													=   0


		def   __snake_case			(						self       ):
						return self.seqlen - (self.fulfilled_idx + 1)






		def   __snake_case			(						self ,    UpperCamelCase__=False       ):
						SCREAMING_SNAKE_CASE_   :	str													=   PhrasalConstraint(self.token_ids       )

						if stateful:
										SCREAMING_SNAKE_CASE_   :	List[Any]													=   self.seqlen
										SCREAMING_SNAKE_CASE_   :	Any													=   self.fulfilled_idx
										SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   self.completed

						return new_constraint






class 							__a							:





		'''simple docstring'''



		def __init__(						self ,    UpperCamelCase__ ,    UpperCamelCase__=True       ):
						SCREAMING_SNAKE_CASE_   :	Optional[int]													=   max([len(UpperCamelCase__       ) for one in nested_token_ids]       )

						SCREAMING_SNAKE_CASE_   :	List[Any]													=   {}
						for token_ids in nested_token_ids:
										SCREAMING_SNAKE_CASE_   :	Dict													=   root
										for tidx, token_id in enumerate(UpperCamelCase__       ):
														if token_id not in level:
																		SCREAMING_SNAKE_CASE_   :	Tuple													=   {}

														SCREAMING_SNAKE_CASE_   :	List[str]													=   level[token_id]

						if no_subsets and self.has_subsets(UpperCamelCase__ ,    UpperCamelCase__       ):
										raise ValueError(
										    'Each list in `nested_token_ids` can\'t be a complete subset of another list, but is'
										    F''' {nested_token_ids}.'''       )

						SCREAMING_SNAKE_CASE_   :	Tuple													=   root


		def   __snake_case			(						self ,    UpperCamelCase__       ):
						SCREAMING_SNAKE_CASE_   :	int													=   self.trie

						for current_token in current_seq:
										SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   start[current_token]

						SCREAMING_SNAKE_CASE_   :	Optional[int]													=   list(start.keys()       )

						return next_tokens


		def   __snake_case			(						self ,    UpperCamelCase__       ):
						SCREAMING_SNAKE_CASE_   :	List[Any]													=   self.next_tokens(UpperCamelCase__       )

						return len(UpperCamelCase__       ) == 0


		def   __snake_case			(						self ,    UpperCamelCase__       ):
						SCREAMING_SNAKE_CASE_   :	List[str]													=   list(root.values()       )
						if len(UpperCamelCase__       ) == 0:
										return 1
						else:
										return sum([self.count_leaves(UpperCamelCase__       ) for nn in next_nodes]       )






		def   __snake_case			(						self ,    UpperCamelCase__ ,    UpperCamelCase__       ):
						SCREAMING_SNAKE_CASE_   :	Dict													=   self.count_leaves(UpperCamelCase__       )
						return len(UpperCamelCase__       ) != leaf_count






class 							__a							(  __A						):





		'''simple docstring'''



		def __init__(						self ,    UpperCamelCase__       ):
						super(UpperCamelCase__ ,    self       ).__init__()

						if not isinstance(UpperCamelCase__ ,    UpperCamelCase__       ) or len(UpperCamelCase__       ) == 0:
										raise ValueError(F'''`nested_token_ids` has to be a non-empty list, but is {nested_token_ids}.'''       )
						if any(not isinstance(UpperCamelCase__ ,    UpperCamelCase__       ) for token_ids in nested_token_ids       ):
										raise ValueError(F'''`nested_token_ids` has to be a list of lists, but is {nested_token_ids}.'''       )
						if any(
						    any((not isinstance(UpperCamelCase__ ,    UpperCamelCase__       ) or token_id < 0) for token_id in token_ids       )
						    for token_ids in nested_token_ids       ):
										raise ValueError(
										    F'''Each list in `nested_token_ids` has to be a list of positive integers, but is {nested_token_ids}.'''       )

						SCREAMING_SNAKE_CASE_   :	Optional[int]													=   DisjunctiveTrie(UpperCamelCase__       )
						SCREAMING_SNAKE_CASE_   :	Dict													=   nested_token_ids

						SCREAMING_SNAKE_CASE_   :	List[str]													=   self.trie.max_height
						SCREAMING_SNAKE_CASE_   :	str													=   []
						SCREAMING_SNAKE_CASE_   :	List[str]													=   False


		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	List[str]													=   self.trie.next_tokens(self.current_seq       )

						if len(UpperCamelCase__       ) == 0:
										return None
						else:
										return token_list


		def   __snake_case			(						self ,    UpperCamelCase__       ):
						if not isinstance(UpperCamelCase__ ,    UpperCamelCase__       ):
										raise ValueError(F'''`token_id` is supposed to be type `int`, but is {token_id} of type {type(UpperCamelCase__       )}'''       )

						SCREAMING_SNAKE_CASE_   :	str													=   self.trie.next_tokens(self.current_seq       )

						return token_id in next_tokens


		def   __snake_case			(						self ,    UpperCamelCase__       ):
						if not isinstance(UpperCamelCase__ ,    UpperCamelCase__       ):
										raise ValueError(F'''`token_id` is supposed to be type `int`, but is {token_id} of type {type(UpperCamelCase__       )}'''       )

						SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   False
						SCREAMING_SNAKE_CASE_   :	Tuple													=   False
						SCREAMING_SNAKE_CASE_   :	Dict													=   False

						if self.does_advance(UpperCamelCase__       ):
										self.current_seq.append(UpperCamelCase__       )
										SCREAMING_SNAKE_CASE_   :	int													=   True
						else:
										SCREAMING_SNAKE_CASE_   :	Tuple													=   True
										self.reset()

						SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   self.trie.reached_leaf(self.current_seq       )
						SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   completed

						return stepped, completed, reset


		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	List[Any]													=   False
						SCREAMING_SNAKE_CASE_   :	Dict													=   []


		def   __snake_case			(						self       ):
						if self.completed:
										# since this can be completed without reaching max height
										return 0
						else:
										return self.seqlen - len(self.current_seq       )






		def   __snake_case			(						self ,    UpperCamelCase__=False       ):
						SCREAMING_SNAKE_CASE_   :	Any													=   DisjunctiveConstraint(self.token_ids       )

						if stateful:
										SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   self.seqlen
										SCREAMING_SNAKE_CASE_   :	Optional[int]													=   self.current_seq
										SCREAMING_SNAKE_CASE_   :	List[str]													=   self.completed

						return new_constraint






class 							__a							:





		'''simple docstring'''



		def __init__(						self ,    UpperCamelCase__       ):
						SCREAMING_SNAKE_CASE_   :	Any													=   constraints

						# max # of steps required to fulfill a given constraint
						SCREAMING_SNAKE_CASE_   :	Dict													=   max([c.seqlen for c in constraints]       )
						SCREAMING_SNAKE_CASE_   :	Tuple													=   len(UpperCamelCase__       )
						SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   False

						self.init_state()


		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	List[Any]													=   []
						SCREAMING_SNAKE_CASE_   :	int													=   None
						SCREAMING_SNAKE_CASE_   :	Optional[int]													=   [constraint.copy(stateful=UpperCamelCase__       ) for constraint in self.constraints]


		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   0
						if self.inprogress_constraint:
										# extra points for having a constraint mid-fulfilled
										add += self.max_seqlen - self.inprogress_constraint.remaining()

						return (len(self.complete_constraints       ) * self.max_seqlen) + add


		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   []
						if self.inprogress_constraint is None:
										for constraint in self.pending_constraints:  # "pending" == "unfulfilled yet"
														SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   constraint.advance()
														if isinstance(UpperCamelCase__ ,    UpperCamelCase__       ):
																		token_list.append(UpperCamelCase__       )
														elif isinstance(UpperCamelCase__ ,    UpperCamelCase__       ):
																		token_list.extend(UpperCamelCase__       )
						else:
										SCREAMING_SNAKE_CASE_   :	List[str]													=   self.inprogress_constraint.advance()
										if isinstance(UpperCamelCase__ ,    UpperCamelCase__       ):
														token_list.append(UpperCamelCase__       )
										elif isinstance(UpperCamelCase__ ,    UpperCamelCase__       ):
														token_list.extend(UpperCamelCase__       )

						if len(UpperCamelCase__       ) == 0:
										return None
						else:
										return token_list


		def   __snake_case			(						self ,    UpperCamelCase__       ):
						self.init_state()

						if token_ids is not None:
										for token in token_ids:
														# completes or steps **one** constraint
														SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_   :	str													=   self.add(UpperCamelCase__       )

														# the entire list of constraints are fulfilled
														if self.completed:
																		break


		def   __snake_case			(						self ,    UpperCamelCase__       ):
						if not isinstance(UpperCamelCase__ ,    UpperCamelCase__       ):
										raise ValueError(F'''`token_id` should be an `int`, but is `{token_id}`.'''       )

						SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_   :	Dict													=   False, False

						if self.completed:
										SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   True
										SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   False
										return complete, stepped

						if self.inprogress_constraint is not None:
										# In the middle of fulfilling a constraint. If the `token_id` *does* makes an incremental progress to current
										# job, simply update the state

										SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_   :	Dict													=   self.inprogress_constraint.update(UpperCamelCase__       )
										if reset:
														# 1. If the next token breaks the progress, then we must restart.
														#     e.g. constraint = "I love pies" and sequence so far is "I love" but `token_id` == "books".

														#     But that doesn't mean we self.init_state(), since we only reset the state for this particular
														#     constraint, not the full list of constraints.

														self.pending_constraints.append(self.inprogress_constraint.copy(stateful=UpperCamelCase__       )       )
														SCREAMING_SNAKE_CASE_   :	Dict													=   None

										if complete:
														# 2. If the next token completes the constraint, move it to completed list, set
														#     inprogress to None. If there are no pending constraints either, then this full list of constraints
														#     is complete.

														self.complete_constraints.append(self.inprogress_constraint       )
														SCREAMING_SNAKE_CASE_   :	str													=   None

														if len(self.pending_constraints       ) == 0:
																		# we're done!
																		SCREAMING_SNAKE_CASE_   :	Tuple													=   True

						else:
										# Not in the middle of fulfilling a constraint. So does this `token_id` helps us step towards any of our list
										# of constraints?

										for cidx, pending_constraint in enumerate(self.pending_constraints       ):
														if pending_constraint.does_advance(UpperCamelCase__       ):
																		SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_   :	Dict													=   pending_constraint.update(UpperCamelCase__       )

																		if not stepped:
																						raise Exception(
																						    '`constraint.update(token_id)` is not yielding incremental progress, '
																						    'even though `constraint.does_advance(token_id)` is true.'       )

																		if complete:
																						self.complete_constraints.append(UpperCamelCase__       )
																						SCREAMING_SNAKE_CASE_   :	List[str]													=   None

																		if not complete and stepped:
																						SCREAMING_SNAKE_CASE_   :	List[str]													=   pending_constraint

																		if complete or stepped:
																						# If we made any progress at all, then it's at least not a "pending constraint".

																						SCREAMING_SNAKE_CASE_   :	Any													=   (
																						    self.pending_constraints[:cidx] + self.pending_constraints[cidx + 1 :]
																						)

																						if len(self.pending_constraints       ) == 0 and self.inprogress_constraint is None:
																										# If there's no longer any pending after this and no inprogress either, then we must be
																										# complete.

																										SCREAMING_SNAKE_CASE_   :	Dict													=   True

																						break  # prevent accidentally stepping through multiple constraints with just one token.

						return complete, stepped






		def   __snake_case			(						self ,    UpperCamelCase__=True       ):
						SCREAMING_SNAKE_CASE_   :	Tuple													=   ConstraintListState(self.constraints       )  # we actually never though self.constraints objects
						# throughout this process. So it's at initialization state.

						if stateful:
										SCREAMING_SNAKE_CASE_   :	List[str]													=   [
										    constraint.copy(stateful=UpperCamelCase__       ) for constraint in self.complete_constraints
										]
										if self.inprogress_constraint is not None:
														SCREAMING_SNAKE_CASE_   :	List[Any]													=   self.inprogress_constraint.copy(stateful=UpperCamelCase__       )
										SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   [constraint.copy() for constraint in self.pending_constraints]

						return new_state