





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





class 					A__       (				__UpperCAmelCase      ):




   """simple docstring"""



   def __init__(   self)     ->		Optional[Any]:







          '''simple docstring'''

          self.test()

   def 				__lowercase						(   self)     ->		int:







          '''simple docstring'''

          a__		:      List[Any]					=							0
          a__		:      Tuple					=							False
          while not completed:
                 if counter == 1:
                        self.reset()
                 a__		:      Optional[int]					=							self.advance()
                 if not self.does_advance(SCREAMING_SNAKE_CASE_):
                        raise Exception(
                            'Custom Constraint is not defined correctly. self.does_advance(self.advance()) must be true.')

                 a__					,				a__					,				a__		:      Union[str, Any]					=							self.update(SCREAMING_SNAKE_CASE_)
                 counter += 1

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

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

   @abstractmethod
   def 				__lowercase						(   self)     ->		str:







          '''simple docstring'''

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

   @abstractmethod
   def 				__lowercase						(   self   ,    lowercase)     ->		Optional[int]:







          '''simple docstring'''

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

   @abstractmethod
   def 				__lowercase						(   self   ,    lowercase)     ->		List[Any]:







          '''simple docstring'''

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

   @abstractmethod
   def 				__lowercase						(   self)     ->		Dict:







          '''simple docstring'''

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

   @abstractmethod
   def 				__lowercase						(   self)     ->		Any:







          '''simple docstring'''

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

   @abstractmethod
   def 				__lowercase						(   self   ,    lowercase=False)     ->		str:







          '''simple docstring'''

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





class 					A__       (				__UpperCAmelCase      ):




   """simple docstring"""



   def __init__(   self   ,    lowercase)     ->		Any:







          '''simple docstring'''

          super(SCREAMING_SNAKE_CASE_   ,    self).__init__()

          if not isinstance(SCREAMING_SNAKE_CASE_   ,    SCREAMING_SNAKE_CASE_) or len(SCREAMING_SNAKE_CASE_) == 0:
                 raise ValueError(F'`token_ids` has to be a non-empty list, but is {token_ids}.')
          if any((not isinstance(SCREAMING_SNAKE_CASE_   ,    SCREAMING_SNAKE_CASE_) 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}.')

          a__		:      List[Any]					=							token_ids

          a__		:      Tuple					=							len(self.token_ids)
          a__		:      Union[str, Any]					=							-1  # the index of the currently fulfilled step
          a__		:      Optional[Any]					=							False

   def 				__lowercase						(   self)     ->		List[Any]:







          '''simple docstring'''

          if self.completed:
                 return None
          return self.token_ids[self.fulfilled_idx + 1]

   def 				__lowercase						(   self   ,    lowercase)     ->		int:







          '''simple docstring'''

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

          if self.completed:
                 return False

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

   def 				__lowercase						(   self   ,    lowercase)     ->		int:







          '''simple docstring'''

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

          a__		:      Optional[Any]					=							False
          a__		:      Union[str, Any]					=							False
          a__		:      Union[str, Any]					=							False

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

   def 				__lowercase						(   self)     ->		Dict:







          '''simple docstring'''

          a__		:      Tuple					=							False
          a__		:      Union[str, Any]					=							0

   def 				__lowercase						(   self)     ->		Optional[Any]:







          '''simple docstring'''

          return self.seqlen - (self.fulfilled_idx + 1)

   def 				__lowercase						(   self   ,    lowercase=False)     ->		Optional[Any]:







          '''simple docstring'''

          a__		:      Union[str, Any]					=							PhrasalConstraint(self.token_ids)

          if stateful:
                 a__		:      List[str]					=							self.seqlen
                 a__		:      str					=							self.fulfilled_idx
                 a__		:      Any					=							self.completed

          return new_constraint





class 					A__       :




   """simple docstring"""



   def __init__(   self   ,    lowercase   ,    lowercase=True)     ->		Dict:







          '''simple docstring'''

          a__		:      Union[str, Any]					=							max([len(SCREAMING_SNAKE_CASE_) for one in nested_token_ids])

          a__		:      Optional[Any]					=							{}
          for token_ids in nested_token_ids:
                 a__		:      int					=							root
                 for tidx, token_id in enumerate(SCREAMING_SNAKE_CASE_):
                        if token_id not in level:
                               a__		:      Dict					=							{}

                        a__		:      Union[str, Any]					=							level[token_id]

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

          a__		:      Union[str, Any]					=							root

   def 				__lowercase						(   self   ,    lowercase)     ->		List[str]:







          '''simple docstring'''

          a__		:      Any					=							self.trie

          for current_token in current_seq:
                 a__		:      Any					=							start[current_token]

          a__		:      Any					=							list(start.keys())

          return next_tokens

   def 				__lowercase						(   self   ,    lowercase)     ->		str:







          '''simple docstring'''

          a__		:      Optional[int]					=							self.next_tokens(SCREAMING_SNAKE_CASE_)

          return len(SCREAMING_SNAKE_CASE_) == 0

   def 				__lowercase						(   self   ,    lowercase)     ->		Dict:







          '''simple docstring'''

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

   def 				__lowercase						(   self   ,    lowercase   ,    lowercase)     ->		Tuple:







          '''simple docstring'''

          a__		:      List[Any]					=							self.count_leaves(SCREAMING_SNAKE_CASE_)
          return len(SCREAMING_SNAKE_CASE_) != leaf_count





class 					A__       (				__UpperCAmelCase      ):




   """simple docstring"""



   def __init__(   self   ,    lowercase)     ->		List[str]:







          '''simple docstring'''

          super(SCREAMING_SNAKE_CASE_   ,    self).__init__()

          if not isinstance(SCREAMING_SNAKE_CASE_   ,    SCREAMING_SNAKE_CASE_) or len(SCREAMING_SNAKE_CASE_) == 0:
                 raise ValueError(F'`nested_token_ids` has to be a non-empty list, but is {nested_token_ids}.')
          if any(not isinstance(SCREAMING_SNAKE_CASE_   ,    SCREAMING_SNAKE_CASE_) 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(SCREAMING_SNAKE_CASE_   ,    SCREAMING_SNAKE_CASE_) 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}.')

          a__		:      Tuple					=							DisjunctiveTrie(SCREAMING_SNAKE_CASE_)
          a__		:      List[Any]					=							nested_token_ids

          a__		:      Any					=							self.trie.max_height
          a__		:      int					=							[]
          a__		:      Dict					=							False

   def 				__lowercase						(   self)     ->		int:







          '''simple docstring'''

          a__		:      Optional[int]					=							self.trie.next_tokens(self.current_seq)

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

   def 				__lowercase						(   self   ,    lowercase)     ->		Dict:







          '''simple docstring'''

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

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

          return token_id in next_tokens

   def 				__lowercase						(   self   ,    lowercase)     ->		str:







          '''simple docstring'''

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

          a__		:      Optional[Any]					=							False
          a__		:      Dict					=							False
          a__		:      Any					=							False

          if self.does_advance(SCREAMING_SNAKE_CASE_):
                 self.current_seq.append(SCREAMING_SNAKE_CASE_)
                 a__		:      Union[str, Any]					=							True
          else:
                 a__		:      List[Any]					=							True
                 self.reset()

          a__		:      int					=							self.trie.reached_leaf(self.current_seq)
          a__		:      Optional[Any]					=							completed

          return stepped, completed, reset

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







          '''simple docstring'''

          a__		:      Dict					=							False
          a__		:      Union[str, Any]					=							[]

   def 				__lowercase						(   self)     ->		int:







          '''simple docstring'''

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

   def 				__lowercase						(   self   ,    lowercase=False)     ->		Dict:







          '''simple docstring'''

          a__		:      int					=							DisjunctiveConstraint(self.token_ids)

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

          return new_constraint





class 					A__       :




   """simple docstring"""



   def __init__(   self   ,    lowercase)     ->		Tuple:







          '''simple docstring'''

          a__		:      Dict					=							constraints

          # max # of steps required to fulfill a given constraint
          a__		:      Union[str, Any]					=							max([c.seqlen for c in constraints])
          a__		:      Optional[int]					=							len(SCREAMING_SNAKE_CASE_)
          a__		:      str					=							False

          self.init_state()

   def 				__lowercase						(   self)     ->		Tuple:







          '''simple docstring'''

          a__		:      List[str]					=							[]
          a__		:      Union[str, Any]					=							None
          a__		:      Optional[int]					=							[constraint.copy(stateful=SCREAMING_SNAKE_CASE_) for constraint in self.constraints]

   def 				__lowercase						(   self)     ->		Any:







          '''simple docstring'''

          a__		:      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 				__lowercase						(   self)     ->		Tuple:







          '''simple docstring'''

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

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

   def 				__lowercase						(   self   ,    lowercase)     ->		Optional[int]:







          '''simple docstring'''

          self.init_state()

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

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

   def 				__lowercase						(   self   ,    lowercase)     ->		Optional[int]:







          '''simple docstring'''

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

          a__					,				a__		:      Union[str, Any]					=							False, False

          if self.completed:
                 a__		:      List[str]					=							True
                 a__		:      List[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

                 a__					,				a__					,				a__		:      Union[str, Any]					=							self.inprogress_constraint.update(SCREAMING_SNAKE_CASE_)
                 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=SCREAMING_SNAKE_CASE_))
                        a__		:      str					=							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)
                        a__		:      Optional[Any]					=							None

                        if len(self.pending_constraints) == 0:
                               # we're done!
                               a__		:      Dict					=							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(SCREAMING_SNAKE_CASE_):
                               a__					,				a__					,				a__		:      Tuple					=							pending_constraint.update(SCREAMING_SNAKE_CASE_)

                               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(SCREAMING_SNAKE_CASE_)
                                      a__		:      Optional[Any]					=							None

                               if not complete and stepped:
                                      a__		:      List[Any]					=							pending_constraint

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

                                      a__		:      Union[str, 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.

                                             a__		:      Dict					=							True

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

          return complete, stepped

   def 				__lowercase						(   self   ,    lowercase=True)     ->		str:







          '''simple docstring'''

          a__		:      Tuple					=							ConstraintListState(self.constraints)  # we actually never though self.constraints objects
          # throughout this process. So it's at initialization state.

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

          return new_state




from __future__ import annotations

__a         =   8.988E9  # units = N * m^s * C^-2




def 							a		(				snake_case__:   float		,  snake_case__:   float		,  snake_case__:   float		,  snake_case__:   float   ):


				'''simple docstring'''
				lowercase_	    =   abs(chargea * chargea   )

				if (force, chargea, chargea, distance).count(0   ) != 1:
								raise ValueError('''One and only one argument must be 0'''   )
				if distance < 0:
								raise ValueError('''Distance cannot be negative'''   )
				if force == 0:
								lowercase_	    =   COULOMBS_CONSTANT * charge_product / (distance**2)
								return {"force": force}
				elif chargea == 0:
								lowercase_	    =   abs(snake_case__   ) * (distance**2) / (COULOMBS_CONSTANT * chargea)
								return {"charge1": chargea}
				elif chargea == 0:
								lowercase_	    =   abs(snake_case__   ) * (distance**2) / (COULOMBS_CONSTANT * chargea)
								return {"charge2": chargea}
				elif distance == 0:
								lowercase_	    =   (COULOMBS_CONSTANT * charge_product / abs(snake_case__   )) ** 0.5
								return {"distance": distance}
				raise ValueError('''Exactly one argument must be 0'''   )


if __name__ == "__main__":
						import doctest

						doctest.testmod()




