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 = list(map(str, input()))
flg = 0

for first, second in [("S", "S"), ("S", "W"), ("W", "S"), ("W", "W"), ]:
	ans = [first, second]
	before_before = first
	before = second
	for i in range(2, N + 1):
		# 今注目している動物は羊か狼か
		cmp_lst = [before_before, before]
		before_before = before
		if cmp_lst == ["S", "S"]:
			if S[i - 1] == "o":
				before = "S"
			else:
				before = "W"
		elif cmp_lst == ["S", "W"]:
			if S[i - 1] == "o":
				before = "W"
			else:
				before = "S"
		elif cmp_lst == ["W", "S"]:
			if S[i - 1] == "o":
				before = "W"
			else:
				before = "S"
		else:
			if S[i - 1] == "o":
				before = "S"
			else:
				before = "W"
		if i != N:
			ans.append(before)

	if first == before:
		cmp_lst = [before_before, before]
		if cmp_lst == ["S", "S"]:
			if S[i - 1] == "o":
				before = "S"
			else:
				before = "W"
		elif cmp_lst == ["S", "W"]:
			if S[i - 1] == "o":
				before = "W"
			else:
				before = "S"
		elif cmp_lst == ["W", "S"]:
			if S[i - 1] == "o":
				before = "W"
			else:
				before = "S"
		else:
			if S[i - 1] == "o":
				before = "S"
			else:
				before = "W"
		if before == second:
			flg = 1
			break
		
if flg:
	for a in ans:
		print(a, end = "")
else:
	print(-1)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(map(str, input()))
flg = 0

for first, second in [("S", "S"), ("S", "W"), ("W", "S"), ("W", "W"), ]:
	ans = [first, second]
	before_before = first
	before = second
	for i in range(2, N + 1):
		# 今注目している動物は羊か狼か
		cmp_lst = [before_before, before]
		before_before = before
		if cmp_lst == ["S", "S"]:
			if S[i - 1] == "o":
				before = "S"
			else:
				before = "W"
		elif cmp_lst == ["S", "W"]:
			if S[i - 1] == "o":
				before = "W"
			else:
				before = "S"
		elif cmp_lst == ["W", "S"]:
			if S[i - 1] == "o":
				before = "W"
			else:
				before = "S"
		else:
			if S[i - 1] == "o":
				before = "S"
			else:
				before = "W"
		if i != N:
			ans.append(before)

	if first == before:
		if cmp_lst == ["S", "S"]:
			if S[i - 1] == "o":
				before = "S"
			else:
				before = "W"
		elif cmp_lst == ["S", "W"]:
			if S[i - 1] == "o":
				before = "W"
			else:
				before = "S"
		elif cmp_lst == ["W", "S"]:
			if S[i - 1] == "o":
				before = "W"
			else:
				before = "S"
		else:
			if S[i - 1] == "o":
				before = "S"
			else:
				before = "W"
		if before == second:
			flg = 1
			break
		
if flg:
	for a in ans:
		print(a, end = "")
else:
	print(-1)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(map(str, input()))
flg = 0

for first, second in [("S", "S"), ("S", "W"), ("W", "S"), ("W", "W"), ]:
	ans = [first, second]
	before_before = first
	before = second
	for i in range(2, N + 1):
		# 今注目している動物は羊か狼か
		cmp_lst = [before_before, before]
		before_before = before
		if cmp_lst == ["S", "S"]:
			if S[i - 1] == "o":
				before = "S"
			else:
				before = "W"
		elif cmp_lst == ["S", "W"]:
			if S[i - 1] == "o":
				before = "W"
			else:
				before = "S"
		elif cmp_lst == ["W", "S"]:
			if S[i - 1] == "o":
				before = "W"
			else:
				before = "S"
		else:
			if S[i - 1] == "o":
				before = "S"
			else:
				before = "W"
		if i != N:
			ans.append(before)

	if first == before:
		flg = 1
		break
		
if flg:
	for a in ans:
		print(a, end = "")
else:
	print(-1)

Submission status: Wrong Answer

Solution code:
N = int(input())
s = input()
start_pattern = ['SS', 'SW', 'WS', 'WW']
s2 = s+s[0]
for start in start_pattern:
    ans = start
    before = s[0]

    for i, now in enumerate(s2[1:]):
        if i == N-1:
            break
        before_state = ans[i]
        now_state = ans[i+1]
        if now_state == 'S':
            yes = 'o'
            no = 'x'
        else:
            yes = 'x'
            no = 'o'

        if now == yes:
            ans += before_state
        else:
            if before_state == 'S':
                ans += 'W'
            else:
                ans += 'S'
    if ans[0] == ans[-1]:
        ok = False
        if s[0] == yes:
            if ans[1] == ans[-2]:
                ok = True
        else:
            if ans[1] != ans[-2]:
                ok = True
        if ok:
            print(ans[:-1])
            exit()
print('-1')

Submission status: Wrong Answer

Solution code:
N = int(input())
s = input()
start_pattern = ['SS', 'SW', 'WS', 'WW']
s2 = s+s[0]
for start in start_pattern:
    ans = start
    before = s[0]

    for i, c in enumerate(s2[1:]):
        if i == N-1:
            break
        now = c
        before_state = ans[i]
        now_state = ans[i+1]
        if now_state == 'S':
            yes = 'o'
            no = 'x'
        else:
            no = 'o'
            yes = 'x'

        if c == yes:
            ans += before_state
        else:
            if before_state == 'S':
                ans += 'W'
            else:
                ans += 'S'
    if ans[0] == ans[-1]:
        print(ans[:-1])
        exit()
print('-1')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def check():
    N = int(input())
    S = input()
    animal = ['W', 'S']
    
    for a in animal:
        for b in animal:
            #print(a,b)
            pre, nex = a, b
            answer = [a,b]
            for i in range(1,N):
                if nex == 'S':
                    if S[i] == 'o':
                        tmp = nex
                        nex = pre
                        pre = tmp
                        answer.append(nex)
                    elif S[i] == 'x':
                        tmp = nex
                        nex = 'W' if pre == 'S' else 'S'
                        pre = tmp
                        answer.append(nex)
                else:
                    if S[i] == 'o':
                        tmp = nex
                        nex = 'W'if pre == 'S' else 'S'
                        pre = tmp
                        answer.append(nex)
                    elif S[i] == 'x':
                        tmp = nex
                        nex = pre
                        pre = tmp
                        answer.append(nex)
                #print(nex)
            if nex == a:
                return answer[:-1]
    else:
        return -1

ans = check()               
if type(ans) == int:
    print(ans)
else:
    print(''.join(ans))

Submission status: Wrong Answer

Solution code:
def check():
    N = int(input())
    S = input()
    animal = ['W', 'S']
    
    for a in animal:
        for b in animal:
            #print(a,b)
            pre, nex = a, b
            answer = [a,b]
            for i in range(1,N):
                if nex == 'S':
                    if S[i] == 'o':
                        tmp = nex
                        nex = pre
                        pre = tmp
                        answer.append(nex)
                    elif S[i] == 'x':
                        tmp = nex
                        nex = 'W' if pre == 'S' else 'S'
                        pre = tmp
                        answer.append(nex)
                else:
                    if S[i] == 'o':
                        tmp = nex
                        nex = 'W'if pre == 'S' else 'S'
                        pre = tmp
                        answer.append(nex)
                    elif S[i] == 'x':
                        tmp = nex
                        nex = pre
                        pre = tmp
                        answer.append(nex)
                #print(nex)
            if nex == a:
                return answer
    else:
        return -1

ans = check()               
if type(ans) == int:
    print(ans)
else:
    print(''.join(ans))

Submission status: Wrong Answer

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

    # print(N, S)

    return N, S


def solve(N, S):
    def inv_animal(animal):
        return "S" if animal == "W" else "W"

    def is_correct(n, st):
        for i in range(1, n):
            pre, next = i - 1, i + 1
            say = S[i]
            animal = st[i]

            if animal == "S":
                if say == "o":
                    if not st[pre] == st[next]:
                        return False
                else:
                    if st[pre] == st[next]:
                        return False
            else:
                if say == "o":
                    if st[pre] == st[next]:
                        return False
                else:
                    if not st[pre] == st[next]:
                        return False
        return True

    lis = []
    def recur(i, st):
            if not i < 2:
                lis.append(st)
                return

            recur(i + 1, st + "S")
            recur(i + 1, st + "W")
    recur(0, "")

    if len(lis) == 0:
        return -1

    def fill(p, n):
        for i in range(1, n):
            pre = i - 1
            say = S[i]
            animal = p[i]

            if animal == "S":
                if say == "o":
                    p += p[pre]
                else:
                    p += inv_animal(p[pre])
            else:
                if say == "o":
                    p += inv_animal(p[pre])
                else:
                    p += p[pre]
        return p

    for p in lis:
        # print(p)
        filled = fill(p, N)
        if filled[0] == filled[-1]:
            # print("ok", filled[:-1])
            return filled[:-1]
    return -1


if __name__ == '__main__':
    res = solve(*args())
    print(res)

Submission status: Wrong Answer

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

    # print(N, S)

    return N, S


def solve(N, S):
    def inv_animal(animal):
        return "S" if animal == "W" else "W"

    def is_correct(n, st):
        for i in range(1, n):
            pre, next = i - 1, i + 1
            say = S[i]
            animal = st[i]

            if animal == "S":
                if say == "o":
                    if not st[pre] == st[next]:
                        return False
                else:
                    if st[pre] == st[next]:
                        return False
            else:
                if say == "o":
                    if st[pre] == st[next]:
                        return False
                else:
                    if not st[pre] == st[next]:
                        return False
        return True

    lis = []
    def recur(i, st):
            if not i < 3:
                if is_correct(2, st):
                    lis.append(st)
                return

            recur(i + 1, st + "S")
            recur(i + 1, st + "W")
    recur(0, "")

    # print(lis)

    if len(lis) == 0:
        return -1

    def fill(p, n):
        for i in range(2, n):
            pre, next = i - 1, i + 1
            say = S[i]
            animal = p[i]

            if animal == "S":
                if say == "o":
                    p += p[pre]
                else:
                    p += inv_animal(p[pre])
            else:
                if say == "o":
                    p += inv_animal(p[pre])
                else:
                    p += p[pre]
        return p

    for p in lis:
        # print(p)
        filled = fill(p, N)
        if filled[0] == filled[-1]:
            # print("ok", filled[:-1])
            return filled[:-1]
    return -1


if __name__ == '__main__':
    res = solve(*args())
    print(res)

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, atan, degrees
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect
import numpy as np

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
s = input()

search = [
["S"]+["_"]*(N-1), 
["S"]+["_"]*(N-1), 
["W"]+["_"]*(N-1),
["W"]+["_"]*(N-1)
]

if s[0] == "o":
	search[0][1] = "S"
	search[0][-1] = "S"
	search[1][1] = "W"
	search[1][-1] = "W"
	search[2][1] = "W"
	search[2][-1] = "S"
	search[3][1] = "S"
	search[3][-1] = "W"
else:
	search[0][1] = "S"
	search[0][-1] = "W"
	search[1][1] = "W"
	search[1][-1] = "S"
	search[2][1] = "W"
	search[2][-1] = "W"
	search[3][1] = "S"
	search[3][1] = "S"
	
for lis in search:
	for i in range(N):
		if s[i] == "o" and lis[i] == "S":
			if lis[-2] != "_" and lis[i-1] != lis[0]:
				break
			if lis[-2] == "_":
				lis[i+1] = lis[i-1]
		elif s[i] == "x" and lis[i] == "S":
			if lis[-2] != "_" and lis[i-1] == lis[0]:
				break
			if lis[-2] == "_":
				if lis[i-1] == "W":
					lis[i+1] = "S"
				else:
					lis[i+1] = "W"

		elif s[i] == "o" and lis[i] == "W":
			if lis[-2] != "_" and lis[i-1] == lis[0]:
				break
			if lis[-2] == "_":
				if lis[i-1] == "W":
					lis[i+1] = "S"
				else:
					lis[i+1] = "W"
			
		elif s[i] == "x" and lis[i] == "W":
			if lis[-2] != "_" and lis[i-1] != lis[0]:
				break
			if lis[-2] == "_":
				lis[i+1] = lis[i-1]

	else:
		print(*lis, sep="")
		break
else:
	print(-1)

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, atan, degrees
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect
import numpy as np

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
s = input()

search = [
["S"]+["_"]*(N-1), 
["S"]+["_"]*(N-1), 
["W"]+["_"]*(N-1),
["W"]+["_"]*(N-1)
]

if s[0] == "o":
	search[0][1] = "S"
	search[0][-1] = "S"
	search[1][1] = "W"
	search[1][-1] = "W"
	search[2][1] = "W"
	search[2][-1] = "S"
	search[3][1] = "S"
	search[3][-1] = "W"
else:
	search[0][1] = "S"
	search[0][-1] = "W"
	search[1][1] = "W"
	search[1][-1] = "S"
	search[2][1] = "W"
	search[2][-1] = "W"
	search[3][1] = "S"
	search[3][1] = "S"
print(search)
for lis in search:
	for i in range(N):
		if s[i] == "o" and lis[i] == "S":
			if lis[-2] != "_" and lis[i-1] != lis[0]:
				break
			if lis[-2] == "_":
				lis[i+1] = lis[i-1]
		elif s[i] == "x" and lis[i] == "S":
			if lis[-2] != "_" and lis[i-1] == lis[0]:
				break
			if lis[-2] == "_":
				if lis[i-1] == "W":
					lis[i+1] = "S"
				else:
					lis[i+1] = "W"

		elif s[i] == "o" and lis[i] == "W":
			if lis[-2] != "_" and lis[i-1] == lis[0]:
				break
			if lis[-2] == "_":
				if lis[i-1] == "W":
					lis[i+1] = "S"
				else:
					lis[i+1] = "W"
			
		elif s[i] == "x" and lis[i] == "W":
			if lis[-2] != "_" and lis[i-1] != lis[0]:
				break
			if lis[-2] == "_":
				lis[i+1] = lis[i-1]

	else:
		print(*lis, sep="")
		break
else:
	print(-1)

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, atan, degrees
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect
import numpy as np

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
s = input()

search = [
["S"]+["_"]*(N-1), 
["S"]+["_"]*(N-1), 
["W"]+["_"]*(N-1),
["W"]+["_"]*(N-1)
]

animal = ["_", "S", "W"]  # 1->S, -1->W

if s[0] == "o":
	search[0][1] = "S"
	search[0][-1] = "S"
	search[1][1] = "W"
	search[1][-1] = "W"
	search[2][1] = "W"
	search[2][-1] = "S"
	search[3][1] = "S"
	search[3][-1] = "W"
else:
	search[0][1] = "S"
	search[0][-1] = "W"
	search[1][1] = "W"
	search[1][-1] = "S"
	search[2][1] = "W"
	search[2][-1] = "W"
	search[3][1] = "S"
	search[3][1] = "S"

for lis in search:
	for i in range(N):
		if s[i] == "o" and lis[i] == "S":
			if i == N-1 and lis[i-1] != lis[0]:
				break
			if i <= N-2:
				lis[i+1] = lis[i-1]
		elif s[i] == "x" and lis[i] == "S":
			if i == N-1 and lis[i-1] == lis[0]:
				break
			if i <= N-2:
				if lis[i-1] == "W":
					lis[i+1] = "S"
				else:
					lis[i+1] = "W"

		elif s[i] == "o" and lis[i] == "W":
			if i == N-1 and lis[i-1] == lis[0]:
				break
			if i <= N-2:
				if lis[i-1] == "W":
					lis[i+1] = "S"
				else:
					lis[i+1] = "W"
			
		elif s[i] == "x" and lis[i] == "W":
			if i == N-1 and lis[i-1] != lis[0]:
				break
			if i <= N-2:
				lis[i+1] = lis[i-1]

	else:
		print(*lis, sep="")
		break
else:
	print(-1)

Submission status: Wrong Answer

Solution code:
#import sys
#input = sys.stdin.buffer.readline

def main():
    N = int(input())
    S = str(input())
    
    def animal(x,s):
        if x[-1] == 1:
            if s == "o":
                return x[-2]
            else:
                return -1*x[-2]
        else:
            if s == "o":
                return -1*x[-2]
            else:
                return x[-2]
                
    poss = [[1,1],[1,-1],[-1,1],[-1,-1]]
    for i in range(4):
        col = poss[i]
        for j in range(N-1):
            put = animal(col,S[j+1])
            col.append(put)
        if col[0] == col[-1]:
            l = len(col)-1
            ans = []
            for k in range(l):
                if col[k] == 1:
                    ans.append("S")
                else:
                    ans.append("W")
            print("".join(ans))
            exit()
            
    print(-1)
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#import sys
#input = sys.stdin.buffer.readline

def main():
    N = int(input())
    S = str(input())
    animal = [[1,-1],[-1,1]]
    def conv(s):
        if s == "o":
            return 0
        else:
            return 1
            
    def invconv(s):
        if s == 1:
            return "S"
        else:
            return "W"
            
    def col(x):
        for i in range(N-1):
            now = (-x[-1]+1)//2
            x.append(animal[now][conv(S[i+1])]*x[i])
        return x
        
    poss = [[1,1],[1,-1],[-1,1],[-1,-1]]
    for i in poss:
        use = col(i)
        if use[0] == use[-1]:
            l = len(use)
            ans = []
            for j in range(l-1):
                ans.append(invconv(use[j]))
            print("".join(ans))
            exit()
        
    print(-1)
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
def f(n):
    if n == 'S':
        return 'W'
    if n == 'W':
        return 'S'
A = ['S','S']
fa = 1
B = ['S','W']
fb = 1
C = ['W','W']
fc = 1
D = ['W','S']
fd = 1
for i in range(1,N-1):
    x = S[i]
    if x == 'o':
        if A[i] == 'S':
            A.append(A[i-1])
        else:
            A.append(f(A[i-1]))
        if B[i] == 'S':
            B.append(B[i-1])
        else:
            B.append(f(B[i-1]))
        if C[i] == 'S':
            C.append(C[i-1])
        else:
            C.append(f(C[i-1]))
        if D[i] == 'S':
            D.append(D[i-1])
        else:
            D.append(f(D[i-1]))
    else:
        if A[i] == 'S':
            A.append(f(A[i-1]))
        else:
            A.append(A[i-1])
        if B[i] == 'S':
            B.append(f(B[i-1]))
        else:
            B.append(B[i-1])
        if C[i] == 'S':
            C.append(f(C[i-1]))
        else:
            C.append(C[i-1])
        if D[i] == 'S':
            D.append(f(D[i-1]))
        else:
            D.append(D[i-1])
if S[0] == 'o':
    if A[0] == 'S':
        if A[1] != A[-1]:
            fa = 0
    else:
        if A[1] == A[-1]:
            fa = 0
else:
    if A[0] == 'S':
        if A[1] == A[-1]:
            fa = 0
    else:
        if A[1] != A[-1]:
            fa = 0
if S[-1] == 'o':
    if A[-1] == 'S':
        if A[-2] != A[0]:
            fa = 0
    else:
        if A[-2] == A[0]:
            fa = 0
else:
    if A[-1] == 'S':
        if A[-2] == A[0]:
            fa = 0
    else:
        if A[-2] != A[0]:
            fa = 0
if fa == 1:
    x = A[0]
    for i in range(1,N):
        x += A[i]
    print(x)
    quit()
if S[0] == 'o':
    if A[0] == 'S':
        if A[1] != A[-1]:
            fa = 0
    else:
        if A[1] == A[-1]:
            fa = 0
else:
    if B[0] == 'S':
        if B[1] == B[-1]:
            fb = 0
    else:
        if B[1] != B[-1]:
            fb = 0
if S[-1] == 'o':
    if B[-1] == 'S':
        if B[-2] != B[0]:
            fb = 0
    else:
        if B[-2] == B[0]:
            fb = 0
else:
    if B[-1] == 'S':
        if B[-2] == B[0]:
            fb = 0
    else:
        if B[-2] != B[0]:
            fb = 0
if fb == 1:
    x = B[0]
    for i in range(1,N):
        x += B[i]
    print(x)
    quit()
if S[0] == 'o':
    if C[0] == 'S':
        if C[1] != C[-1]:
            fc = 0
    else:
        if C[1] == C[-1]:
            fc = 0
else:
    if C[0] == 'S':
        if C[1] == C[-1]:
            fc = 0
    else:
        if C[1] != C[-1]:
            fc = 0
if S[-1] == 'o':
    if C[-1] == 'S':
        if C[-2] != C[0]:
            fc = 0
    else:
        if C[-2] == C[0]:
            fc = 0
else:
    if C[-1] == 'S':
        if C[-2] == C[0]:
            fc = 0
    else:
        if C[-2] != C[0]:
            fc = 0
if fc == 1:
    x = C[0]
    for i in range(1,N):
        x += C[i]
    print(x)
    quit()
if S[0] == 'o':
    if D[0] == 'S':
        if D[1] != D[-1]:
            fd = 0
    else:
        if D[1] == D[-1]:
            fd = 0
else:
    if D[0] == 'S':
        if D[1] == D[-1]:
            fd = 0
    else:
        if D[1] != D[-1]:
            fd = 0
if S[-1] == 'o':
    if D[-1] == 'S':
        if D[-2] != D[0]:
            fd = 0
    else:
        if D[-2] == D[0]:
            fd = 0
else:
    if D[-1] == 'S':
        if D[-2] == D[0]:
            fd = 0
    else:
        if D[-2] != D[0]:
            fd = 0
if fd == 1:
    x = D[0]
    for i in range(1,N):
        x += D[i]
    print(x)
    quit()
if fa + fb + fc + fd == 0:
    print(-1)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
def f(n):
    if n == 'S':
        return 'W'
    if n == 'W':
        return 'S'
A = ['S','S']
fa = 1
B = ['S','W']
fb = 1
C = ['W','W']
fc = 1
D = ['W','S']
fd = 1
for i in range(1,N-1):
    x = S[i]
    if x == 'o':
        if A[i] == 'S':
            A.append(A[i-1])
        else:
            A.append(f(A[i-1]))
        if B[i] == 'S':
            B.append(B[i-1])
        else:
            B.append(f(B[i-1]))
        if C[i] == 'S':
            C.append(C[i-1])
        else:
            C.append(f(C[i-1]))
        if D[i] == 'S':
            D.append(D[i-1])
        else:
            D.append(f(D[i-1]))
    else:
        if A[i] == 'S':
            A.append(f(A[i-1]))
        else:
            A.append(A[i-1])
        if B[i] == 'S':
            B.append(f(B[i-1]))
        else:
            B.append(B[i-1])
        if C[i] == 'S':
            C.append(f(C[i-1]))
        else:
            C.append(C[i-1])
        if D[i] == 'S':
            D.append(f(D[i-1]))
        else:
            D.append(D[i-1])
if S[0] == 'o':
    if A[0] == 'S':
        if A[1] != A[-1]:
            fa = 0
    else:
        if A[1] == A[-1]:
            fa = 0
else:
    if A[0] == 'S':
        if A[1] == A[-1]:
            fa = 0
    else:
        if A[1] != A[-1]:
            fa = 0
if S[-1] == 'o':
    if A[-1] == 'S':
        if A[-2] != A[0]:
            fa = 0
    else:
        if A[-2] == A[0]:
            fa = 0
else:
    if A[-1] == 'S':
        if A[-2] == A[0]:
            fa = 0
    else:
        if A[-2] != A[0]:
            fa = 0
if fa == 1:
    x = A[0]
    for i in range(1,N):
        x += A[i]
    print(x)
    quit()
if S[0] == 'o':
    if A[0] == 'S':
        if A[1] != A[-1]:
            fa = 0
    else:
        if A[1] == A[-1]:
            fa = 0
else:
    if B[0] == 'S':
        if B[1] == B[-1]:
            fb = 0
    else:
        if B[1] != B[-1]:
            fb = 0
if S[-1] == 'o':
    if B[-1] == 'S':
        if B[-2] != B[0]:
            fb = 0
    else:
        if B[-2] == B[0]:
            fb = 0
else:
    if B[-1] == 'S':
        if B[-2] == B[0]:
            fb = 0
    else:
        if B[-2] != B[0]:
            fb = 0
if fb == 1:
    x = B[0]
    for i in range(1,N):
        x += B[i]
    print(x)
    quit()
if S[0] == 'o':
    if C[0] == 'S':
        if C[1] != C[-1]:
            fc = 0
    else:
        if C[1] == C[-1]:
            fc = 0
else:
    if C[0] == 'S':
        if C[1] == C[-1]:
            fc = 0
    else:
        if C[1] != C[-1]:
            fc = 0
if S[-1] == 'o':
    if C[-1] == 'S':
        if C[-2] != C[0]:
            fc = 0
    else:
        if A[-2] == A[0]:
            fc = 0
else:
    if C[-1] == 'S':
        if C[-2] == C[0]:
            fc = 0
    else:
        if C[-2] != C[0]:
            fc = 0
if fc == 1:
    x = C[0]
    for i in range(1,N):
        x += C[i]
    print(x)
    quit()
if S[0] == 'o':
    if D[0] == 'S':
        if D[1] != D[-1]:
            fd = 0
    else:
        if D[1] == D[-1]:
            fd = 0
else:
    if D[0] == 'S':
        if D[1] == D[-1]:
            fd = 0
    else:
        if D[1] != D[-1]:
            fd = 0
if S[-1] == 'o':
    if D[-1] == 'S':
        if D[-2] != D[0]:
            fd = 0
    else:
        if D[-2] == D[0]:
            fd = 0
else:
    if D[-1] == 'S':
        if D[-2] == D[0]:
            fd = 0
    else:
        if D[-2] != D[0]:
            fd = 0
if fd == 1:
    x = D[0]
    for i in range(1,N):
        x += D[i]
    print(x)
    quit()
if fa + fb + fc + fd == 0:
    print(-1)