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 (Python):
n = int(input())
s = list(map(lambda x: 0 if x == 'o' else 1, list(input())))


def decode_animals(l):
    return "".join(list(map(lambda x: 'S' if x == 0 else 'W', animals)))

def check(first, second, pre_last, last, first_coment, last_coment):
    
    f1 = False
    if first == 0:
        if first_coment == 0:
            f1 = second == last
        else:
            f1 = second != last
    else:
        if first_coment == 0:
            f1 = second != last
        else:
            f1 = second == last
    f2 = False
    if last == 0:
        if last_coment == 0:
            f2 = first == pre_last
        else:
            f2 = first != pre_last
    else:
        if last_coment == 0:
            f2 = first != pre_last
        else:
            f2 = first == pre_last
    return f1 and f2

for i in range(4):
    animals = []
    for j in range(2):
        
        if i >> j & 1:
            animals.append(1)
        else:
            animals.append(0)
    for i in range(2, n):
        next_animal = 0
        if animals[i-1] == 0 and s[i-1] == 0 or animals[i-1] == 1 and s[i-1] == 1:
            next_animal = animals[i-2]
        elif animals[i-1] == 0 and s[i-1] == 1 or animals[i-1] == 1 and s[i-1] == 0:
            next_animal = [1, 0][animals[i-2]]
        animals.append(next_animal)
    if check(animals[0], animals[1], animals[-2], animals[-1], s[0], s[-1]):
        ans = decode_animals(animals)
        print(ans)
        exit()
print(-1)

Solution (Python):


import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
s = input()
t = [1 if i == 'o' else 0 for i in s]
def generate(res):
    for i in range(1,n):
        if res[-1]:
            if t[i]:
                if res[-2]:
                    res.append(1)
                else:
                    res.append(0)
            else:
                if res[-2]:
                    res.append(0)
                else:
                    res.append(1)
        else:
            if t[i]:
                if res[-2]:
                    res.append(0)
                else:
                    res.append(1)
            else:
                if res[-2]:
                    res.append(1)
                else:
                    res.append(0)
    return res

def ret(ans):
    res = ["S"]*n
    for i in range(n):
        if ans[i] == 0:
            res[i] = "W"
    return ''.join(res)

ans1 = [1]
ans2 = [1]
ans3 = [1]
ans4 = [1]
if t[0]:
    ans1.append(1)
    ans2.append(0)
    res1 = generate(ans1)
    res2 = generate(ans2)
    if res1[-1] == ans1[0] and ans1[1] == res1[-2]:
        print(ret(res1[:-1]))
        quit()
    elif res2[-1] == ans2[0] and ans2[1] == res2[-2]:
        print(ret(res2[:-1]))
        quit()
else:
    ans3.append(1)
    ans4.append(0)
    res3 = generate(ans3)
    res4 = generate(ans4)
    if res3[-1] == ans3[0] and ans3[1] != res3[-2]:
        print(ret(res3[:-1]))
        quit()
    elif res4[-1] == ans4[0] and ans4[1] != res4[-2]:
        print(ret(res4[:-1])) 
        quit()


ans5 = [0]
ans6 = [0]
ans7 = [0]
ans8 = [0]
if t[0]:
    ans5.append(1)
    ans6.append(0)
    res5 = generate(ans5)
    res6 = generate(ans6)
    if res5[-1] == ans5[0] and ans5[1] != res5[-2]:
        print(ret(res5[:-1]))
        quit()
    elif res6[-1] == ans6[0] and ans6[1] != res6[-2]:
        print(ret(res6[:-1]))
        quit()

else:
    ans7.append(1)
    ans8.append(0)
    res7 = generate(ans7)
    res8 = generate(ans8)
    if res7[-1] == ans7[0] and ans7[1] == res7[-2]:
        print(ret(res7[:-1]))
        quit()
    elif res8[-1] == ans8[0] and ans8[1] == res8[-2]:
        print(ret(res8[:-1]))
        quit()

print(-1)

Solution (Python):
n = int(input())
s = list(input())
u = ["S", "W"]
for i in range(2):
    for j in range(2):
        ans = [0] * n
        ans[0] = u[i]
        ans[1] = u[j]
        for k in range(2, n):
            if s[k - 1] == "o":
                if ans[k - 1] == "S":
                    if ans[k - 2] == "S":
                        c = 0
                    else:
                        c = 1
                else:
                    if ans[k - 2] == "S":
                        c = 1
                    else:
                        c = 0
            else:
                if ans[k - 1] == "S":
                    if ans[k - 2] == "S":
                        c = 1
                    else:
                        c = 0
                else:
                    if ans[k - 2] == "S":
                        c = 0
                    else:
                        c = 1
            ans[k] = u[c]
        m = 0
        if s[0] == "o":
            if ans[0] == "S":
                if ans[1] == ans[n - 1]:
                    m += 1
            else:
                if ans[1] != ans[n - 1]:
                    m += 1
        else:
            if ans[0] == "W":
                if ans[1] == ans[n - 1]:
                    m += 1
            else:
                if ans[1] != ans[n - 1]:
                    m += 1
        if s[n - 1] == "o":
            if ans[n - 1] == "S":
                if ans[0] == ans[n - 2]:
                    m += 1
            else:
                if ans[0] != ans[n - 2]:
                    m += 1
        else:
            if ans[n - 1] == "W":
                if ans[0] == ans[n - 2]:
                    m += 1
            else:
                if ans[0] != ans[n - 2]:
                    m += 1
        if m == 2:
            print("".join(ans))
            exit()
print(-1)

Solution (Python):
n = int(input())
s = input()
seed1 = ["S","W"]
ans = ["SS","SW","WS","WW"]
for i in s[1:]:
    for k,v in enumerate(ans):
        now = 0 if i == "o" else 1
        now = (now + seed1.index(v[-1]) + seed1.index(v[-2])) % 2
        if now:
            ans[k] += "W"
        else:
            ans[k] += "S"
now = 0 if s[0] == "x" else 1
for i in ans:  
    now2 = (now + seed1.index(i[-2]) + seed1.index(i[1]) + seed1.index(i[0])) % 2
    if (i[0] == i[-1]) and now2:
        print(i[:-1])
        exit()
print(-1)

Solution (Python):
import sys
n=int(input())
s = list(input())
l = list(0 for i in range(n))
l[0]='S'
l[1]='S'
for i in range(1,n-1):
    if l[i]=='S':
        if l[i-1]=='S':
            if (s[i]=='o'):
                l[i+1]='S'
            else:
                l[i+1]='W'
        else:
            if s[i]=='o':
                l[i+1]='W'
            else:
                l[i+1]='S'
    else:
        if l[i-1]=='S':
            if (s[i]=='o'):
                l[i+1]='W'
            else:
                l[i+1]='S'
        else:
            if s[i]=='o':
                l[i+1]='S'
            else:
                l[i+1]='W'
if l[n-1]=='S':
    if l[n-2]=='S':
        if (s[n-1]=='o'):
            if l[0]=='S':
                if s[0]=='o':
                    if l[n-1]==l[1]:
                        l=''.join(l)
                        print(l)
                        sys.exit()
                else:
                    if l[n-1]!=l[1]:
                        l=''.join(l)
                        print(l)
                        sys.exit()  
        else:
            if l[0]=='W':
                if s[0]=='o':
                    if l[n-1]!=l[1]:
                        l=''.join(l)
                        print(l)
                        sys.exit()
                else:
                    if l[n-1]==l[1]:
                        l=''.join(l)
                        print(l)
                        sys.exit()    
    else:
        if s[n-1]=='o':
            if l[0]=='W':
                if s[0]=='o':
                    if l[n-1]!=l[1]:
                        l=''.join(l)
                        print(l)
                        sys.exit()
                else:
                    if l[n-1]==l[1]:
                        l=''.join(l)
                        print(l)
                        sys.exit()    
        else:
            if l[0]=='S':
                if s[0]=='o':
                    if l[n-1]==l[1]:
                        l=''.join(l)
                        print(l)
                        sys.exit()
                else:
                    if l[n-1]!=l[1]:
                        l=''.join(l)
                        print(l)
                        sys.exit()    
else:
    if l[n-2]=='S':
        if (s[n-1]=='o'):
            if l[0]=='W':
                if s[0]=='o':
                    if l[n-1]!=l[1]:
                        l=''.join(l)
                        print(l)
                        sys.exit()
                else:
                    if l[n-1]==l[1]:
                        l=''.join(l)
                        print(l)
                        sys.exit()    
        else:
            if l[0]=='S':
                if s[0]=='o':
                    if l[n-1]==l[1]:
                        l=''.join(l)
                        print(l)
                        sys.exit()
                else:
                    if l[n-1]!=l[1]:
                        l=''.join(l)
                        print(l)
                        sys.exit()   
    else:
        if s[n-1]=='o':
            if l[0]=='S':
                if s[0]=='o':
                    if l[n-1]==l[1]:
                        l=''.join(l)
                        print(l)
                        sys.exit()
                else:
                    if l[n-1]!=l[1]:
                        l=''.join(l)
                        print(l)
                        sys.exit()  
        else:
            if l[0]=='W':
                if s[0]=='o':
                    if l[n-1]!=l[1]:
                        l=''.join(l)
                        print(l)
                        sys.exit()
                else:
                    if l[n-1]==l[1]:
                        l=''.join(l)
                        print(l)
                        sys.exit()   
l[0]='S'
l[1]='W'
for i in range(1,n-1):
    if l[i]=='S':
        if l[i-1]=='S':
            if (s[i]=='o'):
                l[i+1]='S'
            else:
                l[i+1]='W'
        else:
            if s[i]=='o':
                l[i+1]='W'
            else:
                l[i+1]='S'
    else:
        if l[i-1]=='S':
            if (s[i]=='o'):
                l[i+1]='W'
            else:
                l[i+1]='S'
        else:
            if s[i]=='o':
                l[i+1]='S'
            else:
                l[i+1]='W'
if l[n-1]=='S':
    if l[n-2]=='S':
        if (s[n-1]=='o'):
            if l[0]=='S':
                if s[0]=='o':
                    if l[n-1]==l[1]:
                        l=''.join(l)
                        print(l)
                        sys.exit()
                else:
                    if l[n-1]!=l[1]:
                        l=''.join(l)
                        print(l)
                        sys.exit()  
        else:
            if l[0]=='W':
                if s[0]=='o':
                    if l[n-1]!=l[1]:
                        l=''.join(l)
                        print(l)
                        sys.exit()
                else:
                    if l[n-1]==l[1]:
                        l=''.join(l)
                        print(l)
                        sys.exit()    
    else:
        if s[n-1]=='o':
            if l[0]=='W':
                if s[0]=='o':
                    if l[n-1]!=l[1]:
                        l=''.join(l)
                        print(l)
                        sys.exit()
                else:
                    if l[n-1]==l[1]:
                        l=''.join(l)
                        print(l)
                        sys.exit()    
        else:
            if l[0]=='S':
                if s[0]=='o':
                    if l[n-1]==l[1]:
                        l=''.join(l)
                        print(l)
                        sys.exit()
                else:
                    if l[n-1]!=l[1]:
                        l=''.join(l)
                        print(l)
                        sys.exit()    
else:
    if l[n-2]=='S':
        if (s[n-1]=='o'):
            if l[0]=='W':
                if s[0]=='o':
                    if l[n-1]!=l[1]:
                        l=''.join(l)
                        print(l)
                        sys.exit()
                else:
                    if l[n-1]==l[1]:
                        l=''.join(l)
                        print(l)
                        sys.exit()    
        else:
            if l[0]=='S':
                if s[0]=='o':
                    if l[n-1]==l[1]:
                        l=''.join(l)
                        print(l)
                        sys.exit()
                else:
                    if l[n-1]!=l[1]:
                        l=''.join(l)
                        print(l)
                        sys.exit()   
    else:
        if s[n-1]=='o':
            if l[0]=='S':
                if s[0]=='o':
                    if l[n-1]==l[1]:
                        l=''.join(l)
                        print(l)
                        sys.exit()
                else:
                    if l[n-1]!=l[1]:
                        l=''.join(l)
                        print(l)
                        sys.exit()  
        else:
            if l[0]=='W':
                if s[0]=='o':
                    if l[n-1]!=l[1]:
                        l=''.join(l)
                        print(l)
                        sys.exit()
                else:
                    if l[n-1]==l[1]:
                        l=''.join(l)
                        print(l)
                        sys.exit()   
l[0]='W'
l[1]='S'
for i in range(1,n-1):
    if l[i]=='S':
        if l[i-1]=='S':
            if (s[i]=='o'):
                l[i+1]='S'
            else:
                l[i+1]='W'
        else:
            if s[i]=='o':
                l[i+1]='W'
            else:
                l[i+1]='S'
    else:
        if l[i-1]=='S':
            if (s[i]=='o'):
                l[i+1]='W'
            else:
                l[i+1]='S'
        else:
            if s[i]=='o':
                l[i+1]='S'
            else:
                l[i+1]='W'
if l[n-1]=='S':
    if l[n-2]=='S':
        if (s[n-1]=='o'):
            if l[0]=='S':
                if s[0]=='o':
                    if l[n-1]==l[1]:
                        l=''.join(l)
                        print(l)
                        sys.exit()
                else:
                    if l[n-1]!=l[1]:
                        l=''.join(l)
                        print(l)
                        sys.exit()  
        else:
            if l[0]=='W':
                if s[0]=='o':
                    if l[n-1]!=l[1]:
                        l=''.join(l)
                        print(l)
                        sys.exit()
                else:
                    if l[n-1]==l[1]:
                        l=''.join(l)
                        print(l)
                        sys.exit()    
    else:
        if s[n-1]=='o':
            if l[0]=='W':
                if s[0]=='o':
                    if l[n-1]!=l[1]:
                        l=''.join(l)
                        print(l)
                        sys.exit()
                else:
                    if l[n-1]==l[1]:
                        l=''.join(l)
                        print(l)
                        sys.exit()    
        else:
            if l[0]=='S':
                if s[0]=='o':
                    if l[n-1]==l[1]:
                        l=''.join(l)
                        print(l)
                        sys.exit()
                else:
                    if l[n-1]!=l[1]:
                        l=''.join(l)
                        print(l)
                        sys.exit()    
else:
    if l[n-2]=='S':
        if (s[n-1]=='o'):
            if l[0]=='W':
                if s[0]=='o':
                    if l[n-1]!=l[1]:
                        l=''.join(l)
                        print(l)
                        sys.exit()
                else:
                    if l[n-1]==l[1]:
                        l=''.join(l)
                        print(l)
                        sys.exit()    
        else:
            if l[0]=='S':
                if s[0]=='o':
                    if l[n-1]==l[1]:
                        l=''.join(l)
                        print(l)
                        sys.exit()
                else:
                    if l[n-1]!=l[1]:
                        l=''.join(l)
                        print(l)
                        sys.exit()   
    else:
        if s[n-1]=='o':
            if l[0]=='S':
                if s[0]=='o':
                    if l[n-1]==l[1]:
                        l=''.join(l)
                        print(l)
                        sys.exit()
                else:
                    if l[n-1]!=l[1]:
                        l=''.join(l)
                        print(l)
                        sys.exit()  
        else:
            if l[0]=='W':
                if s[0]=='o':
                    if l[n-1]!=l[1]:
                        l=''.join(l)
                        print(l)
                        sys.exit()
                else:
                    if l[n-1]==l[1]:
                        l=''.join(l)
                        print(l)
                        sys.exit()   
l[0]='W'
l[1]='W'
for i in range(1,n-1):
    if l[i]=='S':
        if l[i-1]=='S':
            if (s[i]=='o'):
                l[i+1]='S'
            else:
                l[i+1]='W'
        else:
            if s[i]=='o':
                l[i+1]='W'
            else:
                l[i+1]='S'
    else:
        if l[i-1]=='S':
            if (s[i]=='o'):
                l[i+1]='W'
            else:
                l[i+1]='S'
        else:
            if s[i]=='o':
                l[i+1]='S'
            else:
                l[i+1]='W'
if l[n-1]=='S':
    if l[n-2]=='S':
        if (s[n-1]=='o'):
            if l[0]=='S':
                if s[0]=='o':
                    if l[n-1]==l[1]:
                        l=''.join(l)
                        print(l)
                        sys.exit()
                else:
                    if l[n-1]!=l[1]:
                        l=''.join(l)
                        print(l)
                        sys.exit()    
        else:
            if l[0]=='W':
                if s[0]=='o':
                    if l[n-1]!=l[1]:
                        l=''.join(l)
                        print(l)
                        sys.exit()
                else:
                    if l[n-1]==l[1]:
                        l=''.join(l)
                        print(l)
                        sys.exit()    
    else:
        if s[n-1]=='o':
            if l[0]=='W':
                if s[0]=='o':
                    if l[n-1]!=l[1]:
                        l=''.join(l)
                        print(l)
                        sys.exit()
                else:
                    if l[n-1]==l[1]:
                        l=''.join(l)
                        print(l)
                        sys.exit()    
        else:
            if l[0]=='S':
                if s[0]=='o':
                    if l[n-1]==l[1]:
                        l=''.join(l)
                        print(l)
                        sys.exit()
                else:
                    if l[n-1]!=l[1]:
                        l=''.join(l)
                        print(l)
                        sys.exit()    
else:
    if l[n-2]=='S':
        if (s[n-1]=='o'):
            if l[0]=='W':
                if s[0]=='o':
                    if l[n-1]!=l[1]:
                        l=''.join(l)
                        print(l)
                        sys.exit()
                else:
                    if l[n-1]==l[1]:
                        l=''.join(l)
                        print(l)
                        sys.exit()    
        else:
            if l[0]=='S':
                if s[0]=='o':
                    if l[n-1]==l[1]:
                        l=''.join(l)
                        print(l)
                        sys.exit()
                else:
                    if l[n-1]!=l[1]:
                        l=''.join(l)
                        print(l)
                        sys.exit()    
    else:
        if s[n-1]=='o':
            if l[0]=='S':
                if s[0]=='o':
                    if l[n-1]==l[1]:
                        l=''.join(l)
                        print(l)
                        sys.exit()
                else:
                    if l[n-1]!=l[1]:
                        l=''.join(l)
                        print(l)
                        sys.exit()    
        else:
            if l[0]=='W':
                if s[0]=='o':
                    if l[n-1]!=l[1]:
                        l=''.join(l)
                        print(l)
                        sys.exit()
                else:
                    if l[n-1]==l[1]:
                        l=''.join(l)
                        print(l)
                        sys.exit()    
print(-1)

Solution (Python):
N=int(input())
S=list(input().rstrip())
for i in range(N):
  if S[i]=='o': S[i]=True
  else: S[i]=False
S.append(S[0])
A=[True]*(N+2)
for a in [[True,True],[True,False],[False,True],[False,False]]:
  A[0],A[1]=a[0],a[1]
  for j in range(1,N+1):
    if A[j] ^ S[j]:
      A[j+1]=not A[j-1]
    else:
      A[j+1]=A[j-1]
  if A[0]==A[-2] and A[1]==A[-1]:
    for k in range(N):
      if A[k]: A[k]='S'
      else: A[k]='W'
    print("".join(A[:N]))
    exit()
print(-1)

Solution (Python):
n = int(input())
s = input()
from itertools import product

for v in product([1,0], repeat=2):
    v = list(v)
    for i in range(n-2):
        if v[i+1]:
            if s[i+1] == 'o':
                v.append(v[i])
            else:
                v.append(not v[i])
        else:
            if s[i+1] == 'o':
                v.append(not v[i])
            else:
                v.append(v[i])
    ans = [0,0]
    for i in range(-1,1):
        if v[i]:
            if s[i] == 'o':
                if v[i-1] == v[i+1]:
                    ans[i+1] = 1
                else:
                    ans[i+1] = 0
            else:
                if v[i-1] == v[i+1]:
                    ans[i+1] = 0
                else:
                    ans[i+1] = 1
        else:
            if s[i] == 'o':
                if v[i-1] == v[i+1]:
                    ans[i+1] = 0
                else:
                    ans[i+1] = 1
            else:
                if v[i-1] == v[i+1]:
                    ans[i+1] = 1
                else:
                    ans[i+1] = 0
    if ans[0] and ans[1]:
        print(''.join(['S' if x == 1 else 'W' for x in v]))
        exit()
print(-1)

Solution (Python):
n = int(input())
s = input()
from itertools import product

for v in product([1,0], repeat=2):
    v = list(v)
    for i in range(n-2):
        if v[i+1]:
            if s[i+1] == 'o':
                v.append(v[i])
            else:
                v.append(int(not v[i]))
        else:
            if s[i+1] == 'o':
                v.append(int(not v[i]))
            else:
                v.append(v[i])
    ans = [0,0]
    for i in range(-1,1):
        if v[i]:
            if s[i] == 'o':
                if v[i-1] == v[i+1]:
                    ans[i+1] = 1
                else:
                    ans[i+1] = 0
            else:
                if v[i-1] != v[i+1]:
                    ans[i+1] = 1
                else:
                    ans[i+1] = 0
        else:
            if s[i] == 'o':
                if v[i-1] == v[i+1]:
                    ans[i+1] = 0
                else:
                    ans[i+1] = 1
            else:
                if v[i-1] != v[i+1]:
                    ans[i+1] = 0
                else:
                    ans[i+1] = 1
    if ans[0] and ans[1]:
        for i in range(n):
            if v[i]:
                v[i] = 'S'
            else:
                v[i] = 'W'
        print(''.join(v))
        exit()
print(-1)

Solution (Python):
from itertools import product

N = int(input())
S = input()
for s1, s2 in product('SW', repeat=2):
    temp = s1 + s2
    for s in S[1:N-1]:
        if (s == 'o' and temp[-1] == 'S') or (s == 'x' and temp[-1] == 'W'):
            temp += temp[-2]
        else:
            temp += ''.join(set('SW') - set(temp[-2]))
    for i in [N-1, 0]:
        if S[i] == 'o' and temp[i] == 'S' and temp[(i-1) % N] == temp[(i+1) % N]: continue
        elif S[i] == 'o' and temp[i] == 'W' and temp[(i-1) % N] != temp[(i+1) % N]: continue
        elif S[i] == 'x' and temp[i] == 'S' and temp[(i-1) % N] != temp[(i+1) % N]: continue
        elif S[i] == 'x' and temp[i] == 'W' and temp[(i-1) % N] == temp[(i+1) % N]: continue
        else: break
    else:
        print(temp); break
else:
    print(-1)

Solution (Python):
n=int(input())
s=input()
def check(s1,s2):
  ans=[s1,s2]
  for i in range(1,n-1):
    if (ans[i]=='S' and s[i]=='o') or (ans[i]=='W' and s[i]=='x'):
      ans.append(ans[i-1])
    elif ans[i]=='S' and s[i]=='x' and ans[i-1]=='S':
      ans.append('W')
    elif ans[i]=='S' and s[i]=='x' and ans[i-1]=='W':
      ans.append('S')
    elif ans[i]=='W' and s[i]=='o' and ans[i-1]=='S':
      ans.append('W')
    elif ans[i]=='W' and s[i]=='o' and ans[i-1]=='W':
      ans.append('S')
  if ans[-1]=='S':
    if s[-1]=='o' and ans[0]==ans[-2]:
      if ans[0]=='S' and s[0]=='o' and ans[1]==ans[-1]:
        print(''.join(ans))
        exit()
      if ans[0]=='S' and s[0]=='x' and ans[1]!=ans[-1]:
        print(''.join(ans))
        exit()
      if ans[0]=='W' and s[0]=='o' and ans[1]!=ans[-1]:
        print(''.join(ans))
        exit()
      if ans[0]=='W' and s[0]=='x' and ans[1]==ans[-1]:
        print(''.join(ans))
        exit()
    if s[-1]=='x' and ans[0]!=ans[-2]:
      if ans[0]=='S' and s[0]=='o' and ans[1]==ans[-1]:
        print(''.join(ans))
        exit()
      if ans[0]=='S' and s[0]=='x' and ans[1]!=ans[-1]:
        print(''.join(ans))
        exit()
      if ans[0]=='W' and s[0]=='o' and ans[1]!=ans[-1]:
        print(''.join(ans))
        exit()
      if ans[0]=='W' and s[0]=='x' and ans[1]==ans[-1]:
        print(''.join(ans))
        exit()
  else:
    if s[-1]=='o' and ans[0]!=ans[-2]:
      if ans[0]=='S' and s[0]=='o' and ans[1]==ans[-1]:
        print(''.join(ans))
        exit()
      if ans[0]=='S' and s[0]=='x' and ans[1]!=ans[-1]:
        print(''.join(ans))
        exit()
      if ans[0]=='W' and s[0]=='o' and ans[1]!=ans[-1]:
        print(''.join(ans))
        exit()
      if ans[0]=='W' and s[0]=='x' and ans[1]==ans[-1]:
        print(''.join(ans))
        exit()
    if s[-1]=='x' and ans[0]==ans[-2]:
      if ans[0]=='S' and s[0]=='o' and ans[1]==ans[-1]:
        print(''.join(ans))
        exit()
      if ans[0]=='S' and s[0]=='x' and ans[1]!=ans[-1]:
        print(''.join(ans))
        exit()
      if ans[0]=='W' and s[0]=='o' and ans[1]!=ans[-1]:
        print(''.join(ans))
        exit()
      if ans[0]=='W' and s[0]=='x' and ans[1]==ans[-1]:
        print(''.join(ans))
        exit()
  return
check('S','S')
check('S','W')
check('W','S')
check('W','W')
print(-1)

Solution (Python):
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]

n=int(input())
s=input()
lst=[[0,0],[0,1],[1,0],[1,1]]

for i in range(n-1):
    for j in range(4):
        if lst[j][-1]==0 and s[1+i]=="o":
            lst[j].append(lst[j][-2])
        elif lst[j][-1]==0 and s[1+i]=="x":
            lst[j].append(1-lst[j][-2])
        elif lst[j][-1]==1 and s[1+i]=="o":
            lst[j].append(1-lst[j][-2])
        else:
            lst[j].append(lst[j][-2])
for j in range(4):
    if lst[j][-1]==0 and s[0]=="o":
        lst[j].append(lst[j][-2])
    elif lst[j][-1]==0 and s[0]=="x":
        lst[j].append(1-lst[j][-2])
    elif lst[j][-1]==1 and s[0]=="o":
        lst[j].append(1-lst[j][-2])
    else:
        lst[j].append(lst[j][-2])


for i in range(4):
    if lst[i][-2:]==lst[i][:2]:
        tmp=[]
        for j in range(n):
            if lst[i][j]==0:
                tmp.append("S")
            else:
                tmp.append("W")
        print("".join(tmp))
        quit()
print(-1)