fun readStr () = let fun scan reader stream = SOME (StringCvt.splitl (not o Char.isSpace) reader (StringCvt.skipWS reader stream)) in valOf (TextIO.scanStream scan TextIO.stdIn) end exception BadInput fun directionToInt "E" = 0 | directionToInt "S" = 1 | directionToInt "W" = 2 | directionToInt "N" = 3 | directionToInt _ = raise BadInput val () = let val a = readStr () val b = readStr () val ans = (4 + (directionToInt b) - (directionToInt a)) mod 4 in print (Int.toString ans ^ "\n") end