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: Accepted

Solution code:
N=int(input())
S=input()
    
for i in range(4):
  ans=[0]*N
  if i==0:
    ans[-1]="S"
    ans[0]="S"
  elif i==1:
    ans[-1]="S"
    ans[0]="W"
  elif i==2:
    ans[-1]="W"
    ans[0]="S"
  else:
    ans[-1]="W"
    ans[0]="W"
  
  for j,s in enumerate(S):
    if j!=N-1 and j!=N-2:
      if ans[j]=="S":
        if s=="o":
          ans[j+1]=ans[j-1]
        else:
          if ans[j-1]=="S":
            ans[j+1]="W"
          else:
            ans[j+1]="S"
      else:
        if s=="x":
          ans[j+1]=ans[j-1]
        else:
          if ans[j-1]=="S":
            ans[j+1]="W"
          else:
            ans[j+1]="S"
    elif j==N-2:
      flag=0
      if ans[N-2]=="S":
        if s=="o":
          if ans[N-1]==ans[N-3]:
            flag=1
        else:
          if ans[N-1]!=ans[N-3]:
            flag=1
      else:
        if s=="x":
          if ans[N-1]==ans[N-3]:
            flag=1
        else:
          if ans[N-1]!=ans[N-3]:
            flag=1
    elif flag:  
      if ans[N-1]=="S":
        if s=="o":
          if ans[N-2]==ans[0]:
            print("".join(ans));exit()
        else:
          if ans[N-2]!=ans[0]:
            print("".join(ans));exit()
      else:
        if s=="x":
          if ans[N-2]==ans[0]:
            print("".join(ans));exit()
        else:
          if ans[N-2]!=ans[0]:
            print("".join(ans));exit()
print(-1)

Submission status: Accepted

Solution code:
n = int(input())
s = list(input())
# S = 1 W = -1
ss = [1,1]
sw = [1,-1]
ws = [-1,1]
ww = [-1,-1]
ans = []
for i in range(1,n):
  flag = 1
  if s[i] == "x":
    flag = -1
  if ss[i] == 1:
    ss.append(flag*ss[i-1])
  else:
    ss.append(flag*-ss[i-1])
  if sw[i] == 1:
    sw.append(flag*sw[i-1])
  else:
    sw.append(flag*-sw[i-1])
  if ws[i] == 1:
    ws.append(flag*ws[i-1])
  else:
    ws.append(flag*-ws[i-1])
  if ww[i] == 1:
    ww.append(flag*ww[i-1])
  else:
    ww.append(flag*-ww[i-1])
flag = 1
if s[0] == "x":
  flag = -1
if ss[0] == ss[-1] and ss[1] == ss[0]*flag*ss[-2]:
  ans = ss
elif sw[0] == sw[-1] and sw[1] == sw[0]*flag*sw[-2]:
  ans = sw
elif ws[0] == ws[-1] and ws[1] == ws[0]*flag*ws[-2]:
  ans = ws
elif ww[0] == ww[-1] and ww[1] == ww[0]*flag*ww[-2]:
  ans = ww
if ans == []:
  print(-1)
else:
  ans = ans[:n]
  ans = ["S" if i == 1 else "W" for i in ans]
  print("".join(ans))

Submission status: Accepted

Solution code:
rev_ox = {"o":"x", "x":"o"}
rev_sw = {"S":"W", "W":"S"}

def get_next(sw_prev2,sw_prev1,ox_prev1):
        
    sw = sw_prev2
    if sw_prev1 == "W": ox_prev1 = rev_ox[ox_prev1]
    if ox_prev1 == "x": sw = rev_sw[sw]
    
    return sw

n = int(input())
ox = input()

for sw0,sw1 in [("S","S"),("S","W"),("W","S"),("W","W")]:
    ans = ""
    ans = sw0+sw1
    for i,oxi in enumerate(ox[1:]+ox[0],1):
        ans += get_next(ans[i-1],ans[i],oxi)
    
    if ans[0] == ans[-2] and ans[1] == ans[-1]:
        ans = ans[:-2]
        break
else:
    ans = -1

print(ans)

Submission status: Accepted

Solution code:
def get_next(sw_prev2,sw_prev1,ox_prev1):
    
    rev_ox = {"o":"x", "x":"o"}
    rev_sw = {"S":"W", "W":"S"}
    
    sw = sw_prev2
    if sw_prev1 == "W": ox_prev1 = rev_ox[ox_prev1]
    if ox_prev1 == "x": sw = rev_sw[sw]
    
    return sw

n = int(input())
ox = input()

ans = [None] * (n+2)
for sw0,sw1 in [("S","S"),("S","W"),("W","S"),("W","W")]:
     
    ans[0] = sw0
    ans[1] = sw1
    
    for i,oxi in enumerate(ox[1:]+ox[0],1):
        ans[i+1] = get_next(ans[i-1],ans[i],oxi)
    
    if ans[0] == ans[-2] and ans[1] == ans[-1]:
        break
else:
    ans = [-1]

print("".join(map(str,ans[:n])))

Submission status: Accepted

Solution code:
def get_next(sw_prev2,sw_prev1,ox_prev1):
    
    rev_ox = {"o":"x", "x":"o"}
    rev_sw = {"S":"W", "W":"S"}
    
    sw = sw_prev2
    if sw_prev1 == "W": ox_prev1 = rev_ox[ox_prev1]
    if ox_prev1 == "x": sw = rev_sw[sw]
    
    return sw

n = int(input())
ox = input()

for sw0,sw1 in [("S","S"),("S","W"),("W","S"),("W","W")]:
    ans = ""
    ans = sw0+sw1
    for i,oxi in enumerate(ox[1:]+ox[0],1):
        ans += get_next(ans[i-1],ans[i],oxi)
    
    if ans[0] == ans[-2] and ans[1] == ans[-1]:
        ans = ans[:-2]
        break
else:
    ans = -1

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
p1=["W","W"]
p2=["W","S"]
p3=["S","W"]
p4=["S","S"]
p=[p1,p2,p3,p4]
for i in range(4):
	for j in range(n-2):
		same=0
		if p[i][j+1]=="S" and s[j+1]=="o"\
		or p[i][j+1]=="W" and s[j+1]=="x":
			same=1
		if same and p[i][j]=="S" or not same and p[i][j]=="W":
			p[i].append("S")
		else:
			p[i].append("W")
	f=0
	same=0
	if p[i][-1]=="S" and s[-1]=="o"\
	or p[i][-1]=="W" and s[-1]=="x":
		same=1
	if same and p[i][-2]=="S" or not same and p[i][-2]=="W":
		if p[i][0]=="S":
			f=1
	else:
		if p[i][0]=="W":
			f=1
	if f==0:
		continue
	f=0
	same=0
	if p[i][0]=="S" and s[0]=="o"\
	or p[i][0]=="W" and s[0]=="x":
		same=1
	if same and p[i][-1]=="S" or not same and p[i][-1]=="W":
		if p[i][1]=="S":
			f=1
	else:
		if p[i][1]=="W":
			f=1
	if f:
		ans=""
		for x in p[i]:
			ans+=x
		print(ans)
		exit()
print(-1)

Submission status: Accepted

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

ans = [''] * N

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

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

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

print(-1)

Submission status: Accepted

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

ans = [''] * N

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

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

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

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

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

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

print(-1)

Submission status: Accepted

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

for ans in [["S", "S"], ["S", "W"], ["W", "S"], ["W", "W"]]:
    for i in range(n-1):
        if s[(i+1)] == "o":
            if ans[i+1] == "S":
                if ans[i] == "S":
                    ans.append("S")
                else:
                    ans.append("W")
            else:
                if ans[i] == "S":
                    ans.append("W")
                else:
                    ans.append("S")
        if s[(i+1)] == "x":
            if ans[i+1] == "S":
                if ans[i] == "S":
                    ans.append("W")
                else:
                    ans.append("S")
            else:
                if ans[i] == "S":
                    ans.append("S")
                else:
                    ans.append("W")

    if ans[0] == ans[-1]:
        ans.pop()
        flag = 0
        if s[0] == "o":
            if ans[0] == "S":
                if ans[-1] == ans[1]:
                    flag = 1
            else:
                if ans[-1] != ans[1]:
                    flag = 1
        else:
            if ans[0] == "W":
                if ans[-1] == ans[1]:
                    flag = 1
            else:
                if ans[-1] != ans[1]:
                    flag = 1
        if flag == 1:
            print("".join(ans))
            sys.exit()
print(-1)

Submission status: Accepted

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

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

    # Check
    mask_n = (x[-1] == "S") and ((S[-1] == "o" and x[-2] == x[0]) \
                                 or (S[-1] == "x" and x[-2] != x[0]))
    mask_n |= (x[-1] == "W") and ((S[-1] == "o" and x[-2] != x[0]) \
                                  or (S[-1] == "x" and x[-2] == x[0]))
    
    mask_1 = (x[0] == "S") and ((S[0] == "o" and x[-1] == x[1]) \
                                or (S[0] == "x" and x[-1] != x[1]))
    mask_1 |= (x[0] == "W") and ((S[0] == "o" and x[-1] != x[1]) \
                                 or (S[0] == "x" and x[-1] == x[1]))

    if mask_n and mask_1:
        print("".join(x))
        break
else:
    print(-1)

Submission status: Accepted

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

    s = S + S[:2]  # 円環状に並んでいることを考慮
    for ans in ('SS', 'SW', 'WS', 'WW'):  # Sheep, Wolf について1番と2番の種類を仮定する
        for i in range(1, N + 1):
            if (ans[-1] == 'S' and s[i] == 'o') or (ans[-1] == 'W' and s[i] == 'x'):
                # この場合，今注目している動物の両隣は同じ種類．
                # よって，今注目している動物の右隣を左隣と同じにする．
                ans += ans[-2]
            else:
                # 両隣は違う種類．右隣を左隣と逆にする．
                ans += ('S' if ans[-2] == 'W' else 'W')
        if ans[:2] == ans[N:]:
            # sの最初の2文字(仮定)と最後の2文字が一致した文字列のみ受理する．
            return ans[:N]
    return '-1'  # どの割り当て方も矛盾した

print(d_menagerie())

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

def majikayo():
    flag2 = 0
    if A[0] == 'S' and s[0] == 'o':
        if A[1] == A[N-1]:
            #繰り返しゾーン
            #---------------------------------------------↓
            if A[N-1] == 'S' and s[N-1] == 'o':
                if A[0] == A[N-2]:
                    flag2 = 1
            elif A[N-1] == 'S' and s[N-1] == 'x':
                if A[0] != A[N-2]:
                    flag2 = 1
            elif A[N-1] == 'W' and s[N-1] == 'o':
                if A[0] != A[N-2]:
                    flag2 = 1
            elif A[N-1] == 'W' and s[N-1] == 'x':
                if A[0] == A[N-2]:
                    flag2 = 1
            #---------------------------------------------↑

    elif A[0] == 'S' and s[0] == 'x':
        if A[1] != A[N-1]:
            #---------------------------------------------↓
            if A[N-1] == 'S' and s[N-1] == 'o':
                if A[0] == A[N-2]:
                    flag2 = 1
            elif A[N-1] == 'S' and s[N-1] == 'x':
                if A[0] != A[N-2]:
                    flag2 = 1
            elif A[N-1] == 'W' and s[N-1] == 'o':
                if A[0] != A[N-2]:
                    flag2 = 1
            elif A[N-1] == 'W' and s[N-1] == 'x':
                if A[0] == A[N-2]:
                    flag2 = 1
            #---------------------------------------------↑

    elif A[0] == 'W' and s[0] == 'o':
        if A[1] != A[N-1]:
            #---------------------------------------------↓
            if A[N-1] == 'S' and s[N-1] == 'o':
                if A[0] == A[N-2]:
                    flag2 = 1
            elif A[N-1] == 'S' and s[N-1] == 'x':
                if A[0] != A[N-2]:
                    flag2 = 1
            elif A[N-1] == 'W' and s[N-1] == 'o':
                if A[0] != A[N-2]:
                    flag2 = 1
            elif A[N-1] == 'W' and s[N-1] == 'x':
                if A[0] == A[N-2]:
                    flag2 = 1
            #---------------------------------------------↑

    elif A[0] == 'W' and s[0] == 'x':
        if A[1] == A[N-1]:
            #---------------------------------------------↓
            if A[N-1] == 'S' and s[N-1] == 'o':
                if A[0] == A[N-2]:
                    flag2 = 1
            elif A[N-1] == 'S' and s[N-1] == 'x':
                if A[0] != A[N-2]:
                    flag2 = 1
            elif A[N-1] == 'W' and s[N-1] == 'o':
                if A[0] != A[N-2]:
                    flag2 = 1
            elif A[N-1] == 'W' and s[N-1] == 'x':
                if A[0] == A[N-2]:
                    flag2 = 1
            #---------------------------------------------↑

    if flag2 == 1:
        return 1
    else:
        return 0

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