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()
# Sheep:0, Wolf:1
for s in range(2):
    for t in range(2):
        T = [None] * N
        T[0] = s
        T[1] = t
        for j in range(1, N-1):
            if (T[j] == 0) == (S[j] == 'o'):
                T[j + 1] = T[j-1]
            else:
                T[j + 1] = 1 - T[j-1]

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
def main():
    N = int(input())
    S = input()
    # Sheep:0, Wolf:1
    for s in range(2):
        for t in range(2):
            T = [None] * N
            T[0] = s
            T[1] = t
            for j in range(1, N-1):
                if (T[j] == 0) == (S[j] == 'o'):
                    T[j + 1] = T[j-1]
                else:
                    T[j + 1] = 1 - T[j-1]
                #print(S[j], T)

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


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right
from itertools import accumulate

sys.setrecursionlimit(10**6)
INF = 10**12
m = 10**9 + 7


def main():
    N = int(input())
    S = input()
    # Sheep:0, Wolf:1
    for s in range(2):
        for t in range(2):
            T = [None] * N
            T[0] = s
            T[1] = t
            T[-1] = int(s ^ t)
            # print(T)
            for j in range(1, N-1):
                if (S[j] == 'o') == (T[j] == 0):
                    T[j + 1] = T[j-1]
                else:
                    T[j + 1] = 1 - T[j-1]
                # print(S[j], T)
            if (T[N - 1] == 0) == (S[N - 1] == 'o'):
                if T[N-2] == T[0]:
                    ans = [None] * N
                    for i in range(N):
                        ans[i] = ['S', 'W'][T[i]]
                    print(''.join(ans))
                    exit()
            else:
                if T[N-2] != T[0]:
                    ans = [None] * N
                    for i in range(N):
                        ans[i] = ['S', 'W'][T[i]]
                    print(''.join(ans))
                    exit()
    print(-1)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right
from itertools import accumulate

sys.setrecursionlimit(10**6)
INF = 10**12
m = 10**9 + 7


def main():
    N = int(input())
    S = input()
    # Sheep:0, Wolf:1
    for s in range(2):
        for t in range(2):
            T = [None] * N
            T[0] = s
            T[1] = t
            T[-1] = int(s ^ t)
            # print(T)
            for j in range(1, N-1):
                if (S[j] == 'o') == (T[j] == 0):
                    T[j + 1] = T[j-1]
                else:
                    T[j + 1] = 1 - T[j-1]
                # print(S[j], T)
            if T[N - 1] ^ (S[N - 1] == 'o') and T[0] == T[N - 2]:
                ans = [None] * N
                for i in range(N):
                    ans[i] = ['S', 'W'][T[i]]
                print(''.join(ans))
                exit()
            elif T[N-1] ^ (S[N-1] == 'x') and T[0] != T[N-2]:
                ans = [None] * N
                for i in range(N):
                    ans[i] = ['S', 'W'][T[i]]
                print(''.join(ans))
                exit()
    print(-1)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right
from itertools import accumulate

sys.setrecursionlimit(10**6)
INF = 10**12
m = 10**9 + 7


def main():
    N = int(input())
    S = input()
    # Sheep:1, Wolf:0
    for s in range(2):
        for t in range(2):
            T = [None] * N
            T[0] = s
            T[1] = t
            T[-1] = int((s ^ t) == 0)
            # print(T)
            for j in range(1, N-1):
                if T[j] ^ (S[j] == 'o'):
                    T[j + 1] = T[j-1]
                else:
                    T[j + 1] = 1 - T[j-1]
            # print(T)
            if T[N - 1] ^ (S[N - 1] == 'o') and T[0] == T[N - 2]:
                ans = [None] * N
                for i in range(N):
                    ans[i] = ['S', 'W'][T[i]]
                print(''.join(ans))
                exit()
            elif T[N-1] ^ (S[N-1] == 'x') and T[0] != T[N-2]:
                ans = [None] * N
                for i in range(N):
                    ans[i] = ['S', 'W'][T[i]]
                print(''.join(ans))
                exit()
    print(-1)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right
from itertools import accumulate

sys.setrecursionlimit(10**6)
INF = 10**12
m = 10**9 + 7


def main():
    N = int(input())
    S = input()
    # Sheep:1, Wolf:0
    for s in range(2):
        for t in range(2):
            T = [None] * N
            T[0] = s
            T[1] = t
            if s ^ (S[0] == 'o'):
                T[-1] = t
            else:
                T[-1] = 1-t
            # print(T)
            for j in range(1, N-1):
                if T[j] ^ (S[j] == 'o'):
                    T[j + 1] = T[j-1]
                else:
                    T[j + 1] = 1 - T[j-1]
            # print(T)
            if T[N - 1] ^ (S[N - 1] == 'o') and T[0] == T[N - 2]:
                ans = [None] * N
                for i in range(N):
                    ans[i] = ['S', 'W'][T[i]]
                print(''.join(ans))
                exit()
            elif T[N-1] ^ (S[N-1] == 'x') and T[0] != T[N-2]:
                ans = [None] * N
                for i in range(N):
                    ans[i] = ['S', 'W'][T[i]]
                print(''.join(ans))
                exit()
    print(-1)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right
from itertools import accumulate

sys.setrecursionlimit(10**6)
INF = 10**12
m = 10**9 + 7


def main():
    N = int(input())
    S = input()
    # Sheep:1, Wolf:0
    for s in range(2):
        for t in range(2):
            T = [None] * N
            T[0] = s
            T[1] = t
            if s ^ (S[0] == 'o'):
                T[-1] = t
            else:
                T[-1] = 1-t
            # print(T)
            for j in range(1, N-1):
                if T[j] ^ (S[j] == 'o'):
                    T[j + 1] = T[j-1]
                else:
                    T[j + 1] = 1 - T[j-1]
            # print(T)
            if T[N - 1] ^ (S[N - 1] == 'o') and T[0] == T[N - 2]:
                ans = [None] * N
                for i in range(N):
                    ans[i] = ['W', 'S'][T[i]]
                print(''.join(ans))
                exit()
            elif T[N-1] ^ (S[N-1] == 'x') and T[0] != T[N-2]:
                ans = [None] * N
                for i in range(N):
                    ans[i] = ['W', 'S'][T[i]]
                print(''.join(ans))
                exit()
    print(-1)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

# 1番目を決めると全て決まる→これは間違った性質
# 正しくはある連続した2匹の動物の種類がわかれば、その隣にいる動物の種類もわかるということ

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

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

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

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

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

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

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

    L.append(ans)

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

Submission status: Wrong Answer

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

# 1番目を決めると全て決まる→これは間違った性質
# 正しくはある連続した2匹の動物の種類がわかれば、その隣にいる動物の種類もわかるということ

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

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

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

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

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

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

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

    L.append(ans)

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())
s.append(s[0])
x=[["S","S"],["S","W"],["W","S"],["W","W"]]

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

Submission status: Wrong Answer

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

                        if ans[t]=="S":
                            flag=+1
                    else:
                        if ans[t]=="W":
                            flag=+1
                else:
                    if ans[j-1]=="S":
                        if ans[t]=="W":
                            flag=+1
                    else:
                        if ans[t]=="S":
                            flag=+1
            else:
                if S[j]=="o":
                    if ans[j-1]=="S":
                        if ans[t]=="W":
                            flag=+1
                    else:
                        if ans[t]=="S":
                            flag=+1
                else:
                    if ans[j-1]=="S":
                        if ans[t]=="S":
                            flag=+1
                    else:
                        if ans[t]=="W":
                            flag=+1
                            
        else:
            if ans[j]=="S":
                if S[j]=="o":
                    if ans[j-1]=="S":
                        ans.append("S")
                    else:
                        ans.append("W")
                else:
                    if ans[j-1]=="S":
                        ans.append("W")
                    else:
                        ans.append("S")
            else:
                if S[j]=="o":
                    if ans[j-1]=="S":
                        ans.append("W")
                    else:
                        ans.append("S")
                else:
                    if ans[j-1]=="S":
                        ans.append("S")
                    else:
                        ans.append("W")

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

Submission status: Wrong Answer

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

N = INT()
s = input()

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

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

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

else:
	print(-1)

Submission status: Wrong Answer

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

N = INT()
s = input()

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

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

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

else:
	print(-1)

Submission status: Wrong Answer

Solution code:
from itertools import product


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

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

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

Submission status: Wrong Answer

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

for i in ['SS','SW','WS','WW']:
  for j in range(1,n-1):
    if i[j]=='S':
      if s[j]=='o':
        if i[j-1]=='S':
          i+='S'
        else:
          i+='W'
      else:
        if i[j-1]=='S':
          i+='W'
        else:
          i+='S'
    
    else:
      if s[j]=='o':
        if i[j-1]=='S':
          i+='W'
        else:
          i+='S'
      else:
        if i[j-1]=='S':
          i+='S'
        else:
          i+='W'
  

  if i[-1]=='S':
    if s[-1]=='o':
        if i[0]==i[-2]:
            print(i)
            exit()

    else:
        if i[0]!=i[-2]:
            print(i)
            exit()

  else:
    if s[-1]=='o':
        if i[0]!=i[-2]:
            print(i)
            exit()

    else:
        if i[0]==i[-2]:
            print(i)
            exit()


print(-1)

Submission status: Wrong Answer

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

for i in ['SS','SW','WS','WW']:
  for j in range(1,n-1):
    if i[-1]=='S':
      if s[j]=='o':
        if i[-2]=='S':
          i+='S'
        else:
          i+='W'
      else:
        if i[-2]=='S':
          i+='W'
        else:
          i+='S'
    
    else:
      if s[j]=='o':
        if i[-2]=='S':
          i+='W'
        else:
          i+='S'
      else:
        if i[-2]=='S':
          i+='S'
        else:
          i+='W'
  

  if i[-1]=='S':
    if s[-1]=='o':
        if i[0]==i[-2]:
            print(i)
            exit()

    else:
        if i[0]!=i[-2]:
            print(i)
            exit()

  else:
    if s[-1]=='o':
        if i[0]!=i[-2]:
            print(i)
            exit()

    else:
        if i[0]==i[-2]:
            print(i)
            exit()


print(-1)