


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





class  _a							(    lowerCAmelCase__):




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




 def 							UpperCAmelCase__( self						:		Optional[int]		)->	str:
   lowerCAmelCase__       :      Dict   					= 0
   lowerCAmelCase__       :      Any   					= False
   while not completed:
     if counter == 1:
       self.reset()
     lowerCAmelCase__       :      List[str]   					= 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.'''		)

     lowerCAmelCase__					,     lowerCAmelCase__					,     lowerCAmelCase__       :      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 							UpperCAmelCase__( self						:		int		)->	Optional[int]:
   raise NotImplementedError(
       F'{self.__class__} is an abstract class. Only classes inheriting this class can be called.'		)




 @abstractmethod
 def 							UpperCAmelCase__( self						:		Any		, _SCREAMING_SNAKE_CASE						:		Tuple		)->	Any:
   raise NotImplementedError(
       F'{self.__class__} is an abstract class. Only classes inheriting this class can be called.'		)




 @abstractmethod
 def 							UpperCAmelCase__( self						:		Optional[int]		, _SCREAMING_SNAKE_CASE						:		Optional[Any]		)->	Optional[int]:
   raise NotImplementedError(
       F'{self.__class__} is an abstract class. Only classes inheriting this class can be called.'		)




 @abstractmethod
 def 							UpperCAmelCase__( self						:		Tuple		)->	List[Any]:
   raise NotImplementedError(
       F'{self.__class__} is an abstract class. Only classes inheriting this class can be called.'		)




 @abstractmethod
 def 							UpperCAmelCase__( self						:		Tuple		)->	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]		, _SCREAMING_SNAKE_CASE						:		Union[str, Any]=False		)->	str:
   raise NotImplementedError(
       F'{self.__class__} is an abstract class. Only classes inheriting this class can be called.'		)





class  _a							(    lowerCAmelCase__):




 def __init__( self						:		Dict		, _SCREAMING_SNAKE_CASE						:		Union[str, Any]		)->	Optional[int]:
   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}.'		)

   lowerCAmelCase__       :      Optional[Any]   					= token_ids

   lowerCAmelCase__       :      Dict   					= len(self.token_ids		)
   lowerCAmelCase__       :      str   					= -1  # the index of the currently fulfilled step
   lowerCAmelCase__       :      Any   					= False




 def 							UpperCAmelCase__( self						:		int		)->	str:
   if self.completed:
     return None
   return self.token_ids[self.fulfilled_idx + 1]




 def 							UpperCAmelCase__( self						:		int		, _SCREAMING_SNAKE_CASE						:		Dict		)->	Optional[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						:		Dict		, _SCREAMING_SNAKE_CASE						:		int		)->	int:
   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		)}'		)

   lowerCAmelCase__       :      Optional[Any]   					= False
   lowerCAmelCase__       :      Optional[int]   					= False
   lowerCAmelCase__       :      Tuple   					= False

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




 def 							UpperCAmelCase__( self						:		Dict		)->	Union[str, Any]:
   lowerCAmelCase__       :      Optional[int]   					= False
   lowerCAmelCase__       :      Optional[int]   					= 0




 def 							UpperCAmelCase__( self						:		Any		)->	Optional[int]:
   return self.seqlen - (self.fulfilled_idx + 1)




 def 							UpperCAmelCase__( self						:		Tuple		, _SCREAMING_SNAKE_CASE						:		int=False		)->	Dict:
   lowerCAmelCase__       :      Any   					= PhrasalConstraint(self.token_ids		)

   if stateful:
     lowerCAmelCase__       :      Dict   					= self.seqlen
     lowerCAmelCase__       :      Optional[Any]   					= self.fulfilled_idx
     lowerCAmelCase__       :      Tuple   					= self.completed

   return new_constraint





class  _a							:




 def __init__( self						:		int		, _SCREAMING_SNAKE_CASE						:		Union[str, Any]		, _SCREAMING_SNAKE_CASE						:		List[Any]=True		)->	List[str]:
   lowerCAmelCase__       :      List[str]   					= max([len(_SCREAMING_SNAKE_CASE		) for one in nested_token_ids]		)

   lowerCAmelCase__       :      Any   					= {}
   for token_ids in nested_token_ids:
     lowerCAmelCase__       :      Dict   					= root
     for tidx, token_id in enumerate(_SCREAMING_SNAKE_CASE		):
       if token_id not in level:
         lowerCAmelCase__       :      List[str]   					= {}

       lowerCAmelCase__       :      Dict   					= 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}.'		)

   lowerCAmelCase__       :      List[Any]   					= root




 def 							UpperCAmelCase__( self						:		Union[str, Any]		, _SCREAMING_SNAKE_CASE						:		Union[str, Any]		)->	Any:
   lowerCAmelCase__       :      Union[str, Any]   					= self.trie

   for current_token in current_seq:
     lowerCAmelCase__       :      int   					= start[current_token]

   lowerCAmelCase__       :      Dict   					= list(start.keys()		)

   return next_tokens




 def 							UpperCAmelCase__( self						:		str		, _SCREAMING_SNAKE_CASE						:		Union[str, Any]		)->	Dict:
   lowerCAmelCase__       :      Union[str, Any]   					= self.next_tokens(_SCREAMING_SNAKE_CASE		)

   return len(_SCREAMING_SNAKE_CASE		) == 0




 def 							UpperCAmelCase__( self						:		Optional[Any]		, _SCREAMING_SNAKE_CASE						:		Optional[int]		)->	Tuple:
   lowerCAmelCase__       :      Union[str, Any]   					= 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						:		Optional[Any]		, _SCREAMING_SNAKE_CASE						:		Union[str, Any]		, _SCREAMING_SNAKE_CASE						:		Tuple		)->	Optional[int]:
   lowerCAmelCase__       :      Union[str, Any]   					= self.count_leaves(_SCREAMING_SNAKE_CASE		)
   return len(_SCREAMING_SNAKE_CASE		) != leaf_count





class  _a							(    lowerCAmelCase__):




 def __init__( self						:		Optional[Any]		, _SCREAMING_SNAKE_CASE						:		str		)->	Optional[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}.'		)

   lowerCAmelCase__       :      Optional[Any]   					= DisjunctiveTrie(_SCREAMING_SNAKE_CASE		)
   lowerCAmelCase__       :      Optional[Any]   					= nested_token_ids

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




 def 							UpperCAmelCase__( self						:		str		)->	Tuple:
   lowerCAmelCase__       :      List[Any]   					= self.trie.next_tokens(self.current_seq		)

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




 def 							UpperCAmelCase__( self						:		Any		, _SCREAMING_SNAKE_CASE						:		List[Any]		)->	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		)}'		)

   lowerCAmelCase__       :      List[Any]   					= self.trie.next_tokens(self.current_seq		)

   return token_id in next_tokens




 def 							UpperCAmelCase__( self						:		Any		, _SCREAMING_SNAKE_CASE						:		List[Any]		)->	str:
   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		)}'		)

   lowerCAmelCase__       :      Optional[Any]   					= False
   lowerCAmelCase__       :      List[str]   					= False
   lowerCAmelCase__       :      int   					= False

   if self.does_advance(_SCREAMING_SNAKE_CASE		):
     self.current_seq.append(_SCREAMING_SNAKE_CASE		)
     lowerCAmelCase__       :      Dict   					= True
   else:
     lowerCAmelCase__       :      int   					= True
     self.reset()

   lowerCAmelCase__       :      List[str]   					= self.trie.reached_leaf(self.current_seq		)
   lowerCAmelCase__       :      Optional[int]   					= completed

   return stepped, completed, reset




 def 							UpperCAmelCase__( self						:		int		)->	Tuple:
   lowerCAmelCase__       :      Dict   					= False
   lowerCAmelCase__       :      List[str]   					= []




 def 							UpperCAmelCase__( self						:		Dict		)->	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						:		Any		, _SCREAMING_SNAKE_CASE						:		Optional[Any]=False		)->	Union[str, Any]:
   lowerCAmelCase__       :      Dict   					= DisjunctiveConstraint(self.token_ids		)

   if stateful:
     lowerCAmelCase__       :      Union[str, Any]   					= self.seqlen
     lowerCAmelCase__       :      Tuple   					= self.current_seq
     lowerCAmelCase__       :      str   					= self.completed

   return new_constraint





class  _a							:




 def __init__( self						:		Optional[int]		, _SCREAMING_SNAKE_CASE						:		Optional[Any]		)->	int:
   lowerCAmelCase__       :      Optional[int]   					= constraints

   # max # of steps required to fulfill a given constraint
   lowerCAmelCase__       :      Optional[Any]   					= max([c.seqlen for c in constraints]		)
   lowerCAmelCase__       :      List[str]   					= len(_SCREAMING_SNAKE_CASE		)
   lowerCAmelCase__       :      List[str]   					= False

   self.init_state()




 def 							UpperCAmelCase__( self						:		Dict		)->	Union[str, Any]:
   lowerCAmelCase__       :      int   					= []
   lowerCAmelCase__       :      Dict   					= None
   lowerCAmelCase__       :      str   					= [constraint.copy(stateful=_SCREAMING_SNAKE_CASE		) for constraint in self.constraints]




 def 							UpperCAmelCase__( self						:		Dict		)->	Optional[Any]:
   lowerCAmelCase__       :      Optional[int]   					= 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						:		int		)->	str:
   lowerCAmelCase__       :      Any   					= []
   if self.inprogress_constraint is None:
     for constraint in self.pending_constraints:  # "pending" == "unfulfilled yet"
       lowerCAmelCase__       :      List[str]   					= 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:
     lowerCAmelCase__       :      List[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 							UpperCAmelCase__( self						:		Optional[Any]		, _SCREAMING_SNAKE_CASE						:		Union[str, Any]		)->	int:
   self.init_state()

   if token_ids is not None:
     for token in token_ids:
       # completes or steps **one** constraint
       lowerCAmelCase__					,     lowerCAmelCase__       :      Optional[int]   					= self.add(_SCREAMING_SNAKE_CASE		)

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




 def 							UpperCAmelCase__( self						:		List[Any]		, _SCREAMING_SNAKE_CASE						:		Dict		)->	List[Any]:
   if not isinstance(_SCREAMING_SNAKE_CASE		, _SCREAMING_SNAKE_CASE		):
     raise ValueError(F'`token_id` should be an `int`, but is `{token_id}`.'		)

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

   if self.completed:
     lowerCAmelCase__       :      Optional[Any]   					= True
     lowerCAmelCase__       :      int   					= 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

     lowerCAmelCase__					,     lowerCAmelCase__					,     lowerCAmelCase__       :      Dict   					= 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		)		)
       lowerCAmelCase__       :      Optional[int]   					= 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		)
       lowerCAmelCase__       :      List[Any]   					= None

       if len(self.pending_constraints		) == 0:
         # we're done!
         lowerCAmelCase__       :      Any   					= 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		):
         lowerCAmelCase__					,     lowerCAmelCase__					,     lowerCAmelCase__       :      str   					= 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		)
           lowerCAmelCase__       :      Optional[Any]   					= None

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

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

           lowerCAmelCase__       :      Optional[int]   					= (
               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.

             lowerCAmelCase__       :      Union[str, Any]   					= True

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

   return complete, stepped




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

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

   return new_state








from math import isqrt






def 					lowerCamelCase_   (	_a	):




		"""simple docstring"""






		lowerCAmelCase__       :      Dict   					= [True] * max_number
		for i in range(2     ,       isqrt(max_number - 1	) + 1	):
				if is_prime[i]:
						for j in range(i**2     ,       _a     ,       _a	):
								lowerCAmelCase__       :      int   					= False

		return [i for i in range(2     ,       _a	) if is_prime[i]]






def 					lowerCamelCase_   (	_a = 10**8	):




		"""simple docstring"""






		lowerCAmelCase__       :      Any   					= calculate_prime_numbers(max_number // 2	)

		lowerCAmelCase__       :      Tuple   					= 0
		lowerCAmelCase__       :      List[Any]   					= 0
		lowerCAmelCase__       :      Optional[int]   					= len(_a	) - 1
		while left <= right:
				while prime_numbers[left] * prime_numbers[right] >= max_number:
						right -= 1
				semiprimes_count += right - left + 1
				left += 1

		return semiprimes_count


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




