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



Sample input:
6
ooxoox


Sample output:
SSSWWS

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from functools import reduce


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n = I()
s = S()
L = [0] * n
# 0が狼、1が羊
def main():
    for i, j in [(1, 0), (0, 1), (0, 0), (1, 1)]:
        L[0] = i
        L[1] = j
        for k in range(1, n-1):
            if (s[k] == 'o' and L[k]) or (s[k] == 'x' and not L[k]):
                L[k+1] = L[k-1]
            else:
                L[k+1] = L[k-1] ^ 1
        
        
        if (s[n-1] == 'o' and L[n-1]) or (s[n-1] == 'x' and not L[n-1]):
            first = L[n - 2]
        else:
            first = L[n - 2] ^ 1
        if (s[0] == 'o' and L[0]) or (s[0] == 'x' and not L[0]):
            second = L[n - 1]
        else:
            second = L[0] ^ 1
        if first == L[0] and second == L[1]:
            return L


L = main()
if L:
    print(''.join(['S' if i else 'W' for i in L]))
else:
    print(-1)

Submission status: Wrong Answer

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


def check_truth(a_0, a_1):
    a = [True for i in range(N+1)]  # True: Sheep, False: Wolf
    a[0] = a_0
    a[1] = a_1
    for i in range(1, N):
        if a[i]:
            if s[i] == 'o':
                a[i+1] = a[i-1]
            else:
                a[i+1] = not a[i-1]
        else:
            if s[i] == 'o':
                a[i+1] = not a[i-1]
            else:
                a[i+1] = a[i-1]
    if a[N] != a[0]:
        return -1
    else:
        return a


p = [True, False]
for i in range(2):
    for j in range(2):
        ans = check_truth(p[i], p[j])
        if ans != -1:
            for k in range(N):
                if ans[k]:
                    print('S', end='')
                else:
                    print('W', end='')
            print()
            exit()
print(-1)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=[0+(m=="o") for m in input()]

#o:1,x:0
#Sheep:1,wolf:0
def nxt(a,b,m):
	if a==b:
		return m
	else:
		return 1-m

for a,b in ((1,1),(0,1),(1,0),(0,0)):
	check = a
	ans = [a,b]
	for i in range(n-2):
		a,b = b,nxt(a,b,s[i+1])
		ans.append(b)
	if nxt(a,b,s[-1]) == check:
		for x in ans:
			if x:
				print("S",end="")
			else:
				print("W",end="")
		exit()
print(-1)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=[0+(m=="o") for m in input()]

#o:1,x:0
#Sheep:1,wolf:0
def nxt(a,b,m):
	if a==b:
		return m
	else:
		return 1-m

for a,b in ((0,0),(0,1),(1,0),(1,1)):
	check = a
	ans = [a,b]
	for i in range(n-2):
		a,b = b,nxt(a,b,s[i+1])
		ans.append(b)
	if nxt(a,b,s[-1]) == check:
		for x in ans:
			if x:
				print("S",end="")
			else:
				print("W",end="")
		exit()
print(-1)

Submission status: Wrong Answer

Solution code:
def nxt(a,c,l):
  if c=="S":
    return l if a=="o" else "W" if l=="S" else "S"
  else:
    return l if a=="x" else "W" if l=="S" else "S"

N=int(input())
s=input()

t=[["S","S"],["S","W"],["W","S"],["S","W"]]
for i in range(2,N):
  for j in range(4):
    t[j].append(nxt(s[i-1],t[j][i-1],t[j][i-2]))
#print(t)

c=[[0 for _ in range(N)] for _ in range(4)]
for i in range(N):
  for j in range(4):
    if t[j][i]=="S" and s[i]=="o" or t[j][i]=="W" and s[i]=="x":
      if t[j][i-1]==t[j][(i+1)%N]:
        c[j][i]=1
    else:
      if t[j][i-1]!=t[j][(i+1)%N]:
        c[j][i]=1

sw=0
for i in range(4):
  if N==sum(c[i]):
    print("".join(t[i]))
    sw=1
    break
if sw==0:
  print(-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
def decideSorW(n, s, SorW):
  for i in range(2, n):
    #SorWのi番目が狼のとき
    if (s[i - 1] == 'o' and SorW[i - 1] != SorW[i - 2]) or (s[i - 1] == 'x' and SorW[i - 1] == SorW[i - 2]):
      SorW += 'W'
    else:
      SorW += 'S'
  return SorW
for i in range(4):
  if i == 0:
    SorW = 'SS'
  elif i == 1:
    SorW = 'SW'
  elif i == 2:
    SorW = 'WS'
  else:
    SorW == 'WW'
  SorW = decideSorW(n, s, SorW)
  check = False
  if (SorW[n - 1] == 'S' and s[n - 1] == 'o' and SorW[0] == SorW[n - 2]) or (SorW[n - 1] == 'S' and s[n - 1] == 'x' and SorW[0] != SorW[n - 2]):
    check = True
    break
  elif (SorW[n - 1] == 'W' and s[n - 1] == 'o' and SorW[0] != SorW[n - 2]) or (SorW[n - 1] == 'W' and s[n - 1] == 'x' and SorW[0] == SorW[n - 2]):
    check = True
    break
if not check:
  print('-1')
else:
  print(SorW)

Submission status: Wrong Answer

Solution code:
def check():
    if s[0] == "o":
        if ans[0] == "S":
            if ans[1] == ans[-1]:
                return True
        else:
            if ans[1] != ans[-1]:
                return True
    if s[0] == "x":
        if ans[0] == "W":
            if ans[1] == ans[-1]:
                return True
        else:
            if ans[1] != ans[-1]:
                return True
    return False


n = int(input())
s = input()
pattern = ["SS", "SW", "WS", "WW"]
dict_s = {"S":"W", "W":"S"}
not_clear = True
for p in pattern:
    ans = p
    for i in range(1, n - 1):
        if s[i] == "o":
            if ans[i] == "W":
                ans += dict_s[ans[i-1]]
            else:
                ans += ans[i-1]
        else:
            if ans[i] == "S":
                ans += dict_s[ans[i-1]]
            else:
                ans += ans[i-1]
    if s[n - 1] == "o":
        if ans[n - 1] == "S":
            if ans[0] == ans[n - 2]:
                if check:
                    print(ans)
                    exit()
            else:
                continue
        else:
            if ans[0] != ans[n - 2]:
                if check:
                    print(ans)
                    exit()
            else:
                continue
    if s[n - 1] == "x":
        if ans[n - 1] == "W":
            if ans[0] == ans[n - 2]:
                if check:
                    print(ans)
                    exit()
            else:
                continue
        else:
            if ans[0] != ans[n - 2]:
                if check:
                    print(ans)
                    exit()
            else:
                continue            
if not_clear:
    print(-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
pattern = ["SS", "SW", "WS", "WW"]
dict_s = {"S":"W", "W":"S"}
not_clear = True
for p in pattern:
    ans = p
    for i in range(1, n - 1):
        if s[i] == "o":
            if ans[i] == "W":
                ans += dict_s[ans[i-1]]
            else:
                ans += ans[i-1]
        else:
            if ans[i] == "S":
                ans += dict_s[ans[i-1]]
            else:
                ans += ans[i-1]
    if s[n - 1] == "o":
        if ans[n - 1] == "S":
            if ans[0] == ans[n - 2]:
                print(ans)
                exit()
            else:
                continue
        else:
            if ans[0] != ans[n - 2]:
                print(ans)
                exit()
            else:
                continue
    if s[n - 1] == "x":
        if ans[n - 1] == "W":
            if ans[0] == ans[n - 2]:
                print(ans)
                exit()
            else:
                continue
        else:
            if ans[0] != ans[n - 2]:
                print(ans)
                exit()
            else:
                continue            
if not_clear:
    print(-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
pattern = ["SS", "SW", "WS", "WW"]
dict_s = {"S":"W", "W":"S"}
not_clear = True
for p in pattern:
    ans = p
    for i in range(1, n - 1):
        if s[i] == "o":
            if ans[i] == "W":
                ans += dict_s[ans[i-1]]
            else:
                ans += ans[i-1]
        else:
            if ans[i] == "S":
                ans += dict_s[ans[i-1]]
            else:
                ans += ans[i-1]
    if s[n - 1] == "o":
        if ans[0] == ans[n - 2]:
            print(ans)
            exit()
        else:
            continue
    if s[n - 1] == "x":
        if ans[n - 1] == "W":
            if ans[0] == ans[n - 2]:
                print(ans)
                exit()
            else:
                continue
        else:
            if ans[0] != ans[n - 2]:
                print(ans)
                exit()
            else:
                continue            
if not_clear:
    print(-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
pattern = ["SS", "SW", "WS", "WW"]
dict_s = {"S":"W", "W":"S"}
not_clear = True
for p in pattern:
    ans = p
    for i in range(1, n - 1):
        if s[i] == "o":
            if ans[i] == "W":
                ans += dict_s[ans[i-1]]
            else:
                ans += ans[i-1]
        else:
            if ans[i] == "S":
                ans += dict_s[ans[i-1]]
            else:
                ans += ans[i-1]
    if s[n - 1] == "o":
        if ans[0] == ans[n - 2]:
            print(ans)
            exit()
        else:
            continue
    if s[n - 1] == "x":
        if ans[n - 1] == "W":
            if ans[0] != ans[n - 2]:
                print(ans)
                exit()
            else:
                continue
        else:
            if ans[0] == ans[n - 2]:
                print(ans)
                exit()
            else:
                continue            
if not_clear:
    print(-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
pattern = ["oo", "ox", "xo", "xx"]
not_clear = True
for p in pattern:
    ans = p
    for i in range(1, n - 1):
        if s[i] == "o":
            ans += ans[-2]
        else:
            if ans[-2] == "x":
                ans += "o"
            else:
                ans += "x"
    if s[n - 1] == "o":
        if s[0] == s[n - 2]:
            print(ans)
            exit()
        else:
            continue
    if s[n - 1] == "x":
        if s[0] != s[n - 2]:
            print(ans)
            exit()
        else:
            continue
if not_clear:
    print(-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
ans = ""
x = 0
for i in s:
    if i == "o":
        if x % 2 == 0:
            ans += "S"
        else:
            ans += "W"
    else:
        ans += "S"
        x += 1
if (x > 0) & (ans == "S" * n):
    print(-1)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#ABC55 D

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
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()
ans = 'SS'
for i in range(1,n-1):
    if s[i] == 'o':
        if ans[-1] == 'S':
            if ans[-2] == 'W':
                ans += 'W'
            else:
                ans += 'S'
        else:
            if ans[-2] == 'W':
                ans += 'S'
            else:
                ans += 'W'
    else:
        if ans[-1] == 'S':
            if ans[-2] == 'W':
                ans += 'S'
            else:
                ans += 'W'
        else:
            if ans[-2] == 'W':
                ans += 'W'
            else:
                ans += 'S'
flg = True
for i in range(n):
    if ans[i] == 'S':
        if s[i] == 'o':
            if i == n-1:
                if ans[i-1] != ans[0]:
                    flg = False
                    break
            else:
                if ans[i-1] != ans[i+1]:
                    flg = False
                    break
        else:
            if i == n-1:
                if ans[i-1] == ans[0]:
                    flg = False
                    break
            else:
                if ans[i-1] == ans[i+1]:
                    flg = False
                    break
    if ans[i] == 'W':
        if s[i] == 'o':
            if i == n-1:
                if ans[i-1] == ans[0]:
                    flg = False
                    break
            else:
                if ans[i-1] == ans[i+1]:
                    flg = False
                    break
        else:
            if i == n-1:
                if ans[i-1] != ans[0]:
                    flg = False
                    break
            else:
                if ans[i-1] != ans[i+1]:
                    flg = False
                    break
if flg:
    print(ans)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
s=s+s[0]
ans=[1]*(n+2)
for a,b in [(0,0),(0,1),(1,0),(1,1)]:
    ans[0]=a
    ans[1]=b
    for i in range(2,n+2):
        ans[i]^=ans[i-2]^ans[i-1]^(s[i-1]=='o')
    if ans[:2]==ans[-2:]:
        for i in range(n):
            print(['S','W'][ans[i]],end='')
        break
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
ans=[3]*(n+1)
for a,b in [(0,0),(0,1),(1,0),(1,1)]:
    ans[0]=a
    ans[1]=b
    for i in range(2,n+1):
        ans[i]=ans[i-2]^(s[i-1]==['o','x'][ans[i-1]==0])
    if ans[0]==ans[-1]:
        for i in range(n):
            print(['S','W'][ans[i]],end='')
        break
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
# ABC055D - Menagerie (ARC069D)
def check(a: int, b: int) -> list:
    ret, cur, prev = [], a, b
    for i in S:
        ret += [cur]
        if cur ^ (i == "o"):
            prev, cur = cur, prev  # both neighbors are the same
        else:
            prev, cur = cur, prev ^ 1  # both are different
    flg = cur == a and prev == b  # check the consistency of input and result
    return ret if flg else []


def main():
    global S
    N = int(input())
    S = input().rstrip()
    for a in range(2):
        for b in range(2):
            ans = check(a, b)
            if ans:
                print(*["S" if i else "W" for i in ans], sep="")
                return
    print(-1)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N: int, s: str):

    for SW in [[1, 1], [0, 1], [0, 0], [1, 0]]:
        for c in s[1:]:
            if SW[-1] == 1:
                if c == 'o':
                    SW.append(SW[-2])
                else:
                    SW.append(1-SW[-2])
            else:
                if c == 'o':
                    SW.append(1-SW[-2])
                else:
                    SW.append(SW[-2])
        if SW[0] == SW[-1]:
            if ((SW[0] == 1) and (s[0] == 'o') and (SW[-1] == SW[1]))\
               or ((SW[0] == 1) and (s[0] == 'x') and (SW[-1] != SW[1]))\
               or ((SW[0] == 0) and (s[0] == 'o') and (SW[-1] != SW[1]))\
               or ((SW[0] == 0) and (s[0] == 'x') and (SW[-1] == SW[1])):
                print("".join("WS"[sw] for sw in SW[:-1]))
                return

    print(-1)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    s = next(tokens)  # type: str
    solve(N, s)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N: int, s: str):

    for SW in [[1, 1], [0, 1], [0, 0], [1, 0]]:
        for c in s[1:]:
            if SW[-1] == 1:
                if c == 'o':
                    SW.append(SW[-2])
                else:
                    SW.append(1-SW[-2])
            else:
                if c == 'o':
                    SW.append(1-SW[-2])
                else:
                    SW.append(SW[-2])
        if SW[0] == SW[-1]:
            if ((SW[0] == 1) and (s[0] == 'o') and (SW[-1] == SW[1]))\
               or ((SW[0] == 1) and (s[0] == 'x') and (SW[-1] != SW[1]))\
               or ((SW[0] == 0) and (s[0] == 'o') and (SW[-1] != SW[1]))\
               or ((SW[0] == 0) and (s[0] == 'x') and (SW[-1] == SW[1])):
                print("".join("WS"[sw] for sw in SW[:-1]))
            return

    print(-1)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    s = next(tokens)  # type: str
    solve(N, s)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N: int, s: str):

    # SS始まり
    for SW in [[1, 1], [0, 1], [0, 0], [1, 0]]:
        for c in s[1:]:
            if SW[-1] == 1:
                if c == 'o':
                    SW.append(SW[-2])
                else:
                    SW.append(1-SW[-2])
            else:
                if c == 'o':
                    SW.append(1-SW[-2])
                else:
                    SW.append(SW[-2])
        if SW[0] == SW[-1]:
            print("".join("WS"[sw] for sw in SW[:-1]))
            return

    print(-1)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    s = next(tokens)  # type: str
    solve(N, s)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:

N = int(input())
s = input()

SW01 = [[0, 0],[0, 1],[1, 0],[1, 1]]


for i in range(4):
	SW = []
	SW.append(SW01[i][0])
	SW.append(SW01[i][1])
	for loc in range(1, N):
		if s[loc] == "o":
			SW.append(SW[loc-1]^SW[loc])
		else:
			SW.append(SW[loc - 1] ^ (SW[loc]^1))
	if SW[0] == SW[-1]:
		SW2 = []
		for i in range(N):
			if SW[i] == 0:
				SW2.append('S')
			else:
				SW2.append('W')
		print("".join(SW2))
		exit()

print(-1)

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007

#A
def A():
    n = II()
    ans = n * 800
    print(ans-(n//15)*200)
    return

#B
def B():
    n = II()
    print(math.factorial(n)%mod)
    return

#C
def C():
    n, m = LI()
    if n >= m // 2:
        print(m // 2)
        return
    else:
        m -= 2 * n
        print(n+m//4)
    return

#D
def D():
    n = II()
    ss = S()
    s = ["S", "W"]
    for i1 in s:
        for i2 in s:
            for i3 in s:
                ans = [i1, i2, i3]
                for i in range(2, n):
                    if ans[i] == "S":
                        if ss[i] == "o":
                            ans.append(ans[i - 1])
                        else:
                            if ans[i - 1] == "S":
                                ans.append("W")
                            else:
                                ans.append("S")
                    else:
                        if ss[i] == "x":
                            ans.append(ans[i - 1])
                        else:
                            if ans[i - 1] == "S":
                                ans.append("W")
                            else:
                                ans.append("S")

                if ans[0] != ans[-1]:
                    continue
                del ans[-1]

                if ans[0] == "S":
                    if ss[0] == "o":
                        if ans[1] != ans[-1]:
                            continue
                    else:
                        if ans[1] == ans[-1]:
                            continue
                else:
                    if ss[0] == "x":
                        if ans[1] != ans[-1]:
                            continue
                    else:
                        if ans[1] == ans[-1]:
                            continue

                for i in range(1, n - 1):
                    if ans[i] == "S":
                        if ss[i] == "o":
                            if ans[i - 1] != ans[i + 1]:
                                continue
                        else:
                            if ans[i - 1] == ans[i + 1]:
                                continue
                    else:
                        if ss[i] == "x":
                            if ans[i - 1] != ans[i + 1]:
                                continue
                        else:
                            if ans[i - 1] == ans[i + 1]:
                                continue

                if ans[-1] == "S":
                    if ss[-1] == "o":
                        if ans[-2] != ans[0]:
                            continue
                    else:
                        if ans[-2] == ans[0]:
                            continue
                else:
                    if ss[-1] == "x":
                        if ans[-2] != ans[0]:
                            continue
                    else:
                        if ans[-2] == ans[0]:
                            continue

                print("".join(ans))
                return

    print(-1)
    return

#Solve
if __name__ == '__main__':
    D()

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007

#A
def A():
    n = II()
    ans = n * 800
    print(ans-(n//15)*200)
    return

#B
def B():
    n = II()
    print(math.factorial(n)%mod)
    return

#C
def C():
    n, m = LI()
    if n >= m // 2:
        print(m // 2)
        return
    else:
        m -= 2 * n
        print(n+m//4)
    return

#D
def D():
    n = II()
    ss = S()
    s = ["S", "W"]
    for i1 in s:
        for i2 in s:
            for i3 in s:
                ans = [i1, i2, i3]
                for i in range(2, n):
                    if ans[i] == "S":
                        if ss[i] == "o":
                            ans.append(ans[i - 1])
                        else:
                            if ans[i - 1] == "S":
                                ans.append("W")
                            else:
                                ans.append("S")
                    else:
                        if ss[i] == "S":
                            ans.append(ans[i - 1])
                        else:
                            if ans[i - 1] == "S":
                                ans.append("W")
                            else:
                                ans.append("S")

                if ans[0] != ans[-1]:
                    continue
                del ans[-1]

                if ans[0] == "S":
                    if ss[0] == "o":
                        if ans[1] != ans[-1]:
                            continue
                    else:
                        if ans[1] == ans[-1]:
                            continue
                else:
                    if ss[0] == "x":
                        if ans[1] != ans[-1]:
                            continue
                    else:
                        if ans[1] == ans[-1]:
                            continue

                for i in range(1, n - 1):
                    if ans[i] == "S":
                        if ss[i] == "o":
                            if ans[i - 1] != ans[i + 1]:
                                continue
                        else:
                            if ans[i - 1] == ans[i + 1]:
                                continue
                    else:
                        if ss[i] == "x":
                            if ans[i - 1] != ans[i + 1]:
                                continue
                        else:
                            if ans[i - 1] == ans[i + 1]:
                                continue

                if ans[-1] == "S":
                    if ss[-1] == "o":
                        if ans[-2] != ans[0]:
                            continue
                    else:
                        if ans[-2] == ans[0]:
                            continue
                else:
                    if ss[-1] == "x":
                        if ans[-2] != ans[0]:
                            continue
                    else:
                        if ans[-2] == ans[0]:
                            continue

                print("".join(ans))
                return

    print(-1)
    return

#Solve
if __name__ == '__main__':
    D()