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:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
s = input()

import itertools
for a0, a1 in itertools.product(("W", "S"), ("S", "W")):
    print(a0,a1)
    ans = [None]*n
    ans[0] = a0
    ans[-1] = a1
    for i in range(n-1):
        v = (s[i]=="o") + (ans[i-1]=="S") + (ans[i]=="S")
        if v%2==1:
            ans[i+1] = "S"
        else:
            ans[i+1] = "W"
    v = (s[n-1]=="o") + (ans[n-2]=="S") + (ans[0]=="S") + (ans[n-1]=="S")
    if v%2==0:
        write("".join(ans))
        break
else:
    print(-1)

Submission status: Wrong Answer

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


#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode('utf-8')

#import numpy as np
from itertools import combinations

def main():
	n=II()
	s=input().decode()


	def check(a,b,c):
		A=[None]*(n+1)
		A[0]=a
		A[1]=b
		A[n-1]=c
		A[n]=a

		for i in range(1,n):
			if (s[i]=="o" and A[i]=="S") or (s[i]=="x" and A[i]=="W"):
				if A[i+1]==None:
					A[i+1]=A[i-1]
				else:
					if A[i+1]!=A[i-1]:
						return
			#if (s[i]=="o" and A[i]=="W") or (s[i]=="x" and A[i]=="S"):
			else:
				if A[i+1]==None:
					if A[i-1]=="S":
						A[i+1]="W"
					else:
						A[i+1]="S"
				else:
					if A[i+1]==A[i-1]:
						return

		print(*A[:-1],sep="")
		exit(0)

	if s[0]=="o":
		check("S","S","S")
		check("S","W","W")
		check("W","W","S")
		check("W","S","W")

	else:
		check("S","S","W")
		check("S","W","W")
		check("W","S","S")
		check("W","W","W")

	print(-1)













if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")

n = int(input())
s = input()

import itertools
for a0, a1 in itertools.product(("W", "S"), ("S", "W")):
    ans = [None]*n
    ans[0] = a0
    ans[-1] = a1
    for i in range(n-1):
        v = (s[i]=="o") + (ans[i-1]=="S") + (ans[i]=="S")
        if v%2==1:
            ans[i+1] = "S"
        else:
            ans[i+1] = "W"
    v = (s[n-1]=="o") + (ans[n-2]=="S") + (ans[0]=="S") + (ans[n-1]=="S")
    if v%2==0:
        write("".join(ans))
        break
    else:
        pass
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
s = input()

import itertools
for a0, a1 in itertools.product(("S", "W"), ("S", "W")):
    ans = [None]*n
    ans[0] = a0
    ans[-1] = a1
    for i in range(n-1):
        v = (s[i]=="o") + (ans[i-1]=="S") + (ans[i]=="S")
        if v%2==1:
            ans[i+1] = "S"
        else:
            ans[i+1] = "W"
    v = (s[n-1]=="o") + (ans[n-2]=="S") + (ans[0]=="S") + (ans[n-1]=="S")
    if v%2==0:
        write("".join(ans))
        break
    else:
        pass
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
s = input()
ans = [None]*n
import itertools
for a0, a1 in itertools.product(("S", "W"), ("S", "W")):
    ans[0] = a0
    ans[-1] = a1
    for i in range(n-1):
        v = (s[i]=="o") + (ans[i-1]=="S") + (ans[i]=="S")
        if v%2==1:
            ans[i+1] = "S"
        else:
            ans[i+1] = "W"
    v = (s[n-1]=="o") + (ans[n-2]=="S") + (ans[0]=="S") + (ans[n-1]=="S")
    if v%2==0:
        write("".join(ans))
        break
    else:
        pass
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
s = input()
ans = [None]*n
ans[0] = "S"
ans[-1] = "S"
for i in range(n-1):
    v = (s[i]=="o") + (ans[i-1]=="S") + (ans[i]=="S")
    if v%2==1:
        ans[i+1] = "S"
    else:
        ans[i+1] = "W"
v = (s[n-1]=="o") + (ans[n-2]=="S") + (ans[0]=="S") + (ans[n-1]=="S")
if v%2==0:
    write("".join(ans))
else:
    print(-1)

Submission status: Wrong Answer

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

C = ('SS', 'SW', 'WS', 'WW')
for i in range(4):
    ans = list(C[i])
    for j in range(1, N):
        if (ans[-1] == 'S' and S[j] == 'o') or(ans[-1] == 'W' and S[j] == 'x'):
            ans.append(ans[-2])
        else:
            ans.append('S' if ans[-2] == 'W' else 'W')
    if ans[0] == ans[-1]:
        print(''.join(ans[:-1]))
        exit()
print(-1)

Submission status: Wrong Answer

Solution code:
from collections import deque

N = int(input())
S = input()

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

for pat in patterns:
    q = deque(list(pat))
    bef = q[0]
    cur = q[1]
    for i in range(1,N):
        aft = ""
        if (cur == "S" and S[i] == "o") or (cur == "W" and S[i] == "x"):
            aft = "S" if bef == "S" else "W"
        else:
            aft = "S" if bef == "W" else "W"
        q.append(aft)
        bef = cur
        cur = aft

    if q[0] == q[-1]:
        for i in range(N):
            print(q.popleft(), end="")
        print()
        exit()

print(-1)

Submission status: Wrong Answer

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

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def ValueToBits(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res

def BitsToValue(arr):
    n = len(arr)
    ans = 0
    for i in range(n):
        ans+= arr[i] * 2**i
    return ans

def ZipArray(a):
    aa = [[a[i],i]for i in range(n)]

    aa.sort(key = lambda x : x[0])
    for i in range(n):
        aa[i][0]=i+1
    aa.sort(key = lambda x : x[1])
    b=[aa[i][0] for i in range(len(a))]
    return b

def ValueToArray10(x, digit):
    ans = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        ans[digit-i-1] = now%10
        now = now //10
    return ans

def Zeros(a,b):
    if(b<=-1):
        return [0 for i in range(a)]
    else:
        return [[0 for i in range(b)] for i in range(a)]

def AddV2(v,w):
    return [v[0]+w[0],v[1]+w[1]]

dir4 = [[1,0],[0,1],[-1,0],[0,-1]]


def clamp(x,y,z):
    return max(y,min(z,x))

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
            
#
def Zaatsu(a):
    a.sort()
    now = a[0][0]
    od = 0
    for i in range(n):
        if(now==a[i][0]):
            a[i][0]=od
        else:
            now = a[i][0]
            od+=1
            a[i][0] = od
    
    a.sort(key = lambda x : x[1])
    return a

class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)


'''
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 2
N = 10 ** 6 + 2
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

'''

def rl(x):
    return range(len(x))

#a = list(map(int, input().split()))
# list(map(int, input().split()))

#################################################
#################################################
#################################################
#################################################



#22-

n = int(input())

s = input()

ani = [0 for i in range(n)]



def calc():
    for i in range(1,n-1):
        if((ani[i]==0 and s[i]=='o') or (ani[i]==1 and s[i]=='x')):
            ani[i+1] = ani[i-1]
        else:
            ani[i+1] = 1 - ani[i-1]
    if(ani[0]==0):
        if((s[0]=='o' and ani[1]!=ani[-1])or(s[0]=='x' and ani[1]==ani[-1])):
            #print('a',ani)
            return
    else:
        if((s[0]=='x' and ani[1]!=ani[-1])or(s[0]=='o' and ani[1]==ani[-1])):
            #print('a',ani)
            return
    if(ani[-1]==0):
        if((s[-1]=='o' and ani[0]!=ani[-2])or(s[-1]=='x' and ani[0]==ani[-2])):
            #print('b')
            return
    else:
        if((s[-1]=='x' and ani[0]!=ani[-2])or(s[-1]=='o' and ani[0]==ani[-2])):
            #print('b')
            return
    anss=[]
    for j in range(n):
        anss.append('S' if ani[j]==0 else 'W')
    print(''.join(anss))

ani[0] = 0
ani[1] = 0
calc()

ani[0] = 1
ani[1] = 0
calc()

ani[0] = 0
ani[1] = 1
calc()

ani[0] = 1
ani[1] = 1
calc()

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.readline

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

# 0,1がSS,SW,WS,WWの4パターンで始めてN-1まで埋める。
# このとき、0が言っていることに矛盾がなければOK

# 1:S
# 0:W
def answer(arr):
  ans = ""
  for x in arr:
    if x:
      ans += "S"
    else:
      ans += "W"
  return ans

for n in range(4):
  candi = ["."] * N
  candi[0] = n & 1
  candi[1] = (n >> 1) & 1
  for i in range(1,N-1):
    if S[i] == "o":
      if candi[i]:
        candi[i + 1] = candi[i - 1]
      else:
        candi[i + 1] = candi[i - 1] ^ 1
    else:
      if candi[i]:
        candi[i + 1] = candi[i - 1] ^ 1
      else:
        candi[i + 1] = candi[i - 1]
  if candi[N - 1]:
    # 最後が羊の場合
    if S[N - 1] == "o":
      if candi[N - 2] == candi[0]:
        print(answer(candi))
        break
    else:
      if candi[N - 2] != candi[0]:
        print(answer(candi))
        break
  else:
    if S[N - 1] == "o":
      if candi[N - 2] != candi[0]:
        print(answer(candi))
        break
    else:
      if candi[N - 2] == candi[0]:
        print(answer(candi))
        break
else:
  print(-1)

Submission status: Wrong Answer

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

a = [True] * (n+2)

def check(row, x, y):
    row[0] = x
    row[1] = y
    for i in range(1, n+1):
        if row[i] is True:
            if s[i-1] == 'o':
                row[i+1] = row[i-1]
            else:
                row[i+1] = not row[i-1]
        else:
            if s[i-1] == 'x':
                row[i+1] = row[i-1]
            else:
                row[i+1] = not row[i-1]

    if row[1] == row[-1]:
        for i in range(1, n+1):
            if row[i] is True:
                print('S', end='')
            else:
                print('W', end='')
        exit()

l = [[True, True], [True, False], [False, True], [False, False]]

for i, j in l:
    check(a, i, j)

print(-1)

Submission status: Wrong Answer

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

row = [True] * (n+2)
row2 = [False] * (n+2)
row3 = [True] * (n+2)
row4 = [False] * (n+2)
row3[0] = False
row4[0] = True

# １番目が羊と仮定した場合
for i in range(1, n+1):
    if row[i] is True:
        if s[i-1] == 'o':
            row[i+1] = row[i-1]
        else:
            row[i+1] = not row[i-1]
    else:
        if s[i-1] == 'x':
            row[i+1] = row[i-1]
        else:
            row[i+1] = not row[i-1]

if row[1] == row[-1]:
    for i in range(1, n+1):
        if row[i] is True:
            print('S', end='')
        else:
            print('W', end='')
    exit()
    
for i in range(1, n+1):
    if row3[i] is True:
        if s[i-1] == 'o':
            row3[i+1] = row3[i-1]
        else:
            row3[i+1] = not row3[i-1]
    else:
        if s[i-1] == 'x':
            row3[i+1] = row3[i-1]
        else:
            row3[i+1] = not row3[i-1]
            
if row3[1] == row3[-1]:
    for i in range(1, n+1):
        if row3[i] is True:
            print('S', end='')
        else:
            print('W', end='')
    exit()

for i in range(1, n + 1):
    if row4[i] is True:
        if s[i - 1] == 'o':
            row4[i + 1] = row4[i - 1]
        else:
            row4[i + 1] = not row4[i - 1]
    else:
        if s[i - 1] == 'x':
            row4[i + 1] = row4[i - 1]
        else:
            row4[i + 1] = not row4[i - 1]

if row4[1] == row4[-1]:
    for i in range(1, n + 1):
        if row4[i] is True:
            print('S', end='')
        else:
            print('W', end='')
    exit()


# 1番目が狼だと仮定した場合
for i in range(1, n+1):
    if row2[i] is True:
        if s[i-1] == 'o':
            row2[i+1] = row2[i-1]
        else:
            row2[i+1] = not row2[i-1]
    else:
        if s[i-1] == 'x':
            row2[i+1] = row2[i-1]
        else:
            row2[i+1] = not row2[i-1]

if row2[1] == row2[-1]:
    for i in range(1, n+1):
        if row2[i] is True:
            print('S', end='')
        else:
            print('W', end='')

else:
    print(-1)

Submission status: Wrong Answer

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

row = [True] * (n+2)
row2 = [False] * (n+2)

# １番目が羊と仮定した場合
for i in range(1, n+1):
    if row[i] is True:
        if s[i-1] == 'o':
            row[i+1] = row[i-1]
        else:
            row[i+1] = not row[i-1]
    else:
        if s[i-1] == 'x':
            row[i+1] = row[i-1]
        else:
            row[i+1] = not row[i-1]

if row[1] == row[-1]:
    for i in range(1, n+1):
        if row[i] is True:
            print('S', end='')
        else:
            print('W', end='')
    exit()


# 1番目が狼だと仮定した場合
for i in range(1, n+1):
    if row2[i] is True:
        if s[i-1] == 'o':
            row2[i+1] = row2[i-1]
        else:
            row2[i+1] = not row2[i-1]
    else:
        if s[i-1] == 'x':
            row2[i+1] = row2[i-1]
        else:
            row2[i+1] = not row2[i-1]

if row2[1] == row2[-1]:
    for i in range(1, n+1):
        if row2[i] is True:
            print('S', end='')
        else:
            print('W', end='')

else:
    print(-1)

Submission status: Wrong Answer

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

row = [True] * (n+2)
row2 = [False] * (n+2)

# １番目が羊と仮定した場合
for i in range(1, n+1):
    if row[i] is True:
        if s[i-1] == 'o':
            row[i+1] = row[i-1]
        else:
            row[i+1] = not row[i-1]
    else:
        if s[i-1] == 'x':
            row[i+1] = row[i-1]
        else:
            row[i+1] = not row[i-1]

if row[1] == row[-1]:
    for i in range(1, n+1):
        if row[i] is True:
            print('S', end='')
        else:
            print('W', end='')
    exit()


# 1番目が狼だと仮定した場合
for i in range(1, n+1):
    if row2[i] is True:
        if s[i-1] == 'o':
            row2[i+1] = row2[i-1]
        else:
            row2[i+1] = not row[i-1]
    else:
        if s[i-1] == 'x':
            row2[i+1] = row2[i-1]
        else:
            row2[i+1] = not row2[i-1]

if row2[1] == row2[-1]:
    for i in range(1, n+1):
        if row2[i] is True:
            print('S', end='')
        else:
            print('W', end='')

else:
    print(-1)

Submission status: Wrong Answer

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

row = [True] * (n+2)
row2 = [False] * (n+2)

# １番目が羊と仮定した場合
for i in range(1, n+1):
    if row[i] is True:
        if s[i-1] == 'o':
            continue
        else:
            row[i+1] = not row[i-1]
    else:
        if s[i-1] == 'x':
            row[i+1] = row[i-1]
        else:
            row[i+1] = not row[i-1]

if row[1] == row[-1]:
    for i in range(1, n+1):
        if row[i] is True:
            print('S', end='')
        else:
            print('W', end='')
    exit()


# 1番目が狼だと仮定した場合
for i in range(1, n+1):
    if row2[i] is True:
        if s[i-1] == 'o':
            continue
        else:
            row2[i+1] = not row[i-1]
    else:
        if s[i-1] == 'x':
            row2[i+1] = row2[i-1]
        else:
            row2[i+1] = not row2[i-1]

if row2[1] == row2[-1]:
    for i in range(1, n+1):
        if row2[i] is True:
            print('S', end='')
        else:
            print('W', end='')

else:
    print(-1)

Submission status: Wrong Answer

Solution code:
import sys
#import numpy as np
import math
from fractions import Fraction
import itertools

input=sys.stdin.readline

n=int(input())
s=input()
a=[0]*(n+1)
a[0]="S"
a[1]="S"
for i in range(1,n):
    if (a[i]=="S" and s[i]=="o") or (a[i]=="W" and s[i]=="x"):
        a[i+1]=a[i-1]
    else:
        if a[i-1]=="W":
            a[i+1]="S"
        else:
            a[i+1]="W"
if a[n]==a[0] and a[1]==a[n-1]:
    print("".join(a[:n]))
    exit()
a=[None]*(n+1)
a[0]="S"
a[1]="W"
for i in range(1,n):
    if (a[i]=="S" and s[i]=="o") or (a[i]=="W" and s[i]=="x"):
        a[i+1]=a[i-1]
    else:
        if a[i-1]=="W":
            a[i+1]="S"
        else:
            a[i+1]="W"
if a[n]==a[0] and a[1]==a[n-1]:
    print("".join(a[:n]))
    exit()
    
a=[0]*(n+1)
a[0]="W"
a[1]="S"
for i in range(1,n):
    if (a[i]=="S" and s[i]=="o") or (a[i]=="W" and s[i]=="x"):
        a[i+1]=a[i-1]
    else:
        if a[i-1]=="W":
            a[i+1]="S"
        else:
            a[i+1]="W"
if a[n]==a[0] and a[1]!=a[n-1]:
    print("".join(a[:n]))
    exit()
a=[None]*(n+1)
a[0]="W"
a[1]="W"
for i in range(1,n):
    if (a[i]=="S" and s[i]=="o") or (a[i]=="W" and s[i]=="x"):
        a[i+1]=a[i-1]
    else:
        if a[i-1]=="W":
            a[i+1]="S"
        else:
            a[i+1]="W"

if a[n]==a[0] and a[1]!=a[n-1]:
    print("".join(a[:n]))
    exit()
print(-1)

Submission status: Wrong Answer

Solution code:
import sys
# input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

N = int(input())
S = list(input())


#S-->Sと並べる
lst = [None] * (N + 2)
lst[0] = 'S'
if S[0] == 'o':
    lst[1] = 'S'
    lst[-1] = 'S'
else:
    lst[1] = 'S'
    lst[-1] = 'W'
for i in range(1, N):
    if S[i] == 'o':
        if lst[i] == 'S':
            lst[i + 1] = lst[i - 1]
        else:
            lst[i + 1] = 'S' if lst[i - 1] == 'W' else 'W'
    else: #x
        if lst[i] == 'S':
            lst[i + 1] = 'S' if lst[i - 1] == 'W' else 'W'
        else:
            lst[i + 1] = lst[i - 1]

if lst[N] == lst[N + 1]:
    print (*lst[:-2], sep = '')
    exit()

print (-1)
exit()


#S-->Wと並べる
lst = [None] * (N + 2)
lst[0] = 'S'
if S[0] == 'o':
    lst[1] = 'W'
    lst[-1] = 'W'
else:
    lst[1] = 'W'
    lst[-1] = 'S'
for i in range(1, N):
    if S[i] == 'o':
        if lst[i] == 'S':
            lst[i + 1] = lst[i - 1]
        else:
            lst[i + 1] = 'S' if lst[i - 1] == 'W' else 'W'
    else: #x
        if lst[i] == 'S':
            lst[i + 1] = 'S' if lst[i - 1] == 'W' else 'W'
        else:
            lst[i + 1] = lst[i - 1]

if lst[N] == lst[N + 1]:
    print (*lst[:-2], sep = '')
    print (lst)
    exit()

#W-->Wと並べる
lst = [None] * (N + 2)
lst[0] = 'W'
if S[0] == 'o':
    lst[1] = 'W'
    lst[-1] = 'S'
else:
    lst[1] = 'W'
    lst[-1] = 'W'
for i in range(1, N):
    if S[i] == 'o':
        if lst[i] == 'S':
            lst[i + 1] = lst[i - 1]
        else:
            lst[i + 1] = 'S' if lst[i - 1] == 'W' else 'W'
    else: #x
        if lst[i] == 'S':
            lst[i + 1] = 'S' if lst[i - 1] == 'W' else 'W'
        else:
            lst[i + 1] = lst[i - 1]

if lst[N] == lst[N + 1]:
    print (*lst[:-2], sep = '')
    exit()

#W-->Sと並べる
lst = [None] * (N + 2)
lst[0] = 'W'
if S[0] == 'o':
    lst[1] = 'S'
    lst[-1] = 'W'
else:
    lst[1] = 'S'
    lst[-1] = 'S'
for i in range(1, N):
    if S[i] == 'o':
        if lst[i] == 'S':
            lst[i + 1] = lst[i - 1]
        else:
            lst[i + 1] = 'S' if lst[i - 1] == 'W' else 'W'
    else: #x
        if lst[i] == 'S':
            lst[i + 1] = 'S' if lst[i - 1] == 'W' else 'W'
        else:
            lst[i + 1] = lst[i - 1]

if lst[N] == lst[N + 1]:
    print (*lst[:-2], sep = '')
    exit()

print (-1)

Submission status: Wrong Answer

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
s = input()
t = []
for i in range(n):
    if s[i] == 'o':
        t.append(0)
    else:
        t.append(1)
for zero,one in itertools.product(range(2),repeat=2):
    res = [None] * n
    res[0] = zero; res[1] = one
    for i in range(2,n):
        if res[i-1] ^ t[i-1] == 0:
            res[i] = res[i-2]
        else:
            res[i] = res[i-2]^1
    if (res[0] ^ res[-2]) == (res[-1] ^ t[-1]):
        ans = []
        for i in range(n):
            ans.append('W' if res[i] else 'S')
        print(''.join(ans))
        break
else:
    print(-1)

Submission status: Wrong Answer

Solution code:

N = int(input())
S = list(input())


def check(a1, a2):
    ans = [a1, a2]
    for i, s in enumerate(S):
        if i == 0:
            continue

        if ans[i] == 0:
            if s == "o":
                ans.append(ans[i - 1])
            else:
                ans.append(ans[i - 1] ^ 1)
        else:
            if s == "x":
                ans.append(ans[i - 1])
            else:
                ans.append(ans[i - 1] ^ 1)

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


# 0: S / 1:W
for a1 in range(2):
    for a2 in range(2):
        ans = check(a1, a2)
        if ans is not None:
            print("".join(map(lambda x: "S" if x == 0 else "W", ans)))
            exit()


print(-1)

Submission status: Wrong Answer

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

def isOk(prev, now):
    second = now
    ret = [prev]

    for s in S[1:] + S[0]:
        ret.append(now)
        isSame = (s == 'o')

        if isSame == now:
            prev, now = now, prev
        else:
            prev, now = now, not prev

    return ret if second == now else []

for first in [True, False]:
    for second in [True, False]:
        ans = isOk(first, second)
        if ans:
            print(''.join(['S' if a else 'W' for a in ans[:-1]]))
            exit()

print('-1')

Submission status: Wrong Answer

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

def isOk(prev, now):
    first = prev
    ret = [prev]

    for p, s in zip(S, S[1:]):
        ret.append(now)
        isSame = (s == 'o')

        if isSame == now:
            prev, now = now, prev
        else:
            prev, now = now, not prev

    return ret if first == now else []

for first in [True, False]:
    for second in [True, False]:
        ans = isOk(first, second)
        if ans:
            print(''.join(['S' if a else 'W' for a in ans]))
            exit()

print('-1')

Submission status: Wrong Answer

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

for a in ('SS','SW','WS','WW'):
    for c in S[1:]:
        if a[-1]=='S':
            a += 'W' if (a[-2]=='W') ^ (c=='x') else 'S'
        else:
            a += 'S' if (a[-2]=='W') ^ (c=='x') else 'W'
    if a[0] != a[-1]: continue
    if (S[0]=='o' and a[0]=='S') or (S[0]=='x' and a[0]=='W'):
        print(a[:-1])
        exit()
print(-1)

Submission status: Wrong Answer

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

for a in ('SS','SW','WS','WW'):
    for c in S[1:]:
        if a[-1]=='S':
            a += 'W' if (a[-2]=='W') ^ (c=='x') else 'S'
        else:
            a += 'S' if (a[-2]=='W') ^ (c=='x') else 'W'
    if (S[0]=='o' and a[0]==a[-1]) or (S[0]=='x' and a[0]!=a[-1]):
        print(a[:-1])
        exit()
print(-1)

Submission status: Wrong Answer

Solution code:
N=int(input())
s=input()
a,b,c,d='SS','SW','WW','WS'
def f(a,N):
  for i in range(N-2):
    if a[-1]=='S' and s[i+1]=='o':
      if a[-2]=='S':
        a=a+'S'
      else:
        a=a+'W'
    elif a[-1]=='S' and s[i+1]=='x':
      if a[-2]=='S':
        a=a+'W'
      else:
        a=a+'S'
    elif a[-1]=='W' and s[i+1]=='o':
      if a[-2]=='S':
        a=a+'W'
      else:
        a=a+'S'
    else:
      if a[-2]=='S':
        a=a+'S'
      else:
        a=a+'W'
  return a

A,B,C,D=f(a,N),f(b,N),f(c,N),f(d,N)    
def g(s,A):
  a=True
  if A[-1]=='S'and s[-1]=='o':
    if A[-2]!=A[0]:
      a=False
  elif A[-1]=='S'and s[-1]=='x':
    if A[-2]==A[0]:
      a=False
  elif A[-1]=='W'and s[-1]=='o':
    if A[-2]==A[0]:
      a=False    
  elif A[-1]=='W'and s[-1]=='x':
    if A[-2]!=A[0]:
      a=False  
  
  if A[0]=='S'and s[0]=='o':
    if A[-1]!=A[1]:
      a=False
  elif A[0]=='S'and s[0]=='x':
    if A[-1]==A[1]:
      a=False
  elif A[0]=='W'and s[0]=='o':
    if A[-1]==A[1]:
      a=False    
  elif A[0]=='W'and s[0]=='x':
    if A[0]!=A[1]:
      a=False
  return a
      
if g(s,A):
  print(A)
  exit()
if g(s,B):
  print(B)
  exit()      
if g(s,C):
  print(C)
  exit()
if g(s,D):
  print(D)
  exit() 
print(-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input() #sys.stdin.readlineは最後が改行

ans = ['X']*(n+1)

ans[0] = 'S'
ans[1] = 'S'
for i in range(1,n):
    if (s[i] == 'o' and ans[i]=='S') or (s[i] == 'x' and ans[i]=='W'):
        ans[i+1] = ans[i-1]
    else:
        ans[i+1] = 'S' if ans[i-1]=='W' else 'W'

if ans[0] == ans[-1]:
    print(*ans[:n],sep='')
    exit()


ans[0] = 'S'
ans[1] = 'W'
for i in range(1,n):
    if (s[i] == 'o' and ans[i]=='S') or (s[i] == 'x' and ans[i]=='W'):
        ans[i+1] = ans[i-1]
    else:
        ans[i+1] = 'S' if ans[i-1]=='W' else 'W'

if ans[0] == ans[-1]:
    print(*ans[:n],sep='')
    exit()


ans[0] = 'W'
ans[1] = 'S'
for i in range(1,n):
    if (s[i] == 'o' and ans[i]=='S') or (s[i] == 'x' and ans[i]=='W'):
        ans[i+1] = ans[i-1]
    else:
        ans[i+1] = 'S' if ans[i-1]=='W' else 'W'

if ans[0] == ans[-1]:
    print(*ans[:n],sep='')
    exit()


ans[0] = 'W'
ans[1] = 'W'
for i in range(1,n):
    if (s[i] == 'o' and ans[i]=='S') or (s[i] == 'x' and ans[i]=='W'):
        ans[i+1] = ans[i-1]
    else:
        ans[i+1] = 'S' if ans[i-1]=='W' else 'W'

if ans[0] == ans[-1]:
    print(*ans[:n],sep='')
    exit()

print(-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input() #sys.stdin.readlineは最後が改行

ans = ['X']*(n+1)

ans[0] = ans[-1] = 'S'
ans[1] = 'S'
for i in range(1,n):
    if (s[i] == 'o' and ans[i]=='S') or (s[i] == 'x' and ans[i]=='W'):
        ans[i+1] = ans[i-1]
    else:
        ans[i+1] = 'S' if ans[i-1]=='W' else 'W'

if ans[0] == ans[-1]:
    print(*ans[:-1],sep='')
    exit()


ans[0] = ans[-1] = 'S'
ans[1] = 'W'
for i in range(1,n):
    if (s[i] == 'o' and ans[i]=='S') or (s[i] == 'x' and ans[i]=='W'):
        ans[i+1] = ans[i-1]
    else:
        ans[i+1] = 'S' if ans[i-1]=='W' else 'W'

if ans[0] == ans[-1]:
    print(*ans[:-1],sep='')
    exit()


ans[0] = ans[-1] = 'W'
ans[1] = 'S'
for i in range(1,n):
    if (s[i] == 'o' and ans[i]=='S') or (s[i] == 'x' and ans[i]=='W'):
        ans[i+1] = ans[i-1]
    else:
        ans[i+1] = 'S' if ans[i-1]=='W' else 'W'

if ans[0] == ans[-1]:
    print(*ans[:-1],sep='')
    exit()


ans[0] = ans[-1] = 'W'
ans[1] = 'W'
for i in range(1,n):
    if (s[i] == 'o' and ans[i]=='S') or (s[i] == 'x' and ans[i]=='W'):
        ans[i+1] = ans[i-1]
    else:
        ans[i+1] = 'S' if ans[i-1]=='W' else 'W'

if ans[0] == ans[-1]:
    print(*ans[:-1],sep='')
    exit()

print(-1)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())
s+=s[0]+s[1]

# 決め打ちで作ってみる。
ANS=[list("SS"+"?"*(n)),list("WS"+"?"*(n)),list("SW"+"?"*(n)),list("WW"+"?"*(n))]
for ans in ANS:
    for i in range(2, n+2):
        if (ans[i - 2] == 'S' and s[i - 1] == 'o' and ans[i - 1] == 'S') or (
                ans[i - 2] == 'W' and s[i - 1] == 'o' and ans[i - 1] == 'W') \
                or (ans[i - 2] == 'S' and ans[i - 1] == 'W' and s[i - 1] == 'x') or (
                ans[i - 2] == 'W' and ans[i - 1] == 'S' and s[i - 1] == 'x'):
            ans[i] = 'S'
        else:
            ans[i] = 'W'
    if ans[:2]==ans[-2:]:
        print(''.join(ans[2:]))
        exit()


print(-1)