type dir = North | East | West | South let dir_of_char = function | 'N' -> North | 'E' -> East | 'W' -> West | 'S' -> South | _ -> failwith "" let solve s = let slen = String.length s in let rec solve' idx pos = if idx >= slen then pos else let d = dir_of_char s.[idx] and x, y = pos in let nextPos = match d with | North -> (x, y - 1) | East -> (x + 1, y) | West -> (x - 1, y) | South -> (x, y + 1) in solve' (idx + 1) nextPos in let x, y = solve' 0 (0, 0) in x * x + y * y |> float_of_int |> sqrt let () = let s = read_line () in solve s |> Printf.printf "%.3f"