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

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

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

    else:
        if i[0]=='W':
            print(i)
            exit()

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

    else:
        if i[0]=='S':
            print(i)
            exit()


print(-1)

Submission status: Wrong Answer

Solution code:
d = {"WWo": "S",
     "WSo": "W",
     "SWo": "W",
     "SSo": "S",
     "WWx": "W",
     "WSx": "S",
     "SWx": "S",
     "SSx": "W",
    }

combo = ["SS","SW","WS","WW"]

N = int(input())
z = input()

matched = False
txt = []
for c in combo:
  keep = c[0]
  left = c
  txt = [c[1]]
  for i in range(N-1):
    new_ch = d[left+z[i]]
    left = left[1] + new_ch
    txt.append(left[1])
  if txt[-1] + txt[0] == c:
    matched = True
    break

if matched:
  print(*txt,sep="")
else:
  print("-1")

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
ans1="SS"
ans2="SW"
ans3="WS"
ans4="WW"
def check(ans):
    for i in range(1,n-1):
        if s[i]=="o"  and ans[i]=="S":
            ans+=ans[i-1]
        elif s[i]=="o" and ans[i]=="W":
            if ans[i-1]=="W":
                ans+="S"
            else:
                ans+="W"
         
        elif s[i]=="x"  and ans[i]=="S":
            if ans[i-1]=="W":
                ans+="S"
            else:
                ans+="W"
        elif s[i]=="x" and  ans[i]=="W":
            ans+=ans[i-1]
    if s[n-1]=="o":
        if ans[n-1]=="S":
            if ans[0]==ans[n-2]:
                print(ans)
                exit()
    if s[n-1]=="o":
        if ans[n-1]=="W":
            if ans[0]!=ans[n-2]:
                print(ans)
                exit()
    if s[n-1]=="x":
        if ans[n-1]=="S":
            if ans[0]!=ans[n-2]:
                print(ans)
                exit()
    if s[n-1]=="x":
        if ans[n-1]=="W":
            if ans[0]==ans[n-2]:
                print(ans)
                exit()
check(ans1)
check(ans2)
check(ans3)
check(ans4)
print(-1)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
ans1="SS"
ans2="SW"
ans3="WS"
ans4="WW"
def check(ans):
    for i in range(1,n-1):
        if s[i]=="o"  and ans[i]=="S":
            ans+=ans[i-1]
        elif s[i]=="o" and ans[i]=="W":
            if s[i-1]=="W":
                ans+="S"
            else:
                ans+="W"
         
        elif s[i]=="x"  and ans[i]=="S":
            if s[i-1]=="W":
                ans+="S"
            else:
                ans+="W"
        elif s[i]=="x" and  ans[i]=="W":
            ans+=ans[i-1]
    if s[n-1]=="o":
        if ans[n-1]=="S":
            if ans[0]==ans[n-2]:
                print(ans)
                exit()
    if s[n-1]=="o":
        if ans[n-1]=="W":
            if ans[0]!=ans[n-2]:
                print(ans)
                exit()
    if s[n-1]=="x":
        if ans[n-1]=="S":
            if ans[0]!=ans[n-2]:
                print(ans)
                exit()
    if s[n-1]=="x":
        if ans[n-1]=="W":
            if ans[0]==ans[n-2]:
                print(ans)
                exit()
check(ans1)
check(ans2)
check(ans3)
check(ans4)
print(-1)

Submission status: Wrong Answer

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

# ls[i]とls[i-1]の情報からls[i+1]を決定する関数
def decide_right(ls):
    '''
    ls[0]とls[1]が確定したlsを与えられたら、その情報からls全体(一意に定まる)を返す
    '''
    N = len(ls)
    for i in range(1,N-1):
        if ls[i] == 'S':
            if s[i] == 'o':
                ls[i+1] = ls[i-1]
            else:
                if ls[i-1] == 'S':
                    ls[i+1] = 'W'
                else:
                    ls[i+1] = 'S'
        else:
            if s[i] == 'o':
                if ls[i-1] == 'S':
                    ls[i+1] = 'W'
                else:
                    ls[i+1] = 'S'
            else:
                ls[i+1] = ls[i-1]
    return ls

'''
def decide_left(ls):
    #ls[1]とls[0]が確定したlsを与えられたら、その情報からls全体(一意に定まる)を返す
    
    N = len(ls)
    for i in range(N,0,-1):
        if s[i] == 'o':
            ls[i-1] = ls[i+1]
        else:
            if ls[i+1] == 'S':
                ls[i-1] = 'W'
            else:
                ls[i-1] = 'S'
'''

def check(first):
    # 矛盾のないlsを発見し次第それをreturn、可能性が無くなったらFalseをリターン
    # ls1は左から決めていく
    ls1 = [0] * (n+1)
    ls1[0] = first

    for second in ['S','W']:
        ls1[1] = second
        ls1 = decide_right(ls1)
        
        if ls1[0] != ls1[-1]:
            continue
        
        # 0の両隣の判定

        if s[0] == 'o' and ls1[1] != ls1[-2]:
            continue
        if s[0] == 'x' and ls1[1] == ls1[-2]:
            continue
        '''
        ls2 = [0] * (n+1)
        ls2[-1] = first
        if s[0] == 'o':
            ls2[-2] = second
        else:
            if second == 'S':
                ls2[-2] = 'W'
            else:
                ls2[-2] = 'S'
        ls2 = decide_left(ls2)
        if ls2[0] != ls2[-1]:
            continue
        
        for i in range(n+1):
            if ls1[i] != ls2[i]:
                continue
        '''
        
        return ls1[:-1]
    
    return False

for first in ['S','W']:
    c = check(first)
    if c:
        print(*c,sep='')
        sys.exit()
print(-1)

Submission status: Wrong Answer

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

# ls[i]とls[i-1]の情報からls[i+1]を決定する関数
def decide_right(ls):
    '''
    ls[0]とls[1]が確定したlsを与えられたら、その情報からls全体(一意に定まる)を返す
    '''
    N = len(ls)
    for i in range(1,N-1):
        if ls[i] == 'S':
            if s[i] == 'o':
                ls[i+1] = ls[i-1]
            else:
                if ls[i-1] == 'S':
                    ls[i+1] = 'W'
                else:
                    ls[i+1] = 'S'
        else:
            if s[i] == 'o':
                if ls[i-1] == 'S':
                    ls[i+1] = 'W'
                else:
                    ls[i+1] = 'S'
            else:
                ls[i+1] = ls[i-1]
    return ls

'''
def decide_left(ls):
    #ls[1]とls[0]が確定したlsを与えられたら、その情報からls全体(一意に定まる)を返す
    
    N = len(ls)
    for i in range(N,0,-1):
        if s[i] == 'o':
            ls[i-1] = ls[i+1]
        else:
            if ls[i+1] == 'S':
                ls[i-1] = 'W'
            else:
                ls[i-1] = 'S'
'''

def check(first):
    # 矛盾のないlsを発見し次第それをreturn、可能性が無くなったらFalseをリターン
    # ls1は左から決めていく
    ls1 = [0] * (n+1)
    ls1[0] = first

    for second in ['S','W']:
        ls1[1] = second
        ls1 = decide_right(ls1)
        
        if ls1[0] != ls1[-1]:
            continue
        
        # 0の両隣の判定

        if s[0] == 'o' and ls1[1] != ls1[-2]:
            break
        if s[0] == 'x' and ls1[1] == ls1[-2]:
            break
        '''
        ls2 = [0] * (n+1)
        ls2[-1] = first
        if s[0] == 'o':
            ls2[-2] = second
        else:
            if second == 'S':
                ls2[-2] = 'W'
            else:
                ls2[-2] = 'S'
        ls2 = decide_left(ls2)
        if ls2[0] != ls2[-1]:
            continue
        
        for i in range(n+1):
            if ls1[i] != ls2[i]:
                continue
        '''
        
        return ls1[:-1]
    
    return False

for first in ['S','W']:
    c = check(first)
    if c:
        print(*c,sep='')
        sys.exit()
print(-1)

Submission status: Wrong Answer

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

# ls[i]とls[i-1]の情報からls[i+1]を決定する関数
def decide_right(ls):
    '''
    ls[0]とls[1]が確定したlsを与えられたら、その情報からls全体(一意に定まる)を返す
    '''
    N = len(ls)
    for i in range(1,N-1):
        if ls[i] == 'S':
            if s[i] == 'o':
                ls[i+1] = ls[i-1]
            else:
                if ls[i-1] == 'S':
                    ls[i+1] = 'W'
                else:
                    ls[i+1] = 'S'
        else:
            if s[i] == 'o':
                if ls[i-1] == 'S':
                    ls[i+1] = 'W'
                else:
                    ls[i+1] = 'S'
            else:
                ls[i+1] = ls[i-1]
    return ls

'''
def decide_left(ls):
    #ls[1]とls[0]が確定したlsを与えられたら、その情報からls全体(一意に定まる)を返す
    
    N = len(ls)
    for i in range(N,0,-1):
        if s[i] == 'o':
            ls[i-1] = ls[i+1]
        else:
            if ls[i+1] == 'S':
                ls[i-1] = 'W'
            else:
                ls[i-1] = 'S'
'''

def check(first):
    # 矛盾のないlsを発見し次第それをreturn、可能性が無くなったらFalseをリターン
    # ls1は左から決めていく
    ls1 = [0] * (n+1)
    ls1[0] = first

    for second in ['S','W']:
        ls1[1] = second
        ls1 = decide_right(ls1)
        
        if ls1[0] != ls1[-1]:
            continue
        
        '''
        ls2 = [0] * (n+1)
        ls2[-1] = first
        if s[0] == 'o':
            ls2[-2] = second
        else:
            if second == 'S':
                ls2[-2] = 'W'
            else:
                ls2[-2] = 'S'
        ls2 = decide_left(ls2)
        if ls2[0] != ls2[-1]:
            continue
        
        for i in range(n+1):
            if ls1[i] != ls2[i]:
                continue
        '''
        
        return ls1[:-1]
    
    return False

for first in ['S','W']:
    c = check(first)
    if c:
        print(*c,sep='')
        sys.exit()
print(-1)

Submission status: Wrong Answer

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

start = ["SS", "SW", "WS", "WW"]

for st in start:
    ans = st
    for i in range(1, n):
        if s[i] == "o" and ans[i] == "S":
            if ans[i-1] == "S":
                ans += "S"
            else:
                ans += "W"
        elif s[i] == "x" and ans[i] == "S":
            if ans[i-1] == "S":
                ans += "W"
            else:
                ans += "S"
        elif s[i] == "o" and ans[i] == "W":
            if ans[i-1] == "S":
                ans += "W"
            else:
                ans += "S"
        elif s[i] == "x" and ans[i] == "W":
            if ans[i-1] == "S":
                ans += "S"
            else:
                ans += "W"
    if ans[0] == ans[-1]:
        print(ans[:n])
        exit()

print(-1)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
ani = ["S","W"]
ans = ""
par = 0

if S.count("x")%2==1:
  print(-1)
else:
  for s in S:
    if s=="o":
      ans+=ani[par]
    else:
      if par==0:
        ans+=ani[0]
        par = 1
      else:
        ans+=ani[0]
        par = 0
  print(ans)

Submission status: Wrong Answer

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

# S:1 W:-1
T = [[1, 1], [1, -1], [-1, 1], [-1, -1]]
for t in T:
    for i in range(n-2):
        if t[i+1] == 1:
            if s[i+1] == "o":
                t.append(t[i])
            else:
                t.append(-1*t[i])
        else:
            if s[i+1] == "o":
                t.append(-1*t[i])
            else:
                t.append(t[i])
#print(T)
for t in T:
    if t[0] == 1:
        if s[0] == "o" and t[-1] == t[1]:
            ans = t
            break
        elif s[0] == "x" and t[-1] != t[1]:
            ans = t
            break
    elif t[0] == -1:
        if s[0] == "o" and t[-1] != t[1]:
            ans = t
            break
        elif s[0] == "x" and t[-1] == t[1]:
            ans = t
            break
else:
    print(-1)
    exit()
        

str_ans = ""
for i in range(n):
    if ans[i] == 1:
        str_ans += "S"
    elif ans[i] == -1:
        str_ans += "W"
print(str_ans)

Submission status: Wrong Answer

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

# S:1 W:-1
T = [[1, 1], [1, -1], [-1, 1], [-1, -1]]
for t in T:
    for i in range(n-1):
        if t[i+1] == 1:
            if s[i+1] == "o":
                t.append(t[i])
            else:
                t.append(-1*t[i])
        else:
            if s[i+1] == "o":
                t.append(-1*t[i])
            else:
                t.append(t[i])
#print(T)
for t in T:
    if t[0] == t[-1]:
        ans = t[:n]
        break
else:
    print(-1)
    exit()

str_ans = ""
for i in range(n):
    if ans[i] == 1:
        str_ans += "S"
    elif ans[i] == -1:
        str_ans += "W"
print(str_ans)

Submission status: Wrong Answer

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

# 一匹目、二匹目について4通り試す
# 羊:True, 狼:False
from itertools import product
for tf in product([True, False], repeat=2):
    tf = list(tf)
    for i in range(1, n):
        if s[i] == 'o':
            if tf[i]:
                tf.append(tf[i-1])
            else:
                tf.append(not tf[i-1])
        else:
            if tf[i]:
                tf.append(not tf[i-1])
            else:
                tf.append(tf[i-1])

    if tf[0] == tf[-1]:
        tf.pop(-1)
        for i in range(n):
            if tf[i]:
                tf[i] = 'S'
            else:
                tf[i] = 'W'
        print(''.join(tf))
        exit()

print(-1)

Submission status: Wrong Answer

Solution code:
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  N=I()
  s=S()
  a=['S','W']
  aa=(['S','S'],['S','W'],['W','S'],['W','W'])

  for ans in aa:
    for i in range(1,N-1):
      if ans[i]=='S':
        if s[i]=='o':
          ans.append(ans[i-1])
        else:
          ind=a.index(ans[i-1])
          ans.append(a[1-ind])
      else:
        if s[i]=='o':
          ind=a.index(ans[i-1])
          ans.append(a[1-ind])
        else:
          ans.append(ans[i-1])
    if ans[0]==ans[-1]:
      stress=''.join(str(x) for x in ans)
      f=True
      for i in range(N):
        if stress[i]=='S':
          if i==0:
            if s[i]=='o':
              if not (stress[-1]==stress[i+1]):
                # return 'aaa1'+' '+stress
                f=False
            else:
              if not (stress[-1]!=stress[i+1]):
                # return 'aaa2'
                f=False
          elif i==N-1:
            if s[i]=='o':
              if not (stress[i-1]==stress[0]):
                # return 'aaa3'
                f=False
            else:
              if not (stress[i-1]!=stress[0]):
                # return 'aaa4'
                f=False
          else:
            if s[i]=='o':
              if not (stress[i-1]==stress[i+1]):
                # return 'aaa5'
                f=False
            else:
              if not (stress[i-1]!=stress[i+1]):
                # return 'aaa6'
                f=False
        else:
          if i==0:
            if s[i]=='o':
              if not (stress[-1]!=stress[i+1]):
                # return 'bbb1'
                f=False
            else:
              if not (stress[-1]==stress[i+1]):
                # return 'bbb2'
                f=False
          elif i==N-1:
            if s[i]=='o':
              if not (stress[i-1]!=stress[0]):
                # return 'bbb3'
                f=False
            else:
              if not (stress[i-1]==stress[0]):
                # return 'bbb4'
                f=False
          else:
            if s[i]=='o':
              if not (stress[i-1]!=stress[i+1]):
                # return 'bbb5'
                f=False
            else:
              if not (stress[i-1]==stress[i+1]):
                # return 'bbb6'
                f=False

      if f:
        return ''.join(str(x) for x in ans)

  return -1

# main()
print(main())

Submission status: Wrong Answer

Solution code:
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  N=I()
  s=S()
  a=['S','W']
  aa=(['S','S'],['S','W'],['W','S'],['W','W'])

  for ans in aa:
    for i in range(1,N):
      if ans[i]=='S':
        if s[i]=='o':
          ans.append(ans[i-1])
        else:
          ind=a.index(ans[i-1])
          ans.append(a[1-ind])
      else:
        if s[i]=='o':
          ind=a.index(ans[i-1])
          ans.append(a[1-ind])
        else:
          ans.append(ans[i-1])
    if ans[0]==ans[-1]:
      return ''.join(str(x) for x in ans[:-1])

  return -1

# main()
print(main())

Submission status: Wrong Answer

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

init = ["SS", "SW", "WS", "WW"]
next_animal = { ("S","o","S"):"S",
                ("S","o","W"):"W",
                ("S","x","S"):"W",
                ("S","x","W"):"S",
                ("W","o","S"):"W",
                ("W","o","W"):"S",
                ("W","x","S"):"S",
                ("W","x","W"):"W"}
for X in init:
    SW = X
    for i in range(1,N):
        SW += next_animal[SW[i],s[i],SW[i-1]]
    ls = len(SW)
    if SW[0] == SW[ls-1] and next_animal[SW[0],s[0],SW[ls-1]] == SW[1]:
        print(SW[:ls-1])
        break
else:
    print(-1)

Submission status: Wrong Answer

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

init = ["SS", "SW", "WS", "WW"]
next_animal = { ("S","o","S"):"S",
                ("S","o","W"):"W",
                ("S","x","S"):"W",
                ("S","x","W"):"S",
                ("W","o","S"):"W",
                ("W","o","W"):"S",
                ("W","x","S"):"S",
                ("W","x","W"):"W"}
for X in init:
    SW = X
    for i in range(1,N):
        SW += next_animal[SW[i],s[i],SW[i-1]]
    if SW[0] == SW[len(SW)-1]:
        print(SW[:len(SW)-1])
        break
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    s = list(input())
    ans = "-1"
    for init in ["S", "W"]:
        if ans != "-1":
            break
        for next in ["S", "W"]:
            now_ans = ["" for _ in range(n)]
            now_ans[0] = init
            now_ans[1] = next
            for i in range(1, n - 1):
                if [now_ans[i], s[i]] in [["S", "o"], ["W", "x"]]:
                    now_ans[i + 1] = now_ans[i - 1]
                else:
                    now_ans[i + 1] = "W" if now_ans[i - 1] == "S" else "S"
            if [now_ans[-1], s[-1]] in [["S", "o"], ["W", "x"]] and init == now_ans[-2]:
                ans = "".join(now_ans)
                break
            elif [now_ans[-1], s[-1]] in [["S", "x"], ["W", "o"]] and init != now_ans[-2]:
                ans = "".join(now_ans)
                break
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
s = input()
not_sw = {'S':'W', 'W':'S'}

for sw1 in ['S', 'W']:
    for sw2 in ['S', 'W']:
        flag = True
        ans = [''] * (N+1)
        ans[0] = sw1
        ans[-1] = sw1
        if (s[0] == 'o' and ans[0] == 'S')  or (s[0] == 'x' and ans[0] == 'W'):
            ans[1] = sw2
            ans[-2] = sw2
        elif (s[0] == 'x' and ans[0] == 'S')  or (s[0] == 'o' and ans[0] == 'W'):
            ans[1] = not_sw[sw2]
            ans[-2] = sw2
        for i in range(1, N-1):
            if (s[i] == 'o' and ans[i] == 'S')  or (s[i] == 'x' and ans[i] == 'W'):
                ans[i+1] = ans[i-1]
            elif (s[i] == 'x' and ans[i] == 'S')  or (s[i] == 'o' and ans[i] == 'W'):
                ans[i+1] = not_sw[ans[i-1]]
        for i in range(N-2, N):
            if (s[i] == 'o' and ans[i] == 'S')  or (s[i] == 'x' and ans[i] == 'W'):
                if ans[i+1] != ans[i-1]:
                    flag = False
            elif (s[i] == 'x' and ans[i] == 'S')  or (s[i] == 'o' and ans[i] == 'W'):
                if ans[i+1] != not_sw[ans[i-1]]:
                    flag = False
        if flag:
            print(''.join(ans[:-1]))
            sys.exit()
print(-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
res = 'S'
if s[0] == 'o':
    res += 'S'
    for i in range(2,n+1):
        if s[i-1] == 'o':
            if res[i-1] == 'S':
                t = res[i-2]
            else:
                if res[i-2] == 'S':
                    t = 'W'
                else:
                    t = 'S'
        else:
            if res[i - 1] == 'S':
                if res[i-2] == 'S':
                    t = 'W'
                else:
                    t = 'S'
            else:
                t = res[i - 2]
        res += t
    if res[-1] == 'S':
        print(res[:-1])
        exit()
res = 'S'
if s[0] == 'o':
    res += 'W'
    for i in range(2,n+1):
        if s[i-1] == 'o':
            if res[i-1] == 'S':
                t = res[i-2]
            else:
                if res[i-2] == 'S':
                    t = 'W'
                else:
                    t = 'S'
        else:
            if res[i - 1] == 'S':
                if res[i-2] == 'S':
                    t = 'W'
                else:
                    t = 'S'
            else:
                t = res[i - 2]
        res += t
    if res[-1] == 'S':
        print(res[:-1])
        exit()
res = 'S'
if s[0] == 'x':
    res += 'S'
    for i in range(2,n+1):
        if s[i-1] == 'o':
            if res[i-1] == 'S':
                t = res[i-2]
            else:
                if res[i-2] == 'S':
                    t = 'W'
                else:
                    t = 'S'
        else:
            if res[i - 1] == 'S':
                if res[i-2] == 'S':
                    t = 'W'
                else:
                    t = 'S'
            else:
                t = res[i - 2]
        res += t
    if res[-1] == 'S':
        print(res[:-1])
        exit()
res = 'S'
if s[0] == 'x':
    res += 'W'
    for i in range(2,n+1):
        if s[i-1] == 'o':
            if res[i-1] == 'S':
                t = res[i-2]
            else:
                if res[i-2] == 'S':
                    t = 'W'
                else:
                    t = 'S'
        else:
            if res[i - 1] == 'S':
                if res[i-2] == 'S':
                    t = 'W'
                else:
                    t = 'S'
            else:
                t = res[i - 2]
        res += t
    if res[-1] == 'S':
        print(res[:-1])
        exit()

res = 'W'
if s[0] == 'o':
    res += 'S'
    for i in range(2,n+1):
        if s[i-1] == 'o':
            if res[i-1] == 'S':
                t = res[i-2]
            else:
                if res[i-2] == 'S':
                    t = 'W'
                else:
                    t = 'S'
        else:
            if res[i - 1] == 'S':
                if res[i-2] == 'S':
                    t = 'W'
                else:
                    t = 'S'
            else:
                t = res[i - 2]
        res += t
    if res[-1] == 'W':
        print(res[:-1])
        exit()
res = 'W'
if s[0] == 'o':
    res += 'W'
    for i in range(2,n+1):
        if s[i-1] == 'o':
            if res[i-1] == 'S':
                t = res[i-2]
            else:
                if res[i-2] == 'S':
                    t = 'W'
                else:
                    t = 'S'
        else:
            if res[i - 1] == 'S':
                if res[i-2] == 'S':
                    t = 'W'
                else:
                    t = 'S'
            else:
                t = res[i - 2]
        res += t
    if res[-1] == 'W':
        print(res[:-1])
        exit()
res = 'W'
if s[0] == 'x':
    res += 'S'
    for i in range(2,n+1):
        if s[i-1] == 'o':
            if res[i-1] == 'S':
                t = res[i-2]
            else:
                if res[i-2] == 'S':
                    t = 'W'
                else:
                    t = 'S'
        else:
            if res[i - 1] == 'S':
                if res[i-2] == 'S':
                    t = 'W'
                else:
                    t = 'S'
            else:
                t = res[i - 2]
        res += t
    if res[-1] == 'W':
        print(res[:-1])
        exit()
res = 'W'
if s[0] == 'x':
    res += 'W'
    for i in range(2,n+1):
        if s[i-1] == 'o':
            if res[i-1] == 'S':
                t = res[i-2]
            else:
                if res[i-2] == 'S':
                    t = 'W'
                else:
                    t = 'S'
        else:
            if res[i - 1] == 'S':
                if res[i-2] == 'S':
                    t = 'W'
                else:
                    t = 'S'
            else:
                t = res[i - 2]
        res += t
    if res[-1] == 'W':
        print(res[:-1])
        exit()
print(-1)

Submission status: Wrong Answer

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

jdg = False
for s in ['SS', 'SW', 'WS', 'WW']:
    ss = s
    for i in range(1, N):
        if S[i] == 'o':
            if ss[i] == 'S':
                ss += ss[i - 1]
            else:
                if ss[i - 1] == 'W': ss += 'S'
                else: ss += 'W'
        else:
            if ss[i] == 'S':
                if ss[i - 1] == 'W': ss += 'S'
                else: ss += 'W'
            else:
                ss += ss[i - 1]
    if ss[N] == ss[0]:
        if (S[0] == 'o' and ss[N-1] == ss[1]) or (S[0] == 'x' and ss[N-1] != ss[1]):
            jdg = True
            break

print(ss[:-1] if jdg else -1)

Submission status: Wrong Answer

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

jdg = False
for s in ['SS', 'SW', 'WS', 'WW']:
    ss = s
    for i in range(1, N):
        if S[i] == 'o':
            if ss[i] == 'S':
                ss += ss[i - 1]
            else:
                if ss[i - 1] == 'W': ss += 'S'
                else: ss += 'W'
        else:
            if ss[i] == 'S':
                if ss[i - 1] == 'W': ss += 'S'
                else: ss += 'W'
            else:
                ss += ss[i - 1]
    if ss[N] == ss[0]:
        jdg = True
        break

print(ss[:-1] if jdg else -1)

Submission status: Wrong Answer

Solution code:
N = int(input())
s = list(input())
q = [[True,True],[True,False],[False,True],[False,False]]
p = []
ans = []
for k in range(4):
    p = q[k]
    for i in range(N-1):
        if p[i + 1]:
            if s[i + 1] == "o":
                p.append(p[i])
            else:
                p.append(not p[i])
        else:
            if s[i + 1] == "o":
                p.append(not p[i])
            else:
                p.append(p[i])
    if p[0] == p[-1]:
        for i in range(N):
            if p[i]:
                ans.append("S")
            else:
                ans.append("W")
        print("".join(ans))
        break
    if k == 3:
        print(-1)

Submission status: Wrong Answer

Solution code:
N = int(input())
s = list(input())
q = [[True,True],[True,False],[False,True],[False,False]]
p = []
ans = []
for k in range(4):
    p = q[k]
    for i in range(N-1):
        if p[i + 1]:
            if s[i + 1] == "o":
                p.append(p[i])
            else:
                p.append(not p[i])
        else:
            if s[i + 1] == "o":
                p.append(not p[i])
            else:
                p.append(p[i])
    print(p)
    if p[0] == p[-1]:
        for i in range(N):
            if p[i]:
                ans.append("S")
            else:
                ans.append("W")
        print("".join(ans))
        break
    if k == 3:
        print(-1)

Submission status: Wrong Answer

Solution code:
N = int(input())
s = list(input())
q = [[True,True],[True,False],[False,True],[False,False]]
p = []
ans = []
for k in range(4):
    p = q[k]
    for i in range(N-1):
        if p[i + 1]:
            if s[i + 1] == "o":
                p.append(p[i])
            else:
                p.append(not p[i])
        else:
            if s[i + 1] == "o":
                p.append(not p[i])
            else:
                p.append(p[i])
    
    if p[0] == p[-1] and p[1] == p[-2]:
        for i in range(N):
            if p[i]:
                ans.append("S")
            else:
                ans.append("W")
        print("".join(ans))
        break
    if k == 3:
        print(-1)