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 C# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Numerics;
using System.Text;






namespace contest
{





    class contest
    {
        int[] dx = new int[] { 1, 0, -1, 0 };
        int[] dy = new int[] { 0, 1, 0, -1 };

        static void Main(string[] args)
        {



            //Console.WriteLine();




            //int n = int.Parse(Console.ReadLine());
            //var num = Console.ReadLine().Split().Select(int.Parse).ToArray();




            //var arr = new int[n][];
            //for(int i =0; i< n; i++)
            //{
            //    arr[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();
            //}




            //var num = Console.ReadLine().Split().Select(int.Parse).ToArray();
            //int n = num[0];
            //int m = num[1];



            #region


            //var num = Console.ReadLine().Split().Select(int.Parse).ToArray();
            //int n = num[0];
            //int m = num[1];

            int n = int.Parse(Console.ReadLine());
            string s = Console.ReadLine();
            var ans = new char[n];
            bool yes = false;
            var ch = new bool[n];
            for(int i=0; i< n; i++)
            {
                //char l = i > 0 ? ans[i - 1] : ans[n - 1];
                //char r = i < n - 1 ? ans[i + 1] : ans[0];
                char c = s[i];
                //if (ch[i]) continue;
                
                    int j = i < n - 1 ? i + 1 : 0;
                    int count = 1;
                    bool sheep = true;
                    ans[i] = 'S';
                    for(;count<n; count++)
                    {

                        char l = j > 0 ? s[j - 1] : s[n - 1];
                        char r = s[j] ;
                        char nx = j < n - 1 ? s[j + 1] : s[0];
                        char p = pre(j, ans);

                        if (sheep && (count==1 || p=='S') && r=='o')
                        {
                            ans[j] = 'S';
                        }
                        else if (sheep && r == 'x')
                        {
                            ans[j] = 'S';
                            if(p!='W')sheep = false;
                        }
                        else if (!sheep && r == 'o')
                        {
                            //if (l == nx) break;

                            //char p = pre(j, ans);
                            if (p == 'S')
                            {
                                ans[j] = 'W';

                            }
                            else
                            {
                                ans[j] = 'W';
                                sheep = true;
                            }
                        }
                        else if (!sheep && r == 'x')
                        {
                            //char p = pre(j, ans);
                            if (p == 'S')
                            {
                                ans[j] = 'W';
                                sheep = true;
                            }
                            else ans[j] = 'W';
                        }
                        else break;

                        //count++;
                        if (j < n - 1) j++;
                        else j = 0;
                    }
                    if(count==n && check(ans,s))
                    {
                        yes = true;
                        break;
                    }


                j = i < n - 1 ? i + 1 : 0;
                count = 1;
                sheep = false;
                ans[i] = 'W';
                for (; count < n; count++)
                {

                    char l = j > 0 ? s[j - 1] : s[n - 1];
                    char r = s[j];
                    char nx = j < n - 1 ? s[j + 1] : s[0];
                    char p = pre(j, ans);

                    if (sheep && (count == 1 || p == 'S') && r == 'o')
                    {
                        ans[j] = 'S';
                    }
                    else if (sheep && r == 'x')
                    {
                        ans[j] = 'S';
                        sheep = false;
                    }
                    else if (!sheep && r == 'o')
                    {
                        //if (l == nx) break;

                        //char p = pre(j, ans);
                        if (p == 'S')
                        {
                            ans[j] = 'W';

                        }
                        else
                        {
                            ans[j] = 'W';
                            sheep = true;
                        }
                    }
                    else if (!sheep && r == 'x')
                    {
                        //char p = pre(j, ans);
                        if (p == 'S')
                        {
                            ans[j] = 'W';
                            sheep = true;
                        }
                        else ans[j] = 'W';
                    }
                    else break;

                    //count++;
                    if (j < n - 1) j++;
                    else j = 0;
                }
                if (count == n && check(ans, s))
                {
                    yes = true;
                    
                }
                break;

            }


            if (yes) Console.WriteLine(string.Join("", ans));
            else Console.WriteLine("-1");
           





            #endregion







            //Console.WriteLine();





            Console.Read();



        }

        public static char pre(int i , char[] a)
        {
            return i > 0 ? a[i - 1] : a.Last();
        }
        public static char next(int i, char[] a)
        {
            return i < a.Length - 1 ? a[i + 1] : a[0];
        }

        public static bool check(char[] a, string s)
        {
            for (int i = 0; i < s.Length; i++)
            {
                char l = pre(i, a);
                char r = next(i, a);
                char c = s[i];
                if (c == 'x' && a[i] == 'S' && l != r) continue;
                if (c == 'o' && a[i] == 'S' && l == r) continue;
                if (c == 'x' && a[i] == 'W' && l == r) continue;
                if (c == 'o' && a[i] == 'W' && l != r) continue;
                return false;
            }
            return true;
        }

    }




    class Segment
    {
        public long[] arr;


        public long n;
        HashSet<long> list = new HashSet<long>();
        //public List<long> q = new List<long>();    
        public int count = 0;

        public Segment(long m, long k)
        {
            this.n = m;
            //arr = Enumerable.Range(0, n*2).ToArray();
            arr = new long[n * 4];


            for (int i = 0; i < n * 4; i++)
            {
                //arr[i] = int.MaxValue;
                arr[i] = 0;
            }
            for (int i = 1; i < 40; i++)
                list.Add((long)Math.Pow(k, i));


        }


        //public void update(int p, int value)
        //{  // set value at position p
        //    for (arr[p += n] = value; p > 1; p >>= 1) arr[p >> 1] = Math.Min( arr[p] , arr[p ^ 1]);
        //}



        //public void update(int i, int value)
        //{
        //    i += n / 2;
        //    arr[i] = value;
        //    for (; i > 1; i >>= 1)
        //        arr[i >> 1] = Math.Min(arr[i], arr[i ^ 1]);
        //}


        public void update(long i, long x)
        {
            //i = (n / 2) + i - 1;
            i = n + i - 1;
            arr[i] = x;
            //if (list.Contains(x)) count++;

            while (i > 0)
            {
                i = (i - 1) / 2;
                //arr[i] = Math.Min(arr[(i * 2) + 1], arr[(i * 2) + 2]);
                long tmp = arr[(i * 2 + 1)] + arr[(i * 2) + 2];
                arr[i] = tmp;
                //if (list.Contains(tmp)) count++;

                //if (arr[i * 2 + 1] > arr[i * 2 + 2])
                //{
                //    arr[i] = arr[i * 2 + 1];
                //}
                //else
                //{
                //    arr[i] = arr[i * 2 + 2];
                //}
                //arr[i] = arr[i * 2 + 1] + arr[i * 2 + 2];

            }

        }




        //call : query(a,b, 0, 0, n)
        //public int query(int a, int b, int k, int l, int r)
        //{
        //    if (r <= a || b <= l) return int.MaxValue;
        //    if (a <= l && r <= b) return arr[k];

        //    //return Math.Min(query(a, b, (k * 2) + 1, l, (l + r) / 2), query(a, b, (k * 2) + 2, (l + r) / 2, r));      


        //    var vl = query(a, b, (k * 2) + 1, l, (l + r) / 2);
        //    var vr = query(a, b, (k * 2) + 2, (l + r) / 2, r);

        //    //var vl = query(a, b, (k << 1) + 1, l, (l + r) / 2);
        //    //var vr = query(a, b, (k + 1) << 1, (l + r) / 2, r);



        //    if (vl == int.MaxValue && vr == int.MaxValue) return 0;
        //    return Math.Min(vl, vr);


        //}
        public int query()
        {
            for (int i = 0; i < arr.Length; i++)
            {
                long tmp = arr[i];
                if (!list.Contains(tmp)) continue;
                count++;

            }
            return count;
        }


        //public int query(int a, int b, int k, int l, int r)
        //{
        //    // query for arr[i..j]

        //    if (l > b || r < a)               // segment completely outside range
        //        return int.MaxValue;                       // represents a null node

        //    if (a <= l && b >= r)             // segment completely inside range
        //        return arr[k];

        //    int mid = l + (r - l) / 2;       // partial overlap of current segment and queried range. Recurse deeper.

        //    if (a > mid)
        //        return query(2 * k + 2, mid + 1, r, a, b);
        //    else if (b <= mid)
        //        return query(2 * k + 1, l, mid, a, b);

        //    int leftQuery = query(2 * k + 1, l, mid, a, mid);
        //    int rightQuery = query(2 * k + 2, mid + 1, r, mid + 1, b);

        //    // merge query results
        //    if (leftQuery == int.MaxValue && rightQuery == int.MaxValue) return 0;
        //    return Math.Min(leftQuery, rightQuery);


        //}








        //public int query(int l, int r)
        //{
        //    int res = int.MaxValue;
        //    for (l += n, r += n; l < r; l >>= 1, r >>= 1)
        //    {
        //        if ((l & 1) == 1) res = Math.Min(res, arr[l++]);
        //        if ((r & 1) == 1) res = Math.Min(res, arr[--r]);
        //    }
        //    return res;
        //}



        //public int query(int a, int b, int r)
        //{
        //    int res = int.MaxValue;
        //    for (a += r / 2, b += r / 2; a <= b; a = (a + 1) >> 1, b = (b - 1) >> 1)
        //    //for (; a <= b; a = (a + 1) >> 1, b = (b - 1) >> 1)
        //    {
        //        if ((a & 1) != 0)
        //            res = Math.Min(res, arr[a]);
        //        if ((b & 1) == 0)
        //            res = Math.Min(res, arr[b]);
        //    }
        //    return res;
        //}




        //public int query(int l, int r)
        //{  // sum on interval [l, r)
        //    int res = int.MaxValue;
        //    for (l += n, r += n; l < r; l >>= 1, r >>= 1)
        //    {
        //        if ((l & 1) == 1) res = Math.Min(res, arr[l++]);

        //        if ((r & 1) == 1) res = Math.Min(res, arr[--r]);
        //    }
        //    return res;
        //}

    }


    class UnionFind
    {
        public int[] path;
        public int[] size;

        //public int[] parent;
        //public int[] child;

        public UnionFind(int n)
        {
            path = new int[n + 1];
            size = new int[n + 1];
            //parent = new int[n];
            //child = new int[n];

            for (int i = 0; i < n + 1; i++)
            {
                path[i] = i;
                size[i] = 1;
                //parent[i] = i;
                //child[i] = i;
            }

        }

        private int root(int i)
        {
            while (i != path[i])
            {
                path[i] = path[path[i]];
                i = path[i];
            }
            return i;
        }



        public bool find(int p, int q)
        {
            if (p < 0 || q < 0) return false;
            return root(p) == root(q);
        }


        public int rt(int p)
        {
            return root(p);
        }


        public void unite(int p, int q)
        {
            if (p < 0 || q < 0) return;
            //if (p < 0)
            //{
            //    int a = root(p * -1);
            //    int b = root(q);
            //}
            //if (q < 0) q *= -1;

            int i = root(p);
            int j = root(q);
            if (i == j) return;

            if (size[i] > size[j])
            {

                int tmp = i;
                i = j;
                j = tmp;
            }
            size[j] += size[i];
            path[i] = j;



        }


    }
}