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:
import sys
n=int(input())
s=input()
dp=[-1]*n
flag=0
if n%2==0:
    dp[0]=0
    dp[-1]=0
    for i in range(n):
        if not ((s[i]=='o') ^ (dp[i]==0)):
            if dp[(i+1)%n]==-1 or dp[(i+1)%n]==dp[i-1]:
                dp[(i+1)%n]=dp[i-1]
            else:
                flag=-1
        else:
            if dp[(i+1)%n]==-1 or dp[(i+1)%n]!=dp[i-1]:
                dp[(i+1)%n]=1-dp[i-1]
            else:
                flag=-1
else:
    dp[-1]=0
    for i in range(0,2*n,2):
        if not ((s[i%n]=='o') ^ (dp[i%n]==0)):
            if dp[(i+1)%n]==-1 or dp[(i+1)%n]==dp[(i-1)%n]:
                dp[(i+1)%n]=dp[(i-1)%n]
            else:
                flag=-1
        else:
            if dp[(i+1)%n]==-1 or dp[(i+1)%n]!=dp[(i-1)%n]:
                dp[(i+1)%n]=1-dp[(i-1)%n]
            else:
                flag=-1
if flag==-1:
    flag=0
    dp=[-1]*n

    if n%2==0:
        dp[0]=1
        dp[-1]=0
        for i in range(n):
            if not ((s[i]=='o') ^ (dp[i]==0)):
                if dp[(i+1)%n]==-1 or dp[(i+1)%n]==dp[i-1]:
                    dp[(i+1)%n]=dp[i-1]
                else:
                    flag=-1
            else:
                if dp[(i+1)%n]==-1 or dp[(i+1)%n]!=dp[i-1]:
                    dp[(i+1)%n]=1-dp[i-1]
                else:
                    flag=-1
    else:
        dp[-1]=0
        for i in range(0,2*n,2):
            if not ((s[i%n]=='o') ^ (dp[i%n]==0)):
                if dp[(i+1)%n]==-1 or dp[(i+1)%n]==dp[(i-1)%n]:
                    dp[(i+1)%n]=dp[(i-1)%n]
                else:
                    flag=-1
            else:
                if dp[(i+1)%n]==-1 or dp[(i+1)%n]!=dp[(i-1)%n]:
                    dp[(i+1)%n]=1-dp[(i-1)%n]
                else:
                    flag=-1
if flag==-1:
    flag=0
    dp=[-1]*n

    if n%2==0:
        dp[0]=1
        dp[-1]=1
        for i in range(n):
            if not ((s[i]=='o') ^ (dp[i]==0)):
                if dp[(i+1)%n]==-1 or dp[(i+1)%n]==dp[i-1]:
                    dp[(i+1)%n]=dp[i-1]
                else:
                    flag=-1
            else:
                if dp[(i+1)%n]==-1 or dp[(i+1)%n]!=dp[i-1]:
                    dp[(i+1)%n]=1-dp[i-1]
                else:
                    flag=-1
    else:
        dp[-1]=0
        for i in range(0,2*n,2):
            if not ((s[i%n]=='o') ^ (dp[i%n]==0)):
                if dp[(i+1)%n]==-1 or dp[(i+1)%n]==dp[(i-1)%n]:
                    dp[(i+1)%n]=dp[(i-1)%n]
                else:
                    flag=-1
            else:
                if dp[(i+1)%n]==-1 or dp[(i+1)%n]!=dp[(i-1)%n]:
                    dp[(i+1)%n]=1-dp[(i-1)%n]
                else:
                    flag=-1
if flag==-1:
    flag=0
    dp=[-1]*n

    if n%2==0:
        dp[0]=0
        dp[-1]=1
        for i in range(n):
            if not ((s[i]=='o') ^ (dp[i]==0)):
                if dp[(i+1)%n]==-1 or dp[(i+1)%n]==dp[i-1]:
                    dp[(i+1)%n]=dp[i-1]
                else:
                    flag=-1
            else:
                if dp[(i+1)%n]==-1 or dp[(i+1)%n]!=dp[i-1]:
                    dp[(i+1)%n]=1-dp[i-1]
                else:
                    flag=-1
    else:
        dp[-1]=0
        for i in range(0,2*n,2):
            if not ((s[i%n]=='o') ^ (dp[i%n]==0)):
                if dp[(i+1)%n]==-1 or dp[(i+1)%n]==dp[(i-1)%n]:
                    dp[(i+1)%n]=dp[(i-1)%n]
                else:
                    flag=-1
            else:
                if dp[(i+1)%n]==-1 or dp[(i+1)%n]!=dp[(i-1)%n]:
                    dp[(i+1)%n]=1-dp[(i-1)%n]
                else:
                    flag=-1
if flag==-1:
    print(-1)
    sys.exit()
for i in range(n):
    if dp[i]==0:
        print('S',end='')
    else:
        print('W',end='')
print('\n')

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
s=input()
dp=[-1]*n
flag=0
if n%2==0:
    dp[0]=0
    dp[-1]=0
    for i in range(n):
        if not ((s[i]=='o') ^ (dp[i]==0)):
            if dp[(i+1)%n]==-1 or dp[(i+1)%n]==dp[i-1]:
                dp[(i+1)%n]=dp[i-1]
            else:
                flag=-1
        else:
            if dp[(i+1)%n]==-1 or dp[(i+1)%n]!=dp[i-1]:
                dp[(i+1)%n]=1-dp[i-1]
            else:
                flag=-1
else:
    dp[-1]=0
    for i in range(0,2*n,2):
        if not ((s[i%n]=='o') ^ (dp[i%n]==0)):
            if dp[(i+1)%n]==-1 or dp[(i+1)%n]==dp[(i-1)%n]:
                dp[(i+1)%n]=dp[(i-1)%n]
            else:
                flag=-1
        else:
            if dp[(i+1)%n]==-1 or dp[(i+1)%n]!=dp[(i-1)%n]:
                dp[(i+1)%n]=1-dp[(i-1)%n]
            else:
                flag=-1
if flag==-1:
    flag=0
    dp=[-1]*n

    if n%2==0:
        dp[0]=1
        dp[-1]=0
        for i in range(n):
            if not ((s[i]=='o') ^ (dp[i]==0)):
                if dp[(i+1)%n]==-1 or dp[(i+1)%n]==dp[i-1]:
                    dp[(i+1)%n]=dp[i-1]
                else:
                    flag=-1
            else:
                if dp[(i+1)%n]==-1 or dp[(i+1)%n]!=dp[i-1]:
                    dp[(i+1)%n]=1-dp[i-1]
                else:
                    flag=-1
    else:
        dp[-1]=0
        for i in range(0,2*n,2):
            if not ((s[i%n]=='o') ^ (dp[i%n]==0)):
                if dp[(i+1)%n]==-1 or dp[(i+1)%n]==dp[(i-1)%n]:
                    dp[(i+1)%n]=dp[(i-1)%n]
                else:
                    flag=-1
            else:
                if dp[(i+1)%n]==-1 or dp[(i+1)%n]!=dp[(i-1)%n]:
                    dp[(i+1)%n]=1-dp[(i-1)%n]
                else:
                    flag=-1
if flag==-1:
    flag=0
    dp=[-1]*n

    if n%2==0:
        dp[0]=1
        dp[-1]=1
        for i in range(n):
            if not ((s[i]=='o') ^ (dp[i]==0)):
                if dp[(i+1)%n]==-1 or dp[(i+1)%n]==dp[i-1]:
                    dp[(i+1)%n]=dp[i-1]
                else:
                    flag=-1
            else:
                if dp[(i+1)%n]==-1 or dp[(i+1)%n]!=dp[i-1]:
                    dp[(i+1)%n]=1-dp[i-1]
                else:
                    flag=-1
    else:
        dp[-1]=0
        for i in range(0,2*n,2):
            if not ((s[i%n]=='o') ^ (dp[i%n]==0)):
                if dp[(i+1)%n]==-1 or dp[(i+1)%n]==dp[(i-1)%n]:
                    dp[(i+1)%n]=dp[(i-1)%n]
                else:
                    flag=-1
            else:
                if dp[(i+1)%n]==-1 or dp[(i+1)%n]!=dp[(i-1)%n]:
                    dp[(i+1)%n]=1-dp[(i-1)%n]
                else:
                    flag=-1
if flag==-1:
    flag=0
    dp=[-1]*n

    if n%2==0:
        dp[0]=0
        dp[-1]=1
        for i in range(n):
            if not ((s[i]=='o') ^ (dp[i]==0)):
                if dp[(i+1)%n]==-1 or dp[(i+1)%n]==dp[i-1]:
                    dp[(i+1)%n]=dp[i-1]
                else:
                    flag=-1
            else:
                if dp[(i+1)%n]==-1 or dp[(i+1)%n]!=dp[i-1]:
                    dp[(i+1)%n]=1-dp[i-1]
                else:
                    flag=-1
    else:
        dp[-1]=0
        for i in range(0,2*n,2):
            if not ((s[i%n]=='o') ^ (dp[i%n]==0)):
                if dp[(i+1)%n]==-1 or dp[(i+1)%n]==dp[(i-1)%n]:
                    dp[(i+1)%n]=dp[(i-1)%n]
                else:
                    flag=-1
            else:
                if dp[(i+1)%n]==-1 or dp[(i+1)%n]!=dp[(i-1)%n]:
                    dp[(i+1)%n]=1-dp[(i-1)%n]
                else:
                    flag=-1
for i in range(n):
    if dp[i]==0:
        print('S',end='')
    else:
        print('W',end='')
print('\n')

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
s=input()
dp=[-1]*n
flag=0
if n%2==0:
    dp[0]=0
    dp[-1]=0
    for i in range(n):
        if not ((s[i]=='o') ^ (dp[i]==0)):
            if dp[(i+1)%n]==-1 or dp[(i+1)%n]==dp[i-1]:
                dp[(i+1)%n]=dp[i-1]
            else:
                flag=-1
        else:
            if dp[(i+1)%n]==-1 or dp[(i+1)%n]!=dp[i-1]:
                dp[(i+1)%n]=1-dp[i-1]
            else:
                flag=-1
else:
    dp[-1]=0
    for i in range(0,2*n,2):
        if not ((s[i%n]=='o') ^ (dp[i%n]==0)):
            if dp[(i+1)%n]==-1 or dp[(i+1)%n]==dp[(i-1)%n]:
                dp[(i+1)%n]=dp[(i-1)%n]
            else:
                flag=-1
        else:
            if dp[(i+1)%n]==-1 or dp[(i+1)%n]!=dp[(i-1)%n]:
                dp[(i+1)%n]=1-dp[(i-1)%n]
            else:
                flag=-1
if flag==-1:
    flag=0
    if n%2==0:
        dp[0]=1
        dp[-1]=0
        for i in range(n):
            if not ((s[i]=='o') ^ (dp[i]==0)):
                if dp[(i+1)%n]==-1 or dp[(i+1)%n]==dp[i-1]:
                    dp[(i+1)%n]=dp[i-1]
                else:
                    flag=-1
            else:
                if dp[(i+1)%n]==-1 or dp[(i+1)%n]!=dp[i-1]:
                    dp[(i+1)%n]=1-dp[i-1]
                else:
                    flag=-1
    else:
        dp[-1]=0
        for i in range(0,2*n,2):
            if not ((s[i%n]=='o') ^ (dp[i%n]==0)):
                if dp[(i+1)%n]==-1 or dp[(i+1)%n]==dp[(i-1)%n]:
                    dp[(i+1)%n]=dp[(i-1)%n]
                else:
                    flag=-1
            else:
                if dp[(i+1)%n]==-1 or dp[(i+1)%n]!=dp[(i-1)%n]:
                    dp[(i+1)%n]=1-dp[(i-1)%n]
                else:
                    flag=-1
if flag==-1:
    flag=0
    if n%2==0:
        dp[0]=1
        dp[-1]=1
        for i in range(n):
            if not ((s[i]=='o') ^ (dp[i]==0)):
                if dp[(i+1)%n]==-1 or dp[(i+1)%n]==dp[i-1]:
                    dp[(i+1)%n]=dp[i-1]
                else:
                    flag=-1
            else:
                if dp[(i+1)%n]==-1 or dp[(i+1)%n]!=dp[i-1]:
                    dp[(i+1)%n]=1-dp[i-1]
                else:
                    flag=-1
    else:
        dp[-1]=0
        for i in range(0,2*n,2):
            if not ((s[i%n]=='o') ^ (dp[i%n]==0)):
                if dp[(i+1)%n]==-1 or dp[(i+1)%n]==dp[(i-1)%n]:
                    dp[(i+1)%n]=dp[(i-1)%n]
                else:
                    flag=-1
            else:
                if dp[(i+1)%n]==-1 or dp[(i+1)%n]!=dp[(i-1)%n]:
                    dp[(i+1)%n]=1-dp[(i-1)%n]
                else:
                    flag=-1
if flag==-1:
    flag=0
    if n%2==0:
        dp[0]=0
        dp[-1]=1
        for i in range(n):
            if not ((s[i]=='o') ^ (dp[i]==0)):
                if dp[(i+1)%n]==-1 or dp[(i+1)%n]==dp[i-1]:
                    dp[(i+1)%n]=dp[i-1]
                else:
                    flag=-1
            else:
                if dp[(i+1)%n]==-1 or dp[(i+1)%n]!=dp[i-1]:
                    dp[(i+1)%n]=1-dp[i-1]
                else:
                    flag=-1
    else:
        dp[-1]=0
        for i in range(0,2*n,2):
            if not ((s[i%n]=='o') ^ (dp[i%n]==0)):
                if dp[(i+1)%n]==-1 or dp[(i+1)%n]==dp[(i-1)%n]:
                    dp[(i+1)%n]=dp[(i-1)%n]
                else:
                    flag=-1
            else:
                if dp[(i+1)%n]==-1 or dp[(i+1)%n]!=dp[(i-1)%n]:
                    dp[(i+1)%n]=1-dp[(i-1)%n]
                else:
                    flag=-1
for i in range(n):
    if dp[i]==0:
        print('S',end='')
    else:
        print('W',end='')
print('\n')

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
s=input()
dp=[-1]*n
if n%2==0:
    dp[0]=0
    dp[-1]=0
    for i in range(n):
        if not ((s[i]=='o') ^ (dp[i]==0)):
            if dp[(i+1)%n]==-1 or dp[(i+1)%n]==dp[i-1]:
                dp[(i+1)%n]=dp[i-1]
            else:
                print(-1)
                sys.exit()
        else:
            if dp[(i+1)%n]==-1 or dp[(i+1)%n]!=dp[i-1]:
                dp[(i+1)%n]=1-dp[i-1]
            else:
                print(-1)
                sys.exit()
else:
    dp[-1]=0
    for i in range(0,2*n,2):
        if not ((s[i%n]=='o') ^ (dp[i%n]==0)):
            if dp[(i+1)%n]==-1 or dp[(i+1)%n]==dp[(i-1)%n]:
                dp[(i+1)%n]=dp[(i-1)%n]
            else:
                print(-1)
                sys.exit()
        else:
            if dp[(i+1)%n]==-1 or dp[(i+1)%n]!=dp[(i-1)%n]:
                dp[(i+1)%n]=1-dp[(i-1)%n]
            else:
                print(-1)
                sys.exit()
for i in range(n):
    if dp[i]==0:
        print('S',end='')
    else:
        print('W',end='')
print('\n')

Submission status: Wrong Answer

Solution code:
N = int(input())
S = [1 if s == 'o' else -1 for s in input()]

for first in [1, -1]:
    for second in [1, -1]:
        ans = [first, second]
        prev = first
        now = second
        for s in S[1:]:
            if s == 1:
                if now == 1:
                    prev, now = now, prev
                else:
                    prev, now = now, -prev
            else:
                if now == 1:
                    prev, now = now, -prev
                else:
                    prev, now = now, prev
            ans.append(now)
        if now == first:
            print(*['S' if s == 1 else 'W' for s in ans[:-1]], sep='')
            exit()

print(-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = str(input())
s += s[0]
candidate = [[1,-1],[1,1],[-1,-1],[-1,1]]
result = []
checker = 0
while checker < 4:
    result = candidate[checker]
    for i in range(1, n):
        if s[i] == 'o' and result[i] == 1:
            result.append(result[-2])
        elif s[i] == 'x' and result[i] == 1:
            result.append(-result[-2])
        elif s[i] == 'o' and result[i] == -1:
            result.append(-result[-2])
        else:
            result.append(result[-2])
    if result[0] == result[-1]:
        checker += 10
    else:
        checker += 1
if checker == 4:
    print(-1)
else:
    result = ['S' if x == 1 else 'W' for x in result[:n]]
    print(''.join(result))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = str(input())
s += s[0]
def solve(num, r):
    if r[num] == 1:
        if s[num] == 'o':
            r.append(r[num-1])
        else:
            r.append(1-r[num-1])
    else:
        if s[num] =='o':
            r.append(1-r[num-1])
        else:
            r.append(r[num-1])
    return r
c = [[1,1],[1,0],[0,1],[0,0]]
result = []
counter = 0
while counter < 4:
    result = c[counter]
    for i in range(1, len(s)-1):
        result = solve(i, result)
    if result[0] == result[-1]:
        result.pop(-1)
        counter = 10**9
    else:
        counter += 1
if counter == 10**9:
    result = ['S' if i == 1 else 'W' for i in result]
    print(''.join(map(str, result)))
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = str(input())
s += s[0]
print(s)
def solve(num, r):
    if r[num] == 1:
        if s[num] == 'o':
            r.append(r[num-1])
        else:
            r.append(1-r[num-1])
    else:
        if s[num] =='o':
            r.append(1-r[num-1])
        else:
            r.append(r[num-1])
    return r
c = [[1,1],[1,0],[0,1],[0,0]]
result = []
counter = 0
while counter < 4:
    result = c[counter]
    for i in range(1, len(s)-1):
        result = solve(i, result)
    if result[0] == result[-1]:
        result.pop(-1)
        counter = 10**9
    else:
        counter += 1
if counter == 10**9:
    result = ['S' if i == 1 else 'W' for i in result]
    print(''.join(map(str, result)))
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = str(input())
s += s[0]
print(s)
def solve(num, r):
    if r[num] == 1:
        if s[num] == 'o':
            r.append(r[num-1])
        else:
            r.append(1-r[num-1])
    else:
        if s[num] =='o':
            r.append(1-r[num-1])
        else:
            r.append(r[num-1])
    return r
c = [[1,1],[1,0],[0,1],[0,0]]
result = []
counter = 0
while counter < 4:
    result = c[counter]
    for i in range(1, len(s)-1):
        result = solve(i, result)
    if result[0] == result[-1]:
        print(result)
        result.pop(-1)
        counter = 10**9
    else:
        counter += 1
if counter == 10**9:
    result = ['S' if i == 1 else 'W' for i in result]
    print(''.join(map(str, result)))
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = str(input())
def solve(num, r):
    if r[num] == 1:
        if s[num] == 'o':
            r.append(r[num-1])
        else:
            r.append(1-r[num-1])
    else:
        if s[num] =='o':
            r.append(1-r[num-1])
        else:
            r.append(r[num-1])
    return r
c = [[1,1],[1,0],[0,1],[0,0]]
result = []
counter = 0
while counter < 4:
    result = c[counter]
    for i in range(1, len(s)):
        result = solve(i, result)
    if result[0] == result[-1]:
        result.pop(-1)
        counter = 10**9
    else:
        counter += 1
if counter == 10**9:
    result = ['S' if i == 1 else 'W' for i in result]
    print(''.join(map(str, result)))
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
flag=True
lists=["WWW","SWS","WSS","SSW","SWW","WWS","SSS","WSW"]
strings=""
if s[0]=="x":
    j=0
    while j<4:
        strings=lists[j]
        for i in range(n-1):
            if strings[-2]=="W" and strings[-1]=="W" and s[i+1]=="o":
                strings+="S"
            elif strings[-2]=="W" and strings[-1]=="W" and s[i+1]=="x": 
                strings+="W"   
            elif strings[-2]=="W" and strings[-1]=="S" and s[i+1]=="o":
                strings=""
                break
            elif strings[-2]=="W" and strings[-1]=="S" and s[i+1]=="x":
                strings+="S"   
            elif strings[-2]=="S" and strings[-1]=="S" and s[i+1]=="o":
                strings+="S"           
            elif strings[-2]=="S" and strings[-1]=="S" and s[i+1]=="x": 
                strings+="W"
            elif strings[-2]=="S" and strings[-1]=="W" and s[i+1]=="o":
                strings+="W"
            elif strings[-2]=="S" and strings[-1]=="W" and s[i+1]=="x":    
                strings+="S"
            else:
                break
        if len(strings)==n+2 and strings[0]==strings[-2] and strings[1]==strings[-1]:
            flag=False
            print(strings[1:-1])
            strings=""
            break  
        else:
            strings=""
            j+=1
            

elif s[0]=="o":
    j=4
    while j<8:
        strings=lists[j]
        for i in range(n-1):
            if strings[-2]=="W" and strings[-1]=="W" and s[i+1]=="o":
                strings+="S"
            elif strings[-2]=="W" and strings[-1]=="W" and s[i+1]=="x": 
                strings+="W" 
            elif strings[-2]=="W" and strings[-1]=="S" and s[i+1]=="o":
                strings=""
                break
            elif strings[-2]=="W" and strings[-1]=="S" and s[i+1]=="x":
                strings+="S"
            elif strings[-2]=="S" and strings[-1]=="S" and s[i+1]=="o":
                strings+="S"
            elif strings[-2]=="S" and strings[-1]=="S" and s[i+1]=="x": 
                strings+="W"  
            elif strings[-2]=="S" and strings[-1]=="W" and s[i+1]=="o":
                strings+="W"
            elif strings[-2]=="S" and strings[-1]=="W" and s[i+1]=="x":    
                strings+="S"
            else:
                break
        if  len(strings)==n+2 and strings[0]==strings[-2] and strings[1]==strings[-1]:
            flag=False
            print(strings[1:-1])
            strings=""
            break
        else:
            strings=""
            j+=1    
if flag==True:
    print("-1")

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
flag=True
lists=["WWW","SWS","WSS","SSW","SWW","WWS","SSS","WSW"]
strings=""
if s[0]=="x":
    for j in range(4):
        strings+=lists[j]
        for i in range(n-1):
            if strings[-2]=="W" and strings[-1]=="W" and s[i+1]=="o":
                strings+="S"
            elif strings[-2]=="W" and strings[-1]=="W" and s[i+1]=="x": 
                strings+="W"   
            elif strings[-2]=="W" and strings[-1]=="S" and s[i+1]=="o":
                strings=""
                break
            elif strings[-2]=="W" and strings[-1]=="S" and s[i+1]=="x":
                strings+="S"   
            elif strings[-2]=="S" and strings[-1]=="S" and s[i+1]=="o":
                strings+="S"           
            elif strings[-2]=="S" and strings[-1]=="S" and s[i+1]=="x": 
                strings+="W"
            elif strings[-2]=="S" and strings[-1]=="W" and s[i+1]=="o":
                strings+="W"
            elif strings[-2]=="S" and strings[-1]=="W" and s[i+1]=="x":    
                strings+="S"

        if len(strings)==n+2 and strings[0]==strings[-2] and strings[1]==strings[-1]:
            flag=False
            print(strings[1:-1])
            strings=""
            break        
elif s[0]=="o":
    for j in range(4,8):
        strings=lists[j]
        for i in range(n-1):
            if strings[-2]=="W" and strings[-1]=="W" and s[i+1]=="o":
                strings+="S"
            elif strings[-2]=="W" and strings[-1]=="W" and s[i+1]=="x": 
                strings+="W" 
            elif strings[-2]=="W" and strings[-1]=="S" and s[i+1]=="o":
                strings=""
                break
            elif strings[-2]=="W" and strings[-1]=="S" and s[i+1]=="x":
                strings+="S"
            elif strings[-2]=="S" and strings[-1]=="S" and s[i+1]=="o":
                strings+="S"
            elif strings[-2]=="S" and strings[-1]=="S" and s[i+1]=="x": 
                strings+="W"  
            elif strings[-2]=="S" and strings[-1]=="W" and s[i+1]=="o":
                strings+="W"
            elif strings[-2]=="S" and strings[-1]=="W" and s[i+1]=="x":    
                strings+="S"

        if  len(strings)==n+2 and strings[0]==strings[-2] and strings[1]==strings[-1]:
            flag=False
            print(strings[1:-1])
            strings=""
            break
if flag==True:
    print("-1")

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
flag=True
lists=["WWW","SWS","WSS","SSW","SWW","WWS","SSS"]
strings=""
if s[0]=="x":
    for j in range(4):
        strings+=lists[j]
        for i in range(n-1):
            if strings[-2]=="W" and strings[-1]=="W" and s[i+1]=="o":
                strings+="S"
            elif strings[-2]=="W" and strings[-1]=="W" and s[i+1]=="x": 
                strings+="W"   
            elif strings[-2]=="W" and strings[-1]=="S" and s[i+1]=="o":
                strings=""
                break
            elif strings[-2]=="W" and strings[-1]=="S" and s[i+1]=="x":
                strings+="S"   
            elif strings[-2]=="S" and strings[-1]=="S" and s[i+1]=="o":
                strings+="S"           
            elif strings[-2]=="S" and strings[-1]=="S" and s[i+1]=="x": 
                strings+="W"
            elif strings[-2]=="S" and strings[-1]=="W" and s[i+1]=="o":
                strings+="W"
            elif strings[-2]=="S" and strings[-1]=="W" and s[i+1]=="x":    
                strings+="S"

        if len(strings)==n+2 and strings[0]==strings[-2] and strings[1]==strings[-1]:
            flag=False
            print(strings[1:-1])
            strings=""
            break
            
elif s[0]=="o":
    for j in range(4,7):
        strings=lists[j]
        for i in range(n-1):
            if strings[-2]=="W" and strings[-1]=="W" and s[i+1]=="o":
                strings+="S"
            elif strings[-2]=="W" and strings[-1]=="W" and s[i+1]=="x": 
                strings+="W" 
            elif strings[-2]=="W" and strings[-1]=="S" and s[i+1]=="o":
                strings=""
                break
            elif strings[-2]=="W" and strings[-1]=="S" and s[i+1]=="x":
                strings+="S"
            elif strings[-2]=="S" and strings[-1]=="S" and s[i+1]=="o":
                strings+="S"
            elif strings[-2]=="S" and strings[-1]=="S" and s[i+1]=="x": 
                strings+="W"  
            elif strings[-2]=="S" and strings[-1]=="W" and s[i+1]=="o":
                strings+="W"
            elif strings[-2]=="S" and strings[-1]=="W" and s[i+1]=="x":    
                strings+="S"

        if  len(strings)==n+2 and strings[0]==strings[-2] and strings[1]==strings[-1]:
            flag=False
            print(strings[1:-1])
            strings=""
            break
            
            


if flag==True:
    print("-1")

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
flag=True
lists=["WWW","SWS","WSS","SSW","SWW","WWS","SSS"]
if s[0]=="x":
    for j in range(4):
        strings=lists[j]
        
        for i in range(n-1):
            if strings[-2]=="W" and strings[-1]=="W" and s[i+1]=="o":
                strings+="S"
            elif strings[-2]=="W" and strings[-1]=="W" and s[i+1]=="x": 
                strings+="W"   
            elif strings[-2]=="W" and strings[-1]=="S" and s[i+1]=="o":
                break
            elif strings[-2]=="W" and strings[-1]=="S" and s[i+1]=="x":
                strings+="S"   
            elif strings[-2]=="S" and strings[-1]=="S" and s[i+1]=="o":
                strings+="S"           
            elif strings[-2]=="S" and strings[-1]=="S" and s[i+1]=="x": 
                strings+="W"
            elif strings[-2]=="S" and strings[-1]=="W" and s[i+1]=="o":
                strings+="W"
            elif strings[-2]=="S" and strings[-1]=="W" and s[i+1]=="x":    
                strings+="S"

        if len(strings)==n+2 and strings[0]==strings[-2] and strings[1]==strings[-1]:
            flag=False
            print(strings[1:-1])
            break
elif s[0]=="o":
    for j in range(4,7):
        strings=lists[j]
        for i in range(n-1):
            if strings[-2]=="W" and strings[-1]=="W" and s[i+1]=="o":
                strings+="S"
            elif strings[-2]=="W" and strings[-1]=="W" and s[i+1]=="x": 
                strings+="W" 
            elif strings[-2]=="W" and strings[-1]=="S" and s[i+1]=="o":
                break
            elif strings[-2]=="W" and strings[-1]=="S" and s[i+1]=="x":
                strings+="S"
            elif strings[-2]=="S" and strings[-1]=="S" and s[i+1]=="o":
                strings+="S"
            elif strings[-2]=="S" and strings[-1]=="S" and s[i+1]=="x": 
                strings+="W"
                
            elif strings[-2]=="S" and strings[-1]=="W" and s[i+1]=="o":
                strings+="W"
            elif strings[-2]=="S" and strings[-1]=="W" and s[i+1]=="x":    
                strings+="S"

        if  len(strings)==n+2 and strings[0]==strings[-2] and strings[1]==strings[-1]:
            flag=False
            print(strings[1:-1])
            break

if flag:
    print("-1")

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
flag=True
lists=["WWW","SWS","WSS","SSW","SWW","WWS","SSS"]
if s[0]=="x":
    for j in range(4):
        strings=lists[j]
        for i in range(n-1):
            if strings[-2]=="W" and strings[-1]=="W" and s[i+1]=="o":
                strings+="S"
            elif strings[-2]=="W" and strings[-1]=="W" and s[i+1]=="x": 
                strings+="W"
                
            elif strings[-2]=="W" and strings[-1]=="S" and s[i+1]=="o":
                break
            elif strings[-2]=="W" and strings[-1]=="S" and s[i+1]=="x":
                strings+="S"
                
            elif strings[-2]=="S" and strings[-1]=="S" and s[i+1]=="o":
                strings+="S"
            elif strings[-2]=="S" and strings[-1]=="S" and s[i+1]=="x": 
                strings+="W"
                
            elif strings[-2]=="S" and strings[-1]=="W" and s[i+1]=="o":
                strings+="W"
            elif strings[-2]=="S" and strings[-1]=="W" and s[i+1]=="x":    
                strings+="S"

        if strings[0]==strings[-2] and strings[1]==strings[-1]:
            flag=False
            print(strings[1:-1])
            break
        else:
            continue
elif s[0]=="o":
    for j in range(4,7):
        strings=lists[j]
        for i in range(n-1):
            if strings[-2]=="W" and strings[-1]=="W" and s[i+1]=="o":
                strings+="S"
            elif strings[-2]=="W" and strings[-1]=="W" and s[i+1]=="x": 
                strings+="W" 
            elif strings[-2]=="W" and strings[-1]=="S" and s[i+1]=="o":
                break
            elif strings[-2]=="W" and strings[-1]=="S" and s[i+1]=="x":
                strings+="S"
            elif strings[-2]=="S" and strings[-1]=="S" and s[i+1]=="o":
                strings+="S"
            elif strings[-2]=="S" and strings[-1]=="S" and s[i+1]=="x": 
                strings+="W"
                
            elif strings[-2]=="S" and strings[-1]=="W" and s[i+1]=="o":
                strings+="W"
            elif strings[-2]=="S" and strings[-1]=="W" and s[i+1]=="x":    
                strings+="S"

        if  len(strings)==n+2 and strings[0]==strings[-2] and strings[1]==strings[-1]:
            flag=False
            print(strings[1:-1])
            break
        else:
            continue
        
if flag:
    print("-1")