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:
def main():
    N = int(input())
    s = input()

    ok = False
    for ans in ["SS", "SW", "WW", "WS"]:
        for i in range(1, N):
            if s[i] == "o":# oの時
                if ans[i-1] == "S" and ans[i] == "S":
                    ans += "S"
                elif ans[i-1] == "W" and ans[i] == "S":
                    ans += "W"
                elif ans[i-1] == "S" and ans[i] == "W":
                    ans += "W"
                elif ans[i-1] == "W" and ans[i] == "W":
                    ans += "S"
            else:# xの時
                if ans[i-1] == "S" and ans[i] == "S":
                    ans += "W"
                elif ans[i-1] == "W" and ans[i] == "S":
                    ans += "S"
                elif ans[i-1] == "S" and ans[i] == "W":
                    ans += "S"
                elif ans[i-1] == "W" and ans[i] == "W":
                    ans += "W"
    
        if ans[0] == ans[-1]:
            ok = True
            print(ans[:-1])
            break
    if not ok:
        print(-1)

            

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

    ok = False
    for ans in ["SS", "SW", "WW", "WS"]:
        for i in range(1, N-1):
            if s[i] == "o":# oの時
                if ans[i-1] == "S" and ans[i] == "S":
                    ans += "S"
                elif ans[i-1] == "W" and ans[i] == "S":
                    ans += "W"
                elif ans[i-1] == "S" and ans[i] == "W":
                    ans += "W"
                elif ans[i-1] == "W" and ans[i] == "W":
                    ans += "S"
            else:# xの時
                if ans[i-1] == "S" and ans[i] == "S":
                    ans += "W"
                elif ans[i-1] == "W" and ans[i] == "S":
                    ans += "S"
                elif ans[i-1] == "S" and ans[i] == "W":
                    ans += "S"
                elif ans[i-1] == "W" and ans[i] == "W":
                    ans += "W"
    
        if s[-1] == "o":
            if ans[-1] == "S":
                if (ans[-2] == "S" and ans[0] == "S") or (ans[-2] == "W" and ans[0] == "W"):
                    ok = True
            else:
                if (ans[-2] == "S" and ans[0] == "W") or (ans[-2] == "W" and ans[0] == "S"):
                    ok = True
        else:
            if ans[-1] == "W":
                if (ans[-2] == "S" and ans[0] == "S") or (ans[-2] == "W" and ans[0] == "W"):
                    ok = True
            else:
                if (ans[-2] == "S" and ans[0] == "W") or (ans[-2] == "W" and ans[0] == "S"):
                    ok = True
        if ok:
            print(ans)
            break
    if not ok:
        print(-1)

            

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# ARC069D - Menagerie (ABC055D)
def check(a: str, b: str) -> None:
    ret, prev, cur = a + b, a, b
    for i in S[1:]:
        if (cur == "S" and i == "o") or (cur == "W" and i == "x"):
            ret += prev
            prev, cur = cur, prev
        elif (cur == "S" and i == "x") or (cur == "W" and i == "o"):
            x = "W" if prev == "S" else "S"
            ret += x
            prev, cur = cur, x
    if ret[0] == ret[-1]:
        return ret[:-1]
    return None


def main():
    global S
    N = int(input())
    S = input().rstrip()
    for a in ("S", "W"):
        for b in ("S", "W"):
            ans = check(a, b)
            if ans:
                print(ans)
                return
    print(-1)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# ARC069D - Menagerie (ABC055D)
def check(a: str, b: str) -> tuple:
    ret, prev, cur = a + b, a, b
    for i in S[1:]:
        if (cur == "S" and i == "o") or (cur == "W" and i == "x"):
            ret += prev
            prev, cur = cur, prev
        elif (cur == "S" and i == "x") or (cur == "W" and i == "o"):
            x = "W" if prev == "S" else "S"
            ret += x
            prev, cur = cur, x
    return ret[:-1], cur


def main():
    global S
    N = int(input())
    S = input().rstrip()
    for a in ("S", "W"):
        for b in ("S", "W"):
            ans, x = check(a, b)
            if ans[0] == x:
                print(ans)
                return
    print(-1)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# ARC069D - Menagerie (ABC055D)
def check(a: str, b: str) -> tuple:
    ret, prev, cur = a + b, a, b
    for i in S[1:]:
        if cur == "S":
            if i == "o":
                ret += prev
                prev, cur = cur, prev
            else:
                x = "W" if prev == "S" else "S"
                ret += x
                prev, cur = cur, x
        else:
            if i == "o":
                x = "W" if prev == "S" else "S"
                ret += x
                prev, cur = cur, x
            else:
                ret += prev
                prev, cur = cur, prev
    return ret[:-1], cur


def main():
    global S
    N = int(input())
    S = input().rstrip()
    for a in ("S", "W"):
        for b in ("S", "W"):
            ans, x = check(a, b)
            if ans[0] == x:
                print(ans)
                return
    print(-1)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# ARC069D - Menagerie (ABC055D)
def check(a: str, b: str) -> tuple:
    ret, prev, cur = a + b, a, b
    for i in S[1:]:
        if (cur == "S" and i == "o") or (cur == "W" and "x"):
            ret += prev
            prev, cur = cur, prev
        elif (cur == "S" and i == "x") or (cur == "W" and "o"):
            x = "W" if prev == "S" else "S"
            ret += x
            prev, cur = cur, x
    return ret[:-1], cur


def main():
    global S
    N = int(input())
    S = input().rstrip()
    for a in ("S", "W"):
        for b in ("S", "W"):
            ans, x = check(a, b)
            if ans[0] == x:
                print(ans)
                return
    print(-1)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

ans = -1

candidate = [["S", "S"], ["S", "W"], ["W", "S"], ["W", "W"]]

for items in candidate:
  SW = [""] * N
  SW[0] = items[0]
  SW[1] = items[1]
    
  for i in range(1, N-1):
    if s[i] == "o":
      if SW[i] == "S":
        if SW[i-1] == "S":
          SW[i+1] = "S"
        else:
          SW[i+1] = "W"
      if SW[i] == "W":
        if SW[i-1] == "S":
          SW[i+1] = "W"
        else:
          SW[i+1] = "S"
    if s[i] == "x":
      if SW[i] == "S":
        if SW[i-1] == "S":
          SW[i+1] = "W"
        else:
          SW[i+1] = "S"
      if SW[i] == "W":
        if SW[i-1] == "S":
          SW[i+1] = "S"
        else:
          SW[i+1] = "W"
  
  flag = True
  
  for i in range(-1, 0):
    if s[i] == "o":
      if SW[i] == "S":
        if SW[i-1] == "S":
          tmp = "S"
        else:
          tmp = "W"
      if SW[i] == "W":
        if SW[i-1] == "S":
          tmp = "W"
        else:
          tmp = "S"
    if s[i] == "x":
      if SW[i] == "S":
        if SW[i-1] == "S":
          tmp = "W"
        else:
          tmp = "S"
      if SW[i] == "W":
        if SW[i-1] == "S":
          tmp = "S"
        else:
          tmp = "W" 
    if tmp != SW[i]:
      flag = False
    
  if flag:
    ans = "".join(SW)
        
print(ans)

Submission status: Wrong Answer

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

ans = -1

candidate = [["S", "S"], ["S", "W"], ["W", "S"], ["W", "W"]]

for items in candidate:
  SW = [""] * N
  SW[0] = items[0]
  SW[1] = items[1]
    
  for i in range(1, N-1):
    if s[i] == "o":
      if SW[i] == "S":
        if SW[i-1] == "S":
          SW[i+1] = "S"
        else:
          SW[i+1] = "W"
      if SW[i] == "W":
        if SW[i-1] == "S":
          SW[i+1] = "W"
        else:
          SW[i+1] = "S"
    if s[i] == "x":
      if SW[i] == "S":
        if SW[i-1] == "S":
          SW[i+1] = "W"
        else:
          SW[i+1] = "S"
      if SW[i] == "W":
        if SW[i-1] == "S":
          SW[i+1] = "S"
        else:
          SW[i+1] = "W"
         
  for i in range(-1, 0):
    if s[i] == "o":
      if SW[i] == "S":
        if SW[i-1] == "S":
          tmp = "S"
        else:
          tmp = "W"
      if SW[i] == "W":
        if SW[i-1] == "S":
          tmp = "W"
        else:
          tmp = "S"
    if s[i] == "x":
      if SW[i] == "S":
        if SW[i-1] == "S":
          tmp = "W"
        else:
          tmp = "S"
      if SW[i] == "W":
        if SW[i-1] == "S":
          tmp = "S"
        else:
          tmp = "W" 
    if tmp != SW[i]:
      break
    
    ans = "".join(SW)
        
print(ans)

Submission status: Wrong Answer

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

ans = -1

candidate = [["S", "S"], ["S", "W"], ["W", "S"], ["W", "W"]]

for items in candidate:
  SW = [""] * N
  SW[0] = items[0]
  SW[1] = items[1]
    
  for i in range(1, N-1):
    if s[i] == "o":
      if SW[i] == "S":
        if SW[i-1] == "S":
          SW[i+1] = "S"
        else:
          SW[i+1] = "W"
      if SW[i] == "W":
        if SW[i-1] == "S":
          SW[i+1] = "W"
        else:
          SW[i+1] = "S"
    if s[i] == "x":
      if SW[i] == "S":
        if SW[i-1] == "S":
          SW[i+1] = "W"
        else:
          SW[i+1] = "S"
      if SW[i] == "W":
        if SW[i-1] == "S":
          SW[i+1] = "S"
        else:
          SW[i+1] = "W"
          
          
  for i in range(-1, 0):
    if s[i] == "o":
      if SW[i] == "S":
        if SW[i-1] == "S":
          SW[i+1] = "S"
        else:
          SW[i+1] = "W"
      if SW[i] == "W":
        if SW[i-1] == "S":
          SW[i+1] = "W"
        else:
          SW[i+1] = "S"
    if s[i] == "x":
      if SW[i] == "S":
        if SW[i-1] == "S":
          SW[i+1] = "W"
        else:
          SW[i+1] = "S"
      if SW[i] == "W":
        if SW[i-1] == "S":
          SW[i+1] = "S"
        else:
          SW[i+1] = "W"
          
  if SW[1] == items[1]:
    ans = "".join(SW)
    print(ans)
    exit()
        
print(ans)

Submission status: Wrong Answer

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

ans = -1

candidate = [["S", "S"], ["S", "W"], ["W", "S"], ["W", "W"]]

for items in candidate:
  SW = [""] * N
  SW[0] = items[0]
  SW[1] = items[1]
    
  for i in range(1, N-1):
    if s[i] == "o":
      if SW[i] == "S":
        if SW[i-1] == "S":
          SW[i+1] = "S"
        else:
          SW[i+1] = "W"
      if SW[i] == "W":
        if SW[i-1] == "S":
          SW[i+1] = "W"
        else:
          SW[i+1] = "S"
    if s[i] == "x":
      if SW[i] == "S":
        if SW[i-1] == "S":
          SW[i+1] = "W"
        else:
          SW[i+1] = "S"
      if SW[i] == "W":
        if SW[i-1] == "S":
          SW[i+1] = "S"
        else:
          SW[i+1] = "W"
          
          
  for i in range(-1, 0):
    if s[i] == "o":
      if SW[i] == "S":
        if SW[i-1] == "S":
          SW[i+1] = "S"
        else:
          SW[i+1] = "W"
      if SW[i] == "W":
        if SW[i-1] == "S":
          SW[i+1] = "W"
        else:
          SW[i+1] = "S"
    if s[i] == "x":
      if SW[i] == "S":
        if SW[i-1] == "S":
          SW[i+1] = "W"
        else:
          SW[i+1] = "S"
      if SW[i] == "W":
        if SW[i-1] == "S":
          SW[i+1] = "S"
        else:
          SW[i+1] = "W"
          
  if SW[0] == items[0] and SW[1] == items[1]:
    ans = "".join(SW)
    print(ans)
    exit()
        
print(ans)

Submission status: Wrong Answer

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

ans = -1

candidate = [["S", "S"], ["S", "W"], ["W", "S"], ["W", "W"]]

for items in candidate:
  SW = [""] * N
  SW[0] = items[0]
  SW[1] = items[1]
    
  for i in range(1, N-1):
    if s[i] == "o":
      if SW[i] == "S":
        if SW[i-1] == "S":
          SW[i+1] = "S"
        else:
          SW[i+1] = "W"
      if SW[i] == "W":
        if SW[i-1] == "S":
          SW[i+1] = "W"
        else:
          SW[i+1] = "S"
    if s[i] == "x":
      if SW[i] == "S":
        if SW[i-1] == "S":
          SW[i+1] = "W"
        else:
          SW[i+1] = "S"
      if SW[i] == "W":
        if SW[i-1] == "S":
          SW[i+1] = "S"
        else:
          SW[i+1] = "W"
          
          
  for i in range(-1, 0):
    if s[i] == "o":
      if SW[i] == "S":
        if SW[i-1] == "S":
          SW[i+1] = "S"
        else:
          SW[i+1] = "W"
      if SW[i] == "W":
        if SW[i-1] == "S":
          SW[i+1] = "W"
        else:
          SW[i+1] = "S"
    if s[i] == "x":
      if SW[i] == "S":
        if SW[i-1] == "S":
          SW[i+1] = "W"
        else:
          SW[i+1] = "S"
      if SW[i] == "W":
        if SW[i-1] == "S":
          SW[i+1] = "S"
        else:
          SW[i+1] = "W"
          
  if SW[0] == items[0] and SW[1] == items[1]:
    ans = "".join(SW)
        
print(ans)

Submission status: Wrong Answer

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

ans = -1

candidate = [["S", "S"], ["S", "W"], ["W", "S"], ["W", "W"]]

for items in candidate:
  SW = [""] * N
  SW[0] = items[0]
  SW[1] = items[1]
  
  for i in range(1, N-1):
    if s[i] == "o":
      if SW[i] == "S":
        if SW[i-1] == "S":
          SW[i+1] = "S"
        else:
          SW[i+1] = "W"
      if SW[i] == "W":
        if SW[i-1] == "S":
          SW[i+1] = "W"
        else:
          SW[i+1] = "S"
    if s[i] == "x":
      if SW[i] == "S":
        if SW[i-1] == "S":
          SW[i+1] = "W"
        else:
          SW[i+1] = "S"
      if SW[i] == "W":
        if SW[i-1] == "S":
          SW[i+1] = "S"
        else:
          tmp = "W"
          
          
  for i in range(-1, 0):
    if s[i] == "o":
      if SW[i] == "S":
        if SW[i-1] == "S":
          SW[i+1] = "S"
        else:
          SW[i+1] = "W"
      if SW[i] == "W":
        if SW[i-1] == "S":
          SW[i+1] = "W"
        else:
          SW[i+1] = "S"
    if s[i] == "x":
      if SW[i] == "S":
        if SW[i-1] == "S":
          SW[i+1] = "W"
        else:
          SW[i+1] = "S"
      if SW[i] == "W":
        if SW[i-1] == "S":
          SW[i+1] = "S"
        else:
          SW[i+1] = "W"
          
  if SW[0] == items[0] and SW[1] == items[1]:
    print("".join(SW))
    exit()          
        
print(ans)

Submission status: Wrong Answer

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

ans = -1

candidate = [["S", "S"], ["S", "W"], ["W", "S"], ["W", "W"]]

for items in candidate:
  SW = [""] * N
  SW[0] = items[0]
  SW[1] = items[1]
  
  for i in range(1, N):
    if s[i] == "o":
      if SW[i] == "S":
        if SW[i-1] == "S":
          tmp = "S"
        else:
          tmp = "W"
      if SW[i] == "W":
        if SW[i-1] == "S":
          tmp = "W"
        else:
          tmp = "S"
    if s[i] == "x":
      if SW[i] == "S":
        if SW[i-1] == "S":
          tmp = "W"
        else:
          tmp = "S"
      if SW[i] == "W":
        if SW[i-1] == "S":
          tmp = "S"
        else:
          tmp = "W"
          
    if i == N-1:
      i = -1
          
    if SW[i+1] != "":
      if SW[i+1] == tmp:
        ans = "".join(SW)
        print(ans)
        exit()
    else:
      SW[i+1] = tmp
        
print(ans)

Submission status: Wrong Answer

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

possible = 0
finish_flag = 0
for animal0 in range(2):
    if finish_flag == 1:
        break
    for animal1 in range(2):
        if finish_flag == 1:
            break
        animal = [0] * N
        animal[0] = animal0
        animal[1] = animal1
        for i in range(1, N - 1):
            if animal[i] == 0:
                animal[i + 1] = animal[i - 1] if s[i] == 'o' else (animal[i - 1] + 1) % 2
            else:
                animal[i + 1] = (animal[i - 1] + 1) % 2 if s[i] == 'o' else animal[i - 1]
        if animal[N - 1] == 0:
            animal0_true = animal[N - 2] if s[N - 1] == 'o' else (animal[N - 2] + 1) % 2
        else:
            animal0_true = (animal[N - 2] + 1) % 2 if s[N - 1] == 'o' else animal[N - 2]
        if animal0 == animal0_true:
            possible = 1
            finish_flag = 1

if possible:
    ans = [0] * N
    for i in range(N):
        ans[i] = 'S' if animal[i] == 0 else 'W'
    print("".join(ans))
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
import itertools
import math
N = int(input())
S = input()
l = len(S)


#oxooxoxoox
#s → 1 w→-1
temp = []
for c in S:
    if c == "o":
        temp.append(1)
    else:
        temp.append(-1)

S = temp

flag = False
for i in [1,-1]: # 1匹目
    for j in [1,-1]: #2匹目
        nums = [i,j]
        temp = i * j
        for k in range(1,N-1):
            nums.append(temp * S[k])
            temp = nums[k] * nums[k  + 1]
        if temp * nums[0] == S[-1]:
            flag = True
            break
    if flag:
        break

if flag:
    for num in nums:
        if num == -1:
            print("W",end="")
        else:
            print("S", end="")

else:
    print(-1)

Submission status: Wrong Answer

Solution code:
import itertools
import math
N = int(input())
S = input()
l = len(S)


#s → 1 w→-1


flag = False
for i in [1,-1]: #一匹目
    for j in [1,-1]: #二匹目
        nums = [i,j]
        temp = i * j
        for i in range(2,l):
            if S[i-1] == "o":
                nums.append(temp)
            if S[i-1]== "x":
                nums.append( -temp)
        temp = nums[i] * nums[i - 1]

        if S[-1] == "o":
            if nums[-1] * temp == 1:
                flag = True
                break
        if S[-1] == "x":
            if nums[-1] * temp == -1:
                flag = True
                break
    if flag:
        break

if flag:
    for num in nums:
        if num == -1:
            print("W",end="")
        else:
            print("S", end="")

else:
    print(-1)

Submission status: Wrong Answer

Solution code:
n=int(input())
arr=input()
ans=['S']*n
cnt=0
for i in range(n):
  if arr[i]=='o':
    if ans[i]=='S':
      if ans[i-1]==ans[(i+1)%n]:
        continue
      else:
        ans[(i+1)%n]=ans[i-1]
    elif ans[i]=='W':
      if ans[i-1]!=ans[(i+1)%n]:
        continue
      else:
        if ans[(i+1)%n]=='S':
          ans[(i+1)%n]='W'
        else:
          ans[(i+1)%n]='S'
  elif arr[i]=='x':
    if ans[i]=='S':
      if ans[i-1]==ans[(i+1)%n]:
        if ans[(i+1)%n]=='S':
          ans[(i+1)%n]='W'
        else:
          ans[(i+1)%n]='S'
      else:
        continue
    elif ans[i]=='W':
      if ans[i-1]==ans[(i+1)%n]:
        continue
      else:
        if ans[(i+1)%n]=='S':
          ans[(i+1)%n]='W'
        else:
          ans[(i+1)%n]='S'
flag=False
for i in range(n):
  if arr[i]=='o':
    if ans[i]=='S':
      if ans[i-1]==ans[(i+1)%n]:
        continue
      else:
        break
    elif ans[i]=='W':
      if ans[i-1]!=ans[(i+1)%n]:
        continue
      else:
        break
  elif arr[i]=='x':
    if ans[i]=='S':
      if ans[i-1]==ans[(i+1)%n]:
        break
      else:
        continue
    elif ans[i]=='W':
      if ans[i-1]==ans[(i+1)%n]:
        continue
      else:
        break
else:
  flag=True
if flag==True and cnt==0:
  print(''.join(map(str,ans)))
  cnt+=1
ans=['W']*n
for i in range(n):
  if arr[i]=='o':
    if ans[i]=='S':
      if ans[i-1]==ans[(i+1)%n]:
        continue
      else:
        ans[(i+1)%n]=ans[i-1]
    elif ans[i]=='W':
      if ans[i-1]!=ans[(i+1)%n]:
        continue
      else:
        if ans[(i+1)%n]=='S':
          ans[(i+1)%n]='W'
        else:
          ans[(i+1)%n]='S'
  elif arr[i]=='x':
    if ans[i]=='S':
      if ans[i-1]==ans[(i+1)%n]:
        if ans[(i+1)%n]=='S':
          ans[(i+1)%n]='W'
        else:
          ans[(i+1)%n]='S'
      else:
        continue
    elif ans[i]=='W':
      if ans[i-1]==ans[(i+1)%n]:
        continue
      else:
        if ans[(i+1)%n]=='S':
          ans[(i+1)%n]='W'
        else:
          ans[(i+1)%n]='S'
flag=False
for i in range(n):
  if arr[i]=='o':
    if ans[i]=='S':
      if ans[i-1]==ans[(i+1)%n]:
        continue
      else:
        break
    elif ans[i]=='W':
      if ans[i-1]!=ans[(i+1)%n]:
        continue
      else:
        break
  elif arr[i]=='x':
    if ans[i]=='S':
      if ans[i-1]==ans[(i+1)%n]:
        break
      else:
        continue
    elif ans[i]=='W':
      if ans[i-1]==ans[(i+1)%n]:
        continue
      else:
        break
else:
  flag=True
if flag==True and cnt==0:
  print(''.join(map(str,ans)))
  cnt+=1
ans=['S']*n
ans[1]='W'
for i in range(n):
  if arr[i]=='o':
    if ans[i]=='S':
      if ans[i-1]==ans[(i+1)%n]:
        continue
      else:
        ans[(i+1)%n]=ans[i-1]
    elif ans[i]=='W':
      if ans[i-1]!=ans[(i+1)%n]:
        continue
      else:
        if ans[(i+1)%n]=='S':
          ans[(i+1)%n]='W'
        else:
          ans[(i+1)%n]='S'
  elif arr[i]=='x':
    if ans[i]=='S':
      if ans[i-1]==ans[(i+1)%n]:
        if ans[(i+1)%n]=='S':
          ans[(i+1)%n]='W'
        else:
          ans[(i+1)%n]='S'
      else:
        continue
    elif ans[i]=='W':
      if ans[i-1]==ans[(i+1)%n]:
        continue
      else:
        if ans[(i+1)%n]=='S':
          ans[(i+1)%n]='W'
        else:
          ans[(i+1)%n]='S'
flag=False
for i in range(n):
  if arr[i]=='o':
    if ans[i]=='S':
      if ans[i-1]==ans[(i+1)%n]:
        continue
      else:
        break
    elif ans[i]=='W':
      if ans[i-1]!=ans[(i+1)%n]:
        continue
      else:
        break
  elif arr[i]=='x':
    if ans[i]=='S':
      if ans[i-1]==ans[(i+1)%n]:
        break
      else:
        continue
    elif ans[i]=='W':
      if ans[i-1]==ans[(i+1)%n]:
        continue
      else:
        break
else:
  flag=True
if flag==True and cnt==0:
  print(''.join(map(str,ans)))
  cnt+=1
ans=['W']*n
ans[1]='S'
for i in range(n):
  if arr[i]=='o':
    if ans[i]=='S':
      if ans[i-1]==ans[(i+1)%n]:
        continue
      else:
        ans[(i+1)%n]=ans[i-1]
    elif ans[i]=='W':
      if ans[i-1]!=ans[(i+1)%n]:
        continue
      else:
        if ans[(i+1)%n]=='S':
          ans[(i+1)%n]='W'
        else:
          ans[(i+1)%n]='S'
  elif arr[i]=='x':
    if ans[i]=='S':
      if ans[i-1]==ans[(i+1)%n]:
        if ans[(i+1)%n]=='S':
          ans[(i+1)%n]='W'
        else:
          ans[(i+1)%n]='S'
      else:
        continue
    elif ans[i]=='W':
      if ans[i-1]==ans[(i+1)%n]:
        continue
      else:
        if ans[(i+1)%n]=='S':
          ans[(i+1)%n]='W'
        else:
          ans[(i+1)%n]='S'
flag=False
for i in range(n):
  if arr[i]=='o':
    if ans[i]=='S':
      if ans[i-1]==ans[(i+1)%n]:
        continue
      else:
        break
    elif ans[i]=='W':
      if ans[i-1]!=ans[(i+1)%n]:
        continue
      else:
        break
  elif arr[i]=='x':
    if ans[i]=='S':
      if ans[i-1]==ans[(i+1)%n]:
        break
      else:
        continue
    elif ans[i]=='W':
      if ans[i-1]==ans[(i+1)%n]:
        continue
      else:
        break
else:
  flag=True
if flag==True and cnt==0:
  print(''.join(map(str,ans)))
  cnt+=1
if cnt==0:
  print(-1)

Submission status: Wrong Answer

Solution code:
n=int(input())
arr=input()
ans=['S']*n
for i in range(n):
  if arr[i]=='o':
    if ans[i]=='S':
      if ans[i-1]==ans[(i+1)%n]:
        continue
      else:
        ans[(i+1)%n]=ans[i-1]
    elif ans[i]=='W':
      if ans[i-1]!=ans[(i+1)%n]:
        continue
      else:
        if ans[(i+1)%n]=='S':
          ans[(i+1)%n]='W'
        else:
          ans[(i+1)%n]='S'
  elif arr[i]=='x':
    if ans[i]=='S':
      if ans[i-1]==ans[(i+1)%n]:
        if ans[(i+1)%n]=='S':
          ans[(i+1)%n]='W'
        else:
          ans[(i+1)%n]='S'
      else:
        continue
    elif ans[i]=='W':
      if ans[i-1]==ans[(i+1)%n]:
        continue
      else:
        if ans[(i+1)%n]=='S':
          ans[(i+1)%n]='W'
        else:
          ans[(i+1)%n]='S'
flag=False
for i in range(n):
  if arr[i]=='o':
    if ans[i]=='S':
      if ans[i-1]==ans[(i+1)%n]:
        continue
      else:
        break
    elif ans[i]=='W':
      if ans[i-1]!=ans[(i+1)%n]:
        continue
      else:
        break
  elif arr[i]=='x':
    if ans[i]=='S':
      if ans[i-1]==ans[(i+1)%n]:
        break
      else:
        continue
    elif ans[i]=='W':
      if ans[i-1]==ans[(i+1)%n]:
        continue
      else:
        break
else:
  flag=True
if flag==True:
  print(''.join(map(str,ans)))
else:
  ans=['W']*n
  for i in range(n):
    if arr[i]=='o':
      if ans[i]=='S':
        if ans[i-1]==ans[(i+1)%n]:
          continue
        else:
          ans[(i+1)%n]=ans[i-1]
      if ans[i]=='W':
        if ans[i-1]!=ans[(i+1)%n]:
          continue
        else:
          if ans[(i+1)%n]=='S':
            ans[(i+1)%n]='W'
          else:
            ans[(i+1)%n]='S'
    elif arr[i]=='x':
      if ans[i]=='S':
        if ans[i-1]==ans[(i+1)%n]:
          if ans[(i+1)%n]=='S':
            ans[(i+1)%n]='W'
          else:
            ans[(i+1)%n]='S'
        else:
          continue
      if ans[i]=='W':
        if ans[i-1]==ans[(i+1)%n]:
          continue
        else:
          if ans[(i+1)%n]=='S':
            ans[(i+1)%n]='W'
          else:
            ans[(i+1)%n]='S'
  flag=False
  for i in range(n):
    if arr[i]=='o':
      if ans[i]=='S':
        if ans[i-1]==ans[(i+1)%n]:
          continue
        else:
          break
      if ans[i]=='W':
        if ans[i-1]!=ans[(i+1)%n]:
          continue
        else:
          break
    elif arr[i]=='x':
      if ans[i]=='S':
        if ans[i-1]==ans[(i+1)%n]:
          break
        else:
          continue
      if ans[i]=='W':
        if ans[i-1]==ans[(i+1)%n]:
          continue
        else:
          break
  else:
    flag=True
  if flag==True:
    print(''.join(map(str,ans)))
  else:
    ans=['W']*n
    ans[0]='S'
    for i in range(n):
      if arr[i]=='o':
        if ans[i]=='S':
          if ans[i-1]==ans[(i+1)%n]:
            continue
          else:
            ans[(i+1)%n]=ans[i-1]
        if ans[i]=='W':
          if ans[i-1]!=ans[(i+1)%n]:
            continue
          else:
            if ans[(i+1)%n]=='S':
              ans[(i+1)%n]='W'
            else:
              ans[(i+1)%n]='S'
      elif arr[i]=='x':
        if ans[i]=='S':
          if ans[i-1]==ans[(i+1)%n]:
            if ans[(i+1)%n]=='S':
              ans[(i+1)%n]='W'
            else:
              ans[(i+1)%n]='S'
          else:
            continue
        if ans[i]=='W':
          if ans[i-1]==ans[(i+1)%n]:
            continue
          else:
            if ans[(i+1)%n]=='S':
              ans[(i+1)%n]='W'
            else:
              ans[(i+1)%n]='S'
    flag=False
    for i in range(n):
      if arr[i]=='o':
        if ans[i]=='S':
          if ans[i-1]==ans[(i+1)%n]:
            continue
          else:
            break
        if ans[i]=='W':
          if ans[i-1]!=ans[(i+1)%n]:
            continue
          else:
            break
      elif arr[i]=='x':
        if ans[i]=='S':
          if ans[i-1]==ans[(i+1)%n]:
            break
          else:
            continue
        if ans[i]=='W':
          if ans[i-1]==ans[(i+1)%n]:
            continue
          else:
            break
    else:
      flag=True
    if flag==True:
      print(''.join(map(str,ans)))
    else:
      ans=['S']*n
      ans[0]='W'
      for i in range(n):
        if arr[i]=='o':
          if ans[i]=='S':
            if ans[i-1]==ans[(i+1)%n]:
              continue
            else:
              ans[(i+1)%n]=ans[i-1]
            if ans[i]=='W':
              if ans[i-1]!=ans[(i+1)%n]:
                continue
              else:
                if ans[(i+1)%n]=='S':
                  ans[(i+1)%n]='W'
                else:
                  ans[(i+1)%n]='S'
          elif arr[i]=='x':
            if ans[i]=='S':
              if ans[i-1]==ans[(i+1)%n]:
                if ans[(i+1)%n]=='S':
                  ans[(i+1)%n]='W'
                else:
                  ans[(i+1)%n]='S'
              else:
                continue
            if ans[i]=='W':
              if ans[i-1]==ans[(i+1)%n]:
                continue
              else:
                if ans[(i+1)%n]=='S':
                  ans[(i+1)%n]='W'
                else:
                  ans[(i+1)%n]='S'
        flag=False
        for i in range(n):
          if arr[i]=='o':
            if ans[i]=='S':
              if ans[i-1]==ans[(i+1)%n]:
                continue
              else:
                break
            if ans[i]=='W':
              if ans[i-1]!=ans[(i+1)%n]:
                continue
              else:
                break
          elif arr[i]=='x':
            if ans[i]=='S':
              if ans[i-1]==ans[(i+1)%n]:
                break
              else:
                continue
            if ans[i]=='W':
              if ans[i-1]==ans[(i+1)%n]:
                continue
              else:
                break
        else:
          flag=True
        if flag==True:
          print(''.join(map(str,ans)))
        else:
          print(-1)