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(input())
q = [[True,True],[True,False],[False,True],[False,False]]
p = []
ans = []
for k in range(4):
    p = q[k]
    for i in range(N-2):
        if p[i + 1]:
            if s[i + 1] == "o":
                p.append(p[i])
            else:
                p.append(not p[i])
        else:
            if s[i + 1] == "o":
                p.append(not p[i])
            else:
                p.append(p[i])
                
    if p[0] == p[-1]:
        for i in range(N):
            if p[i]:
                ans.append("S")
            else:
                ans.append("W")
        print("".join(ans))
        break
    if k == 3:
        print(-1)

Submission status: Wrong Answer

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(readline())
    s = input()

    if s[1] == "o":
        first = ((True, True, True),
                 (False, True, False),
                 (True, False, False),
                 (False, False, True))
    else:
        first = ((True, True, False),
                 (False, True, True),
                 (True, False, True),
                 (False, False, False))

    for a, b, c in first:
        kinds = [None] * (n + 1)
        kinds[1] = b
        kinds[0] = a
        kinds[2] = c

        for i in range(2, n):
            if kinds[i]:
                if s[i] == "o":
                    kinds[i + 1] = kinds[i - 1]
                else:
                    kinds[i + 1] = not kinds[i - 1]
            else:
                if s[i] == "o":
                    kinds[i + 1] = not kinds[i - 1]
                else:
                    kinds[i + 1] = kinds[i - 1]

        if kinds[n] == kinds[0]:
            res = ""
            for kind in kinds[:n]:
                if kind:
                    res += "S"
                else:
                    res += "W"
            print(res)
            sys.exit()

    print(-1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())

s=list(input())

memo_ss = ['S','S']
memo_sw = ['S','W']
memo_ws = ['W','S']
memo_ww = ['W','W']

def check(memo_ss):
    for i in range(1,n):
        if s[i] == 'o' :
            if memo_ss[i] == 'S':
                if memo_ss[i-1] == 'S':
                    memo_ss.append('S')
                elif memo_ss[i-1] == 'W':
                    memo_ss.append('W')
            elif memo_ss[i] == 'W':
                if memo_ss[i-1] == 'S':
                    memo_ss.append('W')
                elif memo_ss[i-1] == 'W':
                    memo_ss.append('S')
        elif s[i] == 'x' :
            if memo_ss[i] == 'S':
                if memo_ss[i-1] == 'S':
                    memo_ss.append('W')
                elif memo_ss[i-1] == 'W':
                    memo_ss.append('S')
            elif memo_ss[i] == 'W':
                if memo_ss[i-1] == 'S':
                    memo_ss.append('S')
                elif memo_ss[i-1] == 'W':
                    memo_ss.append('W')
    return memo_ss

memo_ss = check(memo_ss)
memo_sw = check(memo_sw)
memo_ws = check(memo_ws)
memo_ww = check(memo_ww)

if memo_ss[0] == memo_ss[-1]:
    print(''.join(map(str,memo_ss[:n])))
elif memo_sw[0] == memo_sw[-1]:
    print(''.join(map(str,memo_sw[:n])))
elif memo_ws[0] == memo_ws[-1]:
    print(''.join(map(str,memo_ws[:n])))
elif memo_ww[0] == memo_ww[-1]:
    print(''.join(map(str,memo_ww[:n])))
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    S = input()
    M = [{'o': 0, 'x': 1}, {'o': 1, 'x': 0}]
    for s1, sn in [(0, 0), (0, 1), (1, 0), (1, 1)]:
        T = [s1]
        p, pp = s1, sn
        for s in S:
            pp, p = p, M[p ^ pp][s]
            T.append(p)
        if (s1, sn) == (p, pp):
            return T
    return None

T = main()
if not T:
    print(-1)
else:
    print(''.join('S' if s == 0 else 'W' for s in T))

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    s = input()
    #0 sheep 1 wolf
    for i in [[0,0],[0,1],[1,0],[1,1]]:
        t = i[:]
        for j in s[1:]:
            if t[-1] == 0:
                if j == 'o':
                    t.append(t[-2])
                else:
                    t.append(1-t[-2])
            elif j == 'o':
                t.append(1-t[-2])
            else:
                t.append(t[-2])
        if t[-1] == t[0]:
                print(''.join(['S' if i == 0 else 'W' for i in t[:-1]]))
                return
    print(-1)
    return
main()

Submission status: Wrong Answer

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

assignable = False

for k in range(4):
    res = [None for _ in range(N)]
    res[0] = k % 2
    res[-1] = k // 2
    for i in range(N - 2):
        if S[i] == 'o':
            if res[i] == 0:
                res[i + 1] = res[i - 1]
            else:
                res[i + 1] = 1 - res[i - 1]
        else:
            if res[i] == 0:
                res[i + 1] = 1 - res[i - 1]
            else:
                res[i + 1] = res[i - 1]
    if S[-2] == 'o':
        if res[-2] == 0:
            if res[-1] == res[-3]:
                continue
        else:
            if res[-1] == 1 - res[-3]:
                continue
    else:
        if res[-2] == 0:
            if res[-1] == 1 - res[-3]:
                continue
        else:
            if res[-1] == res[-3]:
                continue
    if S[-1] == 'o':
        if res[-1] == 0:
            if res[0] == res[-2]:
                assignable = True
        else:
            if res[0] == 1 - res[-2]:
                assignable = True
    else:
        if res[-1] == 0:
            if res[0] == 1 - res[-2]:
                assignable = True
        else:
            if res[0] == res[-2]:
                assignable = True
    if assignable:
        for i in range(N):
            if res[i]:
                print('W', end='')
            else:
                print('S', end='')
        break
else:
    print(-1)

Submission status: Wrong Answer

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

assignable = False

for k in range(4):
    res = [None for _ in range(N)]
    res[0] = k % 2
    res[-1] = k // 2
    for i in range(N - 2):
        if S[i] == 'o':
            if res[i] == 0:
                res[i + 1] = res[i - 1]
            else:
                res[i + 1] = 1 - res[i - 1]
        else:
            if res[i] == 0:
                res[i + 1] = 1 - res[i - 1]
            else:
                res[i + 1] = res[i - 1]
    if S[-1] == 'o':
        if res[-1] == 0:
            if res[0] == res[-2]:
                assignable = True
        else:
            if res[0] == 1 - res[-2]:
                assignable = True
    else:
        if res[-1] == 0:
            if res[0] == 1 - res[-2]:
                assignable = True
        else:
            if res[0] == res[-2]:
                assignable = True
    if assignable:
        for i in range(N):
            if res[i]:
                print('W', end='')
            else:
                print('S', end='')
        break
else:
    print(-1)

Submission status: Wrong Answer

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

X = [''] * (N + 1)
X[0] = 'S'
X[1] = 'S'
for i in range(1, N):
    if X[i] == 'S':
        if S[i] == 'o':
            X[i + 1] = X[i - 1]
        else:
            if X[i - 1] == 'S':
                X[i + 1] = 'W'
            else:
                X[i + 1] = 'S'
    else:
        if S[i] == 'x':
            X[i + 1] = X[i - 1]
        else:
            if X[i - 1] == 'S':
                X[i + 1] = 'W'
            else:
                X[i + 1] = 'S'
if X[-1] == 'S' and S[0] == 'o':
    X.pop()
    for x in X:
        print(x, end='')
    print('')
    sys.exit()

X = [''] * (N + 1)
X[0] = 'S'
X[1] = 'W'
for i in range(1, N):
    if X[i] == 'S':
        if S[i] == 'o':
            X[i + 1] = X[i - 1]
        else:
            if X[i - 1] == 'S':
                X[i + 1] = 'W'
            else:
                X[i + 1] = 'S'
    else:
        if S[i] == 'x':
            X[i + 1] = X[i - 1]
        else:
            if X[i - 1] == 'S':
                X[i + 1] = 'W'
            else:
                X[i + 1] = 'S'
if X[-1] == 'S' and S[0] == 'x':
    X.pop()
    for x in X:
        print(x, end='')
    print('')
    sys.exit()

X = [''] * (N + 1)
X[0] = 'W'
X[1] = 'S'
for i in range(1, N):
    if X[i] == 'S':
        if S[i] == 'o':
            X[i + 1] = X[i - 1]
        else:
            if X[i - 1] == 'S':
                X[i + 1] = 'W'
            else:
                X[i + 1] = 'S'
    else:
        if S[i] == 'x':
            X[i + 1] = X[i - 1]
        else:
            if X[i - 1] == 'S':
                X[i + 1] = 'W'
            else:
                X[i + 1] = 'S'
if X[-1] == 'W' and S[0] == 'o':
    X.pop()
    for x in X:
        print(x, end='')
    print('')
    sys.exit()

X = [''] * (N + 1)
X[0] = 'W'
X[1] = 'W'
for i in range(1, N):
    if X[i] == 'S':
        if S[i] == 'o':
            X[i + 1] = X[i - 1]
        else:
            if X[i - 1] == 'S':
                X[i + 1] = 'W'
            else:
                X[i + 1] = 'S'
    else:
        if S[i] == 'x':
            X[i + 1] = X[i - 1]
        else:
            if X[i - 1] == 'S':
                X[i + 1] = 'W'
            else:
                X[i + 1] = 'S'
if X[-1] == 'W' and S[0] == 'x':
    X.pop()
    for x in X:
        print(x, end='')
    print('')
    sys.exit()

print('-1')

Submission status: Wrong Answer

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

X = [''] * (N + 1)
X[0] = 'S'
X[1] = 'S'
for i in range(1, N):
    if X[i] == 'S':
        if S[i] == 'o':
            X[i + 1] = X[i - 1]
        else:
            if X[i - 1] == 'S':
                X[i + 1] = 'W'
            else:
                X[i + 1] = 'S'
    else:
        if S[i] == 'x':
            X[i + 1] = X[i - 1]
        else:
            if X[i - 1] == 'S':
                X[i + 1] = 'W'
            else:
                X[i + 1] = 'S'
if X[-1] == 'S':
    X.pop()
    for x in X:
        print(x, end='')
    print('')
    sys.exit()

X = [''] * (N + 1)
X[0] = 'S'
X[1] = 'W'
for i in range(1, N):
    if X[i] == 'S':
        if S[i] == 'o':
            X[i + 1] = X[i - 1]
        else:
            if X[i - 1] == 'S':
                X[i + 1] = 'W'
            else:
                X[i + 1] = 'S'
    else:
        if S[i] == 'x':
            X[i + 1] = X[i - 1]
        else:
            if X[i - 1] == 'S':
                X[i + 1] = 'W'
            else:
                X[i + 1] = 'S'
if X[-1] == 'S':
    X.pop()
    for x in X:
        print(x, end='')
    print('')
    sys.exit()

X = [''] * (N + 1)
X[0] = 'W'
X[1] = 'S'
for i in range(1, N):
    if X[i] == 'S':
        if S[i] == 'o':
            X[i + 1] = X[i - 1]
        else:
            if X[i - 1] == 'S':
                X[i + 1] = 'W'
            else:
                X[i + 1] = 'S'
    else:
        if S[i] == 'x':
            X[i + 1] = X[i - 1]
        else:
            if X[i - 1] == 'S':
                X[i + 1] = 'W'
            else:
                X[i + 1] = 'S'
if X[-1] == 'W':
    X.pop()
    for x in X:
        print(x, end='')
    print('')
    sys.exit()

X = [''] * (N + 1)
X[0] = 'W'
X[1] = 'W'
for i in range(1, N):
    if X[i] == 'S':
        if S[i] == 'o':
            X[i + 1] = X[i - 1]
        else:
            if X[i - 1] == 'S':
                X[i + 1] = 'W'
            else:
                X[i + 1] = 'S'
    else:
        if S[i] == 'x':
            X[i + 1] = X[i - 1]
        else:
            if X[i - 1] == 'S':
                X[i + 1] = 'W'
            else:
                X[i + 1] = 'S'
if X[-1] == 'W':
    X.pop()
    for x in X:
        print(x, end='')
    print('')
    sys.exit()

print('-1')

Submission status: Wrong Answer

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

X = [''] * (N + 1)
X[0] = 'S'
X[1] = 'S'
for i in range(1, N):
    if X[i] == 'S':
        if S[i] == 'o':
            X[i + 1] = X[i - 1]
        else:
            if X[i - 1] == 'S':
                X[i + 1] = 'W'
            else:
                X[i + 1] = 'S'
    else:
        if S[i] == 'x':
            X[i + 1] = X[i - 1]
        else:
            if X[i - 1] == 'S':
                X[i + 1] = 'W'
            else:
                X[i + 1] = 'S'
if X[-1] == 'S':
    for x in X:
        print(x, end='')
    print('')
    sys.exit()

X = [''] * (N + 1)
X[0] = 'S'
X[1] = 'W'
for i in range(1, N):
    if X[i] == 'S':
        if S[i] == 'o':
            X[i + 1] = X[i - 1]
        else:
            if X[i - 1] == 'S':
                X[i + 1] = 'W'
            else:
                X[i + 1] = 'S'
    else:
        if S[i] == 'x':
            X[i + 1] = X[i - 1]
        else:
            if X[i - 1] == 'S':
                X[i + 1] = 'W'
            else:
                X[i + 1] = 'S'
if X[-1] == 'S':
    for x in X:
        print(x, end='')
    print('')
    sys.exit()

X = [''] * (N + 1)
X[0] = 'W'
X[1] = 'S'
for i in range(1, N):
    if X[i] == 'S':
        if S[i] == 'o':
            X[i + 1] = X[i - 1]
        else:
            if X[i - 1] == 'S':
                X[i + 1] = 'W'
            else:
                X[i + 1] = 'S'
    else:
        if S[i] == 'x':
            X[i + 1] = X[i - 1]
        else:
            if X[i - 1] == 'S':
                X[i + 1] = 'W'
            else:
                X[i + 1] = 'S'
if X[-1] == 'W':
    for x in X:
        print(x, end='')
    print('')
    sys.exit()

X = [''] * (N + 1)
X[0] = 'W'
X[1] = 'W'
for i in range(1, N):
    if X[i] == 'S':
        if S[i] == 'o':
            X[i + 1] = X[i - 1]
        else:
            if X[i - 1] == 'S':
                X[i + 1] = 'W'
            else:
                X[i + 1] = 'S'
    else:
        if S[i] == 'x':
            X[i + 1] = X[i - 1]
        else:
            if X[i - 1] == 'S':
                X[i + 1] = 'W'
            else:
                X[i + 1] = 'S'
if X[-1] == 'W':
    for x in X:
        print(x, end='')
    print('')
    sys.exit()

print('-1')

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
X = ['S'] * N
if S[0] == 'x':
    X[-1] = 'W'
Y = X[-1]
for i in range(1, N - 1):
    if X[i] == 'S':
        if S[i] == 'o':
            X[i + 1] = X[i - 1]
        else:
            if X[i - 1] == 'S':
                X[i + 1] = 'W'
            else:
                X[i + 1] = 'S'
    else:
        if S[i] == 'x':
            X[i + 1] = X[i - 1]
        else:
            if X[i - 1] == 'S':
                X[i + 1] = 'W'
            else:
                X[i + 1] = 'S'
if X[-1] != Y:
    print('-1')
else:
    if (Y == 'S' and S[-1] == 'o' and X[-2] == 'S') or (Y == 'S' and S[-1] == 'x' and X[-2] == 'W'):
        for x in X:
            print(x, end='')
        print('')
    elif (Y == 'W' and S[-1] == 'o' and X[-2] == 'W') or (Y == 'W' and S[-1] == 'x' and X[-2] == 'S'):
        for x in X:
            print(x, end='')
        print('')
    else:
        print('-1')

Submission status: Wrong Answer

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7


#############
# Main Code #
#############

N = getN()
S = input()
lista = ['SS', 'SW', 'WS', 'WW']

def judge(string):
    alta = copy.deepcopy(string)
    for i in range(1, N - 1):
        if alta[-1] == "S" and alta[-2] == "S":
            if S[i] == "o":
                alta += 'S'
            else:
                alta += "W"
        elif alta[-1] == "S" and alta[-2] == "W":
            if S[i] == "o":
                alta += 'W'
            else:
                alta += "S"
        elif alta[-1] == "W" and alta[-2] == "S":
            if S[i] == "o":
                alta += 'W'
            else:
                alta += "S"
        else:
            if S[i] == "o":
                alta += 'S'
            else:
                alta += "W"

    return alta

for i in lista:
    opt = judge(i)
    opt1 = opt[-2]
    opt2 = opt[0]
    if opt[-1] == "S":
        if S[-1] == "o":
            if opt1 == opt2:
                print(opt)
                exit()
        else:
            if opt1 != opt2:
                print(opt)
                exit()
    else:
        if S[-1] == "o":
            if opt1 != opt2:
                print(opt)
                exit()
        else:
            if opt1 == opt2:
                print(opt)
                exit()
print(-1)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    s = input()
    for t in ["11", "10", "01", "00"]:
        for i in s[1:-1]:
            if i == "o":
                if t[-1] == '1':
                    t += t[-2]
                else:
                    t += str(abs(int(t[-2]) - 1))
            else:
                if t[-1] == '1':
                    t += str(abs(int(t[-2]) - 1))
                else:
                    t += t[-2]

        if t[-1] == '1':
            if s[-1] == 'o':
                f = t[-2] == t[0]
            else:
                f = t[-2] != t[0]
        else:
            if s[-1] == 'o':
                f = t[-2] != t[0]
            else:
                f = t[-2] == t[0]

        if f:
            t = t.replace("1", "S").replace("0", "W")
            print(t)
            break
    else:
        print(-1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def resolve():
    N = int(input())
    S = list(input())

    def get_next(p_prev, prev, prev_mark):
        anms = ["S", "W"]
        p_prev_idx = anms.index(p_prev)
        if prev_mark == "o":
            return anms[p_prev_idx] if prev== "S" else anms[(p_prev_idx+1)%2]
        else:
            return anms[(p_prev_idx+1)%2] if prev == "S" else anms[p_prev_idx]

    out = ["S", "S"]
    for i in range(2, N):
        out.append(get_next(out[i-2], out[i-1], S[i-1]))
    if get_next(out[-2], out[-1], S[-1]) == out[0]:
        print("".join(out))
        return

    out = ["S", "W"]
    for i in range(2, N):
        out.append(get_next(out[i-2], out[i-1], S[i-1]))
    if get_next(out[-2], out[-1], S[-1]) == out[0]:
        print("".join(out))
        return
    
    out = ["W", "S"]
    for i in range(2, N):
        out.append(get_next(out[i-2], out[i-1], S[i-1]))
    if get_next(out[-2], out[-1], S[-1]) == out[0]:
        print("".join(out))
        return
    
    out = ["W", "W"]
    for i in range(2, N):
        out.append(get_next(out[i-2], out[i-1], S[i-1]))
    if get_next(out[-2], out[-1], S[-1]) == out[0]:
        print("".join(out))
        return
    
    print(-1)

if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

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

for p1,p2 in [(True,True),(True,False),(False,True),(False,False)]:
  ans = []
  ans.extend([p1,p2])  
  for i in range(1,n-1):
    if ans[i] == True:
      if s[i]=='o':
        ans.append(ans[i-1])
      else:
        ans.append(not ans[i-1])
    else:
      if s[i]=='o':
        ans.append(not ans[i-1])
      else:
        ans.append(ans[i-1])
  
  if ans[-1]==True:
    if s[-1]=='o' and ans[-2]==ans[0]:
      break
    if s[-1]=='x' and ans[-2]!=ans[0]:
      break
  else:
    if s[-1]=='o' and ans[-2]!=ans[0]:
      break
    if s[-1]=='x' and ans[-2]==ans[0]:
      break    
  ans = ''
  
if len(ans)>0:
  print(''.join(['S' if a else 'W' for a in ans] ))
else:
  print(-1)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())
def func(a,b):
  ans=[a,b] #True:S, False:W
  for i in range(1,n):
    if s[i]=='o':
      if ans[-1]:
        ans.append(ans[-2])
      else:
        ans.append(not ans[-2])
    else:
      if ans[-1]:
        ans.append(not ans[-2])
      else:
        ans.append(ans[-2])
  if s[0]=='o' and a and ans[0]==ans[-1]:
    print(''.join(['S' if ansi else 'W' for ansi in ans[:-1]]))
    exit()
  elif s[0]=='o' and not a and ans[0]!=ans[-1]:
    print(''.join(['S' if ansi else 'W' for ansi in ans[:-1]]))
    exit()
  elif s[0]=='x' and a and ans[0]!=ans[-1]:
    print(''.join(['S' if ansi else 'W' for ansi in ans[:-1]]))
    exit()
  elif s[0]=='x' and not a and ans[0]==ans[-1]:
    print(''.join(['S' if ansi else 'W' for ansi in ans[:-1]]))
    exit()
func(True,True)
func(True,False)
func(False,True)
func(False,False)
print(-1)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())
def func(a,b):
  ans=[a,b]
  for i in range(1,n):
    if s[i]=='o':
      if ans[-1]:
        ans.append(ans[-2])
      else:
        ans.append(not ans[-2])
    else:
      if ans[-1]:
        ans.append(not ans[-2])
      else:
        ans.append(ans[-2])
  if ans[0]==ans[-1]:
    print(''.join(['S' if ansi else 'W' for ansi in ans[:-1]]))
    exit()
func(True,True)
func(True,False)
func(False,True)
func(False,False)
print(-1)

Submission status: Wrong Answer

Solution code:
import itertools
n = int(input())
s = input()
t = [''] * n
for p in itertools.product(['o', 'x'], repeat=2):
  t[-2] = p[0]
  t[-1] = p[1]
  for i in range(n - 2):
    if (t[i - 2] + t[i - 1] + s[i - 1]).count('x') % 2 == 0:
      t[i] = 'o'
    else:
      t[i] = 'x'
  if (t[-3] + t[-2] + t[-1] + s[-2]).count('x') % 2 == 0 and (t[-2] + t[-1] + t[0] + s[-1]).count('x') % 2 == 0:
    ans = []
    for c in t:
      if c == 'o':
        ans.append('S')
      else:
        ans.append('W')
    print(*ans, sep='')
    break
else:
  print(-1)

Submission status: Wrong Answer

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

def func(f, s):
    l = [-1]*N
    l[0] = f
    l[1] = s
    for i in range(1, len(l) - 1):
        if l[i] and S[i] == "o" or not l[i] and S[i] == "x":
            l[i + 1] = l[i - 1] ^ 1
        else:
            l[i + 1] = l[i - 1]
    if l[-1] and S[-1] == "o" and l[-2] != l[0]:
        return l
    elif l[-1] and S[-1] == "x" and l[-2] == l[0]:
        return l
    elif not l[-1] and S[-1] == "o" and l[-2] == l[0]:
        return l
    elif not l[-1] and S[-1] == "x" and l[-2] != l[0]:
        return l
    else:
        return False

for i, j in [(0, 0), (0, 1), (1, 1), (1, 0)]:
    l = func(i, j)
    if l:
        for v in l:
            print("SW"[v], end="")
        print()
        exit()
print(-1)

Submission status: Wrong Answer

Solution code:
from itertools import product

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

swap = {'S': 'W', 'W': 'S'}
for a, b in product('SW', repeat=2):
    t = [None] * N
    t[0] = a
    t[1] = b
    for i in range(1, N - 1):
        if t[i] == 'S':
            if s[i] == 'o':
                t[i + 1] = t[i - 1]
            elif s[i] == 'x':
                t[i + 1] = swap[t[i - 1]]
        elif t[i] == 'W':
            if s[i] == 'o':
                t[i + 1] = swap[t[i - 1]]
            elif s[i] == 'x':
                t[i + 1] = t[i - 1]
    if t[N - 1] == 'S':
        if s[N - 1] == 'o' and t[N - 2] == t[0]:
            print(''.join(t))
            exit()
        elif s[N - 1] == 'x' and t[N - 2] != t[0]:
            print(''.join(t))
            exit()
    elif t[N - 1] == 'W':
        if s[N - 1] == 'o' and t[N - 2] != t[0]:
            print(''.join(t))
            exit()
        elif s[N - 1] == 'x' and t[N - 2] == t[0]:
            print(''.join(t))
            exit()
print(-1)

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline

sys.setrecursionlimit(10 ** 5)
def main():
    N = int(input())
    S = input().strip()

    def solve(current_index, ans):
        if current_index <= 0:
            solve(current_index + 1, ans + "S")
            solve(current_index + 1, ans + "W")

        elif current_index == N - 1:
            if ans[-1] == "S":
                if S[current_index] == 'o':
                    if ans[-2] == ans[0]:
                        print(ans)
                        exit()
                else:
                    if ans[-2] != ans[0]:
                        print(ans)
                        exit()
            else:
                if S[current_index] == 'x':
                    if ans[-2] == ans[0]:
                        print(ans)
                        exit()
                else:
                    if ans[-2] != ans[0]:
                        print(ans)
                        exit()
        else:
            if ans[-1] == "S":
                if S[current_index] == 'o':
                    solve(current_index + 1, ans + ans[-2])
                else:
                    if ans[-2] == "S":
                        solve(current_index + 1, ans + "W")
                    else:
                        solve(current_index + 1, ans + "S")
            else:
                if S[current_index] == 'x':
                    solve(current_index + 1, ans + ans[-2])
                else:
                    if ans[-2] == "S":
                        solve(current_index + 1, ans + "W")
                    else:
                        solve(current_index + 1, ans + "S")

    solve(-1, "")
    print(-1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
s += s[0]
pat = ["WW","WS","SW","SS"]

for j in pat:
    now = j
    flag = True
    for i in range(1,n):
        if (now[i] == "S" and s[i] == "o") or (now[i] == "W" and s[i] == "x"):
            now += now[i-1]
        else:
            if now[i-1] == "S":
                now += "W"
            else:
                now += "S"
    if now[-1] != now[0]:
        flag = False
    ss = s[-1]+ s
    now = now[-1]+now
    if flag:
        for k in range(1,n+1):
            if ss[k] == "o" and now[k] == "S":
                if now[k-1] != now[k+1]:
                    flag = False
                    break
            elif ss[k] == "x" and now[k] == "S":
                if now[k-1] == now[k+1]:
                    flag = False
                    break
            elif ss[k] == "o" and now[k] == "W":
                if now[k-1] == now[k+1]:
                    flag = False
                    break
            elif ss[k] == "x" and now[k] == "W":
                if now[k-1] != now[k+1]:
                    flag = False
                    break
    if flag:
        print(now[1:-1])
        exit()

print(-1)

Submission status: Wrong Answer

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

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

for j in pat:
    now = j
    flag = True
    for i in range(1,n):
        if now[i] == "S" and now[i-1] == "S":
            if s[i] == "o":
                now += "S"
            else:
                now += "W"
        elif now[i] == "S" and now[i-1] == "W":
            if s[i] == "o":
                now += "W"
            else:
                now += "S"
        elif now[i] == "W" and now[i-1] == "S":
            if s[i] == "o":
                now += "W"
            else:
                now += "S"
        else:
            if s[i] == "o":
                now += "S"
            else:
                now += "W"
    if now[-1] != now[0]:
        flag = False
    ss = s[-1]+ s + s[0]
    now = now[-1] + now
    for k in range(1,n+1):
        if ss[k] == "o" and now[k] == "S":
            if now[k-1] != now[k+1]:
                flag = False
                break
        elif ss[k] == "x" and now[k] == "S":
            if now[k-1] == now[k+1]:
                flag = False
                break
        elif ss[k] == "o" and now[k] == "W":
            if now[k-1] == now[k+1]:
                flag = False
                break
        elif ss[k] == "x" and now[k] == "W":
            if now[k-1] != now[k+1]:
                flag = False
                break
    if flag:
        print(now[1:-1])
        exit()
print(-1)

Submission status: Wrong Answer

Solution code:
print(-1)