


'''simple docstring'''






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




class        a   (   lowerCamelCase_				):
 def __init__(       self  )    ->							Union[str, Any]:
      self.test()
 def 							__UpperCAmelCase						(       self  )    ->							Union[str, Any]:
      _a						=							0
      _a						=							False
      while not completed:
           if counter == 1:
                self.reset()
           _a						=							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						=							self.update(__SCREAMING_SNAKE_CASE  )
           counter += 1

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

      if self.remaining() != 0:
           raise Exception('Custom Constraint is not defined correctly.'  )
 @abstractmethod
 def 							__UpperCAmelCase						(       self  )    ->							Tuple:
      raise NotImplementedError(
          f'{self.__class__} is an abstract class. Only classes inheriting this class can be called.'  )
 @abstractmethod
 def 							__UpperCAmelCase						(       self					, __magic_name__  )    ->							int:
      raise NotImplementedError(
          f'{self.__class__} is an abstract class. Only classes inheriting this class can be called.'  )
 @abstractmethod
 def 							__UpperCAmelCase						(       self					, __magic_name__  )    ->							Dict:
      raise NotImplementedError(
          f'{self.__class__} is an abstract class. Only classes inheriting this class can be called.'  )
 @abstractmethod
 def 							__UpperCAmelCase						(       self  )    ->							List[str]:
      raise NotImplementedError(
          f'{self.__class__} is an abstract class. Only classes inheriting this class can be called.'  )
 @abstractmethod
 def 							__UpperCAmelCase						(       self  )    ->							Union[str, Any]:
      raise NotImplementedError(
          f'{self.__class__} is an abstract class. Only classes inheriting this class can be called.'  )




 @abstractmethod
 def 							__UpperCAmelCase						(       self					, __magic_name__=False  )    ->							Union[str, Any]:
      raise NotImplementedError(
          f'{self.__class__} is an abstract class. Only classes inheriting this class can be called.'  )





class        a   (   lowerCamelCase_				):
 def __init__(       self					, __magic_name__  )    ->							List[Any]:
      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						=							token_ids

      _a						=							len(self.token_ids  )
      _a						=							-1  # the index of the currently fulfilled step
      _a						=							False
 def 							__UpperCAmelCase						(       self  )    ->							List[Any]:





      if self.completed:
           return None
      return self.token_ids[self.fulfilled_idx + 1]
 def 							__UpperCAmelCase						(       self					, __magic_name__  )    ->							List[Any]:





      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 							__UpperCAmelCase						(       self					, __magic_name__  )    ->							List[str]:





      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						=							False
      _a						=							False
      _a						=							False

      if self.does_advance(__SCREAMING_SNAKE_CASE  ):
           self.fulfilled_idx += 1
           _a						=							True
           if self.fulfilled_idx == (self.seqlen - 1):
                _a						=							True
           _a						=							completed
      else:
           # failed to make progress.
           _a						=							True
           self.reset()
      return stepped, completed, reset
 def 							__UpperCAmelCase						(       self  )    ->							Optional[Any]:
      _a						=							False
      _a						=							0
 def 							__UpperCAmelCase						(       self  )    ->							str:
      return self.seqlen - (self.fulfilled_idx + 1)




 def 							__UpperCAmelCase						(       self					, __magic_name__=False  )    ->							Optional[Any]:
      _a						=							PhrasalConstraint(self.token_ids  )

      if stateful:
           _a						=							self.seqlen
           _a						=							self.fulfilled_idx
           _a						=							self.completed

      return new_constraint





class        a   :
 def __init__(       self					, __magic_name__					, __magic_name__=True  )    ->							List[Any]:
      _a						=							max([len(__SCREAMING_SNAKE_CASE  ) for one in nested_token_ids]  )

      _a						=							{}
      for token_ids in nested_token_ids:
           _a						=							root
           for tidx, token_id in enumerate(__SCREAMING_SNAKE_CASE  ):
                if token_id not in level:
                     _a						=							{}

                _a						=							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						=							root
 def 							__UpperCAmelCase						(       self					, __magic_name__  )    ->							Union[str, Any]:
      _a						=							self.trie

      for current_token in current_seq:
           _a						=							start[current_token]

      _a						=							list(start.keys()  )

      return next_tokens
 def 							__UpperCAmelCase						(       self					, __magic_name__  )    ->							List[Any]:
      _a						=							self.next_tokens(__SCREAMING_SNAKE_CASE  )

      return len(__SCREAMING_SNAKE_CASE  ) == 0
 def 							__UpperCAmelCase						(       self					, __magic_name__  )    ->							Dict:
      _a						=							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 							__UpperCAmelCase						(       self					, __magic_name__					, __magic_name__  )    ->							List[str]:
      _a						=							self.count_leaves(__SCREAMING_SNAKE_CASE  )
      return len(__SCREAMING_SNAKE_CASE  ) != leaf_count





class        a   (   lowerCamelCase_				):
 def __init__(       self					, __magic_name__  )    ->							List[Any]:
      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						=							DisjunctiveTrie(__SCREAMING_SNAKE_CASE  )
      _a						=							nested_token_ids

      _a						=							self.trie.max_height
      _a						=							[]
      _a						=							False
 def 							__UpperCAmelCase						(       self  )    ->							List[str]:
      _a						=							self.trie.next_tokens(self.current_seq  )

      if len(__SCREAMING_SNAKE_CASE  ) == 0:
           return None
      else:
           return token_list
 def 							__UpperCAmelCase						(       self					, __magic_name__  )    ->							Union[str, Any]:





      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						=							self.trie.next_tokens(self.current_seq  )

      return token_id in next_tokens
 def 							__UpperCAmelCase						(       self					, __magic_name__  )    ->							Optional[int]:





      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						=							False
      _a						=							False
      _a						=							False

      if self.does_advance(__SCREAMING_SNAKE_CASE  ):
           self.current_seq.append(__SCREAMING_SNAKE_CASE  )
           _a						=							True
      else:
           _a						=							True
           self.reset()

      _a						=							self.trie.reached_leaf(self.current_seq  )
      _a						=							completed

      return stepped, completed, reset
 def 							__UpperCAmelCase						(       self  )    ->							Any:
      _a						=							False
      _a						=							[]
 def 							__UpperCAmelCase						(       self  )    ->							Union[str, Any]:





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




 def 							__UpperCAmelCase						(       self					, __magic_name__=False  )    ->							Union[str, Any]:
      _a						=							DisjunctiveConstraint(self.token_ids  )

      if stateful:
           _a						=							self.seqlen
           _a						=							self.current_seq
           _a						=							self.completed

      return new_constraint





class        a   :
 def __init__(       self					, __magic_name__  )    ->							Optional[Any]:
      _a						=							constraints

      # max # of steps required to fulfill a given constraint
      _a						=							max([c.seqlen for c in constraints]  )
      _a						=							len(__SCREAMING_SNAKE_CASE  )
      _a						=							False

      self.init_state()
 def 							__UpperCAmelCase						(       self  )    ->							Optional[Any]:
      _a						=							[]
      _a						=							None
      _a						=							[constraint.copy(stateful=__SCREAMING_SNAKE_CASE  ) for constraint in self.constraints]
 def 							__UpperCAmelCase						(       self  )    ->							Union[str, Any]:
      _a						=							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 							__UpperCAmelCase						(       self  )    ->							Dict:
      _a						=							[]
      if self.inprogress_constraint is None:
           for constraint in self.pending_constraints:  # "pending" == "unfulfilled yet"
                _a						=							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						=							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 							__UpperCAmelCase						(       self					, __magic_name__  )    ->							Union[str, Any]:
      self.init_state()

      if token_ids is not None:
           for token in token_ids:
                # completes or steps **one** constraint
                _a						=							self.add(__SCREAMING_SNAKE_CASE  )

                # the entire list of constraints are fulfilled
                if self.completed:
                     break
 def 							__UpperCAmelCase						(       self					, __magic_name__  )    ->							Any:





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

      _a						=							False, False

      if self.completed:
           _a						=							True
           _a						=							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						=							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						=							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						=							None

                if len(self.pending_constraints  ) == 0:
                     # we're done!
                     _a						=							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						=							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						=							None

                     if not complete and stepped:
                          _a						=							pending_constraint

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

                          _a						=							(
                              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						=							True

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

      return complete, stepped




 def 							__UpperCAmelCase						(       self					, __magic_name__=True  )    ->							List[Any]:
      _a						=							ConstraintListState(self.constraints  )  # we actually never though self.constraints objects
      # throughout this process. So it's at initialization state.

      if stateful:
           _a						=							[
               constraint.copy(stateful=__SCREAMING_SNAKE_CASE  ) for constraint in self.complete_constraints
           ]
           if self.inprogress_constraint is not None:
                _a						=							self.inprogress_constraint.copy(stateful=__SCREAMING_SNAKE_CASE  )
           _a						=							[constraint.copy() for constraint in self.pending_constraints]

      return new_state



'''simple docstring'''







def 					snake_case_		(				__SCREAMING_SNAKE_CASE					: str      ,      __SCREAMING_SNAKE_CASE					: str							):



						"""simple docstring"""





						lowercase_	:     List[str]													=       len(__SCREAMING_SNAKE_CASE							)
						lowercase_	:     Optional[int]													=       []
						for i in range(len(__SCREAMING_SNAKE_CASE							) - pat_len + 1							):
												lowercase_	:     Tuple													=       True
												for j in range(__SCREAMING_SNAKE_CASE							):
																		if s[i + j] != pattern[j]:
																								lowercase_	:     List[str]													=       False
																								break
												if match_found:
																		position.append(__SCREAMING_SNAKE_CASE							)
						return position


if __name__ == "__main__":
							assert naive_pattern_search("ABCDEFG", "DE") == [3]
							print(naive_pattern_search("ABAAABCDBBABCDDEBCABC", "ABC"))



