fun readStr () = valOf (TextIO.inputLine TextIO.stdIn) exception WrongInput fun findAns s = let val (x, y) = List.foldl (fn (ch, (x_acc, y_acc)) => case ch of #"N" => (x_acc, y_acc - 1) | #"E" => (x_acc + 1, y_acc) | #"W" => (x_acc - 1, y_acc) | #"S" => (x_acc, y_acc + 1) | _ => raise WrongInput ) (0, 0) (String.explode s) in Math.sqrt (Real.fromInt (x*x + y*y)) end val () = let val s = readStr () val sWithoutCR = String.substring(s, 0, String.size s - 1) val ans = findAns sWithoutCR in print (Real.toString ans ^ "\n") end