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()

ans = [''] * N

def other(s):
  if s == 'S':
    return 'W'
  else:
    return 'S'

def calc(S):
  global ans
  for i, s in enumerate(S):
    if s == 'o':
      if ans[i] == 'S':
        ans[(i+1)%N] = ans[i-1]
      else:
        ans[(i+1)%N] = other(ans[i-1])
    else:
      if ans[i] == 'S':
        ans[(i+1)%N] = other(ans[i-1])
      else:
        ans[(i+1)%N] = ans[i-1]

ans[-1] = 'S'
ans[0] = 'S'
calc(S)
if (ans[0], ans[1]) == ('S', 'S'):
  print(''.join(ans))
  quit()

ans[-1] = 'S'
ans[0] = 'W'
calc(S)
if (ans[0], ans[-1]) == ('W', 'S'):
  print(''.join(ans))
  quit()

ans[-1] = 'W'
ans[0] = 'S'
calc(S)
if (ans[0], ans[-1]) == ('S', 'W'):
  print(''.join(ans))
  quit()

ans[-1] = 'W'
ans[0] = 'W'
calc(S)
if (ans[0], ans[-1]) == ('W', 'W'):
  print(''.join(ans))
  quit()

print(-1)

Submission status: Wrong Answer

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

ans = [''] * N

def other(s):
  if s == 'S':
    return 'W'
  else:
    return 'S'

def calc(S):
  global ans
  for i, s in enumerate(S[1:], 1):
    if s == 'o':
      if ans[i] == 'S':
        ans[(i+1)%N] = ans[i-1]
      else:
        ans[(i+1)%N] = other(ans[i-1])
    else:
      if ans[i] == 'S':
        ans[(i+1)%N] = other(ans[i-1])
      else:
        ans[(i+1)%N] = ans[i-1]

if S[0] == 'o':
  ans[0] = 'S'
  ans[1] = 'S'
  calc(S)
  if (ans[0], ans[-1]) == ('S', 'S'):
    print(''.join(ans))
    quit()
  ans[0] = 'W'
  calc(S)
  if (ans[0], ans[-1]) == ('W', 'W'):
    print(''.join(ans))
    quit()
  ans[0] = 'S'
  ans[1] = 'W'
  calc(S)
  if (ans[0], ans[-1]) == ('S', 'W'):
    print(''.join(ans))
    quit()
  ans[0] = 'W'
  calc(S)
  if (ans[0], ans[-1]) == ('W', 'S'):
    print(''.join(ans))
    quit()
else:
  ans[0] = 'S'
  ans[1] = 'S'
  calc(S)
  if (ans[0], ans[-1]) == ('S', 'W'):
    print(''.join(ans))
    quit()
  ans[0] = 'W'
  calc(S)
  if (ans[0], ans[-1]) == ('W', 'S'):
    print(''.join(ans))
    quit()
  ans[0] = 'S'
  ans[1] = 'W'
  calc(S)
  if (ans[0], ans[-1]) == ('S', 'S'):
    print(''.join(ans))
    quit()
  ans[0] = 'W'
  if (ans[0], ans[-1]) == ('W', 'W'):
    print(''.join(ans))
    quit()

print(-1)

Submission status: Wrong Answer

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

for a in ["SS", "SW", "WS", "WW"]:
    x = list(a)
    for i in range(N - 2):
        if S[i + 1] == "o":
            if x[i + 1] == "S":
                x.append(x[i])
            else:
                # x[i + 1] == "W"
                if x[i] == "S":
                    x.append("W")
                else:
                    x.append("S")
        else:
            # S[i + 1] == "x"
            if x[i + 1] == "S":
                if x[i] == "S":
                    x.append("W")
                else:
                    x.append("S")
            else:
                x.append(x[i])

    # Check
    if x[-1] == "S":
        if (S[-1] == "o" and x[-2] == x[0]) \
               or (S[-1] == "x" and x[-2] != x[0]):
            print("".join(x))
            break
    else:
        if (S[-1] == "o" and x[-2] != x[0]) \
               or (S[-1] == "x" and x[-2] == x[0]):
            print("".join(x))
            break
else:
    print(-1)

Submission status: Wrong Answer

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

ans = ""
for x in ["SS", "SW", "WS", "WW"]:
    for i in range(N - 2):
        if S[i + 1] == "o":
            if x[i + 1] == "S":
                x += x[i]
            else:
                # x[i + 1] == "W"
                if x[i] == "S":
                    x += "W"
                else:
                    x += "S"
        else:
            # S[i + 1] == "x"
            if x[i + 1] == "S":
                if x[i] == "S":
                    x += "W"
                else:
                    x += "S"
            else:
                x += x[i]

    # Check
    if x[-1] == "S":
        if (S[-1] == "o" and x[-2] == x[0]) \
               or (S[-1] == "x" and x[-2] != x[0]):
            print(x)
            break
    else:
        if (S[-1] == "o" and x[-2] != x[0]) \
               or (S[-1] == "x" and x[-2] == x[0]):
            print(x)
            break
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
N = int(input())
s = str(input())
A = ''

def majikayo():
    k = 0
    if A[0] == 'S' and s[0] == 'o':
        if A[-1] == 'S' and s[-1] == 'o':
            if A[1] == 'S' and A[-2] == 'S':
                k = 1
        elif A[-1] == 'S' and s[-1] == 'x':
            if A[1] == 'S' and A[-2] == 'W':
                k = 1
        elif A[-1] == 'W' and s[-1] == 'o':
            if A[1] == 'S' and A[-2] == 'W':
                k = 1
        elif A[-1] == 'W' and s[-1] == 'x':
            if A[1] == 'S' and A[-2] == 'S':
                k = 1
    elif A[0] == 'S' and s[0] == 'x':
        if A[-1] == 'S' and s[-1] == 'o':
            if A[1] == 'W' and A[-2] == 'S':
                k = 1
        elif A[-1] == 'S' and s[-1] == 'x':
            if A[1] == 'W' and A[-2] == 'W':
                k = 1
        elif A[-1] == 'W' and s[-1] == 'o':
            if A[1] == 'W' and A[-2] == 'W':
                k = 1
        elif A[-1] == 'W' and s[-1] == 'x':
            if A[1] == 'W' and A[-2] == 'S':
                k = 1
    elif A[0] == 'W' and s[0] == 'o':
        if A[-1] == 'S' and s[-1] == 'o':
            if A[1] == 'W' and A[-2] == 'W':
                k = 1
        elif A[-1] == 'S' and s[-1] == 'x':
            if A[1] == 'W' and A[-2] == 'S':
                k = 1
        elif A[-1] == 'W' and s[-1] == 'o':
            if A[1] == 'W' and A[-2] == 'S':
                k = 1
        elif A[-1] == 'W' and s[-1] == 'x':
            if A[1] == 'W' and A[-2] == 'W':
                k = 1
    elif A[0] == 'W' and s[0] == 'x':
        if A[-1] == 'S' and s[-1] == 'o':
            if A[1] == 'S' and A[-2] == 'S':
                k = 1
        elif A[-1] == 'S' and s[-1] == 'x':
            if A[1] == 'S' and A[-2] == 'W':
                k = 1
        elif A[-1] == 'W' and s[-1] == 'o':
            if A[1] == 'S' and A[-2] == 'W':
                k = 1
        elif A[-1] == 'W' and s[-1] == 'x':
            if A[1] == 'S' and A[-2] == 'S':
                k = 1
    if k == 1:
        return 1

A = 'SS'
for i in range(1,N-1):
    if s[i] == 'o' and A[i] == 'S':
        if A[i-1] == 'S':
            A += 'S'
        else:
            A += 'W'
    elif s[i] == 'o' and A[i] == 'W':
        if A[i-1] == 'S':
            A += 'W'
        else:
            A += 'S'
    elif s[i] == 'x' and A[i] == 'S':
        if A[i-1] == 'S':
            A += 'W'
        else:
            A += 'S'
    elif s[i] == 'x' and A[i] == 'W':
        if A[i-1] == 'S':
            A += 'S'
        else:
            A += 'W'
if majikayo() == 1:
    print(A)
else:
    A = 'SW'
    for i in range(1,N-1):
        if s[i] == 'o' and A[i] == 'S':
            if A[i-1] == 'S':
                A += 'S'
            else:
                A += 'W'
        elif s[i] == 'o' and A[i] == 'W':
            if A[i-1] == 'S':
                A += 'W'
            else:
                A += 'S'
        elif s[i] == 'x' and A[i] == 'S':
            if A[i-1] == 'S':
                A += 'W'
            else:
                A += 'S'
        elif s[i] == 'x' and A[i] == 'W':
            if A[i-1] == 'S':
                A += 'S'
            else:
                A += 'W'
    if majikayo() == 1:
        print(A)
    else:
        k = 0
        A = 'WS'
        for i in range(1,N-1):
            if s[i] == 'o' and A[i] == 'S':
                if A[i-1] == 'S':
                    A += 'S'
                else:
                    A += 'W'
            elif s[i] == 'o' and A[i] == 'W':
                if A[i-1] == 'S':
                    A += 'W'
                else:
                    A += 'S'
            elif s[i] == 'x' and A[i] == 'S':
                if A[i-1] == 'S':
                    A += 'W'
                else:
                    A += 'S'
            elif s[i] == 'x' and A[i] == 'W':
                if A[i-1] == 'S':
                    A += 'S'
                else:
                    A += 'W'
        majikayo()
        if majikayo() == 1:
            print(A)
        else:
            k = 0
            A = 'WW'
            for i in range(1,N-1):
                if s[i] == 'o' and A[i] == 'S':
                    if A[i-1] == 'S':
                        A += 'S'
                    else:
                        A += 'W'
                elif s[i] == 'o' and A[i] == 'W':
                    if A[i-1] == 'S':
                        A += 'W'
                    else:
                        A += 'S'
                elif s[i] == 'x' and A[i] == 'S':
                    if A[i-1] == 'S':
                        A += 'W'
                    else:
                        A += 'S'
                elif s[i] == 'x' and A[i] == 'W':
                    if A[i-1] == 'S':
                        A += 'S'
                    else:
                        A += 'W'
            if majikayo() == 1:
                print(A)
            else:
                print(-1)

Submission status: Wrong Answer

Solution code:
N = int(input())
s = input()
first = [['S','S'],['S','W'],['W','S'],['W','W']]
flag = 0

def hypothesis(N,s,ans1,ans2):
    ans = [ans1,ans2]
    for i in range(1,N-1):
        if ans[i] == 'S':
            if s[i] == 'o':
                if ans[i-1] == 'S':
                    ans.append('S')
                else:
                    ans.append('W')
            elif s[i] == 'x':
                if ans[i-1] == 'S':
                    ans.append('W')
                else:
                    ans.append('S')
        if ans[i] == 'W':
            if s[i] == 'o':
                if ans[i-1] == 'S':
                    ans.append('W')
                else:
                    ans.append('S')
            elif s[i] == 'x':
                if ans[i-1] == 'S':
                    ans.append('S')
                else:
                    ans.append('W')
    return ans

def conf(ans_sub):
    flag2 = 0
    if ans_sub[0] == 'S' and s[0] == 'o':
        if ans_sub[1] == ans_sub[N-1]:
            flag2 = 1
    elif ans_sub[0] == 'S' and s[0] == 'x':
        if ans_sub[1] != ans_sub[N-1]:
            flag2 = 1
    elif ans_sub[0] == 'W' and s[0] == 'o':
        if ans_sub[1] != ans_sub[N-1]:
            flag2 = 1
    elif ans_sub[0] == 'W' and s[0] == 'x':
        if ans_sub[1] == ans_sub[N-1]:
            flag2 = 1
    if flag2 == 1:
        return 1
    else:
        return 0

for a in first:
    ans_sub = hypothesis(N,s,a[0],a[1])
    flag = conf(ans_sub)
    if flag == 1:
        print(ans_sub)
        break
    if flag == 0 and a == first[3]:
        print(-1)

Submission status: Wrong Answer

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

print("WWSSSS")

Submission status: Wrong Answer

Solution code:
n=int(input())
s=[str(x) for x in input()]

def change(n):
    if n=='S':
        return 'W'
    else:
        return 'S'
planA=['S','S']
for i in range(2,n):
    if planA[i-1]=='S':
        if s[i-1]=='o':
            planA.append(planA[i-2])
        else:
            planA.append(change(planA[i-2]))
    else:
        if s[i-1]=='o':
            planA.append(change(planA[i-2]))
        else:
            planA.append(planA[i-2])

error=0
if s[0]=='o':
    if planA[n-1]!='S':
        error += 1
    else:
        if s[n-1]=='o':
            if planA[n-2]!=planA[0]:
                error += 1
        else:
            if planA[n-2]==planA[0]:
                error += 1
else:
    if planA[n-1]!='W':
        error += 1
    else:
        if s[n-1]=='o':
            if planA[n-2]==planA[0]:
                error += 1
        else:
            if planA[n-2]!=planA[0]:
                error += 1
if error==1:
    planB=['S','W']
    for i in range(2,n):
        if planB[i-1]=='S':
            if s[i-1]=='o':
                planB.append(planB[i-2])
            else:
                planB.append(change(planB[i-2]))
        else:
            if s[i-1]=='o':
                planB.append(change(planB[i-2]))
            else:
                planB.append(planB[i-2])
                
    if s[0]=='o':
        if planB[n-1]!='S':
            error += 1
        else:
            if s[n-1]=='o':
                if planB[n-2]!=planB[0]:
                    error += 1
            else:
                if planB[n-2]==planB[0]:
                    error += 1
    else:
        if planB[n-1]!='W':
            error += 1
        else:
            if s[n-1]=='o':
                if planB[n-2]==planB[0]:
                    error += 1
            else:
                if planB[n-2]!=planB[0]:
                    error += 1
else:
    print(''.join(planA))

if error==1:
    print(''.join(planB))
    
    
    
    
    
elif error==2:
    def reverse(n):
        if n=='o':
            return 'x'
        else:
            return 'o'
    s=[reverse(i) for i in s]
    planA=['S','S']
    for i in range(2,n):
        if planA[i-1]=='S':
            if s[i-1]=='o':
                planA.append(planA[i-2])
            else:
                planA.append(change(planA[i-2]))
        else:
            if s[i-1]=='o':
                planA.append(change(planA[i-2]))
            else:
                planA.append(planA[i-2])

    error=0
    if s[0]=='o':
        if planA[n-1]!='S':
            error += 1
        else:
            if s[n-1]=='o':
                if planA[n-2]!=planA[0]:
                    error += 1
            else:
                if planA[n-2]==planA[0]:
                    error += 1
    else:
        if planA[n-1]!='W':
            error += 1
        else:
            if s[n-1]=='o':
                if planA[n-2]==planA[0]:
                    error += 1
            else:
                if planA[n-2]!=planA[0]:
                    error += 1
    if error==1:
        planB=['S','W']
        for i in range(2,n):
            if planB[i-1]=='S':
                if s[i-1]=='o':
                    planB.append(planB[i-2])
                else:
                    planB.append(change(planB[i-2]))
            else:
                if s[i-1]=='o':
                    planB.append(change(planB[i-2]))
                else:
                    planB.append(planB[i-2])
                
        if s[0]=='o':
            if planB[n-1]!='S':
                error += 1
            else:
                if s[n-1]=='o':
                    if planB[n-2]!=planB[0]:
                        error += 1
                else:
                    if planB[n-2]==planB[0]:
                        error += 1
        else:
            if planB[n-1]!='W':
                error += 1
            else:
                if s[n-1]=='o':
                    if planB[n-2]==planB[0]:
                        error += 1
                else:
                    if planB[n-2]!=planB[0]:
                        error += 1
    else:
        planA=[change(i) for i in planA]
        print(''.join(planA))
    if error==1:
        planB=[change(i) for i in planB]
    else:
        print(-1)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=[str(x) for x in input()]

def change(n):
    if n=='S':
        return 'W'
    else:
        return 'S'
planA=['S','S']
for i in range(2,n):
    if planA[i-1]=='S':
        if s[i-1]=='o':
            planA.append(planA[i-2])
        else:
            planA.append(change(planA[i-2]))
    else:
        if s[i-1]=='o':
            planA.append(change(planA[i-2]))
        else:
            planA.append(planA[i-2])

error=0
if s[0]=='o':
    if planA[n-1]!='S':
        error += 1
    else:
        if s[n-1]=='o':
            if planA[n-2]!=planA[0]:
                error += 1
        else:
            if planA[n-2]==planA[0]:
                error += 1
else:
    if planA[n-1]!='W':
        error += 1
    else:
        if s[n-1]=='o':
            if planA[n-2]==planA[0]:
                error += 1
        else:
            if planA[n-2]!=planA[0]:
                error += 1
if error==1:
    planB=['S','W']
    for i in range(2,n):
        if planB[i-1]=='S':
            if s[i-1]=='o':
                planB.append(planB[i-2])
            else:
                planB.append(change(planB[i-2]))
        else:
            if s[i-1]=='o':
                planB.append(change(planB[i-2]))
            else:
                planB.append(planB[i-2])
                
    if s[0]=='o':
        if planB[n-1]!='S':
            error += 1
        else:
            if s[n-1]=='o':
                if planB[n-2]!=planB[0]:
                    error += 1
            else:
                if planB[n-2]==planB[0]:
                    error += 1
    else:
        if planB[n-1]!='W':
            error += 1
        else:
            if s[n-1]=='o':
                if planB[n-2]==planB[0]:
                    error += 1
            else:
                if planB[n-2]!=planB[0]:
                    error += 1
else:
    print(''.join(planA))

if error==1:
    print(''.join(planB))
elif error==2:
    print(-1)

Submission status: Wrong Answer

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

def search(t0, t1):
    t = [t0, t1]
    for i in range(1, n):
        if t[i] == 'S':
            if s[i] == 'o':
                t.append(t[i-1])
            else:
                if t[i-1] == 'S':
                    t.append('W')
                else:
                    t.append('S')
        else:
            if s[i] == 'o':
                if t[i-1] == 'S':
                    t.append('W')
                else:
                    t.append('S')
            else:
                t.append(t[i-1])

    if t[0] == t[-1]:
        return t[:-1]
    else:
        return None

flg = True
for i, j in [('W', 'W'), ('S', 'S'), ('S', 'W'), ('W', 'S')]:
    if not search(i, j) is None:
        ans = search(i, j)
        print(*ans, sep='')
        flg = False
        break

if flg:
    print(-1)

Submission status: Wrong Answer

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

def search(t0, t1):
    t = [t0, t1]
    for i in range(1, n):
        if t[i] == 'S':
            if s[i] == 'o':
                t.append(t[i-1])
            else:
                if t[i-1] == 'S':
                    t.append('W')
                else:
                    t.append('S')
        else:
            if s[i] == 'o':
                if t[i-1] == 'S':
                    t.append('W')
                else:
                    t.append('S')
            else:
                t.append(t[i-1])

    if t[0] == t[-1]:
        return t[:-1]
    else:
        return None

flg = True
for i, j in [('S', 'S'), ('S', 'W'), ('W', 'S'), ('W', 'W')]:
    if search(i, j) is not None:
        ans = search(i, j)
        print(*ans, sep='')
        flg = False
        break

if flg:
    print(-1)

Submission status: Wrong Answer

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

def search(t0, t1):
    t = [t0, t1]
    for i in range(1, n):
        if t[i] == 'S':
            if s[i] == 'o':
                t.append(t[i-1])
            else:
                if t[i-1] == 'S':
                    t.append('W')
                else:
                    t.append('S')
        else:
            if s[i] == 'o':
                if t[i-1] == 'S':
                    t.append('W')
                else:
                    t.append('S')
            else:
                t.append(t[i-1])

    if t[0] == t[-1]:
        return t[:-1]
    else:
        return None

flg = True
for i, j in [('S', 'W'), ('S', 'S'), ('W', 'S'), ('W', 'W')]:
    if search(i, j) is not None:
        ans = search(i, j)
        print(*ans, sep='')
        flg = False
        break

if flg:
    print(-1)

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
s = input()
List = [['S','S'], ['S','W'], ['W','S'], ['W','W']]
for i in range(4):
    ans = List[i]
    for i in range(1,N):
        if i != N-1:
            if (ans[i-1] == ans[i] and s[i] == 'o') or (ans[i-1] != ans[i] and s[i] == 'x'):
                ans.append('S')
            else:
                ans.append('W')
        else:
            if (((ans[N-1] == 'S' and s[N-1] == 'o') or (ans[N-1] == 'W' and s[N-1] == 'x')) and (ans[N-2] == ans[0])) or (((ans[N-1] == 'S' and s[N-1] == 'x') or (ans[N-1] == 'W' and s[N-1] == 'o')) and (ans[N-2] != ans[0])):
                print(''.join(ans))
                sys.exit()
print(-1)

Submission status: Wrong Answer

Solution code:
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

N = int(input())
S = input()

ans = ['S'] * N


def ok(ST):
    ret = ['S'] * N
    ret[-1] = ST[-1]
    ret[0] = ST[0]

    for i in range(0, N - 1):
        if ret[i] == 'S':
            if S[i] == 'o':
                ret[i + 1] = ret[i - 1]
            else:
                ret[i + 1] = 'W' if ret[i - 1] == 'S' else 'S'
        else:
            if S[i] == 'o':
                ret[i + 1] = 'W' if ret[i - 1] == 'S' else 'S'
            else:
                ret[i + 1] = ret[i - 1]

    if ret[-1] == 'W':
        return False if S[-1] == 'o' and ret[-2] == ret[0] or S[-1] == 'x' and ret[-2] != ret[0] else "".join(ret)
    else:
        return False if S[-1] == 'o' and ret[-2] != ret[0] or S[-1] == 'x' and ret[-2] == ret[0] else "".join(ret)


def solve():
    for s in ["SS", "SW", "WS", "WW"]:
        r = ok(s)
        if r:
            print(r)
            return

    print(-1)


solve()

Submission status: Wrong Answer

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

ans = ['S']*(n)

ani0 = ['S','S','W','W']
ani1 = ['S','W','S','W']
anim1 = ['S','W','W','S']

for i in range(4):
    ans[0] = ani0[i]
    if s[0] == 'o':
        ans[-1] = anim1[i]
        ans[1] = ani1[i]
    else:
        ans[-1] = anim1[3-i]
        ans[1] = ani1[3-i]
        
    #print(ans)
        
    for j in range(1,n):
        if j >= n-2:
            if s[j] == 'o':
                if ans[j] == 'S':
                    if ans[j-1] == 'S':
                        if ans[(j+1)%n] == 'S':
                            if j == n-1:
                                print(*ans,sep='')
                                exit()
                    else:
                        if ans[(j+1)%n] == 'W':
                            if j == n-1:
                                print(*ans,sep='')
                                exit()
                else:
                    if ans[j-1] == 'S':
                        if ans[(j+1)%n] == 'W':
                            if j == n-1:
                                print(*ans,sep='')
                                exit()
                    else:
                        if ans[(j+1)%n] == 'S':
                            if j == n-1:
                                print(*ans,sep='')
                                exit()
            else:
                #print(ans)
                if ans[j] == 'S':
                    if ans[j-1] == 'S':
                        if ans[(j+1)%n] == 'W':
                            if j == n-1:
                                print(*ans,sep='')
                                exit()
                    else:
                        if ans[(j+1)%n] == 'S':
                            if j == n-1:
                                print(*ans,sep='')
                                exit()
                else:
                    if ans[j-1] == 'S':
                        if ans[(j+1)%n] == 'S':
                            if j == n-1:
                                print(*ans,sep='')
                                exit()
                    else:
                        if ans[(j+1)%n] == 'W':
                            if j == n-1:
                                print(*ans,sep='')
                                exit()
        if j == n-1:
            break
        
        if s[j] == 'o':
            if ans[j] == 'S':
                if ans[j-1] == 'S':
                    ans[j+1] = 'S'
                else:
                    ans[j+1] = 'W'
            else:
                if ans[j-1] == 'S':
                    ans[j+1] = 'W'
                else:
                    ans[j+1] = 'S'
        else:
            if ans[j] == 'S':
                if ans[j-1] == 'S':
                    ans[j+1] = 'W'
                else:
                    ans[j+1] = 'S'
            else:
                if ans[j-1] == 'S':
                    ans[j+1] = 'S'
                else:
                    ans[j+1] = 'W'
print(-1)

Submission status: Wrong Answer

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

ans = ['S']*(n)

ani0 = ['S','S','W','W']
ani1 = ['S','W','S','W']
anim1 = ['S','W','W','S']

for i in range(4):
    ans[0] = ani0[i]
    if s[0] == 'o':
        ans[-1] = anim1[i]
        ans[1] = ani1[i]
    else:
        ans[-1] = anim1[3-i]
        ans[1] = ani1[3-i]
        
    #print(ans)
        
    for j in range(1,n):
        if j == n-1:
            if s[j] == 'o':
                if ans[j] == 'S':
                    if ans[j-1] == 'S':
                        if ans[0] == 'S':
                            print(*ans,sep='')
                            exit()
                    else:
                        if ans[0] == 'W':
                            print(*ans,sep='')
                            exit()
                else:
                    if ans[j-1] == 'S':
                        if ans[0] == 'W':
                            print(*ans,sep='')
                            exit()
                    else:
                        if ans[0] == 'S':
                            print(*ans,sep='')
                            exit()
            else:
                #print(ans)
                if ans[j] == 'S':
                    if ans[j-1] == 'S':
                        if ans[0] == 'W':
                            print(*ans,sep='')
                            exit()
                    else:
                        if ans[0] == 'S':
                            print(*ans,sep='')
                            exit()
                else:
                    if ans[j-1] == 'S':
                        if ans[0] == 'S':
                            print(*ans,sep='')
                            exit()
                    else:
                        if ans[0] == 'W':
                            print(*ans,sep='')
                            exit()
            break
        
        if s[j] == 'o':
            if ans[j] == 'S':
                if ans[j-1] == 'S':
                    ans[j+1] = 'S'
                else:
                    ans[j+1] = 'W'
            else:
                if ans[j-1] == 'S':
                    ans[j+1] = 'W'
                else:
                    ans[j+1] = 'S'
        else:
            if ans[j] == 'S':
                if ans[j-1] == 'S':
                    ans[j+1] = 'W'
                else:
                    ans[j+1] = 'S'
            else:
                if ans[j-1] == 'S':
                    ans[j+1] = 'S'
                else:
                    ans[j+1] = 'W'
print(-1)