uses heap; fn main [ var lines := list_break_to_lines(read_lazy(h[0])); const x := select(len(lines) > 25, 7, 71); const y := x; const n := select(len(lines) > 25, 12, 1024); var a := array_fill(false, [x, y]); for l := 0 to n do [ var coords := map(list_break(lines[l], ','), ston); a[coords[0], coords[1]] := true; ] var visited := array_fill(false, [x, y]); var todo := heap_from_list([ mktuple3(0, 0, 0) ]); visited[0, 0] := true; while heap_is_nonempty(todo) do [ var next : tuple3(int, int, int); todo, next := heap_extract(todo); if next.v2 = x - 1, next.v3 = y - 1 then [ write(h[1], ntos(next.v1) + nl); break; ] for d in [ [0, 1], [0, -1], [1, 0], [-1, 0] ] do [ var nx := next.v2 + d[0]; var ny := next.v3 + d[1]; if nx < 0 or nx >= x or ny < 0 or ny >= y then continue; if a[nx, ny] then continue; if visited[nx, ny] then continue; visited[nx, ny] := true; todo := heap_insert(todo, mktuple3(next.v1 + 1, nx, ny)); ] ] ]