






"""simple docstring"""



_UpperCamelCase						:    Tuple		=						{
    '0': 1,
    '1': 1,
    '2': 2,
    '3': 6,
    '4': 2_4,
    '5': 1_2_0,
    '6': 7_2_0,
    '7': 5_0_4_0,
    '8': 4_0_3_2_0,
    '9': 3_6_2_8_8_0,
}

_UpperCamelCase						:    str		=						{1_4_5: 1_4_5}

_UpperCamelCase						:    Dict		=						{
    1_4_5: 0,
    1_6_9: 3,
    3_6_3_0_1: 3,
    1_4_5_4: 3,
    8_7_1: 2,
    4_5_3_6_1: 2,
    8_7_2: 2,
}
def 		_SCREAMING_SNAKE_CASE					(       __snake_case     :    int       ):





  '''simple docstring'''





  if n in CACHE_SUM_DIGIT_FACTORIALS:
    return CACHE_SUM_DIGIT_FACTORIALS[n]
  lowercase				       =			sum(DIGIT_FACTORIALS[let] for let in str(__snake_case       )       )
  lowercase				       =			ret
  return ret
def 		_SCREAMING_SNAKE_CASE					(       __snake_case     :    int						,   __snake_case     :    set | None = None       ):





  '''simple docstring'''





  lowercase				       =			previous or set()
  if n in CHAIN_LENGTH_CACHE:
    return CHAIN_LENGTH_CACHE[n]
  lowercase				       =			sum_digit_factorials(__snake_case       )
  if next_number in previous:
    lowercase				       =			0
    return 0
  else:
    previous.add(__snake_case       )
    lowercase				       =			1 + chain_length(__snake_case						,   __snake_case       )
    lowercase				       =			ret
    return ret
def 		_SCREAMING_SNAKE_CASE					(       __snake_case     :    int = 60						,   __snake_case     :    int = 1_00_00_00       ):





  '''simple docstring'''





  return sum(1 for i in range(1						,   __snake_case       ) if chain_length(__snake_case       ) == num_terms       )


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










'''simple docstring'''







import math

import torch
from torch import nn
from torch.nn import init

from .binarizer import MagnitudeBinarizer, ThresholdBinarizer, TopKBinarizer




class 					__UpperCAmelCase (		nn.Linear	):

      '''simple docstring'''





      def __init__(					self  ,		_UpperCAmelCase  ,		_UpperCAmelCase  ,		_UpperCAmelCase = True  ,		_UpperCAmelCase = "constant"  ,		_UpperCAmelCase = 0.0  ,		_UpperCAmelCase = "topK"  ,		):
             super(_UpperCAmelCase  ,		self						).__init__(in_features=_UpperCAmelCase  ,		out_features=_UpperCAmelCase  ,		bias=_UpperCAmelCase						)
             assert pruning_method in ["topK", "threshold", "sigmoied_threshold", "magnitude", "l0"]
             UpperCAmelCase__	:   Union[str, Any]												=	pruning_method

             if self.pruning_method in ["topK", "threshold", "sigmoied_threshold", "l0"]:
                    UpperCAmelCase__	:   Union[str, Any]												=	mask_scale
                    UpperCAmelCase__	:   Optional[int]												=	mask_init
                    UpperCAmelCase__	:   List[str]												=	nn.Parameter(torch.empty(self.weight.size()						)						)
                    self.init_mask()




      def 							lowerCamelCase     (					self						):
             if self.mask_init == "constant":
                    init.constant_(self.mask_scores  ,		val=self.mask_scale						)
             elif self.mask_init == "uniform":
                    init.uniform_(self.mask_scores  ,		a=-self.mask_scale  ,		b=self.mask_scale						)
             elif self.mask_init == "kaiming":
                    init.kaiming_uniform_(self.mask_scores  ,		a=math.sqrt(5						)						)




      def 							lowerCamelCase     (					self  ,		_UpperCAmelCase  ,		_UpperCAmelCase						):
             # Get the mask
             if self.pruning_method == "topK":
                    UpperCAmelCase__	:   Union[str, Any]												=	TopKBinarizer.apply(self.mask_scores  ,		_UpperCAmelCase						)
             elif self.pruning_method in ["threshold", "sigmoied_threshold"]:
                    UpperCAmelCase__	:   List[Any]												=	'''sigmoied''' in self.pruning_method
                    UpperCAmelCase__	:   Tuple												=	ThresholdBinarizer.apply(self.mask_scores  ,		_UpperCAmelCase  ,		_UpperCAmelCase						)
             elif self.pruning_method == "magnitude":
                    UpperCAmelCase__	:   Optional[int]												=	MagnitudeBinarizer.apply(self.weight  ,		_UpperCAmelCase						)
             elif self.pruning_method == "l0":
                    UpperCAmelCase__							,							UpperCAmelCase__							,							UpperCAmelCase__	:   int												=	-0.1, 1.1, 2 / 3
                    if self.training:
                           UpperCAmelCase__	:   Optional[int]												=	torch.zeros_like(self.mask_scores						).uniform_().clamp(0.00_01  ,		0.99_99						)
                           UpperCAmelCase__	:   Tuple												=	torch.sigmoid((u.log() - (1 - u).log() + self.mask_scores) / b						)
                    else:
                           UpperCAmelCase__	:   Any												=	torch.sigmoid(self.mask_scores						)
                    UpperCAmelCase__	:   List[Any]												=	s * (r - l) + l
                    UpperCAmelCase__	:   Optional[int]												=	s_bar.clamp(min=0.0  ,		max=1.0						)
             # Mask weights with computed mask
             UpperCAmelCase__	:   Union[str, Any]												=	mask * self.weight
             # Compute output (linear layer) with masked weights
             return nn.functional.linear(_UpperCAmelCase  ,		_UpperCAmelCase  ,		self.bias						)