22 lines
510 B
Python
22 lines
510 B
Python
import sys
|
|
from math import log10
|
|
from functools import cache
|
|
|
|
@cache
|
|
def mutate(n:int, t:int) -> int:
|
|
if t == 0:
|
|
return 1
|
|
if n == 0:
|
|
return mutate(1, t-1)
|
|
if (digits := int(log10(n))+1) & 1 == 0:
|
|
return count(divmod(n, 10**(digits//2)), t-1)
|
|
return mutate(n*2024, t-1)
|
|
|
|
def count(stones: list[int], times: int) -> int:
|
|
return sum(mutate(stone, times) for stone in stones)
|
|
|
|
stones = [int(n) for n in sys.stdin.read().strip().split(" ")]
|
|
|
|
print(count(stones, 25))
|
|
print(count(stones, 75))
|