fn main [ var lines := list_break_to_lines(read_lazy(h[0])); var lines2 := list_break(lines, ""); var area := lines2[0]; area := list_flatten(area); var movements := list_join(lines2[1], ""); const x := len(area[0]); const y := len(area); var a := list_to_array([x, y], list_join(area, "")); a := array_flatten(a); var xp yp : int; for j := 0 to y do [ for i := 0 to x do [ if a[i, j] = '@' then [ xp, yp := i, j; a[i, j] := '.'; goto found; ] ] ] abort; found: for m in movements do [ var dx dy : int; if m = '>' then dx, dy := 1, 0; else if m = '<' then dx, dy := -1, 0; else if m = 'v' then dx, dy := 0, 1; else if m = '^' then dx, dy := 0, -1; else abort; var xn, yn := xp, yp; while true do [ xn += dx; yn += dy; if a[xn, yn] = '#' then goto dont_move; if a[xn, yn] = '.' then break; ] a[xn, yn] := a[xp + dx, yp + dy]; a[xp + dx, yp + dy] := '.'; xp += dx; yp += dy; dont_move: ] var sum := 0; for j := 0 to y do [ for i := 0 to x do [ if a[i, j] = 'O' then [ sum += 100 * j + i; ] ] ] write(h[1], ntos(sum) + nl); ]