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()
def f(n):
    if n == 'S':
        return 'W'
    if n == 'W':
        return 'S'
A = ['S','S']
fa = 1
B = ['S','W']
fb = 1
C = ['W','W']
fc = 1
D = ['W','S']
fd = 1
for i in range(1,N-1):
    x = S[i]
    if x == 'o':
        if A[i] == 'S':
            A.append(A[i-1])
        else:
            A.append(f(A[i-1]))
        if B[i] == 'S':
            B.append(B[i-1])
        else:
            B.append(f(B[i-1]))
        if C[i] == 'S':
            C.append(C[i-1])
        else:
            C.append(f(C[i-1]))
        if D[i] == 'S':
            D.append(D[i-1])
        else:
            D.append(f(D[i-1]))
    else:
        if A[i] == 'S':
            A.append(f(A[i-1]))
        else:
            A.append(A[i-1])
        if B[i] == 'S':
            B.append(f(B[i-1]))
        else:
            B.append(B[i-1])
        if C[i] == 'S':
            C.append(f(C[i-1]))
        else:
            C.append(C[i-1])
        if D[i] == 'S':
            D.append(f(D[i-1]))
        else:
            D.append(D[i-1])
if S[0] == 'o':
    if A[0] == 'S':
        if A[1] != A[-1]:
            fa = 0
    else:
        if A[1] == A[-1]:
            fa = 0
else:
    if A[0] == 'S':
        if A[1] == A[-1]:
            fa = 0
    else:
        if A[1] != A[-1]:
            fa = 0
if S[-1] == 'o':
    if A[-1] == 'S':
        if A[-2] != A[0]:
            fa = 0
    else:
        if A[-2] == A[0]:
            fa = 0
else:
    if A[-1] == 'S':
        if A[-2] == A[0]:
            fa = 0
    else:
        if A[-2] != A[0]:
            fa = 0
if fa == 1:
    x = A[0]
    for i in range(1,N):
        x += A[i]
    print(x)
    quit()
if S[0] == 'o':
    if B[0] == 'S':
        if B[1] != B[-1]:
            fb = 0
    else:
        if B[1] == B[-1]:
            fb = 0
else:
    if B[0] == 'S':
        if B[1] == B[-1]:
            fb = 0
    else:
        if B[1] != B[-1]:
            fb = 0
if S[-1] == 'o':
    if B[-1] == 'S':
        if B[-2] != B[0]:
            fb = 0
    else:
        if B[-2] == B[0]:
            fb = 0
else:
    if B[-1] == 'S':
        if B[-2] == B[0]:
            fb = 0
    else:
        if B[-2] != B[0]:
            fb = 0
if fb == 1:
    x = B[0]
    for i in range(1,N):
        x += B[i]
    print(x)
    quit()
if S[0] == 'o':
    if C[0] == 'S':
        if C[1] != C[-1]:
            fc = 0
    else:
        if C[1] == C[-1]:
            fc = 0
else:
    if C[0] == 'S':
        if C[1] == C[-1]:
            fc = 0
    else:
        if C[1] != C[-1]:
            fc = 0
if S[-1] == 'o':
    if C[-1] == 'S':
        if C[-2] != C[0]:
            fa = 0
    else:
        if C[-2] == C[0]:
            fc = 0
else:
    if C[-1] == 'S':
        if C[-2] == C[0]:
            fc = 0
    else:
        if C[-2] != C[0]:
            fc = 0
if fc == 1:
    x = C[0]
    for i in range(1,N):
        x += C[i]
    print(x)
    quit()
if S[0] == 'o':
    if D[0] == 'S':
        if D[1] != D[-1]:
            fd = 0
    else:
        if D[1] == D[-1]:
            fd = 0
else:
    if D[0] == 'S':
        if D[1] == D[-1]:
            fd = 0
    else:
        if D[1] != D[-1]:
            fd = 0
if S[-1] == 'o':
    if D[-1] == 'S':
        if D[-2] != D[0]:
            fd = 0
    else:
        if D[-2] == D[0]:
            fd = 0
else:
    if D[-1] == 'S':
        if D[-2] == D[0]:
            fd = 0
    else:
        if D[-2] != D[0]:
            fd = 0
if fd == 1:
    x = D[0]
    for i in range(1,N):
        x += D[i]
    print(x)
    quit()
if fa + fb + fc + fd == 0:
    print(-1)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
def f(n):
    if n == 'S':
        return 'W'
    if n == 'W':
        return 'S'
A = ['S','S']
fa = 1
B = ['S','W']
fb = 1
C = ['W','W']
fc = 1
D = ['W','S']
fd = 1
for i in range(1,N-1):
    x = S[i]
    if x == 'o':
        if A[i] == 'S':
            A.append(A[i-1])
        else:
            A.append(f(A[i-1]))
        if B[i] == 'S':
            B.append(B[i-1])
        else:
            B.append(f(B[i-1]))
        if C[i] == 'S':
            C.append(C[i-1])
        else:
            C.append(f(C[i-1]))
        if D[i] == 'S':
            D.append(D[i-1])
        else:
            D.append(f(D[i-1]))
    else:
        if A[i] == 'S':
            A.append(f(A[i-1]))
        else:
            A.append(A[i-1])
        if B[i] == 'S':
            B.append(f(B[i-1]))
        else:
            B.append(B[i-1])
        if C[i] == 'S':
            C.append(f(C[i-1]))
        else:
            C.append(C[i-1])
        if D[i] == 'S':
            D.append(f(D[i-1]))
        else:
            D.append(D[i-1])
if S[0] == 'o':
    if A[0] == 'S':
        if A[1] != A[-1]:
            fa = 0
    else:
        if A[1] == A[-1]:
            fa = 0
else:
    if A[0] == 'S':
        if A[1] == A[-1]:
            fa = 0
    else:
        if A[1] != A[-1]:
            fa = 0
if S[-1] == 'o':
    if A[-1] == 'S':
        if A[-2] != A[0]:
            fa = 0
    else:
        if A[-2] == A[0]:
            fa = 0
else:
    if A[-1] == 'S':
        if A[-2] == A[0]:
            fa = 0
    else:
        if A[-2] != A[0]:
            fa = 0
if fa == 1:
    x = A[0]
    for i in range(1,N):
        x += A[i]
    print(x)
    quit()
if S[0] == 'o':
    if A[0] == 'S':
        if A[1] != A[-1]:
            fa = 0
    else:
        if A[1] == A[-1]:
            fa = 0
else:
    if B[0] == 'S':
        if B[1] == B[-1]:
            fb = 0
    else:
        if B[1] != B[-1]:
            fb = 0
if S[-1] == 'o':
    if B[-1] == 'S':
        if B[-2] != B[0]:
            fb = 0
    else:
        if B[-2] == B[0]:
            fb = 0
else:
    if B[-1] == 'S':
        if B[-2] == B[0]:
            fb = 0
    else:
        if B[-2] != B[0]:
            fb = 0
if fb == 1:
    x = B[0]
    for i in range(1,N):
        x += B[i]
    print(x)
    quit()
if S[0] == 'o':
    if C[0] == 'S':
        if C[1] != C[-1]:
            fc = 0
    else:
        if C[1] == C[-1]:
            fc = 0
else:
    if C[0] == 'S':
        if C[1] == C[-1]:
            fc = 0
    else:
        if C[1] != C[-1]:
            fc = 0
if S[-1] == 'o':
    if C[-1] == 'S':
        if C[-2] != C[0]:
            fa = 0
    else:
        if A[-2] == A[0]:
            fc = 0
else:
    if C[-1] == 'S':
        if C[-2] == C[0]:
            fc = 0
    else:
        if C[-2] != C[0]:
            fc = 0
if fc == 1:
    x = C[0]
    for i in range(1,N):
        x += C[i]
    print(x)
    quit()
if S[0] == 'o':
    if D[0] == 'S':
        if D[1] != D[-1]:
            fd = 0
    else:
        if D[1] == D[-1]:
            fd = 0
else:
    if D[0] == 'S':
        if D[1] == D[-1]:
            fd = 0
    else:
        if D[1] != D[-1]:
            fd = 0
if S[-1] == 'o':
    if D[-1] == 'S':
        if D[-2] != D[0]:
            fd = 0
    else:
        if D[-2] == D[0]:
            fd = 0
else:
    if D[-1] == 'S':
        if D[-2] == D[0]:
            fd = 0
    else:
        if D[-2] != D[0]:
            fd = 0
if fd == 1:
    x = D[0]
    for i in range(1,N):
        x += D[i]
    print(x)
    quit()
if fa + fb + fc + fd == 0:
    print(-1)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
def f(n):
    if n == 'S':
        return 'W'
    if n == 'W':
        return 'S'
A = ['S','S']
fa = 1
B = ['S','W']
fb = 1
C = ['W','W']
fc = 1
D = ['W','S']
fd = 1
s = fa + fb + fc + fd
for i in range(1,N-1):
    x = S[i]
    if x == 'o':
        if A[i] == 'S':
            A.append(A[i-1])
        else:
            A.append(f(A[i-1]))
        if B[i] == 'S':
            B.append(B[i-1])
        else:
            B.append(f(B[i-1]))
        if C[i] == 'S':
            C.append(C[i-1])
        else:
            C.append(f(C[i-1]))
        if D[i] == 'S':
            D.append(D[i-1])
        else:
            D.append(f(D[i-1]))
    else:
        if A[i] == 'S':
            A.append(f(A[i-1]))
        else:
            A.append(A[i-1])
        if B[i] == 'S':
            B.append(f(B[i-1]))
        else:
            B.append(B[i-1])
        if C[i] == 'S':
            C.append(f(C[i-1]))
        else:
            C.append(C[i-1])
        if D[i] == 'S':
            D.append(f(D[i-1]))
        else:
            D.append(D[i-1])
if S[0] == 'o':
    if A[0] == 'S':
        if A[1] != A[-1]:
            fa = 0
    else:
        if A[1] == A[-1]:
            fa = 0
else:
    if A[0] == 'S':
        if A[1] == A[-1]:
            fa = 0
    else:
        if A[1] != A[-1]:
            fa = 0
if S[-1] == 'o':
    if A[-1] == 'S':
        if A[-2] != A[0]:
            fa = 0
    else:
        if A[-2] == A[0]:
            fa = 0
else:
    if A[-1] == 'S':
        if A[-2] == A[0]:
            fa = 0
    else:
        if A[-2] != A[0]:
            fa = 0
if fa == 1:
    x = A[0]
    for i in range(1,N):
        x += A[i]
    print(x)
    quit()
if S[0] == 'o':
    if A[0] == 'S':
        if A[1] != A[-1]:
            fa = 0
    else:
        if A[1] == A[-1]:
            fa = 0
else:
    if B[0] == 'S':
        if B[1] == B[-1]:
            fb = 0
    else:
        if B[1] != B[-1]:
            fb = 0
if S[-1] == 'o':
    if B[-1] == 'S':
        if B[-2] != B[0]:
            fb = 0
    else:
        if B[-2] == B[0]:
            fb = 0
else:
    if B[-1] == 'S':
        if B[-2] == B[0]:
            fb = 0
    else:
        if B[-2] != B[0]:
            fb = 0
if fb == 1:
    x = B[0]
    for i in range(1,N):
        x += B[i]
    print(x)
    quit()
if S[0] == 'o':
    if C[0] == 'S':
        if C[1] != C[-1]:
            fc = 0
    else:
        if C[1] == C[-1]:
            fc = 0
else:
    if C[0] == 'S':
        if C[1] == C[-1]:
            fc = 0
    else:
        if C[1] != C[-1]:
            fc = 0
if S[-1] == 'o':
    if C[-1] == 'S':
        if C[-2] != C[0]:
            fa = 0
    else:
        if A[-2] == A[0]:
            fc = 0
else:
    if C[-1] == 'S':
        if C[-2] == C[0]:
            fc = 0
    else:
        if C[-2] != C[0]:
            fc = 0
if fc == 1:
    x = C[0]
    for i in range(1,N):
        x += C[i]
    print(x)
    quit()
if S[0] == 'o':
    if D[0] == 'S':
        if D[1] != D[-1]:
            fd = 0
    else:
        if D[1] == D[-1]:
            fd = 0
else:
    if D[0] == 'S':
        if D[1] == D[-1]:
            fd = 0
    else:
        if D[1] != D[-1]:
            fd = 0
if S[-1] == 'o':
    if D[-1] == 'S':
        if D[-2] != D[0]:
            fd = 0
    else:
        if D[-2] == D[0]:
            fd = 0
else:
    if D[-1] == 'S':
        if D[-2] == D[0]:
            fd = 0
    else:
        if D[-2] != D[0]:
            fd = 0
if fd == 1:
    x = D[0]
    for i in range(1,N):
        x += D[i]
    print(x)
    quit()
if s == 0:
    print(-1)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n=int(input())
s=input()
def solve():
    for i in range(1,n):
        if (ans[i]=="S" and s[i]=="o") or (ans[i]=="W" and s[i]=="x"):
            ans[i+1]=ans[i-1]
        else:
            if ans[i-1]=="S":
                ans[i+1]="W"
            else:
                ans[i+1]="S"
    if ans[0]==ans[-1]:
        return True
    else:
        return False

ans=[0]*(n+1)

for i in ["S","W"]:
    for j in ["S","W"]:
        ans[0]=i
        ans[1]=j
        if solve():
            print("".join(ans[:-1]))
            exit()
print(-1)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n=int(input())
s=input()
def solve():
    for i in range(1,n):
        if (ans[i]=="S" and s[i]=="o") or (ans[i]=="W" and s[i]=="x"):
            ans[i+1]=ans[i-1]
        else:
            if ans[i-1]=="S":
                ans[i+1]="W"
            else:
                ans[i+1]="S"
    if ans[0]==ans[-1]:
        return True
    else:
        False

ans=[0]*(n+1)

for i in ["S","W"]:
    for j in ["S","W"]:
        ans[0]=i
        ans[1]=j
        if solve():
            print("".join(ans[:-1]))
            exit()
print(-1)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
x=["SS","SW","WS","WW"]

def check(i,j):
    if x[i][j]=="S":
        if s[j]=="o":
            if x[i][j-1]=="S":
                return x[i][j+1]=="S"
            else:
                return x[i][j+1]=="W"
        else:
            if x[i][-1]=="S":
                return x[i][j+1]=="W"
            else:
                return x[i][j+1]=="S"
    else:
        if s[j]=="o":
            if x[i][j-1]=="S":
                return x[i][j+1]=="W"
            else:
                return x[i][j+1]=="S"
        else:
            if x[i][-1]=="S":
                return x[i][j+1]=="S"
            else:
                return x[i][j+1]=="W"

a=["S","W"]
for i in range(4):
    for j in range(n-2):
        if x[i][j+1]=="S":
            if s[j+1]=="o":
                x[i]+=a[x[i][j]!="S"]
            else:
                x[i]+=a[x[i][j]=="S"]
        else:
            if s[j+1]=="o":
                x[i]+=a[x[i][j]=="S"]
            else:
                x[i]+=a[x[i][j]!="S"]
    if check(i,0) and check(i,-1):
        print(x[i])
        break
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
x=["SS","SW","WS","WW"]

def check(i,j):
    if j==0:
        l=0
    else:
        l=1
    if x[i][l]=="S":
        if s[l]=="o":
            if x[i][l-1]=="S":
                return x[i][l+1]=="S"
            else:
                return x[i][l+1]=="W"
        else:
            if x[i][-1]=="S":
                return x[i][l+1]=="W"
            else:
                return x[i][l+1]=="S"
    else:
        if s[l]=="o":
            if x[i][l-1]=="S":
                return x[i][l+1]=="W"
            else:
                return x[i][l+1]=="S"
        else:
            if x[i][-1]=="S":
                return x[i][l+1]=="S"
            else:
                return x[i][l+1]=="W"

a=["S","W"]
for i in range(4):
    for j in range(n-2):
        if x[i][j+1]=="S":
            if s[j+1]=="o":
                x[i]+=a[x[i][j]!="S"]
            else:
                x[i]+=a[x[i][j]=="S"]
        else:
            if s[j+1]=="o":
                x[i]+=a[x[i][j]=="S"]
            else:
                x[i]+=a[x[i][j]!="S"]
    if check(i,0) and check(i,1):
        print(x[i])
        break
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
x=["SS","SW","WS","WW"]

def check0(i):
    if x[i][0]=="S":
        if s[0]=="o":
            if x[i][-1]=="S":
                return x[i][1]=="S"
            else:
                return x[i][1]=="W"
        else:
            if x[i][-1]=="S":
                return x[i][1]=="W"
            else:
                return x[i][1]=="S"
    else:
        if s[0]=="o":
            if x[i][-1]=="S":
                return x[i][1]=="W"
            else:
                return x[i][1]=="S"
        else:
            if x[i][-1]=="S":
                return x[i][1]=="S"
            else:
                return x[i][1]=="W"
def check1(i):
    if x[i][n-1]=="S":
        if s[n-1]=="o":
            return x[i][n-2]=="S" and x[i][0]=="S"
        else:
            return x[i][n-2]=="S" and x[i][0]!="S"
    else:
        if s[n-1]=="o":
            return x[i][n-2]=="S" and x[i][0]=="S"
        else:
            return x[i][n-2]=="S" and x[i][0]!="S"

a=["S","W"]
for i in range(4):
    for j in range(n-2):
        if x[i][j+1]=="S":
            if s[j+1]=="o":
                x[i]+=a[x[i][j]!="S"]
            else:
                x[i]+=a[x[i][j]=="S"]
        else:
            if s[j+1]=="o":
                x[i]+=a[x[i][j]=="S"]
            else:
                x[i]+=a[x[i][j]!="S"]
    if check0(i) and check1(i):
        print(x[i])
        break
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
x=["SS","SW","WS","WW"]

def check0(i):
    if x[i][0]=="S":
        if s[0]=="o":
            if x[i][-1]=="S":
                return x[i][1]=="S"
            else:
                return x[i][1]=="W"
        else:
            if x[i][-1]=="S":
                return x[i][1]=="W"
            else:
                return x[i][1]=="S"
    else:
        if s[0]=="o":
            if x[i][-1]=="S":
                return x[i][1]=="S"
            else:
                return x[i][1]=="W"
        else:
            if x[i][-1]=="S":
                return x[i][1]=="W"
            else:
                return x[i][1]=="S"
def check1(i):
    if x[i][n-1]=="S":
        if s[n-1]=="o":
            if x[i][n-2]=="S":
                return x[i][0]=="S"
            else:
                return x[i][0]=="W"
        else:
            if x[i][n-2]=="S":
                return x[i][0]=="W"
            else:
                return x[i][0]=="S"
    else:
        if s[n-1]=="o":
            if x[i][n-2]=="S":
                return x[i][0]=="W"
            else:
                return x[i][0]=="S"
        else:
            if x[i][n-2]=="S":
                return x[i][0]=="S"
            else:
                return x[i][0]=="W"


for i in range(4):
    for j in range(n-2):
        if x[i][j+1]=="S":
            if s[j+1]=="o":
                if x[i][j]=="S":
                    x[i]+="S"
                else:
                    x[i]+="W"
            else:
                if x[i][j]=="S":
                    x[i]+="W"
                else:
                    x[i]+="S"
        else:
            if s[j+1]=="o":
                if x[i][j]=="S":
                    x[i]+="W"
                else:
                    x[i]+="S"
            else:
                if x[i][j]=="S":
                    x[i]+="S"
                else:
                    x[i]+="W"
    #print(x[i])
    if check0(i) and check1(i):
        print(x[i])
        break
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
s=input()
S=[]
for i in range(n):
  if s[i]=="o":
    S.append(1)
  else:
    S.append(-1)
A=[1,1]
for i in range(1,n-1):
  A.append(S[i]*A[-2]*A[-1])
if S[-1]==A[-2]*A[-1]*A[0]:
  if S[0]==A[-1]*A[0]*A[1]:
    for i in range(n):
      if A[i]==1:
        print("S",end="")
      else:
        print("W",end="")
      if i==n-1:
        print()
    sys.exit()
A=[1,-1]
for i in range(1,n-1):
  A.append(S[i]*A[-2]*A[-1])
if S[-1]==A[-2]*A[-1]*A[0]:
  if S[0]==A[-1]*A[0]*A[1]:
    if A[i]==1:
      print("S",end="")
    else:
      print("W",end="")
    if i==n-1:
      print()
    sys.exit()
A=[-1,1]
for i in range(1,n-1):
  A.append(S[i]*A[-2]*A[-1])
if S[-1]==A[-2]*A[-1]*A[0]:
  if S[0]==A[-1]*A[0]*A[1]:
    if A[i]==1:
      print("S",end="")
    else:
      print("W",end="")
    if i==n-1:
      print()
    sys.exit()
A=[-1,-1]
for i in range(1,n-1):
  A.append(S[i]*A[-2]*A[-1])
if S[-1]==A[-2]*A[-1]*A[0]:
  if S[0]==A[-1]*A[0]*A[1]:
    if A[i]==1:
      print("S",end="")
    else:
      print("W",end="")
    if i==n-1:
      print()
    sys.exit()
print(-1)

Submission status: Wrong Answer

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

def judge(start):
    ans = start
    for i in range(1, N):
        # 羊の処理
        if ans[i]=="S":
            # o or xで分岐
            if s[i]=="o":
                 ans[i+1]=ans[i-1]
            else:
                  # 羊x
                 ans[i+1]= "S" if ans[i-1]=="W" else "W"
        else:
            if s[i]=="o":
                # 狼o
                ans[i+1]= "S" if ans[i-1]=="W" else "W"
            else:
                  # 狼x
                 ans[i+1]=ans[i-1]

    if ans[0]==ans[N]:
        return("".join(ans[:-1]))
    else:
        return(-1)

resultWW=judge(list("W"+"W"*(N)))
resultWS=judge(list("W"+"S"*(N)))
resultSS=judge(list("S"+"S"*(N)))
resultSW=judge(list("S"+"W"*(N)))

if resultWW!=-1:
    print(resultWW)
    exit()
elif resultWS!=-1:
    print(resultWS)
    exit()
elif resultSS!=-1:
    print(resultSS)
    exit()
elif resultSW!=-1:
    print(resultSW)
    exit()
else:
    print(-1)

Submission status: Wrong Answer

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

def judge(start):
    ans = start
    for i in range(0, N):
        # 羊の処理
        if ans[i]=="S":
            # o or xで分岐
            if s[i]=="o":
                 ans[i+1]=ans[i-1]
            else:
                  # 羊x
                 ans[i+1]= "S" if ans[i-1]=="W" else "W"
        else:
            if s[i]=="o":
                # 狼o
                ans[i+1]= "S" if ans[i-1]=="W" else "W"
            else:
                  # 狼x
                 ans[i+1]=ans[i-1]

    if ans[0]==ans[N]:
        return("".join(ans[:-1]))
    else:
        return(-1)

resultWW=judge(list("W"+"W"*(N)))
resultWS=judge(list("W"+"S"*(N)))
resultSS=judge(list("S"+"S"*(N)))
resultSW=judge(list("S"+"W"*(N)))

if resultWW!=-1:
    print(resultWW)
    exit()
elif resultWS!=-1:
    print(resultWS)
    exit()
elif resultSS!=-1:
    print(resultSS)
    exit()
elif resultSW!=-1:
    print(resultSW)
    exit()
else:
    print(-1)

Submission status: Wrong Answer

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

def judge(start):
    ans = list(start*(N+1))
    for i in range(0, N):
        # 羊の処理
        if ans[i]=="S":
            # o or xで分岐
            if s[i]=="o":
                 ans[i+1]=ans[i-1]
            else:
                  # 羊x
                 ans[i+1]= "S" if ans[i-1]=="W" else "W"
        else:
            if s[i]=="o":
                # 狼o
                ans[i+1]= "S" if ans[i-1]=="W" else "W"
            else:
                  # 狼x
                 ans[i+1]=ans[i-1]

    if ans[0]==ans[N]:
        return("".join(ans[:-1]))
    else:
        return(-1)

resultS=judge("S")
resultW=judge("W")

if resultS!=-1:
    print(resultS)
    exit()
elif resultW!=-1:
    print(resultW)
    exit()
else:
    print(-1)

Submission status: Wrong Answer

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

ans = list("S"*(N+1))
for i in range(0, N):
    # 羊の処理
    if ans[i]=="S":
        # o or xで分岐
        if s[i]=="o":
            ans[i+1]=ans[i-1]
        else:
              # 羊x
             ans[i+1]= "S" if ans[i-1]=="W" else "W"
    else:
        if s[i]=="o":
            # 狼o
            ans[i+1]= "S" if ans[i-1]=="W" else "W"
        else:
              # 狼x
             ans[i+1]=ans[i-1]

if ans[0]==ans[N]:
    print("".join(ans[:-1]))
else:
    print(-1)

Submission status: Wrong Answer

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

ans = list("S"*N)
for i in range(0, N-1):
    # 羊の処理
    if ans[i]=="S":
        # o or xで分岐
        if s[i]=="o":
            ans[i+1]=ans[i-1]
        else:
              # 羊x
             ans[i+1]= "S" if ans[i-1]=="W" else "W"
    else:
        if s[i]=="o":
            # 狼o
            ans[i+1]= "S" if ans[i-1]=="W" else "W"
        else:
              # 狼x
             ans[i+1]=ans[i-1]

print("".join(ans))

Submission status: Wrong Answer

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

ans = list("S"*N)
for i in range(0, N-1):
    # 羊の処理
    if ans[i]=="S":
        # o or xで分岐
        if s[i]=="o":
            ans[i+1]=ans[i-1]
        else:
              # 羊x
             ans[i+1]= "S" if ans[i-1]=="W" else "W"
    else:
        if s[i]=="o":
            # 狼o
            ans[i+1]= "S" if ans[i-1]=="W" else "W"
        else:
              # 狼x
             ans[i+1]=ans[i-1]

print(ans)

Submission status: Wrong Answer

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

w = {-1: 'W', 1: 'S'}
p = {1:'o', -1:'x'}
lst = [[1, 1], [-1, -1], [1, -1], [-1, 1]]

tmp = [0 for i in range(n+1)]
for a in lst:
    tmp[0] = a[0]
    tmp[1] = a[1]
    for i in range(1,n):
        tmp[i+1] = tmp[i-1] if s[i] == p[tmp[i]] else (tmp[i-1] * -1)
    if tmp[0] == tmp[-1]:
        tmp.pop()
        print(''.join(map(w.get, tmp)))
        break
else:
    print(-1)

Submission status: Wrong Answer

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

d = {'W': -1, 'S': 1}
w = {-1: 'W', 1: 'S'}
lst = [[1, 1], [-1, 1], [1, -1], [-1, -1]]

for a in lst:
    tmp = [0 for i in range(n+1)]
    tmp[0] = a[0]
    tmp[1] = a[1]
    for i in range(1,n):
        if tmp[i] == d['S']:
            tmp[i+1] = tmp[i-1] if s[i] == 'o' else (tmp[i-1] * -1)
        else:
            tmp[i+1] = (tmp[i-1] * -1) if s[i] == 'o' else tmp[i-1]
    if tmp[0] == tmp[-1]:
        print(''.join([w[i] for i in tmp[:-1]]))
        break
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import sys
from itertools import product

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
S = input()

def check(a, b):
    res = [a, b]
    # 自分と1つ前がS,Wどっちかと、自分の発言のo,xが分かれば、次が定まる
    for i in range(1, N):
        # 隣が同じで発言がo,違ってxなら羊
        if res[i-1] == res[i] and S[i] == 'o' \
                or res[i-1] != res[i] and S[i] == 'x':
            res.append('S')
        # 隣が同じで発言がx,違ってoなら狼
        else:
            res.append('W')
    # 1周して矛盾していないか
    if res[0] == res[N]:
        return res
    else:
        return []

# 1,2番目がS,Wどっちかの4通り試す
for a, b in product(['S', 'W'], repeat=2):
    res = check(a, b)
    if res:
        print(''.join(res[:N]))
        exit()
print(-1)

Submission status: Wrong Answer

Solution code:
import sys

def SorW(s, animal_lst):
  for animal in range(1, N):
    if s[animal] == "o":
      if animal_lst[animal] == "S":
        animal_lst.append(animal_lst[animal-1])
      elif animal_lst[animal] == "W":
        animal_lst.append(oppos_animal(animal_lst[animal-1]))

    if s[animal] == "x":
      if animal_lst[animal] == "S":
        animal_lst.append(oppos_animal(animal_lst[animal-1]))
      elif animal_lst[animal] == "W":
        animal_lst.append(animal_lst[animal-1])

def oppos_animal(animal):
  if animal == "S":
    return "W"
  elif animal == "W":
    return "S"

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

lst = [["S", "S"], ["W", "W"], ["S", "W"], ["W", "S"]]

for i in lst:
  SorW(s, i)
  if i[0] == i[-1]:
    print("".join(i[:-1]))
    sys.exit()
print(-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
ans = ["SS","SW","WS","WW"]
for a in ans:
    for i in range(2,n+1):
        if s[i-1] == "o":
            if a[-2:] == "SS" or a[-2:] == "WW":
                a += "S"
            else:
                a += "W"
        if s[i-1] == "x":
            if a[-2:] == "SW" or a[-2:] == "WS":
                a += "S"
            else:
                a += "W"
    else:
        if a[n] == a[0]:
            if ((s[0] == "o" and a[1] == a[n-1])
                or (s[0] == "x" and a[1] != a[n-1])):
                print(a[:n])
                exit()
print(-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
ans = ["SS","SW","WS","WW"]
for a in ans:
    for i in range(2,n+1):
        if s[i-1] == "o":
            if a[-2:] == "SS" or a[-2:] == "WW":
                a += "S"
            else:
                a += "W"
        if s[i-1] == "x":
            if a[-2:] == "SW" or a[-2:] == "WS":
                a += "S"
            else:
                a += "W"
    else:
        if a[n] == a[0]:
            print(a[:n])
            exit()
print(-1)

Submission status: Wrong Answer

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

#末尾と1番目を羊または狼と仮定して貪欲。4パターン
import itertools
for x,y in itertools.product(["S","W"], repeat=2):
  ans=[None]*n
  ans[-1]=x
  ans[0]=y
  for i in range(n):
    flag=1
    if 0<=i<=n-3:
      if ans[i]=="S":
        if s[i]=="o":
          ans[i+1]=ans[i-1] #同じと言ってる場合は同じのため、次の番号は2つ前と同じ動物。
        else: #そうじゃない場合は、次の番号は2つ前と違う動物。
          if ans[i-1]=="W":
            ans[i+1]="S"
          else:
            ans[i+1]="W"
      #今の番号が狼の場合は上の全部逆にする
      if ans[i]=="W":
        if s[i]=="x":
          ans[i+1]=ans[i-1]
        else:
          if ans[i-1]=="W":
            ans[i+1]="S" 
          else:
            ans[i+1]="W"
    else: #iがn-2とn-1の場合は、先頭と末尾の羊を指定するため、矛盾を確認しないといけない。こっからが肝だよ
      if ans[i]=="S":
        if s[i]=="o":
          if ans[(i+1)%n]!=ans[i-1]:
            flag=0
        else:
          if ans[(i+1)%n]==ans[i-1]:
            flag=0
      #今の番号が狼の場合は上の全部逆にする
      if ans[i]=="W":
        if s[i]=="x":
          if ans[(i+1)%n]!=ans[i-1]:
            flag=0
        else:
          if ans[(i+1)%n]==ans[i-1]:
            flag=0
  if flag==1:
    print("".join(ans))
    exit()

#どんなケースでも矛盾するとループを抜けてしまう
print(-1)