fn treemap_add(tm : treemap(int, int), n m : int) : tm : treemap(int, int) [ var s := treemap_search(tm, n); var ex := select(s is j, 0, s.j); tm := treemap_insert(tm, n, ex + m); return tm; ] fn main [ var stones := map(list_break_whitespace(read_lazy(h[0])), ston); var tm := treemap_init(int, int); for s in stones do tm := treemap_add(tm, s, 1); for i := 0 to 75 do [ var new_tm := treemap_init(int, int); for t in tm do [ var k := t.k; var v := t.v; if k = 0 then [ new_tm := treemap_add(new_tm, 1, v); continue; ] var str := ntos(k); if not len(str) bt 0 then [ var half := len(str) shr 1; new_tm := treemap_add(new_tm, ston(str[ .. half]), v); new_tm := treemap_add(new_tm, ston(str[half .. ]), v); continue; ] new_tm := treemap_add(new_tm, k * 2024, v); ] tm := new_tm; ] var n := 0; for t in tm do n += t.v; write(h[1], ntos(n) + nl); ]