25 lines
552 B
Python
25 lines
552 B
Python
import sys
|
|
from math import log10
|
|
|
|
D = dict() # cache
|
|
|
|
def mutate(n:int, t:int) -> int:
|
|
x = D.get((n,t),-1)
|
|
if x < 0:
|
|
if t == 0:
|
|
x = 1
|
|
elif n == 0:
|
|
x = mutate(1, t-1)
|
|
elif (digits := int(log10(n))+1) & 1 == 0: # even nb of digits
|
|
l, r = divmod(n, 10**(digits//2))
|
|
x = mutate(l, t-1) + mutate(r, t-1)
|
|
else:
|
|
x = mutate(n*2024, t-1)
|
|
D[(n,t)] = x
|
|
return x
|
|
|
|
stones = [int(n) for n in sys.stdin.read().strip().split(" ")]
|
|
|
|
for times in [25,75]:
|
|
print(sum(mutate(stone, times) for stone in stones))
|