Problem:


Score : 500 points

Problem Statement

Snuke, who loves animals, built a zoo.

There are N animals in this zoo. They are conveniently numbered 1 through N, and arranged in a circle.
The animal numbered i (2≤i≤N-1) is adjacent to the animals numbered i-1 and i+1. Also, the animal numbered 1 is adjacent to the animals numbered 2 and N, and the animal numbered N is adjacent to the animals numbered N-1 and 1.

There are two kinds of animals in this zoo: honest sheep that only speak the truth, and lying wolves that only tell lies.

Snuke cannot tell the difference between these two species, and asked each animal the following question: "Are your neighbors of the same species?" The animal numbered i answered s_i. Here, if s_i is o, the animal said that the two neighboring animals are of the same species, and if s_i is x, the animal said that the two neighboring animals are of different species.

More formally, a sheep answered o if the two neighboring animals are both sheep or both wolves, and answered x otherwise.
Similarly, a wolf answered x if the two neighboring animals are both sheep or both wolves, and answered o otherwise.

Snuke is wondering whether there is a valid assignment of species to the animals that is consistent with these responses. If there is such an assignment, show one such assignment. Otherwise, print -1.

Constraints

3 ≤ N ≤ 10^{5}

s is a string of length N consisting of o and x.

Input

The input is given from Standard Input in the following format:

N
s

Output

If there does not exist an valid assignment that is consistent with s, print -1.
Otherwise, print an string t in the following format. The output is considered correct if the assignment described by t is consistent with s.

t is a string of length N consisting of S and W.

If t_i is S, it indicates that the animal numbered i is a sheep. If t_i is W, it indicates that the animal numbered i is a wolf.

Sample Input 1

6
ooxoox

Sample Output 1

SSSWWS

For example, if the animals numbered 1, 2, 3, 4, 5 and 6 are respectively a sheep, sheep, sheep, wolf, wolf, and sheep, it is consistent with their responses. Besides, there is another valid assignment of species: a wolf, sheep, wolf, sheep, wolf and wolf.

Let us remind you: if the neiboring animals are of the same species, a sheep answers o and a wolf answers x. If the neiboring animals are of different species, a sheep answers x and a wolf answers o.

Sample Input 2

3
oox

Sample Output 2

-1

Print -1 if there is no valid assignment of species.

Sample Input 3

10
oxooxoxoox

Sample Output 3

SSWWSSSWWS



Sample input:
6
ooxoox


Sample output:
SSSWWS

Submission status: Wrong Answer

Solution code:

import numpy as np
import sys
sys.setrecursionlimit(100000)


def acinput():
    return list(map(int, input().split(" ")))


directions = np.array([[1, 0], [0, 1], [-1, 0], [0, -1]])
directions = list(map(np.array, directions))

mod = 10**9+7


def factorial(n):
    fact = 1
    for integer in range(1, n + 1):
        fact *= integer
    return fact


def serch(x, count):
    #print("top", x, count)

    for d in directions:
        nx = d+x
        # print(nx)
        if np.all(0 <= nx) and np.all(nx < (H, W)):
            if field[nx[0]][nx[1]] == "E":
                count += 1
                field[nx[0]][nx[1]] = "V"
                count = serch(nx, count)
                continue
            if field[nx[0]][nx[1]] == "#":
                field[nx[0]][nx[1]] = "V"
                count = serch(nx, count)

    return count


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


def chk(init_tf):
    tf = [-1]*(N)

    tf[0:2] = init_tf
    for i in range(2, N):
        if tf[i-1] == 1:
            if s[i-1] == "o":
                # d[i]=d[i-2]
                tf[i] = tf[i-2]
            else:
                tf[i] = (tf[i-2]+1) % 2

        if tf[i-1] == 0:
            if s[i-1] == "o":
                tf[i] = (tf[i-2]+1) % 2
            else:
                tf[i] = tf[i-2]
    """ 
    print(tf)
    print(s)
     """

    for i in range(N):
        
        r=(i+1)%(N)
     #   print(i,r)
        if tf[i] == 1:
            if s[i]=="o":
                if tf[i-1] !=tf[r]:
                    return False       
            else:
                if tf[i-1] == tf[r]:
                    return False

        elif tf[i] == 0:
            if s[i] == "x":
                if tf[i-1] != tf[r]:
                    return False
            else:
                if tf[i-1] == tf[r]:
                    return False

    return ["S" if x == 1 else "W" for x in tf]


for i in range(2):
    for j in range(2):
        res=chk((i,j))
        if res:
            print(res)
            sys.exit()

print(-1)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())
ans=[[0]*n for i in range(4)]
ans[1][1]=1
ans[2][0]=1
ans[3][0]=ans[3][1]=1
idx=-1
for i in range(4):
  for j in range(1,n-1):
    if s[j]=='o' and ans[i][j]==1 and ans[i][j-1]==1:
      ans[i][j+1]=1
    elif s[j]=='o' and ans[i][j]==1 and ans[i][j-1]==0:
      ans[i][j+1]=0
    elif s[j]=='o' and ans[i][j]==0 and ans[i][j-1]==1:
      ans[i][j+1]=0
    elif s[j]=='o' and ans[i][j]==0 and ans[i][j-1]==0:
      ans[i][j+1]=1
    elif s[j]=='x' and ans[i][j]==1 and ans[i][j-1]==1:
      ans[i][j+1]=0
    elif s[j]=='x' and ans[i][j]==1 and ans[i][j-1]==0:
      ans[i][j+1]=1
    elif s[j]=='x' and ans[i][j]==0 and ans[i][j-1]==1:
      ans[i][j+1]=1
    else:
      ans[i][j+1]=0
  if ans[i][n-1]==1 and ans[i][0]==ans[i][n-2] and s[n-1]=='o':
    idx=i
    break
  elif ans[i][n-1]==1 and ans[i][0]!=ans[i][n-2] and s[n-1]=='x':
    idx=i
    break
  elif ans[i][n-1]==0 and ans[i][0]==ans[i][n-2] and s[n-1]=='x':
    idx=i
    break
  elif ans[i][n-1]==0 and ans[i][0]!=ans[i][n-2] and s[n-1]=='o':
    idx=i
    break
if idx==-1:
  print(-1)
  exit()
t=[]
for i in range(n):
  if ans[idx][i]==1:
    t.append('S')
  else:
    t.append('W')
print(''.join(t))

Submission status: Wrong Answer

Solution code:
from collections import *
from itertools import *
import copy
from heapq import *

N=int(input())
S=input()
for s1 in ["S","W"]:
    for s2 in ["S","W"]:
        data=[0 for i in range(N)]
        data[0],data[1]=s1,s2

        for i in range(2,N):
            if data[i-1]=="S" and S[i-1]=="o" or data[i-1]=="W" and S[i-1]=="x":
                data[i]=data[i-2]
            elif data[i-1]=="S" and S[i-1]=="x" or data[i-1]=="W" and S[i-1]=="o":
                data[i]="S" if data[i-2]=="W" else "W"

        if data[-1]=="S" and S[-1]=="o" or data[-1]=="W" and S[-1]=="x":
            if data[-2]!=data[0]:
                break
        else:
            if data[-2]==data[0]:
                break

        if data[0]=="S" and S[0]=="o" or data[0]=="W" and S[0]=="x":
            if data[-1]==data[1]:
                print("".join(list(map(str,data))))
                exit()
        else:
            if data[-1]!=data[1]:
                print("".join(list(map(str,data))))
                exit()
print(-1)

Submission status: Wrong Answer

Solution code:
from collections import *
from itertools import *
import copy
from heapq import *

N=int(input())
S=input()
for s1 in ["S","W"]:
    for s2 in ["S","W"]:
        data=[0 for i in range(N)]
        data[0],data[1]=s1,s2

        for i in range(2,N):
            if data[i-1]=="S" and S[i-1]=="o" or data[i-1]=="W" and S[i-1]=="x":
                data[i]=data[i-2]
            else:
                data[i]="S" if data[i-2]=="W" else "W"

        if N==3:
            if data[-1]=="S" and S[-1]=="o" or data[-1]=="W" and S[-1]=="x":
                if data[-2]!=data[0]:
                    break
            else:
                if data[-2]==data[0]:
                    break

        if data[0]=="S" and S[0]=="o" or data[0]=="W" and S[0]=="x":
            if data[-1]==data[1]:
                print("".join(list(map(str,data))))
                exit()
        else:
            if data[-1]!=data[1]:
                print("".join(list(map(str,data))))
                exit()
print(-1)

Submission status: Wrong Answer

Solution code:
from collections import *
from itertools import *
import copy
from heapq import *

N=int(input())
S=input()
for s1 in ["S","W"]:
    for s2 in ["S","W"]:
        data=[0 for i in range(N)]
        data[0],data[1]=s1,s2

        for i in range(2,N):
            if data[i-1]=="S" and S[i-1]=="o" or data[i-1]=="W" and S[i-1]=="x":
                data[i]=data[i-2]
            else:
                data[i]="S" if data[i-2]=="W" else "W"

        if data[-1]=="S" and S[-1]=="o" or data[-1]=="W" and S[-1]=="x":
            if data[-2]!=data[0]:
                break
        elif data[-1]=="S" and S[-1]=="x" or data[-1]=="W" and S[-1]=="o":
            if data[-2]==data[0]:
                break

        if data[0]=="S" and S[0]=="o" or data[0]=="W" and S[0]=="x":
            if data[-1]==data[1]:
                print("".join(list(map(str,data))))
                exit()
        elif data[0]=="S" and S[0]=="x" or data[0]=="W" and S[0]=="o":
            if data[-1]!=data[1]:
                print("".join(list(map(str,data))))
                exit()
print(-1)

Submission status: Wrong Answer

Solution code:
from collections import *
from itertools import *
import copy
from heapq import *

N=int(input())
S=input()
for s1 in ["S","W"]:
    for s2 in ["S","W"]:
        data=[0 for i in range(N)]
        data[0],data[1]=s1,s2

        for i in range(2,N):
            if data[i-1]=="S" and S[i-1]=="o" or data[i-1]=="W" and S[i-1]=="x":
                data[i]=data[i-2]
            else:
                data[i]="S" if data[i-2]=="W" else "W"

        if data[-1]=="S" and S[-1]=="o" or data[-1]=="W" and S[-1]=="x":
            if data[-2]!=data[0]:
                break
        else:
            if data[-2]==data[0]:
                break
        if 0 in data:
            print(Unko)
        if data[0]=="S" and S[0]=="o" or data[0]=="W" and S[0]=="x":
            if data[-1]==data[1]:
                print("".join(list(map(str,data))))
                exit()
        else:
            if data[-1]!=data[1]:
                print("".join(list(map(str,data))))
                exit()
print(-1)

Submission status: Wrong Answer

Solution code:
from collections import *
from itertools import *
import copy
from heapq import *

N=int(input())
S=input()
for s1 in ["S","W"]:
    for s2 in ["S","W"]:
        data=[0 for i in range(N)]
        data[0],data[1]=s1,s2

        for i in range(2,N):
            if data[i-1]=="S" and S[i-1]=="o" or data[i-1]=="W" and S[i-1]=="x":
                data[i]=data[i-2]
            else:
                data[i]="S" if data[i-2]=="W" else "W"

        if data[-1]=="S" and S[-1]=="o" or data[-1]=="W" and S[-1]=="x":
            if data[-2]!=data[0]:
                break
        else:
            if data[-2]==data[0]:
                break

        if data[0]=="S" and S[0]=="o" or data[0]=="W" and S[0]=="x":
            if data[-1]==data[1]:
                print("".join(list(map(str,data))))
                exit()
        else:
            if data[-1]!=data[1]:
                print("".join(list(map(str,data))))
                exit()
print(-1)

Submission status: Wrong Answer

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

L = ["SS","SW","WS","WW"]
l= len(s)
##0,1に置き換えたりしない
##条件分岐注意する
##ずらす必要はない、Lが固定するのはindexで-2,-1
for t in L:  
    for i in range(l):
        if (s[i]=="x") ^ (t[-1] == "W"):
            if t[-2]=="S":
                t+= "W"
            else:
                t += "S"
            
        else:
            t += t[-2]
    if t[:2]==t[-2:]:
        print(t)
        sys.exit()
print(-1)

Submission status: Wrong Answer

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

L = ["SS","SW","WS","WW"]
l= len(s)
##0,1に置き換えたりしない
##条件分岐注意する
for t in L:  
    for i in range(1,l+1):
        if (s[(i+l)%l]=="x") ^ (t[-1] == "W"):
            if t[-2]=="S":
                t+= "W"
            else:
                t += "S"
            
        else:
            t += t[-2]
    if t[0:2]==t[-2:]:
        print(t)
        sys.exit()
print(-1)

Submission status: Wrong Answer

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

L = ["SS","SW","WS","WW"]
l= len(s)

for t in L:  
    for i in range(1,l+1):
        if (s[(i+l)%l]=="x") ^ (t[-1] == "W"):
            t += t[-2]
        else:
            if t[-2]=="S":
                t+= "W"
            else:
                t += "S"
    if t[0:2]==t[-2:]:
        print(t)
        sys.exit()
print(-1)

Submission status: Wrong Answer

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

L = [0,1,2,3]
l= len(s)

for t in L:
    u = [t&1,(t>>1)&1]
    for i in range(1,l+1):
        if (s[(i+l)%l]=="x") ^ u[(i+l)%l]:
            u.append(u[-2])
        else:
            u.append(1-u[-2])
    if u[0:2]==u[-2:]:
        for i in range(len(s)):
            if u[i]==1:
                print("W",end = "")
            else:
                print("S",end = "")
        sys.exit()
print(-1)

Submission status: Wrong Answer

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

L = [0,1,2,3]
l= len(s)

for t in L:
    u = [t&1,(t>>1)&1]
    for i in range(1,l+1):
        if (s[(i+l)%l]=="x") ^ u[(i+l)%l]:
            u.append(u[-2])
        else:
            u.append(1-u[-2])
    if u[0:3]==u[-3:]:
        for i in range(len(s)):
            if u[i]==1:
                print("W",end = "")
            else:
                print("S",end = "")
        sys.exit()
print(-1)

Submission status: Wrong Answer

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

L = [0,1,2,3]
l= len(s)

for t in L:
    u = [t&1,(t>>1)&1]
    for i in range(1,l+1):
        if (s[(i+l)%l]=="x") ^ u[(i+l)%l]:
            u.append(u[-2])
        else:
            u.append(1-u[-2])
    if u[0:3]==u[-3:]:
        for i in range(len(s)):
            if u[i]==0:
                print("W",end = "")
            else:
                print("S",end = "")
        sys.exit()
print(-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
st = [["S","S"],["S","W"],["W","W"],["W","S"]]
key = "F"
for i in st:
    ans = i
    a0,a1 = i
    for j in range(1,n):
        #print(a0,a1,s[j])
        if s[j] == "o":
            if a1 == "S":
                if a0 == "S":
                    ans.append("S")
                    a0 = "S"
                    a1 = "S"
                else:
                    ans.append("W")
                    a0 = "S"
                    a1 = "W"
            else:
                if a0 == "S":
                    ans.append("W")
                    a0 = "W"
                    a1 = "W"
                else:
                    ans.append("S")
                    a0 = "W"
                    a1 = "S"
        else:
            if a1 == "W":
                if a0 == "S":
                    ans.append("S")
                    a0 = "W"
                    a1 = "S"
                else:
                    ans.append("W")
                    a0 = "W"
                    a1 = "W"
            else:
                if a0 == "S":
                    ans.append("W")
                    a0 = "S"
                    a1 = "W"
                else:
                    ans.append("S")
                    a0 = "S"
                    a1 = "S"
    if ans[0] == ans[n]:
        key = "T"
        break
if key == "T":
    for i in range(n):
        print(ans[i],end="")
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return "".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n = onem()

a = list(input())[:-1]

kkk = []

aa = s(a)

co = 0
for i in range(len(aa)):
    if aa[i][0] == 'o':
        if co % 2 == 0:
            for j in range(aa[i][1]):
                kkk.append("S")
        else:
            for j in range(aa[i][1]):
                kkk.append("W")
        co += 1
    else:
        for j in range(aa[i][1]):
                kkk.append("S")
for i in range(n):
    if i == 0:
        if kkk[i] == "S":
            if a[i] == "o":
                if kkk[-1] != kkk[i+1]:
                    print(-1)
                    exit()
            else:
                if kkk[-1] == kkk[i+1]:
                    print(-1)
                    exit()
    elif i == n-1:
        if kkk[i] == "S":
            if a[i] == "o":
                if kkk[i-1] != kkk[0]:
                    print(-1)
                    exit()
            else:
                if kkk[i-1] == kkk[0]:
                    print(-1)
                    exit()
    else:
        if kkk[i] == "S":
            if a[i] == "o":
                if kkk[i-1] != kkk[i+1]:
                    print(-1)
                    exit()
            else:
                if kkk[i-1] == kkk[i+1]:
                    print(-1)
                    exit()
print(jo(kkk))

Submission status: Wrong Answer

Solution code:
N=int(input())
s=list(input())
for i in range(2**2):
  sw=[1,1]
  ans=[1]*(N+1)
  for j in range(2):
    if (i>>j)%2==1:
      sw[j]=0
      ans[j]=0
  for j in range(1,N):
    if sw[1]== 1:
      if s[j]=="o":
        sw[0],sw[1]=sw[1],sw[0]
      else:
        sw[0],sw[1]=sw[1],(sw[0])^1
    else:
      if s[j]=="o":
        sw[0],sw[1]=sw[1],(sw[0])^1
      else:
        sw[0],sw[1]=sw[1],sw[0]
    ans[j+1]=sw[1]
  if ans[0]==ans[N]:
    for i in range(N):
      if ans[i]==1:
        ans[i]="S"
      else:
        ans[i]="W"
    print("".join(ans[:N]))
    exit(0)
  else:
    continue
print(-1)

Submission status: Wrong Answer

Solution code:
import sys

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

N = ri()
S = rs()
d = {'S': 'W', 'W': 'S'}
for x in ['SS', 'SW', 'WS', 'WW']:
    animals = x
    for i in range(N):
        if S[i] == 'o':
            if animals[i+1] == 'S':
                animals += animals[i]
            else:
                animals += d[animals[i]]
        else:
            if animals[i+1] == 'S':
                animals += d[animals[i]]
            else:
                animals += animals[i]
    if animals[0] == animals[-1]:
        print(animals[1:])
        exit()

print(-1)

#08

Submission status: Wrong Answer

Solution code:
import sys
import math

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

N = ri()
S = rs()
d = {'S': 'W', 'W': 'S'}
for x in ['SS', 'SW', 'WS', 'WW']:
    animals = x
    for i in range(1, N):
        if S[i] == 'o':
            if animals[i] == 'S':
                animals += animals[i-1]
            else:
                animals += d[animals[i-1]]
        else:
            if animals[i] == 'S':
                animals += d[animals[i-1]]
            else:
                animals += animals[i-1]
    if animals[0] == animals[-1]:
        print(animals[:-1])
        exit()

print(-1)

#08

Submission status: Wrong Answer

Solution code:
def main():
  N = int(input())
  s = input()
  L = [["S","S"],["S","W"],["W","W"],["W","S"]]
  for i in range(1,N):
    for j in range(4):
      if s[i] == "o":
        if L[j][-1] == "S":
          L[j].append(L[j][-2])
        else:
          if L[j][-2] == "S":
            L[j].append("W")
          else:
            L[j].append("S")
      else:
        if L[j][-1] == "S":
          if L[j][-2] == "S":
            L[j].append("W")
          else:
            L[j].append("S")
        else:
          L[j].append(L[j][-2])
  for i in range(4):
    if L[i][0] == L[i][-1]:
      print(*L[i][:-1],sep="")
      exit()
  print(-1)
main()

Submission status: Wrong Answer

Solution code:
import math
import random
from operator import itemgetter
import re
import sys
from itertools import accumulate
from collections import defaultdict
from collections import deque
from bisect import bisect_left,bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
N = int(input())
s = input()
ans = ""
for i in range(4):
    ren = i
    if ren %2 == 0:
        ans = "S"
    else:
        ans = "W"
    for j in range(N):
        if ren == 0:
            if s[j] == "o":
                ans = ans + "S"
            else:
                ans = ans + "W"
                ren = 1
        elif ren ==1:
            if s[j] == "o":
                ans = ans + "W"
                ren = 3
            else:
                ans = ans + "S"
                ren = 2
        elif ren ==2:
            if s[j] == "o":
                ans = ans + "W"
                ren = 1
            else:
                ans = ans + "S"
                ren = 0
        else:
            if s[j] == "o":
                ans = ans + "S"
                ren = 2
            else:
                ans = ans + "W"
                ren = 3
    if ans[0] == ans[N]:
        ans = ans[0:N]
        break
    else:
        if i == 3:
            ans = "-1"
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
w1=list(input())
s="S"
w="W"
o="o"
x="x"
l=[[s,s],[s,w],[w,w],[w,s]]
for j in range(4):
    for i in range(1,n):
        if w1[i]==o:
            if l[j][-1]==s:
                if l[j][-2]==s:
                    l[j].append(s)
                else:
                    l[j].append(w)
            else:
                if l[j][-2]==s:
                    l[j].append(w)
                else:
                    l[j].append(s)
        else:
            if l[j][-1]==s:
                if l[j][-2]==s:
                    l[j].append(w)
                else:
                    l[j].append(s)
            else:
                if l[j][-2]==s:
                    l[j].append(s)
                else:
                    l[j].append(w)
b=False
for i in range(4):
  if l[i][0]==l[i][-1] and not b:
    del l[i][-1]
    if (l[i][1]==l[i][n-1] and w1[0]==o) or (l[i][1]!=l[i][n-1] and w1[0]==x):
      answer=l[i]
      b=True
      break
if not b:
    print(-1)
else:
    print("".join(answer))

Submission status: Wrong Answer

Solution code:
n=int(input())
w1=list(input())
s="S"
w="W"
o="o"
x="x"
l=[[s,s],[s,w],[w,w],[w,s]]
for j in range(4):
    for i in range(1,n):
        if w1[i]==o:
            if l[j][-1]==s:
                if l[j][-2]==s:
                    l[j].append(s)
                else:
                    l[j].append(w)
            else:
                if l[j][-2]==s:
                    l[j].append(w)
                else:
                    l[j].append(s)
        else:
            if l[j][-1]==s:
                if l[j][-2]==s:
                    l[j].append(w)
                else:
                    l[j].append(s)
            else:
                if l[j][-2]==s:
                    l[j].append(s)
                else:
                    l[j].append(w)
b=False
for i in range(4):
  if l[i][0]==l[i][-1] and not b:
    del l[i][-1]
    if (l[i][1]==l[i][-1] and w[0]==o) or (l[i][1]!=l[i][-1] and w[0]==x):
      answer=l[i]
      b=True
      break
if not b:
    print(-1)
else:
    print("".join(answer))

Submission status: Wrong Answer

Solution code:
n=int(input())
w1=list(input())
s="S"
w="W"
o="o"
x="x"
l=[[s,s],[s,w],[w,w],[w,s]]
for j in range(4):
    for i in range(1,n):
        if w1[i]==o:
            if l[j][-1]==s:
                if l[j][-2]==s:
                    l[j].append(s)
                else:
                    l[j].append(w)
            else:
                if l[j][-2]==s:
                    l[j].append(w)
                else:
                    l[j].append(s)
        else:
            if l[j][-1]==s:
                if l[j][-2]==s:
                    l[j].append(w)
                else:
                    l[j].append(s)
            else:
                if l[j][-2]==s:
                    l[j].append(s)
                else:
                    l[j].append(w)
b=False
for i in range(4):
  if l[i][0]==l[i][-1]:
    del l[i][-1]
    answer=l[i]
    b=True
    break
if not b:
    print(-1)
else:
    print("".join(answer))

Submission status: Wrong Answer

Solution code:
n=int(input())
w1=list(input())
s="S"
w="W"
o="o"
x="x"
ans=[[s,s],[s,w],[w,w],[w,s]]
def solve(l):
    for i in range(1,n):
        if w1[i]==o:
            if l[-1]==s:
                if l[-2]==s:
                    l.append(s)
                else:
                    l.append(w)
            else:
                if l[-2]==s:
                    l.append(w)
                else:
                    l.append(s)
        else:
            if l[-1]==s:
                if l[-2]==s:
                    l.append(w)
                else:
                    l.append(s)
            else:
                if l[-2]==s:
                    l.append(s)
                else:
                    l.append(w)
    return 
b=False
for i in range(4):
    solve(ans[i])
for i in range(4):
  if ans[i][0]==ans[i][-1]:
    del ans[i][-1]
    answer=ans[i]
    b=True
    break
if not b:
    print(-1)
else:
    print("".join(answer))

Submission status: Wrong Answer

Solution code:
n=int(input())
w1=list(input())
s="S"
w="W"
o="o"
x="x"
ans=[[s,s],[s,w],[w,w],[w,s]]
def solve(l):
    ans1=l
    for i in range(1,n):
        if w1[i]==o:
            if ans1[-1]==s:
                if ans1[-2]==s:
                    ans1.append(s)
                else:
                    ans1.append(w)
            else:
                if ans1[-2]==s:
                    ans1.append(w)
                else:
                    ans1.append(s)
        else:
            if ans1[-1]==s:
                if ans1[-2]==s:
                    ans1.append(w)
                else:
                    ans1.append(s)
            else:
                if ans1[-2]==s:
                    ans1.append(s)
                else:
                    ans1.append(w)
    return ans1
b=False
for i in range(4):
    if not b:
        a=solve(ans[i])
        if a[0]==a[-1]:
            del a[-1]
            answer=a
            b=True
if not b:
    print(-1)
else:
    print("".join(answer))

Submission status: Wrong Answer

Solution code:
n=int(input())
w1=list(input())
s="S"
w="W"
o="o"
x="x"
ans=[[s,s],[s,w],[w,w],[w,s]]
def solve(l):
    ans1=l
    for i in range(1,n):
        if w1[i]==o:
            if ans1[-1]==s:
                if ans1[-2]==s:
                    ans1.append(s)
                else:
                    ans1.append(w)
            else:
                if ans1[-2]==s:
                    ans1.append(w)
                else:
                    ans1.append(s)
        else:
            if ans1[-1]==s:
                if ans1[-2]==s:
                    ans1.append(w)
                else:
                    ans1.append(s)
            else:
                if ans1[-2]==s:
                    ans1.append(s)
                else:
                    ans1.append(w)
    if ans1[-1]==ans1[0]:
        del ans1[-1]
        return ans1
    else:
        return False
b=False
for i in range(4):
    if not b:
         a=solve(ans[i])
         if a!=False:
            b=True
            answer=a
if not b:
    print(-1)
else:
    print("".join(answer))

Submission status: Wrong Answer

Solution code:
n=int(input())
w1=list(input())
s="S"
w="W"
o="o"
x="x"
ans=[[s,s],[s,w],[w,w],[w,s]]
def solve(l):
    ans1=l
    for i in range(1,n):
        if w1[i]==o:
            if ans1[-1]==s:
                if ans1[-2]==s:
                    ans1.append(s)
                else:
                    ans1.append(w)
            else:
                if ans1[-2]==s:
                    ans1.append(w)
                else:
                    ans1.append(s)
        else:
            if ans1[-1]==s:
                if ans1[-2]==s:
                    ans1.append(w)
                else:
                    ans1.append(s)
            else:
                if ans1[-2]==s:
                    ans1.append(s)
                else:
                    ans1.append(w)
    if ans1[-1]==ans1[1]:
        del ans1[-1]
        return ans1
    else:
        return False
b=False
for i in range(4):
    if not b:
         a=solve(ans[i])
         if a!=False:
              b=True
              answer=a
if not b:
    print(-1)
else:
    print("".join(answer))

Submission status: Wrong Answer

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

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

for i in range(4):
    flag=0
    dp=[-1]*n
    flag=test(dp,n,i&1,i>>1)
    if flag!=-1:
        break
    
if flag==-1:
    print(-1)
    sys.exit()
for i in range(n):
    if dp[i]==0:
        print('S',end='')
    else:
        print('W',end='')
print('\n')

Submission status: Wrong Answer

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

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

dp=[-1]*n
for i in range(4):
    flag=0
    flag=test(dp,n,i&1,i>>1)
    if flag!=-1:
        break
    
if flag==-1:
    print(-1)
    sys.exit()
for i in range(n):
    if dp[i]==0:
        print('S',end='')
    else:
        print('W',end='')
print('\n')