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 = input()

for s in range(2):
    for t in range(2):
        T = [None] * N
        T[0] = s
        T[1] = t
        for j in range(1, N-1):
            if (T[j] == 0) == (S[j] == 'o'):
                T[j + 1] = T[j-1]
            else:
                T[j + 1] = 1 - T[j-1]

        if ((T[N - 1] == 0) == (S[N - 1] == 'o')) == (T[N - 2] == T[0]):
            if ((s == 0) == (S[0] == 'o')) == (T[N - 1] == t):
                ans = [None] * N
                for i in range(N):
                    ans[i] = ['S', 'W'][T[i]]
                print(''.join(ans))
                exit()
print(-1)

Solution (Python):
N = int(input())
D = {True: 'S', False: 'W'}
E = {'o': True, 'x': False}
S = list(input())
for i in range(N):
    S[i] = E[S[i]]


L = {(True, True), (True, False), (False, True), (False, False)}

for a, b in L:
    ans = [None]*N
    ans[0], ans[1] = a, b
    for i in range(1, N-1):
        if not ans[i] ^ S[i]:
            ans[i+1] = ans[i-1]
        else:
            ans[i+1] = not ans[i-1]
    if ans[-1] ^ S[-1] == ans[-2] ^ ans[0] and ans[0] ^ S[0] == ans[-1] ^ ans[1]:
        for i in range(N):
            ans[i] = D[ans[i]]
        print(''.join(ans))
        exit()
else:
    print(-1)

Solution (Python):
N = int(input())
s = input()




pattern = [['S', 'S'], ['S', 'W'], ['W', 'S'], ['W', 'W']]

L = []
for i in range(4):
    ans = ''
    for j in range(N):
        if j == 0:
            ans += pattern[i][j]
            continue
        if j == 1:
            ans += pattern[i][j]
            continue

        if s[j -
             2] == 'o' and s[j -
                             1] == 'o' and ans[j -
                                               1] == 'S' and ans[j -
                                                                 2] == 'S':
            ans += 'S'
        elif s[j -
               2] == 'x' and s[j -
                               1] == 'o' and ans[j -
                                                 1] == 'S' and ans[j -
                                                                   2] == 'S':
            ans += 'S'
        elif s[j -
               2] == 'o' and s[j -
                               1] == 'x' and ans[j -
                                                 1] == 'S' and ans[j -
                                                                   2] == 'S':
            ans += 'W'
        elif s[j -
               2] == 'x' and s[j -
                               1] == 'x' and ans[j -
                                                 1] == 'S' and ans[j -
                                                                   2] == 'S':
            ans += 'W'

        elif s[j -
               2] == 'o' and s[j -
                               1] == 'o' and ans[j -
                                                 1] == 'S' and ans[j -
                                                                   2] == 'W':
            ans += 'W'
        elif s[j -
               2] == 'x' and s[j -
                               1] == 'o' and ans[j -
                                                 1] == 'S' and ans[j -
                                                                   2] == 'W':
            ans += 'W'
        elif s[j -
               2] == 'o' and s[j -
                               1] == 'x' and ans[j -
                                                 1] == 'S' and ans[j -
                                                                   2] == 'W':
            ans += 'S'
        elif s[j -
               2] == 'x' and s[j -
                               1] == 'x' and ans[j -
                                                 1] == 'S' and ans[j -
                                                                   2] == 'W':
            ans += 'S'

        elif s[j -
               2] == 'o' and s[j -
                               1] == 'o' and ans[j -
                                                 1] == 'W' and ans[j -
                                                                   2] == 'S':
            ans += 'W'
        elif s[j -
               2] == 'x' and s[j -
                               1] == 'o' and ans[j -
                                                 1] == 'W' and ans[j -
                                                                   2] == 'S':
            ans += 'W'
        elif s[j -
               2] == 'o' and s[j -
                               1] == 'x' and ans[j -
                                                 1] == 'W' and ans[j -
                                                                   2] == 'S':
            ans += 'S'
        elif s[j -
               2] == 'x' and s[j -
                               1] == 'x' and ans[j -
                                                 1] == 'W' and ans[j -
                                                                   2] == 'S':
            ans += 'S'

        elif s[j -
               2] == 'o' and s[j -
                               1] == 'o' and ans[j -
                                                 1] == 'W' and ans[j -
                                                                   2] == 'W':
            ans += 'S'
        elif s[j -
               2] == 'x' and s[j -
                               1] == 'o' and ans[j -
                                                 1] == 'W' and ans[j -
                                                                   2] == 'W':
            ans += 'S'
        elif s[j -
               2] == 'o' and s[j -
                               1] == 'x' and ans[j -
                                                 1] == 'W' and ans[j -
                                                                   2] == 'W':
            ans += 'W'
        elif s[j -
               2] == 'x' and s[j -
                               1] == 'x' and ans[j -
                                                 1] == 'W' and ans[j -
                                                                   2] == 'W':
            ans += 'W'

    if ans[-1] == 'S' and s[-1] == 'o' and ans[0] != ans[-2]:
        continue
    if ans[-1] == 'S' and s[-1] == 'x' and ans[0] == ans[-2]:
        continue
    if ans[-1] == 'W' and s[-1] == 'o' and ans[0] == ans[-2]:
        continue
    if ans[-1] == 'W' and s[-1] == 'x' and ans[0] != ans[-2]:
        continue

    if ans[0] == 'S' and s[0] == 'o' and ans[-1] != ans[1]:
        continue
    if ans[0] == 'S' and s[0] == 'x' and ans[-1] == ans[1]:
        continue
    if ans[0] == 'W' and s[0] == 'o' and ans[-1] == ans[1]:
        continue
    if ans[0] == 'W' and s[0] == 'x' and ans[-1] != ans[1]:
        continue

    L.append(ans)

if len(L) != 0:
    print(L[0])
else:
    print(-1)

Solution (Python):
n = int(input())
s = list(input())
for i in range(4):
    ans = ['?'] * n
    flg = True

    if i == 0:
        ans[0] = 'S'
        ans[1] = 'S'
        if s[0] == 'o':
            ans[-1] = 'S'
        else:
            ans[-1] = 'W'
        if s[1] == 'o':
            if ans[2] == 'W':
                flg = False
            else:
                ans[2] = 'S'
        else:
            if ans[2] == 'S':
                flg = False
            else:
                ans[2] = 'W'

    if i == 1:
        ans[0] = 'S'
        ans[1] = 'W'
        if s[0] == 'o':
            ans[-1] = 'W'
        else:
            ans[-1] = 'S'
        if s[1] == 'o':
            if ans[2] == 'S':
                flg = False
            else:
                ans[2] = 'W'
        else:
            if ans[2] == 'W':
                flg = False
            else:
                ans[2] = 'S'

    if i == 2:
        ans[0] = 'W'
        ans[1] = 'S'
        if s[0] == 'o':
            ans[-1] = 'W'
        else:
            ans[-1] = 'S'
        if s[1] == 'o':
            if ans[2] == 'S':
                flg = False
            else:
                ans[2] = 'W'
        else:
            if ans[2] == 'W':
                flg = False
            else:
                ans[2] = 'S'

    if i == 3:
        ans[0] = 'W'
        ans[1] = 'W'
        if s[0] == 'o':
            ans[-1] = 'S'
        else:
            ans[-1] = 'W'
        if s[1] == 'o':
            if ans[2] == 'W':
                flg = False
            else:
                ans[2] = 'S'
        else:
            if ans[2] == 'S':
                flg = False
            else:
                ans[2] = 'W'
    for i in range(2,n-2):
        if ans[i] == 'S':
            if s[i] == 'o':
                if ans[i-1] == 'S':
                    ans[i+1] = 'S'
                else:
                    ans[i+1] = 'W'
            else:
                if ans[i-1] == 'S':
                    ans[i+1] = 'W'
                else:
                    ans[i+1] = 'S'
        else:
            if s[i] == 'o':
                if ans[i-1] == 'S':
                    ans[i+1] = 'W'
                else:
                    ans[i+1] = 'S'
            else:
                if ans[i-1] == 'S':
                    ans[i+1] = 'S'
                else:
                    ans[i+1] = 'W'
    if ans[-2] == 'S':
        if s[-2] == 'o':
            if ans[-3] != ans[-1]:
                flg = False
        else:
            if ans[-3] == ans[-1]:
                flg = False
    else:
        if s[-2] == 'o':
            if ans[-3] == ans[-1]:
                flg = False
        else:
            if ans[-3] != ans[-1]:
                flg = False
    if ans[-1] == 'S':
        if s[-1] == 'o':
            if ans[-2] != ans[0]:
                flg = False
        else:
            if ans[-2] == ans[0]:
                flg = False
    else:
        if s[-1] == 'o':
            if ans[-2] == ans[0]:
                flg = False
        else:
            if ans[-2] != ans[0]:
                flg = False
    if flg:
        print(''.join(ans))
        exit(0)
print(-1)

Solution (Python):
n = int(input())
s = list(input())
for i in range(4):

    ans = ['?'] * n
    flg = True
    if i == 0:
        ans[0] = 'S'
        ans[1] = 'S'
        if s[0] == 'o':
            ans[-1] = 'S'
        else:
            ans[-1] = 'W'
        if s[1] == 'o':
            if ans[2] == 'W':
                flg = False
            else:
                ans[2] = 'S'
        else:
            if ans[2] == 'S':
                flg = False
            else:
                ans[2] = 'W'

    if i == 1:
        ans[0] = 'S'
        ans[1] = 'W'
        if s[0] == 'o':
            ans[-1] = 'W'
        else:
            ans[-1] = 'S'
        if s[1] == 'o':
            if ans[2] == 'S':
                flg = False
            else:
                ans[2] = 'W'
        else:
            if ans[2] == 'W':
                flg = False
            else:
                ans[2] = 'S'

    if i == 2:
        ans[0] = 'W'
        ans[1] = 'S'
        if s[0] == 'o':
            ans[-1] = 'W'
        else:
            ans[-1] = 'S'
        if s[1] == 'o':
            if ans[2] == 'S':
                flg = False
            else:
                ans[2] = 'W'
        else:
            if ans[2] == 'W':
                flg = False
            else:
                ans[2] = 'S'

    if i == 3:
        ans[0] = 'W'
        ans[1] = 'W'
        if s[0] == 'o':
            ans[-1] = 'S'
        else:
            ans[-1] = 'W'
        if s[1] == 'o':
            if ans[2] == 'W':
                flg = False
            else:
                ans[2] = 'S'
        else:
            if ans[2] == 'S':
                flg = False
            else:
                ans[2] = 'W'
    if flg:
        for i in range(2,n-1):
            if ans[i] == 'S':
                if s[i] == 'o':
                    if ans[i-1] == 'S':
                        if ans[i+1] == 'W':
                            flg = False
                        else:
                            ans[i+1] = 'S'
                    else:
                        if ans[i+1] == 'S':
                            flg = False
                        else:
                            ans[i+1] = 'W'
                else:
                    if ans[i-1] == 'S':
                        if ans[i+1] == 'S':
                            flg = False
                        else:
                            ans[i+1] = 'W'
                    else:
                        if ans[i+1] == 'W':
                            flg = False
                        else:
                            ans[i+1] = 'S'
            else:
                if s[i] == 'o':
                    if ans[i-1] == 'S':
                        if ans[i+1] == 'S':
                            flg = False
                        else:
                            ans[i+1] = 'W'
                    else:
                        if ans[i+1] == 'W':
                            flg = False
                        else:
                            ans[i+1] = 'S'
                else:
                    if ans[i-1] == 'S':
                        if ans[i+1] == 'W':
                            flg = False
                        else:
                            ans[i+1] = 'S'
                    else:
                        if ans[i+1] == 'S':
                            flg = False
                        else:
                            ans[i+1] = 'W'
        if ans[-1] == 'S':
            if s[-1] == 'o':
                if ans[-2] != ans[0]:
                    flg = False
            else:
                if ans[-2] == ans[0]:
                    flg = False
        else:
            if s[-1] == 'o':
                if ans[-2] == ans[0]:
                    flg = False
            else:
                if ans[-2] != ans[0]:
                    flg = False
    if flg:
        print(''.join(ans))
        exit(0)
print(-1)

Solution (Python):
n=int(input())
s=list(input())
s=s+s
x=[["S","S"],["S","W"],["W","S"],["W","W"]]

for temp1 in x:
    if s[0]=="o":
        c=temp1[1]
    else:
        if temp1[1]=="S":
            c="W"
        else:
            c="S"
    for i in range(1,n+1):
        if s[i]=="o":
            if temp1[i]=="S":
                temp1.append(temp1[i-1])
                
            else:
                if temp1[i-1]=="S":
                    temp1.append("W")
                else:
                    temp1.append("S")
        else:
            if temp1[i]=="W":
                temp1.append(temp1[i-1])
            else:
                if temp1[i-1]=="W":
                    temp1.append("S")
                else:
                    temp1.append("W")
    
    
    if temp1[0]==temp1[-2] and temp1[1]==temp1[-1]:
        print("".join(temp1[:n]))
        exit()
print(-1)

Solution (Python):
N=int(input())
S=list(str(input()))
hyp=[["S","S"],["S","W"],["W","S"],["W","W"]]
flag=0
for i in range(4):
    if flag==2:
        break
    flag=0
    ans=[]
    ans.append(hyp[i][0])
    ans.append(hyp[i][1])
    for j in range(1,N+1):
        if j>=N-1:
            if j==N:
                j=0
                t=1
            else:
                t=0
            
            if ans[j]=="S":
                if S[j]=="o":
                    if ans[j-1]=="S":
                        if ans[t]=="S":
                            flag+=1
                    else:
                        if ans[t]=="W":
                            flag+=1
                else:
                    if ans[j-1]=="S":
                        if ans[t]=="W":
                            flag+=1
                    else:
                        if ans[t]=="S":
                            flag+=1
            else:
                if S[j]=="o":
                    if ans[j-1]=="S":
                        if ans[t]=="W":
                            flag+=1
                    else:
                        if ans[t]=="S":
                            flag+=1
                else:
                    if ans[j-1]=="S":
                        if ans[t]=="S":
                            flag+=1
                    else:
                        if ans[t]=="W":
                            flag+=1
                            
        else:
            if ans[j]=="S":
                if S[j]=="o":
                    if ans[j-1]=="S":
                        ans.append("S")
                    else:
                        ans.append("W")
                else:
                    if ans[j-1]=="S":
                        ans.append("W")
                    else:
                        ans.append("S")
            else:
                if S[j]=="o":
                    if ans[j-1]=="S":
                        ans.append("W")
                    else:
                        ans.append("S")
                else:
                    if ans[j-1]=="S":
                        ans.append("S")
                    else:
                        ans.append("W")

if flag!=2:
    print(-1)
else:
    for i in range(len(ans)):
        if i!=len(ans)-1:
            print(ans[i],end="")
        else:
            print(ans[i])

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 

from decimal import *



N = INT()
s = input()

def is_ok(x, idx):
	if s[idx] == "o":
		if x[idx] == "S" and x[idx-1] == x[idx+1]:
			return True
		elif x[idx] == "W" and x[idx-1] != x[idx+1]:
			return True
		else:
			return False
	elif s[idx] == "x":
		if x[idx] == "S" and x[idx-1] != x[idx+1]:
			return True
		elif x[idx] == "W" and x[idx-1] == x[idx+1]:
			return True
		else:
			return False

start = list(product(["S", "W"], repeat=2))

for i in range(4):
	ws = []
	ws.extend(start[i])
	for j in range(1, N-1):
		if ws[j] == "S":
			if s[j] == "o":
				ws.append(ws[j-1])
			else:
				if ws[j-1] == "S":
					ws.append("W")
				else:
					ws.append("S")
		elif ws[j] == "W":
			if s[j] == "x":
				ws.append(ws[j-1])
			else:
				if ws[j-1] == "S":
					ws.append("W")
				else:
					ws.append("S")
	if is_ok(ws, -1) and is_ok(ws, 0):
		print(*ws, sep="")
		break

else:
	print(-1)

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

ans = None
for s0, s1 in product(range(2), repeat=2):
    tmp = [s0, s1]
    for i in range(1, N):
        if (tmp[i] == 0 and s[i] == "o") or (tmp[i] == 1 and s[i] == "x"):
            if tmp[i-1] == 0:
                tmp.append(1)
            else:
                tmp.append(0)
        else:
            if tmp[i-1] == 0:
                tmp.append(0)
            else:
                tmp.append(1)
    if s0 == tmp[-1]:
        if (s0 == 0 and s[0] == "o") or (s0 == 1 and s[0] == "x"):
            if s1 == tmp[-2]:
                continue
        else:
            if s1 != tmp[-2]:
                continue
        ans = tmp 
        break

if ans is None:
    print(-1)
else:
    ans = ans[:-1]
    final = ""
    for a in ans:
        if a == 0:
            final += "W"
        else:
            final += "S"
    print(final)

Solution (Python):
N = int(input())
S = input()
from collections import deque
T = [deque([0, 0]),
     deque([0, 1]),
     deque([1, 0]),
     deque([1, 1])]
for s in S:
    for t in T:
        l = len(t)
        if (s == 'o') ^ t[l-1]:
            t.append(t[l-2])
        else:
            t.append(t[l-2]^1)

ans = '-1'
wrap = lambda x:'{' + str(x) + '}'
for t in T:
    if t[0] == t[N] and t[1] == t[N+1]:
        t.pop(); t.popleft()
        ans = ''.join(wrap(i) for i in t).format('S','W')
        break
print(ans)

Solution (Python):
N = int(input())
s = list(input())
rev = {"S":"W","W":"S"}

ok = False
for x,y in [("S","S"),("S","W"),("W","S"),("W","W")]:
    ans = [x,y]+["a"]*(N-2)

    for i in range(1,N-1):
        if ans[i]=="S" and s[i]=="o":
            ans[i+1]=ans[i-1]
        elif ans[i]=="S" and s[i]=="x":
            ans[i+1]=rev[ans[i-1]]
        elif ans[i]=="W" and s[i]=="o":
            ans[i+1]=rev[ans[i-1]]
        elif ans[i]=="W" and s[i]=="x":
            ans[i+1]=ans[i-1]

    if ans[N-1]==ans[1] and ((s[0]=="o" and ans[0]=="S") or (s[0]=="x" and ans[0]=="W")):
        ok = True
    if ans[N-1]!=ans[1] and ((s[0]=="x" and ans[0]=="S") or (s[0]=="o" and ans[0]=="W")):
        ok = True

    if not ok:
        continue
    
    ok=False
    if ans[N-2]==ans[0] and ((s[N-1]=="o" and ans[N-1]=="S") or (s[N-1]=="x" and ans[N-1]=="W")):
        ok = True
    if ans[N-2]!=ans[0] and ((s[N-1]=="x" and ans[N-1]=="S") or (s[N-1]=="o" and ans[N-1]=="W")):
        ok = True

    if ok:
        break

if ok:
    print("".join(ans))
else:
    print(-1)

Solution (Python):
d = {"WWo": "S",
     "WSo": "W",
     "SWo": "W",
     "SSo": "S",
     "WWx": "W",
     "WSx": "S",
     "SWx": "S",
     "SSx": "W",
    }

combo = ["SS","SW","WS","WW"]

N = int(input())
z = input()

matched = False
txt = []
for c in combo:
  keep = c[0]
  left = c
  txt = []
  for i in range(N):
    txt.append(left[1])
    new_ch = d[left+z[i]]
    left = left[1] + new_ch
  if left == c:
    matched = True
    break

if matched:
  print(*txt,sep="")
else:
  print("-1")

Solution (Python):
n = int(input())
s = input()








for ptn in [[True, True], [True, False], [False, True], [False, False]]:
    
    for i in range(1, n):
        if ptn[i] == True and s[i] == "o":
            ptn.append(ptn[i - 1])
        elif ptn[i] == True and s[i] == "x":
            ptn.append(not ptn[i - 1])
        elif ptn[i] == False and s[i] == "o":
            ptn.append(not ptn[i - 1])
        elif ptn[i] == False and s[i] == "x":
            ptn.append(ptn[i - 1])

    
    
    if ptn[0] == ptn[-1]:
        
        ptn.pop(-1)
        flag = False

        if ptn[0] == True and s[0] == "o":
            if ptn[-1] == ptn[1]:
                flag = True
        if ptn[0] == True and s[0] == "x":
            if ptn[-1] != ptn[1]:
                flag = True
        if ptn[0] == False and s[0] == "o":
            if ptn[-1] != ptn[1]:
                flag = True
        if ptn[0] == False and s[0] == "x":
            if ptn[-1] == ptn[1]:
                flag = True

        
        if flag == True:
            ans = []
            for i in range(n):
                if ptn[i] == True:
                    ans.append("S")
                elif ptn[i] == False:
                    ans.append("W")

            print("".join(ans))
            exit()


print(-1)

Solution (Python):
n=int(input())
s=input()
ans1="SS"
ans2="SW"
ans3="WS"
ans4="WW"

def check(ans):
    for i in range(1,n-1):
        if s[i]=="o"  and ans[i]=="S":
            ans+=ans[i-1]
        elif s[i]=="o" and ans[i]=="W":
            if ans[i-1]=="W":
                ans+="S"
            else:
                ans+="W"
         
        elif s[i]=="x"  and ans[i]=="S":
            if ans[i-1]=="W":
                ans+="S"
            else:
                ans+="W"
        elif s[i]=="x" and  ans[i]=="W":
            ans+=ans[i-1]
    flg=False
    if s[n-1]=="o":
        if ans[n-1]=="S":
            if ans[0]==ans[n-2]:
                flg=True
    if s[n-1]=="o":
        if ans[n-1]=="W":
            if ans[0]!=ans[n-2]:
                flg=True
    if s[n-1]=="x":
        if ans[n-1]=="S":
            if ans[0]!=ans[n-2]:
                flg=True
    if s[n-1]=="x":
        if ans[n-1]=="W":
            if ans[0]==ans[n-2]:
                flg=True
    if flg:
        if s[0]=="o":
            if ans[0]=="S":
                if ans[1]==ans[n-1]:
                    print(ans)
                    exit()
        if s[0]=="o":
            if ans[0]=="W":
                if ans[1]!=ans[n-1]:
                    print(ans)
                    exit()
        if s[0]=="x":
            if ans[0]=="S":
                if ans[1]!=ans[n-1]:
                    print(ans)
                    exit()
        if s[0]=="x":
            if ans[0]=="W":
                if ans[1]==ans[n-1]:
                    print(ans)
                    exit()
check(ans1)
check(ans2)
check(ans3)
check(ans4)
print(-1)

Solution (Python):
import sys
n = int(input())
s = input()


def decide_right(ls):
    '''
    ls[0]とls[1]が確定したlsを与えられたら、その情報からls全体(一意に定まる)を返す
    '''
    N = len(ls)
    for i in range(1,N-1):
        if ls[i] == 'S':
            if s[i] == 'o':
                ls[i+1] = ls[i-1]
            else:
                if ls[i-1] == 'S':
                    ls[i+1] = 'W'
                else:
                    ls[i+1] = 'S'
        else:
            if s[i] == 'o':
                if ls[i-1] == 'S':
                    ls[i+1] = 'W'
                else:
                    ls[i+1] = 'S'
            else:
                ls[i+1] = ls[i-1]
    return ls

'''
def decide_left(ls):
    
    
    N = len(ls)
    for i in range(N,0,-1):
        if s[i] == 'o':
            ls[i-1] = ls[i+1]
        else:
            if ls[i+1] == 'S':
                ls[i-1] = 'W'
            else:
                ls[i-1] = 'S'
'''

def check(first):
    
    
    ls1 = [0] * (n+1)
    ls1[0] = first

    for second in ['S','W']:
        ls1[1] = second
        ls1 = decide_right(ls1)
        
        if ls1[0] != ls1[-1]:
            continue
        
        

        ls = ls1[:-1]
        res = True
        for i in range(n):
            r = i+1
            if r == n:
                r = 0
            if ls[i] == 'S':
                if s[i] == 'o' and ls[i-1] != ls[r]:
                    res = False
                    break
                elif s[i] == 'x' and ls[i-1] == ls[r]:
                    res = False
                    break
            else:
                if s[i] == 'o' and ls[i-1] == ls[r]:
                    res = False
                    break
                elif s[i] == 'x' and ls[i-1] != ls[r]:
                    res = False
                    break
        if not res:
            continue
        '''
        ls2 = [0] * (n+1)
        ls2[-1] = first
        if s[0] == 'o':
            ls2[-2] = second
        else:
            if second == 'S':
                ls2[-2] = 'W'
            else:
                ls2[-2] = 'S'
        ls2 = decide_left(ls2)
        if ls2[0] != ls2[-1]:
            continue
        
        for i in range(n+1):
            if ls1[i] != ls2[i]:
                continue
        '''
        
        return ls1[:-1]
    
    return False

for first in ['S','W']:
    c = check(first)
    if c:
        print(*c,sep='')
        sys.exit()
print(-1)

Solution (Python):
n = int(input())
s = input()
a = ["SS", "SW", "WS", "WW"]
for i in a:
    ans = i
    for j in range(n - 2):
        if ans[j + 1] == "S":
            if s[j + 1] == "o":
                if ans[j] == "S":
                    ans += "S"
                else:
                    ans += "W"
            else:
                if ans[j] == "S":
                    ans += "W"
                else:
                    ans += "S"
        else:
            if s[j + 1] == "o":
                if ans[j] == "S":
                    ans += "W"
                else:
                    ans += "S"
            else:
                if ans[j] == "S":
                    ans += "S"
                else:
                    ans += "W"
    flag = True
    if ans[n - 1] == "S":
        if s[n - 1] == "o":
            if ans[n - 2] != ans[0]:
                flag = False
        else:
            if ans[n - 2] == ans[0]:
                flag = False
    else:
        if s[n - 1] == "o":
            if ans[n - 2] == ans[0]:
                flag = False
        else:
            if ans[n - 2] != ans[0]:
                flag = False
    if ans[0] == "S":
        if s[0] == "o":
            if ans[n - 1] != ans[1]:
                flag = False
        else:
            if ans[n - 1] == ans[1]:
                flag = False
    else:
        if s[0] == "o":
            if ans[n - 1] == ans[1]:
                flag = False
        else:
            if ans[n - 1] != ans[1]:
                flag = False
    if flag == True:
        print(ans)
        break
    else:
        continue
else:
    print(-1)