
"""simple docstring"""




import re

from flax.core.frozen_dict import freeze
from flax.traverse_util import flatten_dict, unflatten_dict
from jax.experimental import PartitionSpec as P


# Sentinels
A__      :	List[Any]          =    object()

# For specifying empty leaf dict `{}`
A__      :	str          =    object()



def 							a__ (				lowerCAmelCase	:       Tuple       ,    lowerCAmelCase	:       List[Any]		):






     '''simple docstring'''
     UpperCAmelCase__							: Optional[int] 							=						tuple((re.compile(x + "$"		) for x in qs)		)
     for i in range(len(lowerCAmelCase		) - len(lowerCAmelCase		) + 1		):
          UpperCAmelCase__							: Dict 							=						[x.match(lowerCAmelCase		) for x, y in zip(lowerCAmelCase       ,    ks[i:]		)]
          if matches and all(lowerCAmelCase		):
               return True
     return False



def 							a__ (				lowerCAmelCase	:       List[str]		):






     '''simple docstring'''
     def replace(lowerCAmelCase	:       Dict       ,    lowerCAmelCase	:       Optional[int]		):
          for rule, replacement in rules:
               if _match(lowerCAmelCase       ,    lowerCAmelCase		):
                    return replacement
          return val

     return replace



def 							a__ (				):






     '''simple docstring'''
     return [
         # embeddings
         (("transformer", "wpe", "embedding"), P("mp"       ,    lowerCAmelCase		)),
         (("transformer", "wte", "embedding"), P("mp"       ,    lowerCAmelCase		)),
         # atention
         (("attention", "(q_proj|k_proj|v_proj)", "kernel"), P(lowerCAmelCase       ,    "mp"		)),
         (("attention", "out_proj", "kernel"), P("mp"       ,    lowerCAmelCase		)),
         (("attention", "out_proj", "bias"), None),
         # mlp
         (("mlp", "c_fc", "kernel"), P(lowerCAmelCase       ,    "mp"		)),
         (("mlp", "c_fc", "bias"), P("mp"		)),
         (("mlp", "c_proj", "kernel"), P("mp"       ,    lowerCAmelCase		)),
         (("mlp", "c_proj", "bias"), None),
         # layer norms
         ((r"ln_\d+", "bias"), None),
         ((r"\d+", r"ln_\d+", "scale"), None),
         (("ln_f", "bias"), None),
         (("ln_f", "scale"), None),
     ]



def 							a__ (				lowerCAmelCase	:       List[str]		):






     '''simple docstring'''
     UpperCAmelCase__							: Any 							=						_get_partition_rules()
     UpperCAmelCase__							: Any 							=						_replacement_rules(lowerCAmelCase		)
     UpperCAmelCase__							: Tuple 							=						{k: _unmatched for k in flatten_dict(lowerCAmelCase		)}
     UpperCAmelCase__							: List[Any] 							=						{k: replace(lowerCAmelCase       ,    lowerCAmelCase		) for k, v in initd.items()}
     assert _unmatched not in result.values(), "Incomplete partition spec."
     return freeze(unflatten_dict(lowerCAmelCase		)		)





"""simple docstring"""




from math import isqrt



def 							a__ (				lowerCAmelCase	:       int		):






     '''simple docstring'''
     UpperCAmelCase__							: Tuple 							=						[True] * max_number
     for i in range(2       ,    isqrt(max_number - 1		) + 1		):
          if is_prime[i]:
               for j in range(i**2       ,    lowerCAmelCase       ,    lowerCAmelCase		):
                    UpperCAmelCase__							: List[Any] 							=						False

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



def 							a__ (				lowerCAmelCase	:       int = 10**8		):






     '''simple docstring'''
     UpperCAmelCase__							: Dict 							=						calculate_prime_numbers(max_number // 2		)

     UpperCAmelCase__							: Optional[int] 							=						0
     UpperCAmelCase__							: Optional[int] 							=						0
     UpperCAmelCase__							: Tuple 							=						len(lowerCAmelCase		) - 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() = }""")



