fn main [ var lines := list_break_to_lines(read_lazy(h[0])); const x := select(len(lines) > 12, 11, 101); const y := select(len(lines) > 12, 7, 103); var robots := empty(tuple4(int, int, int, int)); for l in lines do [ for i := 0 to len(l) do if l[i] <> '-', l[i] < '0' or l[i] > '9' then l[i] := ' '; var p := map(list_break_whitespace(l), ston); robots +<= mktuple4(p[0], p[1], p[2], p[3]); ] var steps := 0; var adjacent := empty(tuple2(int, int)); var visited := treeset_init(list(list(byte))); while not is_exception w do [ var a := fill(fill(byte, ' ', x), y); for r in robots do [ var xp, yp := r.v1, r.v2; a[yp][xp] := select(byte, a[yp][xp] <> ' ', '1', a[yp][xp] + 1); ] var adj := 0; write(h[1], "step: " + ntos(steps) + nl); for j := 0 to y do [ write(h[1], a[j] + nl); for i := 1 to x do [ if a[j][i] <> ' ', a[j][i - 1] <> ' ' then adj += 1; ] ] write(h[1], nl); adjacent +<= mktuple2(adj, steps); for r := 0 to len(robots) do [ var xp := (robots[r].v1 + robots[r].v3) mod x; if xp < 0 then xp += x; var yp := (robots[r].v2 + robots[r].v4) mod y; if yp < 0 then yp += y; robots[r].v1 := xp; robots[r].v2 := yp; ] if treeset_test(visited, a) then break; visited := treeset_set(visited, a); steps += 1; ] adjacent := list_sort(adjacent); write(h[1], ntos(adjacent[len(adjacent) - 1].v2) + nl); ]