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()
S = ['SSS', 'SSW', 'SWW', 'WWW', 'WWS', 'WSS', 'SWS', 'WSW']
ans = []
for n in range(4):
    ans = []
    if len(s) == 3:
        print(-1)
        exit()
    elif s[1] == 'o' and n == 0:
        ans.append('S')
        ans.append('S')
    elif s[1] == 'x' and n == 0:
        ans.append('W')
        ans.append('S')
    elif s[1] == 'o' and n == 1:
        ans.append('S')
        ans.append('W')
    elif s[1] == 'x' and n == 1:
        ans.append('S')
        ans.append('W')
    elif s[1] == 'o' and n == 2:
        ans.append('W')
        ans.append('S')
    elif s[1] == 'x' and n == 2:
        ans.append('W')
        ans.append('W')
    elif s[1] == 'o' and n == 3:
        ans.append('W')
        ans.append('W')
    elif s[1] == 'x' and n == 3:
        ans.append('S')
        ans.append('S')

    for i in range(1, N):
        if ans[i - 1] == 'S':
            if ans[i] == 'S':
                if s[i] == 'o':
                    ans.append('S')
                else:
                    ans.append('W')
            else:
                if s[i] == 'o':
                    ans.append('W')
                else:
                    ans.append('S')
        else:
            if ans[i] == 'S':
                if s[i] == 'o':
                    ans.append('W')
                else:
                    ans.append('S')
            else:
                if s[i] == 'o':
                    ans.append('S')
                else:
                    ans.append('W')
    if ans[N-1] == 'S' and ans[N] == ans[0]:
        if ans[0] == 'S':
            if s[0] == 'o' and ans[1] == 'S':
                break
            elif s[0] == 'x' and ans[1] == 'W':
                break
        else:
            if s[0] == 'o' and ans[1] == 'W':
                break
            elif s[0] == 'x' and ans[1] == 'S':
                break
    elif ans[N-1] == 'W' and ans[N] == ans[0]:
        if ans[0] == 'S':
            if s[0] == 'o' and ans[1] == 'W':
                break
            elif s[0] == 'x' and ans[1] == 'S':
                break
        else:
            if s[0] == 'o' and ans[1] == 'S':
                break
            elif s[0] == 'x' and ans[1] == 'W':
                break
ans.pop()
ans = ''.join(ans)
print(ans)

Submission status: Wrong Answer

Solution code:
# これを四通り＊２で試す。

N = int(input())
s = input()
S = ['SSS', 'SSW', 'SWW', 'WWW', 'WWS', 'WSS', 'SWS', 'WSW']
ans = []
for n in range(4):
    ans = []
    if len(s) == 3:
        print(-1)
        exit()
    elif s[1] == 'o' and n == 0:
        ans.append('S')
        ans.append('S')
    elif s[1] == 'x' and n == 0:
        ans.append('W')
        ans.append('S')
    elif s[1] == 'o' and n == 1:
        ans.append('S')
        ans.append('W')
    elif s[1] == 'x' and n == 1:
        ans.append('S')
        ans.append('W')
    elif s[1] == 'o' and n == 2:
        ans.append('W')
        ans.append('S')
    elif s[1] == 'x' and n == 2:
        ans.append('W')
        ans.append('W')
    elif s[1] == 'o' and n == 3:
        ans.append('W')
        ans.append('W')
    elif s[1] == 'x' and n == 3:
        ans.append('S')
        ans.append('S')

    for i in range(1, N):
        if ans[i - 1] == 'S':
            if ans[i] == 'S':
                if s[i] == 'o':
                    ans.append('S')
                else:
                    ans.append('W')
            else:
                if s[i] == 'o':
                    ans.append('W')
                else:
                    ans.append('S')
        else:
            if ans[i] == 'S':
                if s[i] == 'o':
                    ans.append('W')
                else:
                    ans.append('S')
            else:
                if s[i] == 'o':
                    ans.append('S')
                else:
                    ans.append('W')
    if ans[N] == 'S' and ans[N] == ans[0]:
        if ans[0] == 'S':
            if s[0] == 'o' and ans[1] == 'S':
                break
            elif s[0] == 'x' and ans[1] == 'W':
                break
        else:
            if s[0] == 'o' and ans[1] == 'W':
                break
            elif s[0] == 'x' and ans[1] == 'S':
                break
    elif ans[N] == 'W' and ans[N] == ans[0]:
        if ans[0] == 'S':
            if s[0] == 'o' and ans[1] == 'W':
                break
            elif s[0] == 'x' and ans[1] == 'S':
                break
        else:
            if s[0] == 'o' and ans[1] == 'S':
                break
            elif s[0] == 'x' and ans[1] == 'W':
                break
ans.pop()
ans = ''.join(ans)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

s = input()

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

cand_oo = ["SSSS", "SWWS", "WWSW", "WSWW"]
cand_ox = ["SSSW", "SWWW", "WWSS", "SSWS"]
cand_xo = ["WSSS", "WWWS", "SWSW", "SSWW"]
cand_xx = ["WSSW", "WWWW", "SWSS", "WSWS"]

answered = False

for a in ans_first:
    for i in range(1, N-1):
        if (s[i] == "o" and a[i] == "S") or (s[i] == "x" and a[i] == "W"):
            a = a + a[i-1]
            
        elif (s[i] == "o" and a[i] == "W") or (s[i] == "x" and a[i] == "S") :
            if a[i-1] == "S":
                a = a + "W"
            else:
                a = a + "S"
            
    if s[-1] + s[0] == "oo": 
        for can in cand_oo:
            if can == a[-2:] + a[:2]:
                print(a)
                break
                
    elif s[-1] + s[0] == "ox": 
        for can in cand_ox:
            if can == a[-2:] + a[:2]:
                print(a)
                break
    
    elif s[-1] + s[0] == "xo": 
        for can in cand_xo:
            if can == a[-2:] + a[:2]:
                print(a)
                break
    
    elif s[-1] + s[0] == "xx": 
        for can in cand_xx:
            if can == a[-2:] + a[:2]:
                print(a)
                break
                
if answered == False:
    print(-1)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict


def ok(l, s):
    for i in range(len(s) * 2):
        now = i % len(l)
        pre = now - 1
        nex = (now + 1) % len(l)
        if (l[now] == -1 and s[now] == 'x') or (l[now] == 1 and s[now] == 'o'):
            if l[nex] is None:
                l[nex] = l[pre]
            else:
                if l[nex] != l[pre]:
                    return False
        else:
            if l[nex] is None:
                l[nex] = -1 * l[pre]
            else:
                if l[nex] != -1 * l[pre]:
                    return False

    return True


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

    for x in [(-1, -1), (-1, 1), (1, -1), (1, 1)]:
        l = [None] * N
        l[-1], l[0] = x[0], x[1]
        if ok(l, s):
            print("".join(['w' if x == -1 else 's' for x in l]))
            return
    print(-1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

sl = list(s)

def calc(i, resl):
  now = resl[i]
  back = resl[i-1]

  if now == 'W':
    if back == 'W':
      if sl[i] == 'o':
        resl[i+1] = 'S'
      else:
        resl[i+1] = 'W'
    else:
      if sl[i] == 'o':
        resl[i+1] = 'W'
      else:
        resl[i+1] = 'S'
  else: # 'S'
    if back == 'W':
      if sl[i] == 'o':
        resl[i+1] = 'W'
      else:
        resl[i+1] = 'S'
    else:
      if sl[i] == 'o':
        resl[i+1] = 'S'
      else:
        resl[i+1] = 'W'

def test(resl):
  i = N-1
  now = resl[-1]
  back = resl[-2]

  if now == 'W':
    if back == 'W':
      if sl[i] == 'o':
        return resl[0] == 'S'
      else:
        return resl[0] == 'W'
    else:
      if sl[i] == 'o':
        return resl[0] == 'W'
      else:
        return resl[0] == 'S'
  else: # 'S'
    if back == 'W':
      if sl[i] == 'o':
        return resl[0] == 'W'
      else:
        return resl[0] == 'S'
    else:
      if sl[i] == 'o':
        return resl[0] == 'S'
      else:
        return resl[0] == 'W'


def printer(resl):
  print("".join(resl))

def check(resl):
  for i in range(1, N-1):
    calc(i, resl)
  return test(resl)

resl = [""]*N
(resl[0], resl[1]) = ('W', 'W')
if check(resl):
  printer(resl)
else:
  resl = [""]*N
  (resl[0], resl[1]) = ('W', 'S')
  if check(resl):
    printer(resl)
  else:
    resl = [""]*N
    (resl[0], resl[1]) = ('S', 'W')
    if check(resl):
      printer(resl)
    else:
      resl = [""]*N
      (resl[0], resl[1]) = ('S', 'S')
      if check(resl):
        printer(resl)
      else:
        print(-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
for i in range(len(s)):
    if s[i] == 'o':
        s[i] = True
    else:
        s[i] = False

state = [None]*n
state[0] = 1
state[1] = 1


def next_predict(before_state,current_state,output):#i+1の動物を出力する
    if current_state == 1:
        if output == True:
            if before_state == 1:
                return 1
            else:
                return 0
        else:
            if before_state == 1:
                return 0
            else:
                return 1
    else:
        return next_predict(before_state,1,not(output))

isFound = -1
for i in range(4):
    for j in range(1,n-1):
        state[j+1] = next_predict(state[j-1],state[j],s[j])
    tmp = next_predict(state[n-2],state[n-1],s[n-1])
    if tmp == state[0]:
        isFound = 1
        ans = []
        for k in range(n):
            if state[k] == 0:
                ans.append('W')
            else:
                ans.append('S')
        print("".join(ans))
        break
    else:
        if i == 0:
            state[1] = 0
        elif i == 1:
            state[0] = 0
        else:
            state[1] = 1

if isFound == -1:
    print(-1)

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
s = [i for i in input()]

ans = [i for i in range(N)]
animal = ['S','W']

for x in animal:
    ans[-1] = x

    for y in animal:
        ans[0] = y
        for i in range(N):
            if (s[i] == 'o' and ans[i] == 'S') or (s[i] == 'x' and ans[i] == 'W'):
                if i < N-2:
                    ans[i+1] = ans[i-1]
                elif i == N-2:
                    if ans[i-1] != ans[i+1]:
                        continue
                elif i == N-1:
                    if ans[i-1] == ans[0]:
                        print(''.join(ans))
                        sys.exit()
            elif (s[i] == 'x' and ans[i] == 'S') or (s[i] == 'o' and ans[i] == 'W'):
                if i < N-2:
                    if i == 0: print(ans)
                    if ans[i-1] == 'S':
                        ans[i+1] = 'W'
                    elif ans[i-1] == 'W':
                        ans[i+1] = 'S'
                elif i == N-2:
                    if ans[i-1] == ans[i+1]:
                        continue
                elif i == N-1:
                    if ans[i-1] != ans[0]:
                        print(''.join(ans))
                        sys.exit()

print(-1)

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
s = [i for i in input()]

ans = [i for i in range(N)]
animal = ['S','W']

for x in animal:
    ans[-1] = x

    for y in animal:
        ans[0] = y
        for i in range(N):
            if (s[i] == 'o' and ans[i] == 'S') or (s[i] == 'x' and ans[i] == 'W'):
                if i < N-2:
                    ans[i+1] = ans[i-1]
                elif i == N-2:
                    if ans[i-1] != ans[i+1]:
                        break
                elif i == N-1:
                    if ans[i-1] == ans[0]:
                        print(''.join(ans))
                        sys.exit()
            elif (s[i] == 'x' and ans[i] == 'S') or (s[i] == 'o' and ans[i] == 'W'):
                if i < N-2:
                    if i == 0: print(ans)
                    if ans[i-1] == 'S':
                        ans[i+1] = 'W'
                    elif ans[i-1] == 'W':
                        ans[i+1] = 'S'
                elif i == N-2:
                    if ans[i-1] == ans[i+1]:
                        break
                elif i == N-1:
                    if ans[i-1] != ans[0]:
                        print(''.join(ans))
                        sys.exit()

print(-1)

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
s = [i for i in input()]

ans = ['' for i in range(N)]
animal = ['S','W']
count = 0

for x in animal:
    for y in animal:
        ans[-1] = x
        ans[0] = y
        
        for i in range(N):
            if (s[i] == 'o' and ans[i] == 'S') or (s[i] == 'x' and ans[i] == 'W'):
                if i < N-1:
                    ans[i+1] = ans[i-1]
                elif i == N-1:
                    if ans[i-1] == ans[0]:
                        print(''.join(ans))
                        sys.exit()
            elif (s[i] == 'x' and ans[i] == 'S') or (s[i] == 'o' and ans[i] == 'W'):
                if i < N-1:
                    if ans[i-1] == 'S':
                        ans[i+1] = 'W'
                    else:
                        ans[i+1] = 'S'
                elif i == N-1:
                    if ans[i-1] != ans[0]:
                        print(''.join(ans))
                        sys.exit()

print(-1)

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
s = [i for i in input()]

ans = ['' for i in range(N)]
animal = ['S','W']
count = 0

for x in animal:
    for y in animal:
        ans[-1] = x
        ans[0] = y
        start = x
        for i in range(N):
            if (s[i] == 'o' and ans[i] == 'S') or (s[i] == 'x' and ans[i] == 'W'):
                if i < N-1:
                    ans[i+1] = ans[i-1]
                elif i == N-1:
                    if ans[i-1] == ans[0]:
                        print(''.join(ans))
                        sys.exit()
            elif (s[i] == 'x' and ans[i] == 'S') or (s[i] == 'o' and ans[i] == 'W'):
                if i < N-1:
                    if ans[i-1] == 'S':
                        ans[i+1] = 'W'
                    else:
                        ans[i+1] = 'S'
                elif i == N-1:
                    if ans[i - 1] != ans[0]:
                       print(''.join(ans))
                       sys.exit()

print(-1)

Submission status: Wrong Answer

Solution code:
import sys
N=int(input())
s=str(input())
t=s.replace("o","2")
t=t.replace("x","0")
t=str(t)

ans="22"
for i in range(1,N):
  ans+=str( (int(t[i])-1) * (int(ans[i-1])-1)*(int(ans[i])-1)+1 )
if ans[0]==ans[N]:
  ans=ans.replace("2","S")
  ans=ans.replace("0","W")
  print(ans[0:N])
  sys.exit()

ans="20"
for i in range(1,N):
  ans+=str( (int(t[i])-1) * (int(ans[i-1])-1)*(int(ans[i])-1)+1 )
if ans[0]==ans[N]:
  ans=ans.replace("2","S")
  ans=ans.replace("0","W")
  print(ans[0:N])
  sys.exit()

ans="02"
for i in range(1,N):
  ans+=str( (int(t[i])-1) * (int(ans[i-1])-1)*(int(ans[i])-1)+1 )
if ans[0]==ans[N]:
  ans=ans.replace("2","S")
  ans=ans.replace("0","W")
  print(ans[0:N])
  sys.exit()
ans="22"
for i in range(1,N):
  ans+=str( (int(t[i])-1) * (int(ans[i-1])-1)*(int(ans[i])-1)+1 )
if ans[0]==ans[N]:
  ans=ans.replace("2","S")
  ans=ans.replace("0","W")
  print(ans[0:N])
  sys.exit()

ans="00"
for i in range(1,N):
  ans+=str( (int(t[i])-1) * (int(ans[i-1])-1)*(int(ans[i])-1)+1 )
if ans[0]==ans[N]:
  ans=ans.replace("2","S")
  ans=ans.replace("0","W")
  print(ans[0:N])
  sys.exit()

print(-1)

Submission status: Wrong Answer

Solution code:
N = int(input())
ox = input()
swf1 = "ss"
swf2 = "sw"
swf3 = "ws"
swf4 = "ww"


def phrase(sw,ox,N) :
    for i in range(N) :
        if i == 0 :
            continue
        elif i == 1 :
            continue
        else :
            if ox[i-1] == "o" and sw[i-1] == "s" :
                sw = sw + sw[i-2]
            elif ox[i-1] == "o" and sw[i-1] == "w" :
                sw = sw + "s" if sw[i-2] == "w" else sw + "w"
            elif ox[i-1] == "x" and sw[i-1] == "s" :
                sw = sw + "s" if sw[i-2] == "w" else sw + "w"
            elif ox[i-1] == "x" and sw[i-1] == "w" :
                sw = sw + sw[i-2]
    if ox[N-1] == "o" :
        if sw[N-1] == "s" :
            if sw[N-2] == sw[0] :
                if ox[0] == "o" :
                    if sw[0] == "s" :
                        if sw[1] == sw[N-1] :
                            return sw
                        else :
                            return False
                    else :
                        if sw[1] == sw[N-1] :
                            return False
                        else :
                            return sw
                else :
                    if sw[0] == "s" :
                        if sw[1] == sw[N-1] :
                            return False
                        else :
                            return sw
                    else :
                        if sw[1] == sw[N-1] :
                            return sw
                        else :
                            return False
            else :
                return False
        else :
            if sw[N-2] == sw[0] :
                return False
            else :
                if ox[0] == "o" :
                    if sw[0] == "s" :
                        if sw[1] == sw[N-1] :
                            return sw
                        else :
                            return False
                    else :
                        if sw[1] == sw[N-1] :
                            return False
                        else :
                            return sw
                else :
                    if sw[0] == "s" :
                        if sw[1] == sw[N-1] :
                            return False
                        else :
                            return sw
                    else :
                        if sw[1] == sw[N-1] :
                            return sw
                        else :
                            return False
    else :
        if sw[N-1] == "s" :
            if sw[N-2] == sw[0] :
                return False
            else :
                if ox[0] == "o" :
                    if sw[0] == "s" :
                        if sw[1] == sw[N-1] :
                            return sw
                        else :
                            return False
                    else :
                        if sw[1] == sw[N-1] :
                            return False
                        else :
                            return sw
                else :
                    if sw[0] == "s" :
                        if sw[1] == sw[N-1] :
                            return False
                        else :
                            return sw
                    else :
                        if sw[1] == sw[N-1] :
                            return sw
                        else :
                            return False
        else :
            if sw[N-2] == sw[0] :
                if ox[0] == "o" :
                    if sw[0] == "s" :
                        if sw[1] == sw[N-1] :
                            return sw
                        else :
                            return False
                    else :
                        if sw[1] == sw[N-1] :
                            return False
                        else :
                            return sw
                else :
                    if sw[0] == "s" :
                        if sw[1] == sw[N-1] :
                            return False
                        else :
                            return sw
                    else :
                        if sw[1] == sw[N-1] :
                            return sw
                        else :
                            return False
            else :
                return False

sw1 = phrase(swf1,ox,N)
sw2 = phrase(swf2,ox,N)
sw3 = phrase(swf3,ox,N)
sw4 = phrase(swf4,ox,N)

if sw1 :
    print(sw1)
elif sw2 :
    print(sw2)
elif sw3 :
    print(sw3)
elif sw4 :
    print(sw4)
else :
    print("-1")

Submission status: Wrong Answer

Solution code:
N = int(input())
ox = input()
swf1 = "ss"
swf2 = "sw"
swf3 = "ws"
swf4 = "ww"


def phrase(sw,ox,N) :
    for i in range(N) :
        if i == 0 :
            continue
        elif i == 1 :
            continue
        else :
            if ox[i-1] == "o" and sw[i-1] == "s" :
                sw = sw + sw[i-2]
            elif ox[i-1] == "o" and sw[i-1] == "w" :
                sw = sw + "s" if sw[i-2] == "w" else sw + "w"
            elif ox[i-1] == "x" and sw[i-1] == "s" :
                sw = sw + "s" if sw[i-2] == "w" else sw + "w"
            elif ox[i-1] == "x" and sw[i-1] == "w" :
                sw = sw + sw[i-2]
    if ox[N-1] == "o" :
        if sw[N-1] == "s" :
            if sw[N-2] == sw[0] :
                return sw
            else :
                return False
        else :
            if sw[N-2] == sw[0] :
                return False
            else :
                return sw
    else :
        if sw[N-1] == "s" :
            if sw[N-2] == sw[0] :
                return False
            else :
                return sw
        else :
            if sw[N-2] == sw[0] :
                return sw
            else :
                return False

sw1 = phrase(swf1,ox,N)
sw2 = phrase(swf2,ox,N)
sw3 = phrase(swf3,ox,N)
sw4 = phrase(swf4,ox,N)

if sw1 :
    print(sw1)
elif sw2 :
    print(sw2)
elif sw3 :
    print(sw3)
elif sw4 :
    print(sw4)
else :
    print("-1")

Submission status: Wrong Answer

Solution code:
N = int(input())
ox = input()
sw1 = "ss"
sw2 = "sw"
sw3 = "ws"
sw4 = "ww"


def phrase(sw,ox,N) :
    for i in range(N) :
        if i == 0 :
            continue
        elif i == 1 :
            continue
        else :
            if ox[i-1] == "o" and sw[i-1] == "s" :
                sw = sw + sw[i-2]
            elif ox[i-1] == "o" and sw[i-1] == "w" :
                sw = sw + "s" if sw[i-2] == "w" else sw + "w"
            elif ox[i-1] == "x" and sw[i-1] == "s" :
                sw = sw + "s" if sw[i-2] == "w" else sw + "w"
            elif ox[i-1] == "x" and sw[i-1] == "w" :
                sw = sw + sw[i-2]
    if ox[N-1] == "o" :
        if sw[N-1] == "s" :
            if sw[N-2] == sw[0] :
                return sw
            else :
                return False
        else :
            if sw[N-2] == sw[0] :
                return False
            else :
                return sw
    else :
        if sw[N-1] == "s" :
            if sw[N-2] == sw[0] :
                return False
            else :
                return sw
        else :
            if sw[N-2] == sw[0] :
                return sw
            else :
                return False

sw1 = phrase(sw1,ox,N)
sw2 = phrase(sw2,ox,N)
sw3 = phrase(sw3,ox,N)
sw4 = phrase(sw4,ox,N)

if sw1 :
    print(sw1)
elif sw2 :
    print(sw2)
elif sw3 :
    print(sw3)
elif sw4 :
    print(sw4)
else :
    print(-1)

Submission status: Wrong Answer

Solution code:
N = int(input())
ox = input()
sw1 = "ss"
sw2 = "sw"
sw3 = "ws"
sw4 = "ww"


def phrase(sw,ox,N) :
    for i in range(N) :
        if i == 0 :
            continue
        elif i == 1 :
            continue
        else :
            if ox[i-1] == "o" and sw[i-1] == "s" :
                sw = sw + sw[i-2]
            elif ox[i-1] == "o" and sw[i-1] == "w" :
                sw = sw + "s" if sw[i-2] == "w" else sw + "w"
            elif ox[i-1] == "x" and sw[i-1] == "s" :
                sw = sw + "s" if sw[i-2] == "w" else sw + "w"
            elif ox[i-1] == "x" and sw[i-1] == "w" :
                sw = sw + sw[i-2]
    if ox[N-1] == "o" :
        if sw[N-1] == "s" :
            if sw[N-2] == sw[0] :
                return sw
            else :
                return False
        else :
            if sw[N-2] == sw[0] :
                return False
            else :
                return sw
    else :
        if sw[N-1] == "s" :
            if sw[N-2] == sw[0] :
                return False
            else :
                return sw
        else :
            if sw[N-2] == sw[0] :
                return sw
            else :
                return False

sw1 = phrase(sw1,ox,N)
sw2 = phrase(sw2,ox,N)
sw3 = phrase(sw3,ox,N)
sw4 = phrase(sw4,ox,N)

if sw1 :
    print(sw1)
elif sw2 :
    print(sw2)
elif sw3 :
    print(sw3)
elif sw4 :
    print(sw4)
else :
    print("-1")

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import sys
import os


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


def judge(X):
    for i in range(1, N - 1):
        left = X[i - 1]

        if X[i] == 0:
            if s[i] == 'o':
                right = left
            else:
                right = 1 - left
        else:
            if s[i] == 'o':
                right = 1 - left
            else:
                right = left
        X.append(right)

    # 全体で確認
    is_consistent = True
    X.append(X[0])
    for i in range(N):
        if X[i] == 0:
            if s[i] == 'o':
                if X[i-1] != X[i+1]:
                    is_consistent = False
            else:
                if X[i-1] == X[i+1]:
                    is_consistent = False
        else:
            if s[i] == 'o':
                if X[i-1] == X[i+1]:
                    is_consistent = False
            else:
                if X[i-1] != X[i+1]:
                    is_consistent = False
    return is_consistent, X[:N]

# 0: sheep
# 1: wolf
X_list = [[0, 0], [0, 1], [1, 0], [1, 1]]

results = []
for X in X_list:
    results.append(judge(X))

trues = [result for result in results if result[0] is True]
if trues:
    result = trues[0]
    X = result[1]
    for x in X:
        if x == 0:
            print('S', end='')
        else:
            print('W', end='')
    print()
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import sys
import os


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


def judge(X):
    for i in range(1, N - 1):
        left = X[i - 1]

        if X[i] == 0:
            if s[i] == 'o':
                right = left
            else:
                right = 1 - left
        else:
            if s[i] == 'o':
                right = 1 - left
            else:
                right = left
        X.append(right)

    # 入れた後、後端で判定
    if X[-1] == 0:
        if s[-1] == 'o':
            return X[0] == X[-2], X
        else:
            return X[0] != X[-2], X
    else:
        if s[-1] == 'o':
            return X[0] != X[-2], X
        else:
            return X[0] == X[-2], X

# 0: sheep
# 1: wolf
X_list = [[0, 0], [0, 1], [1, 0], [1, 1]]

results = []
for X in X_list:
    results.append(judge(X))

trues = [result for result in results if result[0] is True]
if trues:
    result = trues[0]
    X = result[1]
    for x in X:
        if x == 0:
            print('S', end='')
        else:
            print('W', end='')
    print()
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import sys
import os


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


def judge(X):
    for i in range(1, N - 1):
        if X[i] == 0:
            if s[i] == 'o':
                X.append(X[i - 1])
            else:
                X.append(1 - X[i - 1])
        else:
            if s[i] == 'o':
                X.append(1 - X[i - 1])
            else:
                X.append(X[i - 1])

    # 入れた後、後端で判定
    if X[-1] == 0:
        if s[-1] == 'o':
            return X[0] == X[-2], X
        else:
            return X[0] != X[-2], X
    else:
        if s[-1] == 'o':
            return X[0] != X[-2], X
        else:
            return X[0] == X[-2], X

# 0: sheep
# 1: wolf
X_list = [[0, 0], [0, 1], [1, 0], [1, 1]]

results = []
for X in X_list:
    results.append(judge(X))

trues = [result for result in results if result[0] is True]
if trues:
    result = trues[0]
    X = result[1]
    for x in X:
        if x == 0:
            print('S', end='')
        else:
            print('W', end='')
    print()
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import sys
import os


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

#print(N, s)



def judge(X):
    for i in range(1, N - 1):
        if X[i] == 0 and s[i] == 'o':
            X.append(X[i - 1])
        elif X[i] == 0 and s[i] == 'x':
            X.append(1 - X[i - 1])

        elif X[i] == 1 and s[i] == 'o':
            X.append(1 - X[i - 1])
        elif X[i] == 1 and s[i] == 'x':
            X.append(X[i - 1])

    # 入れた後、後端で判定
    if X[-1] == 0 and s[-1] == 'o':
        return X[0] == X[-2], X
    elif X[-1] == 0 and s[-1] == 'x':
        return X[0] != X[-2], X

    elif X[-1] == 1 and s[-1] == 'o':
        return X[0] != X[-2], X
    elif X[-1] == 1 and s[-1] == 'x':
        return X[0] == X[-2], X

# 0: sheep
# 1: wolf
X_list = [[0, 0], [0, 1], [1, 0], [1, 1]]

results = []
for X in X_list:
    results.append(judge(X))

trues = [result for result in results if result[0] is True]
if trues:
    result = trues[0]
    X = result[1]
    for x in X:
        if x == 0:
            print('S', end='')
        else:
            print('W', end='')
    print()
else:
    print(-1)