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:
n = int(input())
s = input()
flag = False
for i in range(4):
    if i == 0:
        ans = 'SS'
        past = 'S'
        cur = 'S'
        for j in range(1,n-1):
            if cur == 'S':
                if s[j] == 'o':
                    if past == 'S':
                        ans += 'S'
                    else:
                        ans += 'W'
                        past = 'S'
                        cur = 'W'
                else:
                    if past == 'S':
                        ans += 'W'
                        cur = 'W'
                    else:
                        ans += 'S'
                        past = 'S'
            else:
                if cur == 'W':
                    if s[j] == 'o':
                        if past == 'S':
                            ans += 'W'
                            past = 'W'
                        else:
                            ans += 'S'
                            cur = 'S'
                    else:
                        if past == 'S':
                            ans += 'S'
                            past = 'W'
                            cur = 'S'
                        else:
                            ans += 'W'
        if ans[len(ans)-1] == 'S':
            if s[n-1] == 'o':
                if ans[0] == ans[len(ans)-2]:
                    if s[0] == 'o':
                        if ans[1] == ans[len(ans)-1]:
                            flag = True
                            break
                    else:
                        if ans[1] != ans[len(ans)-1]:
                            flag = True
                            break
            else:
                if ans[0] != ans[len(ans)-2]:
                    if s[0] == 'o':
                        if ans[1] == ans[len(ans)-1]:
                            flag = True
                            break
                    else:
                        if ans[1] != ans[len(ans)-1]:
                            flag = True
                            break
        else:
            if s[n-1] == 'o':
                if ans[0] != ans[len(ans)-2]:
                    if s[0] == 'o':
                        if ans[1] == ans[len(ans)-1]:
                            flag = True
                            break
                    else:
                        if ans[1] != ans[len(ans)-1]:
                            flag = True
                            break
            else:
                if ans[0] == ans[len(ans)-2]:
                    if s[0] == 'o':
                        if ans[1] == ans[len(ans)-1]:
                            flag = True
                            break
                    else:
                        if ans[1] != ans[len(ans)-1]:
                            flag = True
                            break
    elif i == 1:
        ans = 'SW'
        past = 'S'
        cur = 'W'
        for j in range(1,n-1):
            if cur == 'S':
                if s[j] == 'o':
                    if past == 'S':
                        ans += 'S'
                    else:
                        ans += 'W'
                        past = 'S'
                        cur = 'W'
                else:
                    if past == 'S':
                        ans += 'W'
                        cur = 'W'
                    else:
                        ans += 'S'
                        past = 'S'
            else:
                if cur == 'W':
                    if s[j] == 'o':
                        if past == 'S':
                            ans += 'W'
                            past = 'W'
                        else:
                            ans += 'S'
                            cur = 'S'
                    else:
                        if past == 'S':
                            ans += 'S'
                            past = 'W'
                            cur = 'S'
                        else:
                            ans += 'W'
        if ans[len(ans)-1] == 'S':
            if s[n-1] == 'o':
                if ans[0] == ans[len(ans)-2]:
                    if s[0] == 'o':
                        if ans[1] == ans[len(ans)-1]:
                            flag = True
                            break
                    else:
                        if ans[1] != ans[len(ans)-1]:
                            flag = True
                            break
            else:
                if ans[0] != ans[len(ans)-2]:
                    if s[0] == 'o':
                        if ans[1] == ans[len(ans)-1]:
                            flag = True
                            break
                    else:
                        if ans[1] != ans[len(ans)-1]:
                            flag = True
                            break
        else:
            if s[n-1] == 'o':
                if ans[0] != ans[len(ans)-2]:
                    if s[0] == 'o':
                        if ans[1] == ans[len(ans)-1]:
                            flag = True
                            break
                    else:
                        if ans[1] != ans[len(ans)-1]:
                            flag = True
                            break
            else:
                if ans[0] == ans[len(ans)-2]:
                    if s[0] == 'o':
                        if ans[1] == ans[len(ans)-1]:
                            flag = True
                            break
                    else:
                        if ans[1] != ans[len(ans)-1]:
                            flag = True
                            break
    elif i == 2:
        ans = 'WS'
        past = 'W'
        cur = 'S'
        for j in range(1,n-1):
            if cur == 'S':
                if s[j] == 'o':
                    if past == 'S':
                        ans += 'S'
                    else:
                        ans += 'W'
                        past = 'S'
                        cur = 'W'
                else:
                    if past == 'S':
                        ans += 'W'
                        cur = 'W'
                    else:
                        ans += 'S'
                        past = 'S'
            else:
                if cur == 'W':
                    if s[j] == 'o':
                        if past == 'S':
                            ans += 'W'
                            past = 'W'
                        else:
                            ans += 'S'
                            cur = 'S'
                    else:
                        if past == 'S':
                            ans += 'S'
                            past = 'W'
                            cur = 'S'
                        else:
                            ans += 'W'
        if ans[len(ans)-1] == 'S':
            if s[n-1] == 'o':
                if ans[0] == ans[len(ans)-2]:
                    if s[0] == 'o':
                        if ans[1] == ans[len(ans)-1]:
                            flag = True
                            break
                    else:
                        if ans[1] != ans[len(ans)-1]:
                            flag = True
                            break
            else:
                if ans[0] != ans[len(ans)-2]:
                    if s[0] == 'o':
                        if ans[1] == ans[len(ans)-1]:
                            flag = True
                            break
                    else:
                        if ans[1] != ans[len(ans)-1]:
                            flag = True
                            break
        else:
            if s[n-1] == 'o':
                if ans[0] != ans[len(ans)-2]:
                    if s[0] == 'o':
                        if ans[1] == ans[len(ans)-1]:
                            flag = True
                            break
                    else:
                        if ans[1] != ans[len(ans)-1]:
                            flag = True
                            break
            else:
                if ans[0] == ans[len(ans)-2]:
                    if s[0] == 'o':
                        if ans[1] == ans[len(ans)-1]:
                            flag = True
                            break
                    else:
                        if ans[1] != ans[len(ans)-1]:
                            flag = True
                            break
    else:
        ans = 'WW'
        past = 'W'
        cur = 'W'
        for j in range(1,n-1):
            if cur == 'S':
                if s[j] == 'o':
                    if past == 'S':
                        ans += 'S'
                    else:
                        ans += 'W'
                        past = 'S'
                        cur = 'W'
                else:
                    if past == 'S':
                        ans += 'W'
                        cur = 'W'
                    else:
                        ans += 'S'
                        past = 'S'
            else:
                if cur == 'W':
                    if s[j] == 'o':
                        if past == 'S':
                            ans += 'W'
                            past = 'W'
                        else:
                            ans += 'S'
                            cur = 'S'
                    else:
                        if past == 'S':
                            ans += 'S'
                            past = 'W'
                            cur = 'S'
                        else:
                            ans += 'W'
        if ans[len(ans)-1] == 'S':
            if s[n-1] == 'o':
                if ans[0] == ans[len(ans)-2]:
                    if s[0] == 'o':
                        if ans[1] == ans[len(ans)-1]:
                            flag = True
                            break
                    else:
                        if ans[1] != ans[len(ans)-1]:
                            flag = True
                            break
            else:
                if ans[0] != ans[len(ans)-2]:
                    if s[0] == 'o':
                        if ans[1] == ans[len(ans)-1]:
                            flag = True
                            break
                    else:
                        if ans[1] != ans[len(ans)-1]:
                            flag = True
                            break
        else:
            if s[n-1] == 'o':
                if ans[0] != ans[len(ans)-2]:
                    if s[0] == 'o':
                        if ans[1] == ans[len(ans)-1]:
                            flag = True
                            break
                    else:
                        if ans[1] != ans[len(ans)-1]:
                            flag = True
                            break
            else:
                if ans[0] == ans[len(ans)-2]:
                    if s[0] == 'o':
                        if ans[1] == ans[len(ans)-1]:
                            flag = True
                            break
                    else:
                        if ans[1] != ans[len(ans)-1]:
                            flag = True
                            break
if flag:
    print(ans)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
flag = False
for i in range(4):
    if i == 0:
        ans = 'SS'
        past = 'S'
        cur = 'S'
        for j in range(1,n-1):
            if cur == 'S':
                if s[j] == 'o':
                    if past == 'S':
                        ans += 'S'
                    else:
                        ans += 'W'
                        past = 'S'
                        cur = 'W'
                else:
                    if past == 'S':
                        ans += 'W'
                        cur = 'W'
                    else:
                        ans += 'S'
                        past = 'S'
            else:
                if cur == 'W':
                    if s[j] == 'o':
                        if past == 'S':
                            ans += 'W'
                            past = 'W'
                        else:
                            ans += 'S'
                            cur = 'S'
                    else:
                        if past == 'S':
                            ans += 'S'
                            past = 'W'
                            cur = 'S'
                        else:
                            ans += 'W'
        if ans[len(ans)-1] == 'S':
            if s[n-1] == 'o':
                if ans[0] == ans[len(ans)-2]:
                    flag = True
                    break
            else:
                if ans[0] != ans[len(ans)-2]:
                    flag = True
                    break
        else:
            if s[n-1] == 'o':
                if ans[0] != ans[len(ans)-2]:
                    flag = True
                    break
            else:
                if ans[0] == ans[len(ans)-2]:
                    flag = True
                    break
    elif i == 1:
        ans = 'SW'
        past = 'S'
        cur = 'W'
        for j in range(1,n-1):
            if cur == 'S':
                if s[j] == 'o':
                    if past == 'S':
                        ans += 'S'
                    else:
                        ans += 'W'
                        past = 'S'
                        cur = 'W'
                else:
                    if past == 'S':
                        ans += 'W'
                        cur = 'W'
                    else:
                        ans += 'S'
                        past = 'S'
            else:
                if cur == 'W':
                    if s[j] == 'o':
                        if past == 'S':
                            ans += 'W'
                            past = 'W'
                        else:
                            ans += 'S'
                            cur = 'S'
                    else:
                        if past == 'S':
                            ans += 'S'
                            past = 'W'
                            cur = 'S'
                        else:
                            ans += 'W'
        if ans[len(ans)-1] == 'S':
            if s[n-1] == 'o':
                if ans[0] == ans[len(ans)-2]:
                    flag = True
                    break
            else:
                if ans[0] != ans[len(ans)-2]:
                    flag = True
                    break
        else:
            if s[n-1] == 'o':
                if ans[0] != ans[len(ans)-2]:
                    flag = True
                    break
            else:
                if ans[0] == ans[len(ans)-2]:
                    flag = True
                    break
    elif i == 2:
        ans = 'WS'
        past = 'W'
        cur = 'S'
        for j in range(1,n-1):
            if cur == 'S':
                if s[j] == 'o':
                    if past == 'S':
                        ans += 'S'
                    else:
                        ans += 'W'
                        past = 'S'
                        cur = 'W'
                else:
                    if past == 'S':
                        ans += 'W'
                        cur = 'W'
                    else:
                        ans += 'S'
                        past = 'S'
            else:
                if cur == 'W':
                    if s[j] == 'o':
                        if past == 'S':
                            ans += 'W'
                            past = 'W'
                        else:
                            ans += 'S'
                            cur = 'S'
                    else:
                        if past == 'S':
                            ans += 'S'
                            past = 'W'
                            cur = 'S'
                        else:
                            ans += 'W'
        if ans[len(ans)-1] == 'S':
            if s[n-1] == 'o':
                if ans[0] == ans[len(ans)-2]:
                    flag = True
                    break
            else:
                if ans[0] != ans[len(ans)-2]:
                    flag = True
                    break
        else:
            if s[n-1] == 'o':
                if ans[0] != ans[len(ans)-2]:
                    flag = True
                    break
            else:
                if ans[0] == ans[len(ans)-2]:
                    flag = True
                    break
    else:
        ans = 'WW'
        past = 'W'
        cur = 'W'
        for j in range(1,n-1):
            if cur == 'S':
                if s[j] == 'o':
                    if past == 'S':
                        ans += 'S'
                    else:
                        ans += 'W'
                        past = 'S'
                        cur = 'W'
                else:
                    if past == 'S':
                        ans += 'W'
                        cur = 'W'
                    else:
                        ans += 'S'
                        past = 'S'
            else:
                if cur == 'W':
                    if s[j] == 'o':
                        if past == 'S':
                            ans += 'W'
                            past = 'W'
                        else:
                            ans += 'S'
                            cur = 'S'
                    else:
                        if past == 'S':
                            ans += 'S'
                            past = 'W'
                            cur = 'S'
                        else:
                            ans += 'W'
        if ans[len(ans)-1] == 'S':
            if s[n-1] == 'o':
                if ans[0] == ans[len(ans)-2]:
                    flag = True
                    break
            else:
                if ans[0] != ans[len(ans)-2]:
                    flag = True
                    break
        else:
            if s[n-1] == 'o':
                if ans[0] != ans[len(ans)-2]:
                    flag = True
                    break
            else:
                if ans[0] == ans[len(ans)-2]:
                    flag = True
                    break
if flag:
    print(ans)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())
l=['SS','SW','WS','WW']
if s[0]=='o':
    g=['S','W','W','S']
else:
    g=['W','S','S','W']
for i in range(4):
    ans=l[i]
    for j in range(1,n):
        if s[j]=='o':
            for k in range(4):
                if ans[j-1]+ans[j]==l[k]:
                    if k==0 or k==3:
                        ans+='S'
                    else:
                        ans+='W'
        else:
            for k in range(4):
                if ans[j-1]+ans[j]==l[k]:
                    if k==0 or k==3:
                        ans+='W'
                    else:
                        ans+='S'
    if ans[-1]==ans[0]:
        print(ans[:-1])
        exit()
print(-1)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())
l=['SS','SW','WS','WW']
if s[0]=='o':
    g=['S','W','W','S']
else:
    g=['W','S','S','W']
for i in range(4):
    ans=l[i]
    for j in range(1,n-1):
        if s[j]=='o':
            for k in range(4):
                if ans[j-1]+ans[j]==l[k]:
                    if k==0 or k==3:
                        ans+='S'
                    else:
                        ans+='W'
        else:
            for k in range(4):
                if ans[j-1]+ans[j]==l[k]:
                    if k==0 or k==3:
                        ans+='W'
                    else:
                        ans+='S'
    if ans[-1]==g[i]:
        print(ans)
        exit()
print(-1)

Submission status: Wrong Answer

Solution code:
N = int(input())
s = input()
s += s[0]

def isOK(x, y):
    lst = [-1] * (N+2)
    lst[0] = x
    lst[1] = y
    for i in range(1, N+1):
        if (s[i] == 'o') ^ (lst[i]):    # 両隣は違う
            lst[i+1] = 1 - lst[i-1]
        else:                       # 両隣は同じ
            lst[i+1] = lst[i-1]
    if lst[0] == lst[-2] and lst[1] == lst[-1]:     # 1周回って同じ
        return lst[:-2]
    else:
        return []

for x in range(2):
    for y in range(2):
        lst = isOK(x, y)
        if len(lst) > 0:
            break

if len(lst) == 0:
    ans = -1
else:
    ans = ''
    for x in lst:
        if x:
            ans += 'S'
        else:
            ans += 'W'
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
n = int(input())
s = input()

def solve(first,second):
    sheep=[]

    sheep.append(first)
    sheep.append(second)

    for i in range(1,n):
        rep= s[i] == "o"
#        print("are you sheep?",sheep[i])
 #       print("rep:",rep)
  #      print()
        if not rep ^ sheep[i]:
            sheep.append(sheep[i-1])
        else:
            sheep.append(not sheep[i-1])
    return sheep

fir=[False,True]
sec=[True,False]

for i in fir:
    for j in sec:
        ans = solve(i,j)
#        print(ans)
        if ans[0]==ans[-1]:
            for a in ans[:-1]:
                if a:
                    print("S",end="")
                else:
                    print("W",end="")
            print()
            exit()
print(-1)

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
n = int(input())
s = input()

def solve(first,second):
    sheep=[]

    sheep.append(first)
    sheep.append(second)

    for i in range(1,n):
        rep= s[i] == "o"
        if not rep ^ sheep[i]:
            sheep.append(sheep[i-1])
        else:
            sheep.append(not sheep[i-1])
    return sheep

fir=[False,True]
sec=[True,False]

for i in fir:
    for j in sec:
        ans = solve(i,j)
        if ans[0]==ans[-1]:
            for a in ans[:-1]:
                if a:
                    print("S",end="")
                else:
                    print("W",end="")
            exit()
print(-1)

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
n = int(input())
s = input()

def solve(first,second):
    sheep=[]

    sheep.append(first)
    sheep.append(second)

    for i in range(1,n):
        rep= s[i] == "o"
        if not rep ^ sheep[i]:
            sheep.append(sheep[i-1])
        else:
            sheep.append(not sheep[i-1])
    return sheep


fir=[True,False]
sec=[True,False]

for i in fir:
    for j in sec:
        ans = solve(i,j)
        if ans[0]==ans[-1]:
            for a in ans[:-1]:
                if a:
                    print("S",end="")
                else:
                    print("W",end="")
            exit()
print(-1)

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
n = int(input())
s = input()

def solve(first,second):
    sheep=[]

    sheep.append(first)
    sheep.append(second)

    for i in range(1,n):
        rep= s[i] == "o"
        if not rep ^ sheep[i]:
            sheep.append(sheep[i-1])
        else:
            sheep.append(not sheep[i-1])
    return sheep


fir=[True,False]
sec=[True,False]

for i in fir:
    for j in sec:
        ans = solve(i,j)
        if ans[0]==ans[-1]:
            for a in ans:
                if a:
                    print("S",end="")
                else:
                    print("W",end="")
            exit()
print(-1)

Submission status: Wrong Answer

Solution code:
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

N = I()
s = str(input())

# 0:羊  1:狼
a = [-1]*(N+1)
A1,A2,A3,A4 = a[:],a[:],a[:],a[:]

def check(A):
    for i in range(1,N):
        now = 0 if s[i] == 'o' else 1
        temp = A[i-1] ^ A[i] ^ now
        if 1 <= i <= N-2:
            A[i+1] = temp
        else:
            if temp != A[0]:
                return
    if A[0] == 0:
        if A[1] != A[N-1]:
            return
    else:
        if A[1] == A[N-1]:
            return
    return A

A1[0],A1[-1],A1[1] = 0,0,0
A2[0],A2[-1],A2[1] = 0,0,1
A3[0],A3[-1],A3[1] = 1,1,0
A4[0],A4[-1],A4[1] = 1,1,1

ans = []
ans.extend([check(A1),check(A2),check(A3),check(A4)])
for x in ans:
    if x is not None:
        x = map(str,x[:-1])
        print(''.join(x).replace('0','S').replace('1','W'))
        exit()

print(-1)

Submission status: Wrong Answer

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

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

for e in L:
    for k in range(1,N):
        if s[k] == "o" and e[-1] == "S":
            e += e[-2]
        elif (s[k] == "x" and e[-1] == "S") or (s[k] == "o" and e[-1] == "W"):
            if e[-2] == "S":
                e += "W"
            else:
                e += "S"
        elif s[k] == "o" and e[-1] == "W":
            if e[-2] == "W":
                e += "S"
            else:
                e += "W"
        else:
            e += e[-2]
    if e[-1] == e[0]:
        print(e[:-1])
        exit(0)
print(-1)

Submission status: Wrong Answer

Solution code:
# True -> S or o
# False -> W or x

N = int(input())
s = [x=="o" for x in input()]

def is_true(L1:bool, L2:bool):
    L = [False] * N

    L[0] = L1
    L[1] = L2
    for i in range(1,N-1):
        if s[i]: # o
            L[i+1] = L[i-1] if L[i] else (not L[i-1])
        else: # x
            L[i+1] = L[i-1] if not L[i] else (not L[i-1])
    
    if s[-1]: # o
        if L[-1]: # 羊
            return (True, L) if L[-2] == L[0] else (False, L)
        else: # 狼
            return (True, L) if L[-2] != L[0] else (False, L)
    else: # x
        if L[-1]: # 羊
            return (True, L) if L[-2] != L[0] else (False, L)
        else: # 狼
            return (True, L) if L[-2] == L[0] else (False, L)

def main():
    for L1 in (True, False):
        for L2 in (True, False):
            flag, tmp = is_true(L1, L2)
            if not flag:
                continue
            else:
                ans = ""
                for x in tmp:
                    ans += "S" if x else "W"
                print(ans)
                exit()
    
    print(-1)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# True -> S or o
# False -> W or x

N = int(input())
s = [x=="o" for x in input()]

def is_true(L1:int, L2:int):
    L = [None] * N

    L[0] = L1
    L[1] = L2
    for i in range(1,N-1):
        # o
        if s[i]:
            if L[i]:
                # 羊
                L[i+1] = L[i-1]
            else:
                # 狼
                L[i+1] = not L[i-1]
        else:
            if L[i]:
                # 羊
                L[i+1] = not L[i-1]
            else:
                # 狼
                L[i+1] = L[i-1]
    
    # o
    if s[-1]:
        # 羊
        if L[-1]:
            if L[-2] == L[0]:
                return True, L
            else:
                return False, L
        # 狼
        else:
            if L[-2] != L[0]:
                return True, L
            else:
                return False, L
    # x
    else:
        # 羊
        if L[-1]:
            if L[-2] != L[0]:
                return True, L
            else:
                return False, L
        # 狼
        else:
            if L[-2] == L[0]:
                return True, L
            else:
                return False, L

def main():
    for L1 in (True, False):
        for L2 in (True, False):
            flag, tmp = is_true(L1, L2)
            if not flag:
                continue
            else:
                ans = ""
                for x in tmp:
                    ans += "S" if x else "W"
                print(ans)
                exit()
    
    print(-1)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    S = input()
    dsw = tuple([("S", "S"), ("S", "W"), ("W", "S"), ("W", "W")])
    for d1, d2 in dsw:
        cur = d1+d2
        for s in S[1:N-1]:
            if cur[-1] == "S":
                if s == "o":
                    cur += cur[-2]
                else:
                    cur += ("W" if cur[-2] == "S" else "S")
            else:
                if s == "o":
                    cur += ("W" if cur[-2] == "S" else "S")
                else:
                    cur += cur[-2]
        flag = False
        if cur[-1] == "S":
            if S[-1] == "o":
                flag = (cur[-2] == cur[0])
            else:
                flag = (cur[-2] != cur[0])
        else:
            if S[-1] == "o":
                flag = (cur[-2] != cur[0])
            else:
                flag = (cur[-2] == cur[0])
        if flag:
            return print(cur)

    print(-1)


if __name__ == '__main__':
    main()