fn main [ var lines := list_break_to_lines(read_lazy(h[0])); const x := len(lines[0]); const y := len(lines); var x_dist := array_fill(-1, [x]); var x_pos := 0; for i := 0 to x do [ x_dist[i] := x_pos; for j := 0 to y do if lines[j][i] = '#' then goto no_exp1; x_pos += 1; no_exp1: x_pos += 1; ] var y_dist := array_fill(-1, [y]); var y_pos := 0; for j := 0 to y do [ y_dist[j] := y_pos; for i := 0 to x do if lines[j][i] = '#' then goto no_exp2; y_pos += 1; no_exp2: y_pos += 1; ] var galaxies := empty(tuple2(int, int)); for i := 0 to x do [ for j := 0 to y do [ if lines[j][i] = '#' then [ galaxies +<= mktuple2(x_dist[i], y_dist[j]); ] ] ] var total := 0; for g1 in galaxies do [ for g2 in galaxies do [ if g1 >= g2 then continue; total += abs(g1.v1 - g2.v1) + abs(g1.v2 - g2.v2); ] ] write(h[1], ntos(total) + nl); ]