





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

class  __A(						__UpperCAmelCase ):

     def __init__(      self      ):





            """simple docstring"""

            self.test()

     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            _UpperCamelCase              =						0
            _UpperCamelCase              =						False
            while not completed:
                   if counter == 1:
                          self.reset()
                   _UpperCamelCase              =						self.advance()
                   if not self.does_advance(A      ):
                          raise Exception(
                              '''Custom Constraint is not defined correctly. self.does_advance(self.advance()) must be true.'''      )

                   _UpperCamelCase       ,		_UpperCamelCase       ,		_UpperCamelCase              =						self.update(A      )
                   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 	_UpperCamelCase     (      self      ):





            """simple docstring"""

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

     @abstractmethod
     def 	_UpperCamelCase     (      self,       A      ):





            """simple docstring"""

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

     @abstractmethod
     def 	_UpperCamelCase     (      self,       A      ):





            """simple docstring"""

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

     @abstractmethod
     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

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

     @abstractmethod
     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

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



     @abstractmethod
     def 	_UpperCamelCase     (      self,       A=False      ):





            """simple docstring"""

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






class  __A(						__UpperCAmelCase ):

     def __init__(      self,       A      ):





            """simple docstring"""

            super(A,       self      ).__init__()

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

            _UpperCamelCase              =						token_ids

            _UpperCamelCase              =						len(self.token_ids      )
            _UpperCamelCase              =						-1  # the index of the currently fulfilled step
            _UpperCamelCase              =						False

     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

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

     def 	_UpperCamelCase     (      self,       A      ):





            """simple docstring"""

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

            if self.completed:
                   return False

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

     def 	_UpperCamelCase     (      self,       A      ):





            """simple docstring"""

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

            _UpperCamelCase              =						False
            _UpperCamelCase              =						False
            _UpperCamelCase              =						False

            if self.does_advance(A      ):
                   self.fulfilled_idx += 1
                   _UpperCamelCase              =						True
                   if self.fulfilled_idx == (self.seqlen - 1):
                          _UpperCamelCase              =						True
                   _UpperCamelCase              =						completed
            else:
                   # failed to make progress.
                   _UpperCamelCase              =						True
                   self.reset()
            return stepped, completed, reset

     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            _UpperCamelCase              =						False
            _UpperCamelCase              =						0

     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

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



     def 	_UpperCamelCase     (      self,       A=False      ):





            """simple docstring"""

            _UpperCamelCase              =						PhrasalConstraint(self.token_ids      )

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

            return new_constraint






class  __A:

     def __init__(      self,       A,       A=True      ):





            """simple docstring"""

            _UpperCamelCase              =						max([len(A      ) for one in nested_token_ids]      )

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

                          _UpperCamelCase              =						level[token_id]

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

            _UpperCamelCase              =						root

     def 	_UpperCamelCase     (      self,       A      ):





            """simple docstring"""

            _UpperCamelCase              =						self.trie

            for current_token in current_seq:
                   _UpperCamelCase              =						start[current_token]

            _UpperCamelCase              =						list(start.keys()      )

            return next_tokens

     def 	_UpperCamelCase     (      self,       A      ):





            """simple docstring"""

            _UpperCamelCase              =						self.next_tokens(A      )

            return len(A      ) == 0

     def 	_UpperCamelCase     (      self,       A      ):





            """simple docstring"""

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



     def 	_UpperCamelCase     (      self,       A,       A      ):





            """simple docstring"""

            _UpperCamelCase              =						self.count_leaves(A      )
            return len(A      ) != leaf_count






class  __A(						__UpperCAmelCase ):

     def __init__(      self,       A      ):





            """simple docstring"""

            super(A,       self      ).__init__()

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

            _UpperCamelCase              =						DisjunctiveTrie(A      )
            _UpperCamelCase              =						nested_token_ids

            _UpperCamelCase              =						self.trie.max_height
            _UpperCamelCase              =						[]
            _UpperCamelCase              =						False

     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            _UpperCamelCase              =						self.trie.next_tokens(self.current_seq      )

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

     def 	_UpperCamelCase     (      self,       A      ):





            """simple docstring"""

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

            _UpperCamelCase              =						self.trie.next_tokens(self.current_seq      )

            return token_id in next_tokens

     def 	_UpperCamelCase     (      self,       A      ):





            """simple docstring"""

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

            _UpperCamelCase              =						False
            _UpperCamelCase              =						False
            _UpperCamelCase              =						False

            if self.does_advance(A      ):
                   self.current_seq.append(A      )
                   _UpperCamelCase              =						True
            else:
                   _UpperCamelCase              =						True
                   self.reset()

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

            return stepped, completed, reset

     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            _UpperCamelCase              =						False
            _UpperCamelCase              =						[]

     def 	_UpperCamelCase     (      self      ):





            """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 	_UpperCamelCase     (      self,       A=False      ):





            """simple docstring"""

            _UpperCamelCase              =						DisjunctiveConstraint(self.token_ids      )

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

            return new_constraint






class  __A:

     def __init__(      self,       A      ):





            """simple docstring"""

            _UpperCamelCase              =						constraints

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

            self.init_state()

     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            _UpperCamelCase              =						[]
            _UpperCamelCase              =						None
            _UpperCamelCase              =						[constraint.copy(stateful=A      ) for constraint in self.constraints]

     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            _UpperCamelCase              =						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      ):





            """simple docstring"""

            _UpperCamelCase              =						[]
            if self.inprogress_constraint is None:
                   for constraint in self.pending_constraints:  # "pending" == "unfulfilled yet"
                          _UpperCamelCase              =						constraint.advance()
                          if isinstance(A,       A      ):
                                 token_list.append(A      )
                          elif isinstance(A,       A      ):
                                 token_list.extend(A      )
            else:
                   _UpperCamelCase              =						self.inprogress_constraint.advance()
                   if isinstance(A,       A      ):
                          token_list.append(A      )
                   elif isinstance(A,       A      ):
                          token_list.extend(A      )

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

     def 	_UpperCamelCase     (      self,       A      ):





            """simple docstring"""

            self.init_state()

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

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

     def 	_UpperCamelCase     (      self,       A      ):





            """simple docstring"""

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

            _UpperCamelCase       ,		_UpperCamelCase              =						False, False

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

                   _UpperCamelCase       ,		_UpperCamelCase       ,		_UpperCamelCase              =						self.inprogress_constraint.update(A      )
                   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=A      )      )
                          _UpperCamelCase              =						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      )
                          _UpperCamelCase              =						None

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

                                 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(A      )
                                        _UpperCamelCase              =						None

                                 if not complete and stepped:
                                        _UpperCamelCase              =						pending_constraint

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

                                        _UpperCamelCase              =						(
                                            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.

                                               _UpperCamelCase              =						True

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

            return complete, stepped



     def 	_UpperCamelCase     (      self,       A=True      ):





            """simple docstring"""

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

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

            return new_state













def     SCREAMING_SNAKE_CASE			(      lowerCAmelCase = 1_000					):
       _UpperCamelCase              =						3
       _UpperCamelCase              =						0
       while a < n:
              if a % 3 == 0 or a % 5 == 0:
                     result += a
              elif a % 15 == 0:
                     result -= a
              a += 1
       return result


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






