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:
def solver(array):
    for index in range(1, n+1):
        if index == n:
            index = 0
        if array[index] == "S" and s[index]:
            if index == n - 1:
                if array[index-1] != array[0] and array[1]:
                    return False
                else:
                    continue
            array[index + 1] = array[index - 1]
        elif array[index] == "S" and not s[index]:
            if index == n - 1:
                if array[index-1] == array[0]:
                    return False
                else:
                    continue
            if array[index - 1] == "W":
                array[index + 1] = "S"
            else:
                array[index + 1] = "W"
        elif array[index] == "W" and s[index]:
            if index == n - 1:
                if array[index-1] == array[0]:
                    return False
                else:
                    continue
            if array[index - 1] == "W":
                array[index + 1] = "S"
            else:
                array[index + 1] = "W"
        elif array[index] == "W" and not s[index]:
            if index == n - 1:
                if array[index-1] != array[0]:
                    return False
                else:
                    continue
            array[index + 1] = array[index - 1]
    return array


n = int(input())
s = [True if x == "o" else False for x in list(input())]
ws = ["W", "S"] + ["*" for x in range(n - 2)]
sw = ["S", "W"] + ["*" for x in range(n - 2)]
ss = ["S", "S"] + ["*" for x in range(n - 2)]
ww = ["W", "W"] + ["*" for x in range(n - 2)]

for array in [ws, sw, ss, ww]:
    res = solver(array)
    if not res:
        continue
    else:
        print("".join(res))
        exit()
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
def solver(array):
    for index in range(1, n):
        if array[index] == "S" and s[index]:
            if index == n - 1:
                if array[index-1] != array[0]:
                    return False
                else:
                    continue
            array[index + 1] = array[index - 1]
        elif array[index] == "S" and not s[index]:
            if index == n - 1:
                if array[index-1] == array[0]:
                    return False
                else:
                    continue
            if array[index - 1] == "W":
                array[index + 1] = "S"
            else:
                array[index + 1] = "W"
        elif array[index] == "W" and s[index]:
            if index == n - 1:
                if array[index-1] == array[0]:
                    return False
                else:
                    continue
            if array[index - 1] == "W":
                array[index + 1] = "S"
            else:
                array[index + 1] = "W"
        elif array[index] == "W" and not s[index]:
            if index == n - 1:
                if array[index-1] != array[0]:
                    return False
                else:
                    continue
            array[index + 1] = array[index - 1]
    return array


n = int(input())
s = [True if x == "o" else False for x in list(input())]
ws = ["W", "S"] + ["*" for x in range(n - 2)]
sw = ["S", "W"] + ["*" for x in range(n - 2)]
ss = ["S", "S"] + ["*" for x in range(n - 2)]
ww = ["W", "W"] + ["*" for x in range(n - 2)]

for array in [ws, sw, ss, ww]:
    res = solver(array)
    if not res:
        continue
    else:
        print("".join(res))
        exit()
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
a = [0 for i in range(n)]
b = [0 for i in range(n)]
b[1] = 1
c = [0 for i in range(n)]
c[0] = 1
d = [0 for i in range(n)]
d[0] = 1
d[1] = 1


def check(ha):
    for i in range(1,n-1):
        if s[i] == "o" and ha[i] == 0:
            ha[i+1] = ha[i-1]
        elif s[i] == "o" and ha[i] == 1:
            ha[i+1] = (1- ha[i-1])
        elif s[i] == "x" and ha[i] == 0:
            ha[i+1] = (1-ha[i-1])
        elif s[i] == "x" and ha[i] == 1:
            ha[i+1] = ha[i-1]

    if s[n-1] == "o" and ha[n-1] == 0:
        k = ha[n-2]
    elif s[n-1] == "o" and ha[n-1] == 1:
        k = (1-ha[n-2])
    elif s[n-1] == "x" and ha[n-1] == 0:
        k = (1-ha[n-2])
    elif s[n-1] == "x" and ha[n-1] == 1:
        k = ha[n-2]

    if k == ha[0]:
        return (1,ha)
    else:
        return (0,ha)

ala = 0
for ha in [a,b,c,d]:
    soso,he = check(ha)
    #print(he)
    ala += soso
    if soso == 1:
        s = ""
        for i in range(n):
            if he[i] == 0:
                s += "S"
            else:
                s += "W"
        print(s)
        break

if ala == 0:
    print("-1")

Submission status: Wrong Answer

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

li = ["N"]*(n+1)

li[0] = "W"
li[1] = "W"

for i in range(1,n):
  if li[i]=="W" and s[i]=="o":
    if li[i-1] == "W":
      li[i+1] = "S"
    else:
      li[i+1] = "W"
  
  elif li[i]=="S" and s[i]=="o":
    if li[i-1] == "W":
      li[i+1] = "W"
    else:
      li[i+1] = "S"
 
  elif li[i]=="W" and s[i]=="x":
    if li[i-1] == "W":
      li[i+1] = "W"
    else:
      li[i+1] = "S"

  elif li[i]=="S" and s[i]=="x":
    if li[i-1] == "W":
      li[i+1] = "S"
    else:
      li[i+1] = "W"
     
if li[0]==li[n]:
  print(str(li[0:n]).replace("[","").replace("]","").replace(",","").replace("'","").replace(" ",""))
  exit()

li[0] = "S"
li[1] = "W"

for i in range(1,n):
  if li[i]=="W" and s[i]=="o":
    if li[i-1] == "W":
      li[i+1] = "S"
    else:
      li[i+1] = "W"
  
  elif li[i]=="S" and s[i]=="o":
    if li[i-1] == "W":
      li[i+1] = "W"
    else:
      li[i+1] = "S"
 
  elif li[i]=="W" and s[i]=="x":
    if li[i-1] == "W":
      li[i+1] = "W"
    else:
      li[i+1] = "S"

  elif li[i]=="S" and s[i]=="x":
    if li[i-1] == "W":
      li[i+1] = "S"
    else:
      li[i+1] = "W"
     
if li[0]==li[n]:
  print(str(li[0:n]).replace("[","").replace("]","").replace(",","").replace("'","").replace(" ",""))
  exit()

li[0] = "W"
li[1] = "S"

for i in range(1,n):
  if li[i]=="W" and s[i]=="o":
    if li[i-1] == "W":
      li[i+1] = "S"
    else:
      li[i+1] = "W"
  
  elif li[i]=="S" and s[i]=="o":
    if li[i-1] == "W":
      li[i+1] = "W"
    else:
      li[i+1] = "S"
 
  elif li[i]=="W" and s[i]=="x":
    if li[i-1] == "W":
      li[i+1] = "W"
    else:
      li[i+1] = "S"

  elif li[i]=="S" and s[i]=="x":
    if li[i-1] == "W":
      li[i+1] = "S"
    else:
      li[i+1] = "W"
      
if li[0]==li[n]:
  print(str(li[0:n]).replace("[","").replace("]","").replace(",","").replace("'","").replace(" ",""))
  exit()

li[0] = "S"
li[1] = "S"

for i in range(1,n):
  if li[i]=="W" and s[i]=="o":
    if li[i-1] == "W":
      li[i+1] = "S"
    else:
      li[i+1] = "W"
  
  elif li[i]=="S" and s[i]=="o":
    if li[i-1] == "W":
      li[i+1] = "W"
    else:
      li[i+1] = "S"
 
  elif li[i]=="W" and s[i]=="x":
    if li[i-1] == "W":
      li[i+1] = "W"
    else:
      li[i+1] = "S"

  elif li[i]=="S" and s[i]=="x":
    if li[i-1] == "W":
      li[i+1] = "S"
    else:
      li[i+1] = "W"
      
if li[0]==li[n]:
  print(str(li[0:n]).replace("[","").replace("]","").replace(",","").replace("'","").replace(" ",""))
  exit()
print(-1)

Submission status: Wrong Answer

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

"""
参考：https://img.atcoder.jp/arc069/editorial.pdf
"""

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

def verify(t):
    # 2か所決まれば芋づる式に全て定まる
    for i in range(1, N-1):
        # 羊がoと言ってるor狼がxと言ってる
        if t[i] == 'S' and s[i] == 'o' or t[i] == 'W' and s[i] == 'x':
            # 両隣は同じ
            if t[i-1] == 'S':
                t[i+1] = 'S'
            else:
                t[i+1] = 'W'
        # 逆
        else:
            # 両隣は違う
            if t[i-1] == 'S':
                t[i+1] = 'W'
            else:
                t[i+1] = 'S'
    # 終端と始点の辻褄が合っているか検証する
    if t[-1] == 'S' and s[-1] == 'o' or t[-1] == 'W' and s[-1] == 'x':
        if t[-2] == 'S' and t[0] == 'S' or t[-2] == 'W' and t[0] == 'W':
            return True
    else:
        if t[-2] == 'S' and t[0] == 'W' or t[-2] == 'W' and t[0] == 'S':
            return True
    return False

# 2か所決める方法4通り
for a, b in [('S', 'S'), ('W', 'W'), ('S', 'W'), ('W', 'S')]:
    t = [''] * N
    t[0] = a
    t[1] = b
    if verify(t): 
        print(''.join(t))
        exit()
print(-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
sw4li = ["SS", "SW", "WS", "WW"]
t = ""
for v in sw4li:
    t = ""
    t += v
    for i in range(1, len(s)):
        if t[-2] == "S" and t[-1] == "S":
            if s[i] == "o":
                t += "S"
            elif s[i] == "x":
                t += "W"
        elif t[-2] == "S" and t[-1] == "W":
            if s[i] == "o":
                t += "W"
            elif s[i] == "x":
                t += "S"
        elif t[-2] == "W" and t[-1] == "S":
            if s[i] == "o":
                t += "W"
            elif s[i] == "x":
                t += "S"
        elif t[-2] == "W" and t[-1] == "W":
            if s[i] == "o":
                t += "S"
            elif s[i] == "x":
                t += "W"
    if t[-1] == t[0]:
        print(t[:-1])
        exit()
print(-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
sw4li = ["SS", "SW", "WS", "WW"]
t = ""
for v in sw4li:
    t = ""
    t += v
    for i in range(1, len(s)):
        if t[-2] == "S" and t[-1] == "S":
            if s[i] == "o":
                t += "S"
            elif s[i] == "x":
                t += "W"
        elif t[-2] == "S" and t[-1] == "W":
            if s[i] == "o":
                t += "W"
            elif s[i] == "x":
                t += "S"
        elif t[-2] == "W" and t[-1] == "S":
            if s[i] == "o":
                t += "W"
            elif s[i] == "x":
                t += "S"
        elif t[-2] == "W" and t[-1] == "W":
            if s[i] == "o":
                t += "S"
            elif s[i] == "x":
                t += "W"
    if t[-1] == t[0]:
        print(t[:-1])
        exit()
    else:
        break
print(-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
sw4li = ["SS", "SW", "WS", "WW"]
t = ""
for v in sw4li:
    t += v
    for i in range(1, len(s)):
        if t[-2] == "S" and t[-1] == "S":
            if s[i] == "o":
                t += "S"
            elif s[i] == "x":
                t += "W"
        elif t[-2] == "S" and t[-1] == "W":
            if s[i] == "o":
                t += "W"
            elif s[i] == "x":
                t += "S"
        elif t[-2] == "W" and t[-1] == "S":
            if s[i] == "o":
                t += "W"
            elif s[i] == "x":
                t += "S"
        elif t[-2] == "W" and t[-1] == "W":
            if s[i] == "o":
                t += "S"
            elif s[i] == "x":
                t += "W"
    if t[-1] == t[0]:
        print(t[:-1])
        exit()
    else:
        break
print(-1)

Submission status: Wrong Answer

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

# 0: S, 1: Wとする
X = ['S', 'W']
for P in [[0, 0], [0, 1], [1, 0], [1, 1]]:
    for i, s in enumerate(S[1:], start=1):
        if s == 'o' and P[i] == 0:
            P.append(P[i - 1])

        if s == 'o' and P[i] == 1:
            P.append(P[i - 1] ^ 1)

        if s == 'x' and P[i] == 0:
            P.append(P[i - 1] ^ 1)

        if s == 'x' and P[i] == 1:
            P.append(P[i - 1])

    P = P[:-1]
    # 先頭条件を確認
    if S[0] == 'o':
        if not (P[0] == 0 and P[-1] == P[1]) or (P[0] == 1 and P[-1] != P[1]):
            continue
    else:
        if not (P[0] == 0 and P[-1] != P[1]) or (P[0] == 1 and P[-1] == P[1]):
            continue

    # 最後尾条件を確認
    if S[-1] == 'o':
        if not (P[-1] == 0 and P[-2] == P[0]) or (P[-1] == 1 and P[-2] != P[0]):
            continue
    else:
        if not (P[-1] == 0 and P[-2] != P[0]) or (P[-1] == 1 and P[-2] == P[0]):
            continue

    ans = [X[p] for p in P]
    print(''.join(ans))
    exit()

print(-1)

Submission status: Wrong Answer

Solution code:
# coding:utf-8

import sys
# from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


n = II()
s = SI()

s += s[0]
P = ('00', '01', '10', '11')  # 0: S, 1: W
for p in P:
    for i in range(1, n):
        # print(i, p[-1], s[i])
        if s[i] == 'o':
            p += p[-2] if p[-1] == '0' else str(int(p[-2]) ^ 1)
        else:
            p += p[-2] if p[-1] == '1' else str(int(p[-2]) ^ 1)

    if p[0] == p[-1]:
        ans = ''
        for a in p[:-1]: ans += 'S' if a == '0' else 'W'
        print(ans)
        exit()

print(-1)

Submission status: Wrong Answer

Solution code:
N=int(input())
s=input()
assum=["SS","SW","WS","WW"]
for item in assum:
  t=item
  for i in range(1,N-1):
    if ((s[i]=="o") and (t[i]=="S")) or ((s[i]=="x") and (t[i]=="W")):
      t+=t[i-1]
    else:
      if t[i-1]=="S":
        t+="W"
      else:
        t+="S"
  if (t[N-2]==t[0] and ((s[N-1]=="o" and t[N-1]=="S") or (s[N-1]=="x" and t[N-1]=="W"))) or (t[N-2]!=t[0] and ((s[N-1]=="o" and t[N-1]=="W") or (s[N-1]=="x" and t[N-1]=="S"))):
    if (t[N-1]==t[1] and ((s[1]=="o" and t[1]=="S") or (s[1]=="x" and t[1]=="W"))) or (t[N-1]!=t[1] and ((s[1]=="o" and t[1]=="W") or (s[1]=="x" and t[1]=="S"))):
      print(t)
      break
else:
  print(-1)

Submission status: Wrong Answer

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

S1 = "SS"
S2 = "WW"
S3 = "SW"
S4 = "WS"
S_list = [S1, S2, S3, S4]
for S in S_list:
    last = ""
    for i in range(n):
        if i == 0:
            if S[0] == "S":
                if s[i] == "o":
                    last = S[1]
                else:
                    last = "S" if S[1] == "W" else "W"
            else:
                if s[i] == "o":
                    last = "S" if S[1] == "W" else "W"
                else:
                    last = "S" if S[1] == "S" else "W"

        elif 1 <= i < n - 1:
            if S[i] == "S":
                if s[i] == "o":
                    S += S[i-1]
                else:
                    S += "W" if S[i-1] == "S" else "S"
            else:
                if s[i] == "o":
                    S += "S" if S[i-1] == "W" else "S"
                else:
                    S += "S" if S[i-1] == "S" else "W"
        elif i == n - 1:
            if S[i] == "S":
                if s[i] == "o" and S[0] == S[i - 1] and S[i] == last:
                    print(S)
                    exit()
                if s[i] == "x" and S[0] != S[i - 1] and S[i] == last:
                    print(S)
                    exit()
            else:
                if s[i] == "o" and S[0] != S[i - 1] and S[i] == last:
                    print(S)
                    exit()
                if s[i] == "x" and S[0] == S[i - 1] and S[i] == last:
                    print(S)
                    exit()

print(-1)

Submission status: Wrong Answer

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

S1 = "SS"
S2 = "WW"
S3 = "SW"
S4 = "WW"
S_list = [S1, S2, S3, S4]
for S in S_list:
    last = ""
    for i in range(n):
        if i == 0:
            if S[0] == "S":
                if s[i] == "o":
                    last = S[1]
                else:
                    last = "S" if S[1] == "W" else "W"
            else:
                if s[i] == "o":
                    last = "S" if S[1] == "W" else "W"
                else:
                    last = "S" if S[1] == "S" else "W"

        elif 1 <= i < n - 1:
            if S[i] == "S":
                if s[i] == "o":
                    S += S[i-1]
                else:
                    S += "W" if S[i-1] == "S" else "S"
            else:
                if s[i] == "o":
                    S += "S" if S[i-1] == "W" else "S"
                else:
                    S += "S" if S[i-1] == "S" else "W"
        elif i == n - 1:
            if S[i] == "S":
                if s[i] == "o" and S[0] == S[i - 1] and S[i] == last:
                    print(S)
                    exit()
                if s[i] == "x" and S[0] != S[i - 1] and S[i] == last:
                    print(S)
                    exit()
            else:
                if s[i] == "o" and S[0] != S[i - 1] and S[i] == last:
                    print(S)
                    exit()
                if s[i] == "x" and S[0] == S[i - 1] and S[i] == last:
                    print(S)
                    exit()
print(-1)

Submission status: Wrong Answer

Solution code:
def inductive_inference(animal, statement, other):
    if animal == 'S':
        if statement == 'o':
            return other
        else:
            return {'S': 'W', 'W': 'S'}[other]
    else:
        if statement == 'x':
            return other
        else:
            return {'S': 'W', 'W': 'S'}[other]

N = int(input())
S = input()
for a1, a2 in ['SS', 'SW', 'WS', 'WW']:
    assumption = inductive_inference(a1, S[0], a2)  # the animal numbered N
    a, b = a1, a2
    animals = [a, b]
    for c in S[1:]:
        a, b = b, inductive_inference(b, c, a)
        animals.append(b)
    if animals[0] == animals[-1] == assumption:
        print(''.join(animals[:-1]))
        exit()
print(-1)

Submission status: Wrong Answer

Solution code:
def inductive_inference(animal, statement, other):
    if animal == 'S':
        if statement == 'o':
            return other
        else:
            return {'S': 'W', 'W': 'S'}[other]
    else:
        if statement == 'x':
            return other
        else:
            return {'S': 'W', 'W': 'S'}[other]

N = int(input())
S = input()
for a, b in ['SS', 'SW', 'WS', 'WW']:
    animals = [a, b]
    for c in S[1:]:
        a, b = b, inductive_inference(b, c, a)
        animals.append(b)
    if animals[0] == animals[-1]:
        print(''.join(animals[:-1]))
        exit()
print(-1)

Submission status: Wrong Answer

Solution code:
N = int(input())
nums = [[1, 1], [1, 0], [0, 1], [0, 0]]
i = 0
ans = ""

for s in list(input()):
    if i == 0:
        if s == "o":
            nums[0] = [[1, 1, 1]]
            nums[1] = [[0, 1, 0]]
            nums[2] = [[0, 0, 1]]
            nums[3] = [[1, 0, 0]]
        elif s == "x":
            nums[0] = [[0, 1, 1]]
            nums[1] = [[0, 1, 1]]
            nums[2] = [[1, 0, 1]]
            nums[3] = [[0, 0, 0]]
    else:
        for j in range(4):
            a_i_1 = nums[j][i-1][1]
            a_i = nums[j][i-1][2]
            if s == "o" and a_i == 1:
                nums[j].append([a_i_1, a_i, a_i_1])
            elif s == "o" and a_i == 0:
                nums[j].append([a_i_1, a_i, (1 - a_i_1)])
            elif s == "x" and a_i == 1:
                nums[j].append([a_i_1, a_i, (1 - a_i_1)])
            else:
                nums[j].append([a_i_1, a_i, a_i_1])
    i += 1

for j in range(4):
    if nums[j][0][0] == nums[j][N-1][1]:
        for k in range(N):
            if nums[j][k][1] == 1:
                ans += "S"
            else:
                ans += "W"
        print(ans)
        break
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
def swap(w):
    return("S" if w == "W" else "W")

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

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

for init in inits:
    ans = init
    for i in range(1,N):
        if(ans[i] == 'S'):
            if(s[i] == 'o'):
                ans = ans + ans[i-1]
            else:
                ans = ans + swap(ans[i-1])
        else:
            if(s[i] == 'o'):
                ans = ans + swap(ans[i-1])
            else:
                ans = ans + ans[i-1]
    if (ans[-1] == ans[0]):
        ans = ans[0:N]
        break
    else:
        ans = "-1"

print(ans)

Submission status: Wrong Answer

Solution code:
def swap(w):
    return("S" if w == "W" else "W")

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

inits = ["SS","SW","WS","WW"]
init = ["SW"]

for init in inits:
    ans = init
    for i in range(1,N):
        if(ans[i] == 'S'):
            if(s[i] == 'o'):
                ans = ans + ans[i-1]
            else:
                ans = ans + swap(ans[i-1])
        else:
            if(s[i] == 'o'):
                ans = ans + swap(ans[i-1])
            else:
                ans = ans + ans[i-1]
    if (ans[-1] == ans[0]):
        ans = ans[0:N]
        break
    else:
        ans = "-1"

print(ans)

Submission status: Wrong Answer

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

def next(previous, myself, ans):
    if myself == "S":
        if previous == "S":
            if ans == "o":
                return "S"
            else:
                return "W"
        else:
            if ans == "o":
                return "W"
            else:
                return "S"
    else:
        if previous == "S":
            if ans == "o":
                return "W"
            else:
                return "S"
        else:
            if ans == "o":
                return "S"
            else:
                return "W"


ret = "SS"
for i in range(len(s))[1:-1]:
    ret += next(ret[i - 1], ret[i], s[i])
if next(ret[-2], ret[-1], s[-1]) == ret[0]:
    print(ret)
    quit()

ret = "SW"
for i in range(len(s))[1:-1]:
    ret += next(ret[i - 1], ret[i], s[i])
if next(ret[-2], ret[-1], s[-1]) == ret[0]:
    print(ret)
    quit()

ret = "WS"
for i in range(len(s))[1:-1]:
    ret += next(ret[i - 1], ret[i], s[i])
if next(ret[-2], ret[-1], s[-1]) == ret[0]:
    print(ret)
    quit()

ret = "WW"
for i in range(len(s))[1:-1]:
    ret += next(ret[i - 1], ret[i], s[i])
if next(ret[-2], ret[-1], s[-1]) == ret[0]:
    print(ret)
    quit()

print(-1)

Submission status: Wrong Answer

Solution code:
N = int(input())
s = input()
rec = [[""] * N for i in range(4)]
rec[0][0] = "S"
rec[0][1] = "S"
rec[1][0] = "S"
rec[1][1] = "W"
rec[2][0] = "W"
rec[2][1] = "S"
rec[3][0] = "W"
rec[3][1] = "W"
k = -1
for i in range(4):
    for j in range(1, N):
        if s[j] == "o":
            if rec[i][j] == "S":
                rec[i][(j + 1) % N] = rec[i][j - 1]
            else:
                if rec[i][j - 1] == "S":
                    rec[i][(j + 1) % N] = "W"
                else:
                    rec[i][(j + 1) % N] = "S"
        else:
            if rec[i][j] == "S":
                if rec[i][j - 1] == "S":
                    rec[i][(j + 1) % N] = "W"
                else:
                    rec[i][(j + 1) % N] = "S"
            else:
                rec[i][(j + 1) % N] = rec[i][j - 1]

if rec[0][0] =="S":
    k = 0
elif rec[1][0] == "S":
    k = 1
elif rec[2][0] == "W":
    k = 2
elif rec[3][0] == "W":
    k = 3

if k == -1:
    print(-1)
else:
    print("".join(rec[k]))

Submission status: Wrong Answer

Solution code:
N = int( input())
s = list( input())
I = ['S', 'W']
Flag = False
for x in I:
    for y in I:
        ANS = ['']*N
        ANS[0] = x
        ANS[-1] = y
        for i in range(N-2):
            if ANS[i] == 'S':
                if s[i] == 'o':
                    ANS[i+1] = ANS[i-1]
                else:
                    if ANS[i-1] == 'S':
                        ANS[i+1] = 'W'
                    else:
                        ANS[i+1] = 'S'
            else:
                if s[i] == 'x':
                    ANS[i+1] = ANS[i-1]
                else:
                    if ANS[i-1] == 'S':
                        ANS[i+1] = 'W'
                    else:
                        ANS[i+1] = 'S'
        if ANS[-2] == 'S':
            if s[-2] == 'o':
                if ANS[-3] == ANS[-1]:
                    pass
                else:
                    break
            else:
                if ANS[-3] == ANS[-1]:
                    break
                else:
                    pass
        else:
            if s[-2] == 'o':
                if ANS[-3] != ANS[-1]:
                    pass
                else:
                    break
            else:
                if ANS[-3] != ANS[-1]:
                    break
                else:
                    pass
        if ANS[-1] == 'S':
            if s[-1] == 'o':
                if ANS[-2] == ANS[0]:
                    pass
                else:
                    break
            else:
                if ANS[-2] == ANS[0]:
                    break
                else:
                    pass
        else:
            if s[-1] == 'o':
                if ANS[-2] != ANS[0]:
                    pass
                else:
                    break
            else:
                if ANS[-2] != ANS[0]:
                    break
                else:
                    pass
        print(''.join(ANS))
        Flag = True
        break
    if Flag:
        break
if Flag == False:
    print(-1)

Submission status: Wrong Answer

Solution code:
from itertools import product
 
def solve():
	N = int(input())
	S = [0 if i == 'o' else 1 for i in input()]
 
	for i, j in product(range(2), repeat=2):
		pattern = [i, j] + [0] * (N - 2) 
		for k in range(2, N):
			pattern[k] = (pattern[k - 1] + pattern[k - 2] + S[k] ) % 2
		if S[-1] != (pattern[-2] + pattern[-1] + pattern[0]) % 2 : 
			continue
		if S[0] != (pattern[-1] + pattern[0] + pattern[1]) % 2 :
			continue 	
		answer = [ 'S' if pattern[k] == 0 else 'W' for k in range(N)]
		print(''.join(answer))
		return None
	print(-1)
 
if __name__ == '__main__':
	solve()

Submission status: Wrong Answer

Solution code:
from itertools import product
 
N = int(input())
S = [0 if i == 'o' else 1 for i in input()]
 
for i, j in product(range(2), repeat=2):
	pattern = [i, j] + [0] * (N - 2) 
	for k in range(2, N):
		pattern[k] = ( S[k-1] - (pattern[k - 1] + pattern[k - 2] )) % 2
	if S[-1] != (pattern[-2] + pattern[-1] + pattern[0]) % 2 : 
		continue
	if S[0] != (pattern[-1] + pattern[0] + pattern[1]) % 2 :
		continue 	
	answer = [ 'S' if pattern[k] == 0 else 'W' for k in range(N)]
	print(''.join(answer))
print(-1)

Submission status: Wrong Answer

Solution code:
from itertools import product

N = int(input())
S = [0 if i == 'o' else 1 for i in input()]

for i, j in product(range(2), repeat=2):
	pattern = [i, j] + [0] * (N - 2) 
	for k in range(2, N):
		pattern[k] = ( S[k-1] - (pattern[k - 1] + pattern[k - 2] )) % 2
	if S[-1] != (pattern[-2] + pattern[-1] + pattern[0]) % 2 : 
		continue
	if S[0] != (pattern[-1] + pattern[0] + pattern[1]) % 2 :
		continue 	
	answer = [ 'S' if pattern[k] == 0 else 'W' for k in range(N)]
	print(''.join(answer))
	None
print(-1)

Submission status: Wrong Answer

Solution code:
from itertools import product


N = int(input())
S = [0 if i == 'o' else 1 for i in input()]
for i, j in product(range(2), repeat=2):
	pattern = [i, j] + [0] * (N - 2) 
	for k in range(2, N):
		pattern[k] = (pattern[k - 1] + pattern[k - 2] + S[k] ) % 2
	if S[-1] != (pattern[-2] + pattern[-1] + pattern[0]) % 2 : 
		continue
	if S[0] != (pattern[-1] + pattern[0] + pattern[1]) % 2 :
		continue 	
	answer = [ 'S' if pattern[k] == 0 else 'W' for k in range(N)]
	print(''.join(answer))
print(-1)

Submission status: Wrong Answer

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

# n=1,Nが(S,S)(S,W)(W,S)(W,W)の4通りを仮定してずらずら決めていけばよいはず
# S=0, W=1として, 1-xで切り替える
# 最後に矛盾が生じないやつだけえらぶO(1)で判定できそうだけど。。

pat = [(0,0),(0,1),(1,0),(1,1)]
fl = False

for p in pat:
  ans = []
  x_now = p[0]
  x_prev = p[1]
  ans.append(x_now)
  for i in range(N):
    if ST[i] == 'o':
      if x_now == 0:
        x_next = x_prev
      else:
        x_next = 1 - x_prev
    else:
      if x_now == 0:
        x_next = 1 - x_prev
      else:
        x_next = x_prev
  
    #print(i, ST[i], x_prev, x_now, x_next)
    ans.append(x_next)
    x_prev, x_now = x_now, x_next

  if ans[-1] == ans[0]:
    #correct case
    fl = True
    break

if fl:
  for i in range(N):
    print("S" if ans[i] == 0 else "W", end="")
  print()
else:
  print("-1")

Submission status: Wrong Answer

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

# n=1,Nが(S,S)(S,W)(W,S)(W,W)の4通りを仮定してずらずら決めていけばよいはず
# S=0, W=1として, 1-xで切り替える
# 最後に矛盾が生じないやつだけえらぶO(1)で判定できそうだけど。。

pat = [(0,0),(0,1),(1,0),(1,1)]
fl = False

for p in pat:
  ans = []
  x_now = p[0]
  x_prev = p[1]
  ans.append(x_now)
  for i in range(N):
    if ST[i] == 'o':
      if x_now == 0:
        x_next = x_prev
      else:
        x_next = 1 - x_prev
    else:
      if x_now == 0:
        x_next = 1 - x_prev
      else:
        x_next = x_prev
  
    x_prev, x_now = x_now, x_next
    ans.append(x_next)

  #print(p, ans)
  if ans[-1] == ans[0]:
    #correct case
    fl = True
    break

if fl:
  for i in range(N):
    print("S" if ans[i] == 0 else "W", end="")
else:
  print("-1")