Problem:
Score : 500 points

Problem Statement

Snuke, who loves animals, built a zoo.

There are N animals in this zoo. They are conveniently numbered 1 through N, and arranged in a circle.
The animal numbered i (2≤i≤N-1) is adjacent to the animals numbered i-1 and i+1. Also, the animal numbered 1 is adjacent to the animals numbered 2 and N, and the animal numbered N is adjacent to the animals numbered N-1 and 1.

There are two kinds of animals in this zoo: honest sheep that only speak the truth, and lying wolves that only tell lies.

Snuke cannot tell the difference between these two species, and asked each animal the following question: "Are your neighbors of the same species?" The animal numbered i answered s_i. Here, if s_i is o, the animal said that the two neighboring animals are of the same species, and if s_i is x, the animal said that the two neighboring animals are of different species.

More formally, a sheep answered o if the two neighboring animals are both sheep or both wolves, and answered x otherwise.
Similarly, a wolf answered x if the two neighboring animals are both sheep or both wolves, and answered o otherwise.

Snuke is wondering whether there is a valid assignment of species to the animals that is consistent with these responses. If there is such an assignment, show one such assignment. Otherwise, print -1.

Constraints

3 ≤ N ≤ 10^{5}

s is a string of length N consisting of o and x.

Input

The input is given from Standard Input in the following format:

N
s

Output

If there does not exist an valid assignment that is consistent with s, print -1.
Otherwise, print an string t in the following format. The output is considered correct if the assignment described by t is consistent with s.

t is a string of length N consisting of S and W.

If t_i is S, it indicates that the animal numbered i is a sheep. If t_i is W, it indicates that the animal numbered i is a wolf.

Sample Input 1

6
ooxoox

Sample Output 1

SSSWWS

For example, if the animals numbered 1, 2, 3, 4, 5 and 6 are respectively a sheep, sheep, sheep, wolf, wolf, and sheep, it is consistent with their responses. Besides, there is another valid assignment of species: a wolf, sheep, wolf, sheep, wolf and wolf.

Let us remind you: if the neiboring animals are of the same species, a sheep answers o and a wolf answers x. If the neiboring animals are of different species, a sheep answers x and a wolf answers o.

Sample Input 2

3
oox

Sample Output 2

-1

Print -1 if there is no valid assignment of species.

Sample Input 3

10
oxooxoxoox

Sample Output 3

SSWWSSSWWS

Solution in Haskell (GHC 7.10.3) (judge verdict: Accepted)

{-# LANGUAGE BangPatterns #-}
import           Control.Exception           (assert)
import           Control.Monad
import           Control.Monad.Primitive
import qualified Control.Monad.ST            as ST
import qualified Data.Array.IO               as IO
import qualified Data.Array.ST               as ST
import qualified Data.Array.Unboxed          as A
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Foldable
import           Data.List
import qualified Data.Map.Strict             as Map
import           Data.Maybe
import qualified Data.Sequence               as Seq
import qualified Data.Set                    as Set
import qualified Data.Vector                 as VB
import qualified Data.Vector.Mutable         as VBM
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM
import           Debug.Trace

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readInteger = fst . fromJust . BS.readInteger
readIntegerList = map readInteger . BS.words
getInteger = readInteger <$> BS.getLine
getIntegerList = readIntegerList <$> BS.getLine

inf :: Int
inf = 10^18

main = do
  n <- getInt
  (c0:cs) <- getLine

  d <- VM.new n

  let inito0 = do
        VM.set d '-'
        VM.write d (n-1) 'W'
        VM.write d 0     'S'
        VM.write d 1     'W'
      inito1 = do
        VM.set d '-'
        VM.write d (n-1) 'S'
        VM.write d 0     'S'
        VM.write d 1     'S'
      inito2 = do
        VM.set d '-'
        VM.write d (n-1) 'W'
        VM.write d 0     'W'
        VM.write d 1     'S'
      inito3 = do
        VM.set d '-'
        VM.write d (n-1) 'S'
        VM.write d 0     'W'
        VM.write d 1     'W'

  let initx0 = do
        VM.set d '-'
        VM.write d (n-1) 'W'
        VM.write d 0     'W'
        VM.write d 1     'W'
      initx1 = do
        VM.set d '-'
        VM.write d (n-1) 'S'
        VM.write d 0     'W'
        VM.write d 1     'S'
      initx2 = do
        VM.set d '-'
        VM.write d (n-1) 'W'
        VM.write d 0     'S'
        VM.write d 1     'S'
      initx3 = do
        VM.set d '-'
        VM.write d (n-1) 'S'
        VM.write d 0     'S'
        VM.write d 1     'W'


  let initsx :: [IO ()]
      initsx = [initx0, initx1, initx2, initx3]
      initso :: [IO ()]
      initso = [inito0, inito1, inito2, inito3]

  let expectedChar i = do
        tn_2 <- VM.read d (i-1)
        tn_1 <- VM.read d i
        t0   <- VM.read d (if i == n-1 then 0 else i+1)
        if tn_2 == t0
          then return (if tn_1 == 'S' then 'o' else 'x')
          else return (if tn_1 == 'S' then 'x' else 'o')

      flipT 'S' = 'W'
      flipT 'W' = 'S'

  let solve :: Int -> String -> IO Bool
      solve i [c]= do
        e <- expectedChar i
        return (c == e)
      solve i (c:[x])= do
        e <- expectedChar i
        if (c == e)
          then solve (i+1) [x]
          else return False
      solve i ('o':cs) = do
        ti_1 <- VM.read d (i-1)
        ti   <- VM.read d i
        if ti == 'W'
          then VM.write d (i+1) (flipT ti_1)
          else VM.write d (i+1) ti_1
        solve (i+1) cs
      solve i ('x':cs) = do
        ti_1 <- VM.read d (i-1)
        ti   <- VM.read d i
        if ti == 'S'
          then VM.write d (i+1) (flipT ti_1)
          else VM.write d (i+1) ti_1
        solve (i+1) cs

      initsc = if c0 == 'o' then initso else initsx

      solveAll [] = print (-1)
      solveAll (f:fs) = do
        f
        res <- solve 1 cs
        if res
          then do v <- V.freeze d
                  let d' = V.toList v
                  putStrLn d'
                  -- print $ checkResult v 0
          else solveAll fs

      checkResult v i
        | i == n = (True, i)
        | otherwise = let l = if i == 0 then v V.! (n-1) else v V.! (i-1)
                          t = v V.! i
                          r = if i == (n-1) then v V.! 0 else v V.! (i+1)
                          mk = (c0:cs) !! i
                          ok | t == 'S' && mk == 'o' = l == r
                             | t == 'S' && mk == 'x' = l /= r
                             | t == 'W' && mk == 'o' = l /= r
                             | t == 'W' && mk == 'x' = l == r
                      in if ok then checkResult v (i+1)
                         else (False, i)


  solveAll initsc