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





class     __UpperCamelCase (							lowerCAmelCase__       ):






     """simple docstring"""







     def __init__(				self							:							Union[str, Any] ):







       """simple docstring"""




       self.test()



     def  UpperCAmelCase__							(				self							:							List[str] ):







       """simple docstring"""




       __SCREAMING_SNAKE_CASE      :	List[str]					=		0
       __SCREAMING_SNAKE_CASE      :	str					=		False
       while not completed:
         if counter == 1:
           self.reset()
         __SCREAMING_SNAKE_CASE      :	int					=		self.advance()
         if not self.does_advance(_A ):
           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      :	Optional[int]					=		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							:							List[Any] ):







       """simple docstring"""




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



     @abstractmethod
     def  UpperCAmelCase__							(				self							:							Tuple     ,						_A							:							int ):







       """simple docstring"""




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



     @abstractmethod
     def  UpperCAmelCase__							(				self							:							Any     ,						_A							:							int ):







       """simple docstring"""




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



     @abstractmethod
     def  UpperCAmelCase__							(				self							:							List[str] ):







       """simple docstring"""




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



     @abstractmethod
     def  UpperCAmelCase__							(				self							:							Optional[int] ):







       """simple docstring"""




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




     @abstractmethod
     def  UpperCAmelCase__							(				self							:							Tuple     ,						_A							:							Dict=False ):







       """simple docstring"""




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






class     __UpperCamelCase (							lowerCAmelCase__       ):






     """simple docstring"""







     def __init__(				self							:							int     ,						_A							:							List[int] ):







       """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}.''' )

       __SCREAMING_SNAKE_CASE      :	Tuple					=		token_ids

       __SCREAMING_SNAKE_CASE      :	List[Any]					=		len(self.token_ids )
       __SCREAMING_SNAKE_CASE      :	Optional[Any]					=		-1  # the index of the currently fulfilled step
       __SCREAMING_SNAKE_CASE      :	int					=		False



     def  UpperCAmelCase__							(				self							:							Dict ):







       """simple docstring"""




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



     def  UpperCAmelCase__							(				self							:							Tuple     ,						_A							:							int ):







       """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							:							str     ,						_A							:							int ):







       """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 )}''' )

       __SCREAMING_SNAKE_CASE      :	Any					=		False
       __SCREAMING_SNAKE_CASE      :	Tuple					=		False
       __SCREAMING_SNAKE_CASE      :	Union[str, Any]					=		False

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



     def  UpperCAmelCase__							(				self							:							Optional[int] ):







       """simple docstring"""




       __SCREAMING_SNAKE_CASE      :	Any					=		False
       __SCREAMING_SNAKE_CASE      :	List[Any]					=		0



     def  UpperCAmelCase__							(				self							:							int ):







       """simple docstring"""




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




     def  UpperCAmelCase__							(				self							:							Union[str, Any]     ,						_A							:							List[Any]=False ):







       """simple docstring"""




       __SCREAMING_SNAKE_CASE      :	Optional[Any]					=		PhrasalConstraint(self.token_ids )

       if stateful:
         __SCREAMING_SNAKE_CASE      :	Union[str, Any]					=		self.seqlen
         __SCREAMING_SNAKE_CASE      :	Optional[int]					=		self.fulfilled_idx
         __SCREAMING_SNAKE_CASE      :	Dict					=		self.completed

       return new_constraint






class     __UpperCamelCase :






     """simple docstring"""







     def __init__(				self							:							Optional[int]     ,						_A							:							List[List[int]]     ,						_A							:							Tuple=True ):







       """simple docstring"""




       __SCREAMING_SNAKE_CASE      :	str					=		max([len(_A ) for one in nested_token_ids] )

       __SCREAMING_SNAKE_CASE      :	List[str]					=		{}
       for token_ids in nested_token_ids:
         __SCREAMING_SNAKE_CASE      :	List[str]					=		root
         for tidx, token_id in enumerate(_A ):
           if token_id not in level:
             __SCREAMING_SNAKE_CASE      :	Optional[Any]					=		{}

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

       __SCREAMING_SNAKE_CASE      :	Dict					=		root



     def  UpperCAmelCase__							(				self							:							Dict     ,						_A							:							Any ):







       """simple docstring"""




       __SCREAMING_SNAKE_CASE      :	List[str]					=		self.trie

       for current_token in current_seq:
         __SCREAMING_SNAKE_CASE      :	str					=		start[current_token]

       __SCREAMING_SNAKE_CASE      :	Optional[Any]					=		list(start.keys() )

       return next_tokens



     def  UpperCAmelCase__							(				self							:							Tuple     ,						_A							:							Dict ):







       """simple docstring"""




       __SCREAMING_SNAKE_CASE      :	List[str]					=		self.next_tokens(_A )

       return len(_A ) == 0



     def  UpperCAmelCase__							(				self							:							int     ,						_A							:							Tuple ):







       """simple docstring"""




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




     def  UpperCAmelCase__							(				self							:							Union[str, Any]     ,						_A							:							List[Any]     ,						_A							:							int ):







       """simple docstring"""




       __SCREAMING_SNAKE_CASE      :	Union[str, Any]					=		self.count_leaves(_A )
       return len(_A ) != leaf_count






class     __UpperCamelCase (							lowerCAmelCase__       ):






     """simple docstring"""







     def __init__(				self							:							str     ,						_A							:							List[List[int]] ):







       """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}.''' )

       __SCREAMING_SNAKE_CASE      :	Optional[Any]					=		DisjunctiveTrie(_A )
       __SCREAMING_SNAKE_CASE      :	Optional[Any]					=		nested_token_ids

       __SCREAMING_SNAKE_CASE      :	Any					=		self.trie.max_height
       __SCREAMING_SNAKE_CASE      :	List[Any]					=		[]
       __SCREAMING_SNAKE_CASE      :	Optional[int]					=		False



     def  UpperCAmelCase__							(				self							:							int ):







       """simple docstring"""




       __SCREAMING_SNAKE_CASE      :	List[str]					=		self.trie.next_tokens(self.current_seq )

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



     def  UpperCAmelCase__							(				self							:							Union[str, Any]     ,						_A							:							int ):







       """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 )}''' )

       __SCREAMING_SNAKE_CASE      :	List[str]					=		self.trie.next_tokens(self.current_seq )

       return token_id in next_tokens



     def  UpperCAmelCase__							(				self							:							List[str]     ,						_A							:							int ):







       """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 )}''' )

       __SCREAMING_SNAKE_CASE      :	int					=		False
       __SCREAMING_SNAKE_CASE      :	Dict					=		False
       __SCREAMING_SNAKE_CASE      :	Union[str, Any]					=		False

       if self.does_advance(_A ):
         self.current_seq.append(_A )
         __SCREAMING_SNAKE_CASE      :	Union[str, Any]					=		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  UpperCAmelCase__							(				self							:							Tuple ):







       """simple docstring"""




       __SCREAMING_SNAKE_CASE      :	Any					=		False
       __SCREAMING_SNAKE_CASE      :	Any					=		[]



     def  UpperCAmelCase__							(				self							:							Any ):







       """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							:							Dict     ,						_A							:							List[str]=False ):







       """simple docstring"""




       __SCREAMING_SNAKE_CASE      :	str					=		DisjunctiveConstraint(self.token_ids )

       if stateful:
         __SCREAMING_SNAKE_CASE      :	Dict					=		self.seqlen
         __SCREAMING_SNAKE_CASE      :	Tuple					=		self.current_seq
         __SCREAMING_SNAKE_CASE      :	Optional[int]					=		self.completed

       return new_constraint






class     __UpperCamelCase :






     """simple docstring"""







     def __init__(				self							:							Dict     ,						_A							:							List[Constraint] ):







       """simple docstring"""




       __SCREAMING_SNAKE_CASE      :	Optional[int]					=		constraints

       # max # of steps required to fulfill a given constraint
       __SCREAMING_SNAKE_CASE      :	Dict					=		max([c.seqlen for c in constraints] )
       __SCREAMING_SNAKE_CASE      :	Union[str, Any]					=		len(_A )
       __SCREAMING_SNAKE_CASE      :	List[str]					=		False

       self.init_state()



     def  UpperCAmelCase__							(				self							:							Union[str, Any] ):







       """simple docstring"""




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



     def  UpperCAmelCase__							(				self							:							int ):







       """simple docstring"""




       __SCREAMING_SNAKE_CASE      :	Optional[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  UpperCAmelCase__							(				self							:							List[str] ):







       """simple docstring"""




       __SCREAMING_SNAKE_CASE      :	List[str]					=		[]
       if self.inprogress_constraint is None:
         for constraint in self.pending_constraints:  # "pending" == "unfulfilled yet"
           __SCREAMING_SNAKE_CASE      :	Any					=		constraint.advance()
           if isinstance(_A     ,						_A ):
             token_list.append(_A )
           elif isinstance(_A     ,						_A ):
             token_list.extend(_A )
       else:
         __SCREAMING_SNAKE_CASE      :	Any					=		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							:							int     ,						_A							:							Optional[List[int]] ):







       """simple docstring"""




       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      :	Optional[Any]					=		self.add(_A )

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



     def  UpperCAmelCase__							(				self							:							Optional[int]     ,						_A							:							int ):







       """simple docstring"""




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

       __SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE      :	List[Any]					=		False, False

       if self.completed:
         __SCREAMING_SNAKE_CASE      :	Dict					=		True
         __SCREAMING_SNAKE_CASE      :	List[str]					=		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      :	Union[str, Any]					=		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 ) )
           __SCREAMING_SNAKE_CASE      :	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 )
           __SCREAMING_SNAKE_CASE      :	Union[str, Any]					=		None

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

                 __SCREAMING_SNAKE_CASE      :	Any					=		True

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

       return complete, stepped




     def  UpperCAmelCase__							(				self							:							Union[str, Any]     ,						_A							:							int=True ):







       """simple docstring"""




       __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=_A ) for constraint in self.complete_constraints
         ]
         if self.inprogress_constraint is not None:
           __SCREAMING_SNAKE_CASE      :	Tuple					=		self.inprogress_constraint.copy(stateful=_A )
         __SCREAMING_SNAKE_CASE      :	Optional[Any]					=		[constraint.copy() for constraint in self.pending_constraints]

       return new_state




"""simple docstring"""






def 				A_       ( snake_case__		)					->  int:
			_UpperCamelCase					:Dict					     =	1
			for i in range(1       ,					num + 1		):
						fact *= i
			return fact





def 				A_       ( snake_case__		)					->  int:
			_UpperCamelCase					:Dict					     =	0
			while number > 0:
						_UpperCamelCase					:Tuple					     =	number % 10
						sum_of_digits += last_digit
						_UpperCamelCase					:str					     =	number // 10  # Removing the last_digit from the given number
			return sum_of_digits





def 				A_       ( snake_case__ = 1_00		)					->  int:
			_UpperCamelCase					:int					     =	factorial(snake_case__		)
			_UpperCamelCase					:Dict					     =	split_and_add(snake_case__		)
			return result


if __name__ == "__main__":
					print(solution(int(input("""Enter the Number: """).strip())))

