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 Rust (1.15.1) (judge verdict: Accepted)

#[allow(unused_imports)]
use std::char::from_digit;
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::fs::File;
#[allow(unused_imports)]
use std::io::prelude::*;
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufReader, BufWriter, Stdin, Stdout, Write};
#[allow(unused_imports)]
use std::mem::swap;
#[allow(unused_imports)]
use std::str::FromStr;
type BoxResult<T> = Result<T, Box<std::error::Error>>;
fn main() {
    let mut scanner = Scanner::new(stdin());
    let _n = scanner.read::<usize>().unwrap();
    let arr = scanner.read_chars().unwrap();
    let category = vec!['S', 'W'];
    for &init in category.iter() {
        for &end in category.iter() {
            if let Some(ans) = solve(init, end, &arr) {
                println!("{}", ans.into_iter().collect::<String>());
                return;
            }
        }
    }
    println!("-1");
}

fn solve(init: char, end: char, arr: &[char]) -> Option<Vec<char>> {
    let n = arr.len();
    let mut kinds = vec!['.'; n];
    kinds[0] = init;
    kinds[n - 1] = end;
    for i in 0..n {
        let prv = kinds[(i + n - 1) % n];
        let opposite = if prv == 'S' { 'W' } else { 'S' };
        let nxt = if (kinds[i] == 'S' && arr[i] == 'o') || (kinds[i] == 'W' && arr[i] == 'x') {
            prv
        } else {
            opposite
        };
        if kinds[(i + 1) % n] != '.' && kinds[(i + 1) % n] != nxt {
            return None;
        } else {
            kinds[(i + 1) % n] = nxt;
        }
    }
    Some(kinds)
}

pub struct UnionFindTree {
    parents: Vec<usize>,
    heights: Vec<usize>,
    sizes: Vec<usize>,
    group_num: usize,
}

impl UnionFindTree {
    pub fn new(size: usize) -> UnionFindTree {
        UnionFindTree {
            parents: (0..size).collect(),
            heights: vec![0; size],
            sizes: vec![1; size],
            group_num: size,
        }
    }

    pub fn climb_up(&mut self, node: usize) -> usize {
        let mut parents_to_root = vec![];
        let mut present = node;
        while self.parents[present] != present {
            parents_to_root.push(present);
            present = self.parents[present];
        }
        for &node in parents_to_root.iter() {
            self.parents[node] = present;
        }
        present
    }

    pub fn is_same_group(&mut self, x: usize, y: usize) -> bool {
        self.climb_up(x) == self.climb_up(y)
    }

    pub fn unite(&mut self, x: usize, y: usize) {
        let root_x = self.climb_up(x);
        let root_y = self.climb_up(y);
        if root_x == root_y {
            return;
        }
        if self.heights[root_x] > self.heights[root_y] {
            self.parents[root_y] = root_x;
            self.sizes[root_x] += self.sizes[root_y];
        } else if self.heights[root_x] < self.heights[root_y] {
            self.parents[root_x] = root_y;
            self.sizes[root_y] += self.sizes[root_x];
        } else {
            self.parents[root_y] = root_x;
            self.heights[root_x] += 1;
            self.sizes[root_x] += self.sizes[root_y];
        }
        self.group_num -= 1;
    }

    pub fn group_num(&self) -> usize {
        self.group_num
    }
}

#[allow(dead_code)]
struct Scanner<R> {
    reader: BufReader<R>,
    buffer: String,
}
impl<R> Scanner<R>
where
    R: Read,
{
    #[allow(dead_code)]
    fn new(inner: R) -> Scanner<R> {
        let reader = BufReader::new(inner);
        let buffer = String::new();
        Scanner {
            reader: reader,
            buffer: buffer,
        }
    }
    #[allow(dead_code)]
    fn with_capacity(capacity: usize, inner: R) -> Scanner<R> {
        let reader = BufReader::with_capacity(capacity, inner);
        let buffer = String::new();
        Scanner {
            reader: reader,
            buffer: buffer,
        }
    }
    #[allow(dead_code)]
    fn read_line(&mut self) -> BoxResult<String> {
        self.reader.read_line(&mut self.buffer)?;
        let cloned = self.buffer.trim().to_string();
        self.buffer.clear();
        Ok(cloned)
    }
    #[allow(dead_code)]
    fn read<T>(&mut self) -> BoxResult<T>
    where
        T: FromStr,
        T::Err: std::fmt::Debug,
        T::Err: std::error::Error,
        T::Err: 'static,
    {
        self.reader.read_line(&mut self.buffer)?;
        let parsed = self.buffer.trim().parse()?;
        self.buffer.clear();
        Ok(parsed)
    }
    #[allow(dead_code)]
    fn read_vector<T>(&mut self) -> BoxResult<Vec<T>>
    where
        T: FromStr,
        T::Err: std::fmt::Debug,
        T::Err: std::error::Error,
        T::Err: 'static,
    {
        self.reader.read_line(&mut self.buffer)?;
        let parsed_vec = self
            .buffer
            .trim()
            .split_whitespace()
            .map(|s| s.parse())
            .collect::<Result<Vec<_>, _>>()?;
        self.buffer.clear();
        Ok(parsed_vec)
    }
    #[allow(dead_code)]
    fn read_matrix<T>(&mut self, lines: usize) -> BoxResult<Vec<Vec<T>>>
    where
        T: FromStr,
        T::Err: std::fmt::Debug,
        T::Err: std::error::Error,
        T::Err: 'static,
    {
        let mut parsed_matrix = vec![];
        for _ in 0..lines {
            self.reader.read_line(&mut self.buffer)?;
            parsed_matrix.push(
                self.buffer
                    .trim()
                    .split_whitespace()
                    .map(|s| s.parse())
                    .collect::<Result<Vec<_>, _>>()?,
            );
            self.buffer.clear();
        }
        Ok(parsed_matrix)
    }
    #[allow(dead_code)]
    fn read_chars(&mut self) -> BoxResult<Vec<char>> {
        self.reader.read_line(&mut self.buffer)?;
        let chars = self.buffer.trim().chars().collect::<Vec<_>>();
        self.buffer.clear();
        Ok(chars)
    }
}