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:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007

#A
def A():
    n = II()
    ans = n * 800
    print(ans-(n//15)*200)
    return

#B
def B():
    n = II()
    print(math.factorial(n)%mod)
    return

#C
def C():
    n, m = LI()
    if n >= m // 2:
        print(m // 2)
        return
    else:
        m -= 2 * n
        print(n+m//4)
    return

#D
def D():
    n = II()
    ss = S()
    s = ["S", "W"]
    for i1 in s:
        for i2 in s:
            for i3 in s:
                ans = [i1, i2, i3]
                for i in range(2, n):
                    if ans[i] == "S":
                        if ss[i] == "o":
                            ans.append(ans[i - 1])
                        else:
                            if ans[i - 1] == "S":
                                ans.append("W")
                            else:
                                ans.append("S")
                    else:
                        if ss[i] == "S":
                            ans.append(ans[i - 1])
                        else:
                            if ans[i - 1] == "S":
                                ans.append("W")
                            else:
                                ans.append("S")

                if ans[0] == "S":
                    if ss[0] == "o":
                        if ans[1] != ans[-2]:
                            continue
                    else:
                        if ans[1] == ans[-2]:
                            continue
                else:
                    if ss[0] == "x":
                        if ans[1] != ans[-2]:
                            continue
                    else:
                        if ans[1] == ans[-2]:
                            continue

                if ans[1] == "S":
                    if ss[1] == "o":
                        if ans[0] != ans[2]:
                            continue
                    else:
                        if ans[0] == ans[2]:
                            continue
                else:
                    if ss[1] == "x":
                        if ans[0] != ans[2]:
                            continue
                    else:
                        if ans[0] == ans[2]:
                            continue

                if ans[2] == "S":
                    if ss[2] == "o":
                        if ans[1] != ans[3]:
                            continue
                    else:
                        if ans[1] == ans[3]:
                            continue
                else:
                    if ss[2] == "x":
                        if ans[1] != ans[3]:
                            continue
                    else:
                        if ans[1] == ans[3]:
                            continue

                if ans[0] != ans[-1]:
                    continue
                del ans[-1]

                print("".join(ans))
                return
    print(-1)
    return

#Solve
if __name__ == '__main__':
    D()

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
s += s[:2]

for ans in ["SS", "SW", "WW", "WS"]:
    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[0] == ans[n]:
        print(ans[:n])
        exit()

print(-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
s += s[:2]

for ans in ["SS", "SW", "WW", "WS"]:
    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[0] == ans[n]:
        print(ans)
        exit()

print(-1)

Submission status: Wrong Answer

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


def solve(n, ans):
    
    for i in range(2, n):
        if n != 3 and i != n-1:
            if ans[i] == "S":
                if s[i] == "o":
                    if ans[i-1] == "S":
                        ans[i+1] = "S"
                    else:
                        ans[i+1] = "W"
                else:
                    if ans[i-1] == "S":
                        ans[i+1] = "W"
                    else:
                        ans[i+1] = "S"
            else:
                if s[i] == "o":
                    if ans[i-1] == "S":
                        ans[i+1] = "W"
                    else:
                        ans[i+1] = "S"
                else:
                    if ans[i-1] == "S":
                        ans[i+1] = "S"
                    else:
                        ans[i+1] = "W"
        else:
            if ans[i] == "S":
                if s[i] == "o":
                    if ans[i-1] == "S":
                        tmp = "S"
                    else:
                        tmp = "W"
                else:
                    if ans[i-1] == "S":
                        tmp = "W"
                    else:
                        tmp = "S"
            else:
                if s[i] == "o":
                    if ans[i-1] == "S":
                        tmp = "W"
                    else:
                        tmp = "S"
                else:
                    if ans[i-1] == "S":
                        tmp = "S"
                    else:
                        tmp = "W"
            #print(ans, tmp)
            if ans[0] == tmp:
                print("".join(ans))
                exit()
            else:
                return

# 2,3番目の組み合わせで４回走査すればわかる
ans = [""] * n
tmp = ""
#SS の時
ans[1] = "S"
ans[2] = "S"
if s[1] == "o":
    ans[0] = "S"
else:
    ans[0] = "W"

solve(n,ans)

#SW の時
ans = [""] * n
tmp = ""
ans[1] = "S"
ans[2] = "W"
if s[1] == "o":
    ans[0] = "W"
else:
    ans[0] = "S"
solve(n,ans)

#WS の時
ans = [""] * n
tmp = ""
ans[1] = "W"
ans[2] = "S"
if s[1] == "o":
    ans[0] = "W"
else:
    ans[0] = "S"
solve(n, ans)

#WW の時
ans = [""] * n
tmp = ""
ans[1] = "W"
ans[2] = "W"
if s[1] == "o":
    ans[0] = "S"
else:
    ans[0] = "W"
solve(n, ans)


print(-1)

Submission status: Wrong Answer

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

def judge() :
    # 要するに最初の2個を決めれば良い
    for comb in (('S', 'S'), ('S', 'W'), ('W', 'S'), ('W', 'W')) :
        t = [None] * N
        t[0], t[1] = comb
            
        for i in range(1, N - 1) :
            if (s[i] == 'o') == (t[i] == 'S') :
                t[i + 1] = t[i - 1]
            else :
                t[i + 1] = 'S' if t[i - 1] == 'W' else 'W' 
        
        con1 = ((s[0] == 'o') == (t[0] == 'S')) == (t[N-1] == t[1])
        con2 = ((s[N - 1] == 'o') == (t[N - 1] == 'S')) == (t[N-2] == t[0])
        if con1 and con2 :
            return ''.join(t)
        
        return -1
print(judge())

Submission status: Wrong Answer

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

def judge() :
    # 要するに最初の2個を決めれば良い
    for comb in (('S', 'S'), ('S', 'W'), ('W', 'S'), ('W', 'W')) :
        t = [None] * N
        t[0], t[1] = comb
            
        for i in range(1, N - 1) :
            if (s[i] == 'o') == (t[i] == 'S') :
                t[i + 1] = t[i - 1]
            else :
                t[i + 1] = 'S' if t[i - 1] == 'W' else 'W' 
                
        if ((s[N - 1] == 'o') == (t[N - 1] == 'S')) == (t[N-2] == t[0]) :
            return ''.join(t)
        
        return -1
print(judge())

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)


def solve(N: int, s: str):
    r = None
    for c0 in [0, 1]:
        for c1 in [0, 1]:
            ret = [0] * N
            ret[0] = c0
            ret[1] = c1
            for i in range(1, N - 1):
                if s[i] == 'o':
                    ret[i + 1] = (ret[i - 1] + ret[i]) % 2
                else:
                    ret[i + 1] = (ret[i - 1] + ret[i] + 1) % 2
            if (s[N - 1] == 'o' and ret[0] == (ret[N - 2] + ret[N - 1]) % 2 or
                s[N - 1] == 'x' and ret[0] == (ret[N - 2] + ret[N - 1] + 1) % 2):
                r = ['W' if t else 'S' for t in ret]
                break
    if r:
        print(''.join(r))
    else:
        print(-1)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    s = next(tokens)  # type: str
    solve(N, s)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
s = [c == 'o' for c in input()]
def next_s(s, flag):
  d = {'S' : 'W', 'W' : 'S'}
  if flag:
    return s
  else:
    return d[s]

def sim(s0):
  ans = ['.' for _ in range(n+1)]
  ans[0] = s0[0]
  ans[1] = s0[1]
  for i in range(2, n+1):
    if ans[i-1] == 'S':
      ans[i] = next_s(ans[i-2], s[i-1])
    else:
      ans[i] = next_s(ans[i-2], not s[i-1])
  res = ans[1] == ans[-1]
  if s0[0] == 'S':
    if res == s[0] and ans[-1] == ans[0]:
      return ans[:-1]
  else:
    if res != s[0] and ans[-1] == ans[0]:
      return ans[:-1]
  return False

def solve():
  for item in ["SS", "SW", "WS", "WW"]:
    ans = sim(item)
    if ans:
      return print(''.join(ans))
  return print(-1)

solve()

Submission status: Wrong Answer

Solution code:
n = int(input())
s = [c == 'o' for c in input()]
def next_s(s, flag):
  d = {'S' : 'W', 'W' : 'S'}
  if flag:
    return s
  else:
    return d[s]

def sim(s0):
  ans = ['.' for _ in range(n)]
  ans[0] = s0[0]
  ans[1] = s0[1]
  for i in range(2, n):
    if ans[i-1] == 'S':
      ans[i] = next_s(ans[i-2], s[i-1])
    else:
      ans[i] = next_s(ans[i-2], not s[i-1])
  res = ans[1] == ans[-1]
  if s0[0] == 'S':
    if res == s[0]:
      return ans
  else:
    if res != s[0]:
      return ans
  return False

def solve():
  for item in ["SS", "SW", "WS", "WW"]:
    ans = sim(item)
    if ans:
      return print(''.join(ans))
  return print(-1)

solve()

Submission status: Wrong Answer

Solution code:
n = int(input())
s = [c == 'o' for c in input()]
def next_s(s, flag):
  d = {'S' : 'W', 'W' : 'S'}
  if flag:
    return s
  else:
    return d[s]

def sim(s0):
  ans = ['.' for _ in range(n)]
  ans[0] = s0[0]
  ans[1] = s0[1]
  for i in range(2, n):
    if ans[i-1] == 'S':
      ans[i] = next_s(ans[i-2], s[i-1])
    else:
      ans[i] = next_s(ans[i-2], not s[i-1])
  res = ans[1] == ans[-1]
  if s0[0] == 'S':
    if res == s[0]:
      return ans
  else:
    if res != s[0]:
      return ans
  return False

def solve():
  for item in ["SS", "SW", "WS", "WW"]:
    ans = sim(item)
    if ans:
      return print(''.join(ans))
  return print(-1)

Submission status: Wrong Answer

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

inv = { "S": "W", "W": "S" }

for zero, one in [["S", "S"], ["S", "W"], ["W", "S"], ["W", "W"]]:
    animals = [zero, one]
    for i in range(2, n + 1):
        if animals[i - 1] == "S":
            if s[i - 1] == "o":
                animals.append(animals[i - 2])
            else:
                animals.append(inv[animals[i - 2]])
        else:
            if s[i - 1] == "o":
                animals.append(inv[animals[i - 2]])
            else:
                animals.append(animals[i - 2])
    if animals[0] == animals[n]:
        animals.pop()
        print("".join(animals))
        exit(0)

print(-1)

Submission status: Wrong Answer

Solution code:
import bisect
import heapq
import itertools
import math
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18

N = int(sys.stdin.readline())
S = sys.stdin.readline().rstrip()


def flip(c):
    return 'W' if c == 'S' else 'S'


def solve(a1, a2):
    """
    :param a1:
    :param a2:
    :rtype: str
    """
    ans = a1 + a2
    cursor = 1
    while cursor < N:
        if S[cursor] == 'o' and ans[-1] == 'S' or S[cursor] == 'x' and ans[-1] == 'W':
            ans += ans[-2]
        else:
            ans += flip(ans[-2])
        cursor += 1

    if ans[0] == ans[-1]:
        if (ans[0] == 'S' and S[0] == 'o' and ans[1] == ans[-1] or
                ans[0] == 'S' and S[0] == 'x' and ans[1] != ans[-1] or
                ans[0] == 'W' and S[0] == 'o' and ans[1] != ans[-1] or
                ans[0] == 'W' and S[0] == 'x' and ans[1] == ans[-1]):
            return ans[:-1]
    return ''


# 最初の 2 個が決まれば最後まで決まる
for a1, a2 in itertools.product('SW', repeat=2):
    ret = solve(a1, a2)
    if ret:
        print(ret)
        exit()
print(-1)

Submission status: Wrong Answer

Solution code:
import bisect
import heapq
import itertools
import math
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18

N = int(sys.stdin.readline())
S = sys.stdin.readline().rstrip()


def flip(c):
    return 'W' if c == 'S' else 'S'


def solve(a1, a2):
    """
    :param a1:
    :param a2:
    :rtype: str
    """
    ans = a1 + a2
    cursor = 1
    while cursor < N:
        if S[cursor] == 'o' and ans[-1] == 'S' or S[cursor] == 'x' and ans[-1] == 'W':
            ans += ans[-2]
        else:
            ans += flip(ans[-2])
        cursor += 1

    if ans[0] == ans[-1]:
        return ans[:-1]
    else:
        return ''


# 最初の 2 個が決まれば最後まで決まる
for a1, a2 in itertools.product('SW', repeat=2):
    ret = solve(a1, a2)
    if ret:
        print(ret)
        exit()
print(-1)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
#S += S[0]
#print(S)
for a in [["S","S"],["S","W"],["W","S"],["W","W"]]:
    ans = a[0]+a[1]
    for i in range(1,N-1):
        if S[i] == "o":
            if ans[i] == "S" and ans[i-1] == "S":
                ans += "S"
            elif ans[i] == "S" and ans[i-1] == "W":
                ans += "W"
            elif ans[i] =="W" and ans[i-1] == "S":
                ans += "W"
            elif ans[i] =="W" and ans[i-1] == "W":
                ans += "S"
        elif S[i] == "x":
            if ans[i] == "S" and ans[i-1] == "S":
                ans += "W"
            elif ans[i] == "S" and ans[i-1] == "W":
                ans += "S"
            elif ans[i] =="W" and ans[i-1] == "S":
                ans += "S"
            elif ans[i] =="W" and ans[i-1] == "W":
                ans += "W"

    if S[-1] == "o":
        if ans[-1] == "S":
            if ans[-2] != ans[0]:
                ans = ""
        else:
            if ans[-2] == ans[0]:
                ans = ""
    elif S[-1] == "x":
        if ans[-1] == "S":
            if ans[-2] == ans[0]:
                ans = ""
        else:
            if ans[-2] != ans[0]:
                ans = ""
    
    if ans == "":
        break

    if S[0] == "o":
        if ans[0] == "S":
            if ans[1] != ans[-1]:
                ans = ""
        else:
            if ans[1] == ans[-1]:
                ans = ""
    elif S[0] == "x":
        if ans[0] == "S":
            if ans[1] == ans[-1]:
                ans = ""
        else:
            if ans[1] != ans[-1]:
                ans = ""
    
    if ans != "":
        print(ans)
        exit()
print(-1)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
#S += S[0]
#print(S)
for a in [["S","S"],["S","W"],["W","S"],["W","W"]]:
    ans = a[0]+a[1]
    for i in range(1,N-1):
        if S[i] == "o":
            if ans[i] == "S" and ans[i-1] == "S":
                ans += "S"
            elif ans[i] == "S" and ans[i-1] == "W":
                ans += "W"
            elif ans[i] =="W" and ans[i-1] == "S":
                ans += "W"
            elif ans[i] =="W" and ans[i-1] == "W":
                ans += "S"
        elif S[i] == "x":
            if ans[i] == "S" and ans[i-1] == "S":
                ans += "W"
            elif ans[i] == "S" and ans[i-1] == "W":
                ans += "S"
            elif ans[i] =="W" and ans[i-1] == "S":
                ans += "S"
            elif ans[i] =="W" and ans[i-1] == "W":
                ans += "W"
    if S[-1] == "o":
        if ans[-1] == "S":
            if ans[-2] != ans[0]:
                ans = ""
        else:
            if ans[-2] == ans[0]:
                ans = ""
    elif S[-1] == "x":
        if ans[-1] == "S":
            if ans[-2] == ans[0]:
                ans = ""
        else:
            if ans[-2] != ans[0]:
                ans = ""
    
    if ans == "":
        break

    if S[0] == "o":
        if ans[0] == "S":
            if ans[1] != ans[-1]:
                ans = ""
        else:
            if ans[1] == ans[-1]:
                ans = ""
    elif S[0] == "x":
        if ans[0] == "S":
            if ans[1] == ans[-1]:
                ans = ""
        else:
            if ans[1] != ans[-1]:
                ans = ""
    
    if ans != "":
        print(ans)
        exit()
print(-1)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
S += S[0]

for a in [["S","S"],["S","W"],["W","S"],["W","W"]]:
    ans = a[0]+a[1]
    for i in range(1,N):
        if S[i] == "o":
            if ans[i] == "S" and ans[i-1] == "S":
                ans += "S"
            elif ans[i] == "S" and ans[i-1] == "W":
                ans += "W"
            elif ans[i] =="W" and ans[i-1] == "S":
                ans += "W"
            elif ans[i] =="W" and ans[i-1] == "W":
                ans += "S"
        elif S[i] == "x":
            if ans[i] == "S" and ans[i-1] == "S":
                ans += "W"
            elif ans[i] == "S" and ans[i-1] == "W":
                ans += "S"
            elif ans[i] =="W" and ans[i-1] == "S":
                ans += "S"
            elif ans[i] =="W" and ans[i-1] == "W":
                ans += "W"

    if S[-1] == "o":
        if ans[-1] == "S":
            if ans[-2] != ans[0]:
                ans = ""
        else:
            if ans[-2] == ans[0]:
                ans = ""
    elif S[-1] == "x":
        if ans[-1] == "S":
            if ans[-2] == ans[0]:
                ans = ""
        else:
            if ans[-2] != ans[0]:
                ans = ""
    
    if ans =="":
        break

    if S[0] == "o":
        if ans[0] == "S":
            if ans[1] != ans[-1]:
                ans = ""
        else:
            if ans[1] == ans[-1]:
                ans = ""
    elif S[0] == "x":
        if ans[0] == "S":
            if ans[1] == ans[-1]:
                ans = ""
        else:
            if ans[1] != ans[-1]:
                ans = ""

    if ans != "":
        print(ans[:-1])
        exit()
print(-1)

Submission status: Wrong Answer

Solution code:
input()
input()
print(-1)

Submission status: Wrong Answer

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


def check(ans):
    for i in range(1, N):
        if (ans[i] == 0) == (S[i] == 'o'):
            ans += [ans[i - 1]]
        else:
            ans += [1 - ans[i - 1]]
    if ans[0] == ans[-1]:
        print(*['W' if _ else 'S' for _ in ans[:-1]], sep='')
        exit()


check([0, 0])
check([0, 1])
check([1, 0])
check([1, 1])
print(-1)

Submission status: Wrong Answer

Solution code:
def next_to_you(t,a):
	if a == "o":
		if t[-1] == "S":
			if  t[-2] == "W":
				return "W"
			elif t[-2] == "S":
				return "S"
		elif t[-1] == "W":
			if  t[-2] == "W":
				return "S"
			elif t[-2] == "S":
				return "W"
	elif a == "x":
		if t[-1] == "S":
			if  t[-2] == "W":
				return "S"
			elif t[-2] == "S":
				return "W"
		elif t[-1] == "W":
			if  t[-2] == "W":
				return "W"
			elif t[-2] == "S":
				return "S"



n = int(input())
s = input()
t1, t2, t3, t4 = "SS", "SW", "WS", "WW"

for i in range(1,n):
	t1 += next_to_you(t1,s[i])
	t2 += next_to_you(t2,s[i])
	t3 += next_to_you(t3,s[i])
	t4 += next_to_you(t4,s[i])

ans = -1
for i in [t1,t2,t3,t4]:
	if i[0] == i[-1]:
		ans = i[:n]
		break
print(ans)

Submission status: Wrong Answer

Solution code:
def next_to_you(t,a):
	if a == "o":
		if t[-1] == "S":
			if  t[-2] == "W":
				return "W"
			else:
				return "S"
		elif t[-1] == "W":
			if  t[-2] == "W":
				return "S"
			else:
				return "W"
	else:
		if t[-1] == "S":
			if  t[-2] == "W":
				return "S"
			else:
				return "W"
		elif t[-1] == "W":
			if  t[-2] == "W":
				return "W"
			else:
				return "S"



n = int(input())
s = input()
t1, t2, t3, t4 = "SS", "SW", "WS", "WW"

for i in range(1,n):
	t1 += next_to_you(t1,s[i])
	t2 += next_to_you(t2,s[i])
	t3 += next_to_you(t3,s[i])
	t4 += next_to_you(t4,s[i])

ans = -1
for i in [t1,t2,t3,t4]:
	if i[0] == i[-1]:
		ans = i[:n]
		break
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
l = ['SS','WS','SW','WW']

for i in range(n):
  for j in range(len(l)):
    l[j] += 'SW'[::-1 if i=='o' else 1][l[j][i]==l[j][i+1]]
for i in range(n):
  if l[i][1]==l[i][n+1] and l[i][0]==l[i][n]:
    print(l[i][1:n+1])
    exit()
print(-1)

Submission status: Wrong Answer

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def neg(i):
    if i == 'S':
        return 'W'
    else:
        return 'S'

s  = ''
n = 0

def check(build):
    poss = [0, n-1]
    for pos in poss:
        if build[pos] == 'S':
            if s[pos] == 'o' and build[(pos-1+n)%n] == build[(pos+1+n)%n]:
                return True
            if s[pos] == 'x' and build[(pos-1+n)%n] != build[(pos+1+n)%n]:
                print(build)
                return True
        else:
            if s[pos] == 'o' and build[(pos-1+n)%n] != build[(pos+1+n)%n]:
                return True
            if s[pos] == 'x' and build[(pos-1+n)%n] == build[(pos+1+n)%n]:
                return True
    
    return False

def solve():
    global s, n
    n = f()[0]
    s = input()

    for i in [ 'S', 'W']:
        for j in ['S','W']:
            build = i + j
            
            for k in range(1, n-1):
                if s[k] == 'o':
                    if build[k] == 'S':
                        build += build[k-1]
                    else:
                        build += neg(build[k-1])
                else:
                    if build[k] == 'S':
                        build += neg(build[k-1])
                    else:
                        build += build[k-1]

            if check(build):
                print(build)
                return

    print(-1)


solve()

Submission status: Wrong Answer

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def neg(i):
    if i == 'S':
        return 'W'
    else:
        return 'S'

s  = ''
n = 0

def check(build):
    poss = [0, n-1]
    for pos in poss:
        if build[pos] == 'S':
            if s[pos] == 'o' and build[(pos-1+n)%n] == build[(pos+1+n)%n]:
                return True
            if s[pos] == 'x' and build[(pos-1+n)%n] != build[(pos+1+n)%n]:
                print(build)
                return True
        else:
            if s[pos] == 'o' and build[(pos-1+n)%n] != build[(pos+1+n)%n]:
                return True
            if s[pos] == 'x' and build[(pos-1+n)%n] == build[(pos+1+n)%n]:
                return True

def solve():
    global s, n
    n = f()[0]
    s = input()

    for i in [ 'S', 'W']:
        for j in ['S','W']:
            build = i + j
            
            for k in range(1, n-1):
                if s[k] == 'o':
                    if build[k] == 'S':
                        build += build[k-1]
                    else:
                        build += neg(build[k-1])
                else:
                    if build[k] == 'S':
                        build += neg(build[k-1])
                    else:
                        build += build[k-1]

            if check(build):
                print(build)
                return

    print(-1)


solve()

Submission status: Wrong Answer

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def neg(i):
    if i == 'S':
        return 'W'
    else:
        return 'S'

s  = ''
n = 0

def check(build):
    poss = [0, n-1]
    for pos in poss:
        if build[pos] == 'S':
            if s[pos] == 'o' and build[(pos-1+n)%n] == build[(pos+1+n)%n]:
                return True
            if s[pos] == 'x' and build[(pos-1+n)%n] != build[(pos+1+n)%n]:
                print(build)
                return True
        else:
            if s[pos] == 'o' and build[(pos-1+n)%n] != build[(pos+1+n)%n]:
                return True
            if s[pos] == 'x' and build[(pos-1+n)%n] == build[(pos+1+n)%n]:
                return True

def solve():
    global s, n
    n = f()[0]
    s = input()

    for i in [ 'S', 'W']:
        for j in ['S','W']:
            build = i + j
            
            for k in range(1, n):
                if s[k] == 'o':
                    if build[k] == 'S':
                        build += build[k-1]
                    else:
                        build += neg(build[k-1])
                else:
                    if build[k] == 'S':
                        build += neg(build[k-1])
                    else:
                        build += build[k-1]

            if check(build):
                print(build)
                return

    print(-1)

            
                



solve()

Submission status: Wrong Answer

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def neg(i):
    if i == 'S':
        return 'W'
    else:
        return 'S'

def solve():
    n = f()[0]
    s = input()


    for i in [ 'S', 'W']:
        for j in ['S','W']:
            build = i + j
            
            for k in range(1, n-1):
                if s[k] == 'o':
                    if build[k] == 'S':
                        build += build[k-1]
                    else:
                        build += neg(build[k-1])
                else:
                    if build[k] == 'S':
                        build += neg(build[k-1])
                    else:
                        build += build[k-1]

            if build[n-1] == 'S':
                if s[n-1] == 'o' and build[n-2] == build[0]:
                    print(build)
                    return
                if s[n-1] == 'x' and build[n-2] != build[0]:
                    print(build)
                    return
            else:
                if s[n-1] == 'o' and build[n-2] != build[0]:
                    print(build)
                    return
                if s[n-1] == 'x' and build[n-2] == build[0]:
                    print(build)
                    return

    print(-1)

            
                



solve()