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 = input()

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

for i in range(4):
    for j in range(1, n):
        if s[j] == "o" and ans[i][j] == "S":
            ans[i] += ans[i][j-1]
        elif s[j] == "o" and ans[i][j] == "W":
            ans[i] += "W" if ans[i][j-1] == "S" else "S"
        elif s[j] == "x" and ans[i][j] == "S":
            ans[i] += "W" if ans[i][j-1] == "S" else "S"
        else:
            ans[i] += ans[i][j - 1]
            
    if ans[i][0] == ans[i][n]:
        if ans[i][n-1] == ans[i][1] and ((s[0] == "o" and ans[0] == "S") or (s[0] == "x" and ans[0] == "W")):
            print(ans[i][:-1])
            break
        if ans[i][n-1] != ans[i][1] and ((s[0] == "o" and ans[0] == "W") or (s[0] == "x" and ans[0] == "S")):
            print(ans[i][:-1])
            break
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin

def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())

def nex_animal(prev: str, cur:str, say: str) -> str:
    ret_dic = {("S", "S", "o"): "S", ("S", "S", "x"): "W",
               ("S", "W", "o"): "W", ("S", "W", "x"): "S",
               ("W", "S", "o"): "W", ("W", "S", "x"): "S",
               ("W", "W", "o"): "S", ("W", "W", "x"): "W"}
    
    return ret_dic[(prev, cur, say)]

n = ni()
s = lc()
ans = [""]*n

init = {"o":[("S", "S", "S"), ("W","S","W"), ("W","W","S"), ("S","W","W")],
        "x":[("W", "S", "S"), ("S","S","W"), ("S","W","S"), ("W","W","W")]}

exist = False
if s[-1] == "o":
    for a1,a2,a3 in init["o"]:
        ans[-2], ans[-1], ans[0] = a1, a2, a3
        
        for i in range(n-2):
            if i != n-3:
                ans[i+1] = nex_animal(ans[i-1], ans[i], s[i])
            else:
                if ans[i+1] != nex_animal(ans[i-1], ans[i], s[i]):
                    break
                else:
                    print("".join(ans))
                    exist = True
                    break
                
        if exist:
            break
                
else:
    for a1,a2,a3 in init["x"]:
        ans[-2], ans[-1], ans[0] = a1, a2, a3
        
        for i in range(n-2):
            if i != n-3:
                ans[i+1] = nex_animal(ans[i-1], ans[i], s[i])
            else:
                if ans[i+1] != nex_animal(ans[i-1], ans[i], s[i]):
                    break
                else:
                    print("".join(ans))
                    exist = True
                    break
    
        if exist:
            break
    
                    
if not exist:
    print(-1)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

for i in range(4):
    for j in range(1, n):
        if s[j] == "o" and ans[i][j] == "S":
            ans[i] += ans[i][j-1]
        elif s[j] == "o" and ans[i][j] == "W":
            ans[i] += "W" if ans[i][j-1] == "S" else "S"
        elif s[j] == "x" and ans[i][j] == "S":
            ans[i] += "W" if ans[i][j-1] == "S" else "S"
        else:
            ans[i] += ans[i][j - 1]
    if ans[i][0] == ans[i][n]:
        print(ans[i][:-1])
        exit()
else:
    print(-1)

Submission status: Wrong Answer

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

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

for i in range(4):
    for j in range(1, n):
        if s[j] == "o" and ans[i][j] == "S":
            ans[i] += ans[i][j-1]
        elif s[j] == "o" and ans[i][j] == "W":
            ans[i] += "W" if ans[i][j-1] == "S" else "S"
        elif s[j] == "x" and ans[i][j] == "S":
            ans[i] += "W" if ans[i][j-1] == "S" else "S"
        else:
            ans[i] += ans[i][j - 1]
    if ans[i][0] == ans[i][n]:
        print(ans[i][:-1])
        break
else:
    print(-1)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

def kakunin(animal):
    for i in range(2,n):
        if s[i-1]=='o':
            if (animal[i-1]==0) and (animal[i-2]==0 ):
                animal[i]=0
            elif (animal[i-1]==1) and (animal[i-2]==0 ):
                animal[i]+=1
            elif (animal[i-1]==0) and (animal[i-2]==1 ):
                animal[i]+=1
            elif (animal[i-1]==1) and (animal[i-2]==1 ):
                animal[i]=0
        else:
            if (animal[i-1]==0) and (animal[i-2]==0 ):
                animal[i]+=1
            elif (animal[i-1]==1) and (animal[i-2]==0 ):
                animal[i]=0
            elif (animal[i-1]==0) and (animal[i-2]==1 ):
                animal[i]=0
            elif (animal[i-1]==1) and (animal[i-2]==1 ):
                animal[i]+=1
    if s[0]=='o':
        if (animal[0]==0):
            if (animal[1]==0) and (animal[-1]==0 ):
                if ((s[-1]=='o')and(animal[-2]==0))or((s[-1]=='x')and(animal[-2]==1)):
                    return True
            elif (animal[1]==1) and (animal[-1]==1):
                if ((s[-1]=='o')and(animal[-2]==1))or((s[-1]=='x')and(animal[-2]==0)):
                    return True
        else:
            if (animal[1]==1) and (animal[-1]==0 ):
                if ((s[-1]=='o')and(animal[-2]==1))or((s[-1]=='x')and(animal[-2]==0)):
                    return True
            elif (animal[1]==0) and (animal[-1]==1):
                if ((s[-1]=='o')and(animal[-2]==0))or((s[-1]=='x')and(animal[-2]==1)):
                    return True
            
            
    else:
        if (animal[0]==0):
            if (animal[1]==1) and (animal[-1]==0 ):
                if ((s[-1]=='o')and(animal[-2]==0))or((s[-1]=='x')and(animal[-2]==1)):
                    return True
            elif (animal[1]==0) and (animal[-1]==1):
                if ((s[-1]=='o')and(animal[-2]==1))or((s[-1]=='x')and(animal[-2]==0)):
                    return True
        else:
            if (animal[1]==1) and (animal[-1]==1):
                if ((s[-1]=='o')and(animal[-2]==0))or((s[-1]=='x')and(animal[-2]==1)):
                    return True
            elif (animal[1]==0) and (animal[-1]==0):
                if ((s[-1]=='o')and(animal[-2]==0))or((s[-1]=='x')and(animal[-2]==1)):
                    return True
    return False
f = [False]     
for i in range(0,4):
    animal = [0]*n
    if i == 1:
        animal[0]+=1
    elif i==2:
        animal[1]+=1
    elif i==3:
        animal[0]+=1
        animal[1]+=1
    f[0]= kakunin(animal) 
    if f[0]==True:
        u = ''
        for j in range(0,n):
            if animal[j]==0:
                u = u+'S'
            else:
                u = u + 'W'
        # print(u,i,animal)
        break

if f[0] == False:
    print(-1)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, S):
    def f(cnd):
        for i in range(1, N):
            if S[i] == 'o' and cnd[i] == 'S':
                cnd.append(cnd[i-1])
            elif S[i] == 'o' and cnd[i] == 'W':
                cnd.append('S' if cnd[i-1] == 'W' else 'W')
            elif S[i] == 'x' and cnd[i] == 'S':
                cnd.append('S' if cnd[i-1] == 'W' else 'W')
            elif S[i] == 'x' and cnd[i] == 'W':
                cnd.append(cnd[i-1])

        if cnd[0] != cnd[-1]:
            return None

        if cnd[0] == 'S' and S[0] == 'o' and cnd[1] == cnd[-1]:
            return ''.join(cnd[:-1])
        elif cnd[0] == 'S' and S[0] == 'x' and cnd[1] != cnd[-1]:
            return ''.join(cnd[:-1])
        elif cnd[0] == 'W' and S[0] == 'o' and cnd[1] != cnd[-1]:
            return ''.join(cnd[:-1])
        elif cnd[0] == 'W' and S[0] == 'x' and cnd[1] == cnd[-1]:
            return ''.join(cnd[:-1])

        return None
    # SS
    ans = f(['S', 'S'])
    if ans:
        return ans

    # SW
    ans = f(['S', 'W'])
    if ans:
        return ans

    # WS
    ans = f(['W', 'S'])
    if ans:
        return ans

    # WW
    ans = f(['W', 'W'])
    if ans:
        return ans

    return -1


def main():
    N = read_int()
    S = read_str()
    print(slv(N, S))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, S):
    def f(cnd):
        for i in range(1, N):
            if S[i] == 'o' and cnd[i] == 'S':
                cnd.append(cnd[i-1])
            elif S[i] == 'o' and cnd[i] == 'W':
                cnd.append('S' if cnd[i-1] == 'W' else 'W')
            elif S[i] == 'x' and cnd[i] == 'S':
                cnd.append('S' if cnd[i-1] == 'W' else 'W')
            elif S[i] == 'x' and cnd[i] == 'W':
                cnd.append(cnd[i-1])
        if cnd[0] == cnd[-1]:
            return ''.join(cnd[:-1])

        return None

    ans = f(['S', 'S'])
    if ans:
        return ans

    ans = f(['S', 'W'])
    if ans:
        return ans

    ans = f(['W', 'S'])
    if ans:
        return ans

    ans = f(['W', 'W'])
    if ans:
        return ans

    return -1


def main():
    N = read_int()
    S = read_str()
    print(slv(N, S))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

is_ans = False
for ans in ['SS', 'SW', 'WS', 'WW']:
    for i in range(1, n):
        a_0 = ans[i-1]
        a_1 = ans[i]
        if s[i] == 'o' and a_1 == 'S':
            if a_0 == 'S':
                ans += 'S'
            else:
                ans += 'W'
        elif s[i] == 'x' and a_1 == 'S':
            if a_0 == 'S':
                ans += 'W'
            else:
                ans += 'S'
        elif s[i] == 'o' and a_1 == 'W':
            if a_0 == 'S':
                ans += 'W'
            else:
                ans += 'S'
        else:
            if a_0 == 'S':
                ans += 'S'
            else:
                ans += 'W'
    if ans[-1] == ans[0]:
        print(ans[:-1])
        is_ans = True
        break
if not is_ans:
    print(-1)

Submission status: Wrong Answer

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

ans = 'SS'
for i in range(1, n):
    a_0 = ans[i-1]
    a_1 = ans[i]
    if s[i] == 'o' and a_1 == 'S':
        if a_0 == 'S':
            ans += 'S'
        else:
            ans += 'W'
    elif s[i] == 'x' and a_1 == 'S':
        if a_0 == 'S':
            ans += 'W'
        else:
            ans += 'S'
    elif s[i] == 'o' and a_1 == 'W':
        if a_0 == 'S':
            ans += 'W'
        else:
            ans += 'S'
    else:
        if a_0 == 'S':
            ans += 'S'
        else:
            ans += 'W'
if ans[-1] != 'S':
    print(-1)
else:
    print(ans[:-1])

Submission status: Wrong Answer

Solution code:
N = int(input())
s = list(input())
c_list = [['W','W'],['W','S'],['S','W'],['S','S']]

for c in c_list:
    for current in range(1,N):
        pre = current-1
        if ((c[current] == 'W' and s[current] == 'o') or (c[current] == 'S' and s[current] == 'x')):
            if(c[pre] == 'W'):
                c.append('S')
            else:
                c.append('W')
        elif ((c[current] == 'W' and s[current] == 'x') or (c[current] == 'S' and s[current] == 'o')):
            c.append(c[pre])
    if(c[0] == c[N]):
        print(''.join(c[0:N]))
        quit()
    """
    if ((c[0] == 'W' and s[0] == 'o') or (c[0] == 'S' and s[0] == 'x')):
        if (c[N-1] != c[1]):
            print(''.join(c[0:N]))
            quit()
    else:
        if (c[N-1] == c[1]):
            print(''.join(c[0:N]))
            quit()
    """
print(-1)

Submission status: Wrong Answer

Solution code:
#a = int(input())
#b,c = map(int,input().split())
#s = input()
#list_s = list(input())
#list_int = list(map(int,input().split()))

#list = [0 for i in range(n)]
#dp = [[0 for i in range(A)] for j in range(B)]

#list_int 並べて出力 print (' '.join(map(str,ans_li)))
#list_str 並べて出力 print (' '.join(list))

# 2進数 format(10, 'b') # '1010'

# aa=[int(input()) for i in range(n)]

#for i,name in enumerate(list)

''' 二次元配列を一列ずつ
for i in ans:
	print(*i)
'''
''' heapq
queue = []
heapq.heapify(queue) #heapqの作成
heapq.heappush(queue,num) #numのpush(値の追加)
pop = heapq.heappop(queue) #numのpop(最小値の出力)
pop = heapq.heappushpop(queue,num) #push -> pop

'''

from collections import defaultdict
import sys,heapq,bisect,math,itertools,string
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7


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


def check(SW):
	global N
	global s
	for i in range(1,N):
		if SW[i]:
			if s[i] == 'o':
				SW.append(SW[i-1])
			else:
				SW.append(not SW[i-1])
		else:
			if s[i] == 'o':
				SW.append(not SW[i-1])
			else:
				SW.append(SW[i-1])

	if SW[N] == SW[0]:
		for i in range(N):
			if SW[i]:
				sys.stdout.write("S")
			else:
				sys.stdout.write("W")
		print()
		sys.exit()

check([True,True])
check([True,False])
check([False,True])
check([False,False])
print(-1)

Submission status: Wrong Answer

Solution code:
#a = int(input())
#b,c = map(int,input().split())
#s = input()
#list_s = list(input())
#list_int = list(map(int,input().split()))

#list = [0 for i in range(n)]
#dp = [[0 for i in range(A)] for j in range(B)]

#list_int 並べて出力 print (' '.join(map(str,ans_li)))
#list_str 並べて出力 print (' '.join(list))

# 2進数 format(10, 'b') # '1010'

# aa=[int(input()) for i in range(n)]

#for i,name in enumerate(list)

''' 二次元配列を一列ずつ
for i in ans:
	print(*i)
'''
''' heapq
queue = []
heapq.heapify(queue) #heapqの作成
heapq.heappush(queue,num) #numのpush(値の追加)
pop = heapq.heappop(queue) #numのpop(最小値の出力)
pop = heapq.heappushpop(queue,num) #push -> pop

'''

from collections import defaultdict
import sys,heapq,bisect,math,itertools,string
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7


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


def check(SW):
	global N
	for i in range(1,N):
		if SW[i]:
			if s[i] == 'o':
				SW.append(SW[i-1])
			else:
				SW.append(not SW[i-1])
		else:
			if s[i] == 'o':
				SW.append(not SW[i-1])
			else:
				SW.append(SW[i-1])

	if SW[N] == SW[0]:
		for i in range(N):
			if SW[i]:
				sys.stdout.write("S")
			else:
				sys.stdout.write("W")
		print()
		sys.exit()

check([True,True])
check([True,False])
check([False,True])
check([False,False])
print(-1)

Submission status: Wrong Answer

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

def rev(anim):
    if anim == 'S':
        return 'W'
    else:
        return 'S'

import sys
for init in ('SS', 'SW', 'WS', 'WW'):
    T = init
    for i in range(2, n):
        ans = S[i-1]
        anim = T[i-1]
        prev = T[i-2]
        if ans == 'o':
            if anim == 'S':
                T += prev
            else:
                T += rev(prev)
        else:
            if anim == 'S':
                T += rev(prev)
            else:
                T += prev
    last_ans = S[n-1]
    last_anim = T[n-1]
    if last_ans == 'o':
        if last_anim == 'S':
            if T[n-2] == T[0]:
                print(T)
                sys.exit(0)
        else:
            if T[n-2] != T[0]:
                print(T)
                sys.exit(0)
    else:
        if last_anim == 'S':
            if T[n-2] != T[0]:
                print(T)
                sys.exit(0)
        else:
            if T[n-2] == T[0]:
                print(T)
                sys.exit(0)
print(-1)

Submission status: Wrong Answer

Solution code:
from itertools import product

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


def r(x):
    if x == 'S':
        return 'W'
    else:
        return 'S'


def f(x1, x2):
    res = [None] * (N + 1)
    res[0] = x1
    res[1] = x2
    for i in range(1, N):
        if S[i] == 'o':
            if res[i] == 'S':
                res[i + 1] = res[i - 1]
            else:
                res[i + 1] = r(res[i - 1])
        else:
            if res[i] == 'S':
                res[i + 1] = r(res[i - 1])
            else:
                res[i + 1] = res[i - 1]
    return res


ans = ['-1']
for x1, x2 in product('SW', repeat=2):
    res = f(x1, x2)
    if res[0] == res[-1]:
        res.pop()
        ans = res
        break

print(''.join(ans))

Submission status: Wrong Answer

Solution code:
N = int(input())
s = input()
animals = ['SS', 'SW', 'WS', 'WW']
for i, animal in enumerate(animals):
  for j in range(N):
    a = 1 if animals[i][-1] == 'S' else -1
    b = 1 if animals[i][-2] == 'S' else -1
    c = 1 if s[(j + 1) % N] == 'o' else -1
    animals[i] += 'S' if a * b * c > 0 else 'W'
ans = -1
for animal in animals:
  if animal[:2] == animal[-2:]:
    ans = animal[2:]
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
s = input()
animals = ['SS', 'SW', 'WS', 'WW']
for i, animal in enumerate(animals):
  for j in range(1, N):
    a = 1 if animals[i][-1] == 'S' else -1
    b = 1 if animals[i][-2] == 'S' else -1
    c = 1 if s[j] == 'o' else -1
    animals[i] += 'S' if a * b * c > 0 else 'W'
ans = -1
for animal in animals:
  if animal[0] == animal[-1]:
    ans = animal[1:]
print(ans)

Submission status: Wrong Answer

Solution code:
import copy
n = int(input())
s = list(input())

def search_pattern(input_list):
    temp = copy.deepcopy(input_list)
    for i in range(2, n):
        if temp[i - 1] == 'S':
            if s[i - 1] == 'o':
                temp.append(temp[i - 2])
            else:
                if temp[i - 2] == 'S':
                    temp.append('W')
                else:
                    temp.append('S')
        else:
            if s[i - 1] == 'x':
                temp.append(temp[i - 2])
            else:
                if temp[i - 2] == 'S':
                    temp.append('W')
                else:
                    temp.append('S')

    if temp[n - 1] == 'S':
        if s[n - 1] == 'o':
            if temp[n - 2] != s[0]:
                return -1
        else:
            if temp[n - 2] == 'S':
                if temp[0] == 'S':
                    return -1
            else:
                if temp[0] != 'S':
                    return -1
    else:
        if s[n - 1] == 'x':
            if temp[n - 2] != s[0]:
                return -1
        else:
            if temp[n - 2] == 'S':
                if temp[0] == 'S':
                    return -1
            else:
                if temp[0] != 'S':
                    return -1

    if temp[0] == 'S':
        if s[0] == 'o':
            if temp[n - 1] != temp[1]:
                return -1
        else:
            if temp[n - 1] == 'S':
                if temp[1] == 'S':
                    return -1
            else:
                if temp[1] != 'S':
                    return -1
    else:
        if s[0] == 'x':
            if temp[n - 1] != temp[1]:
                return -1
        else:
            if temp[n - 1] == 'S':
                if temp[1] == 'S':
                    return -1
            else:
                if temp[1] != 'S':
                    return -1
    print("".join(temp))
    exit()

search_pattern(list("SS"))
search_pattern(list("SW"))
search_pattern(list("WS"))
search_pattern(list("WW"))

print("-1")

Submission status: Wrong Answer

Solution code:
import copy
n = int(input())
s = list(input())

def search_pattern(input_list):
    temp = copy.deepcopy(input_list)
    for i in range(2, n + 1):
        if temp[i - 1] == 'S':
            if s[i - 1] == 'o':
                temp.append(temp[i - 2])
            else:
                if temp[i - 2] == 'S':
                    temp.append('W')
                else:
                    temp.append('S')
        else:
            if s[i - 1] == 'x':
                temp.append(temp[i - 2])
            else:
                if temp[i - 2] == 'S':
                    temp.append('W')
                else:
                    temp.append('S')
    if temp[n] == temp[0]:
        print("".join(temp[:n]))
        exit()
    else:
        return 1

search_pattern(list("SS"))
search_pattern(list("SW"))
search_pattern(list("WS"))
search_pattern(list("WW"))

print("-1")

Submission status: Wrong Answer

Solution code:
N=int(input())
s=input()
animals = ["" for _ in range(N)]

def convert(animal):
    if animal == "S":
        return "W"
    else:
        return "S"

def animalOnRight(left,center,sig):
    if center == "S":
        if sig == "o":
            return left
        else:
            return convert(left)
    else:
        if sig == "o":
            return convert(left)
        else:
            return left
for (a0,a1) in [("S","S"),("S","W"),("W","S"),("W","W")]:
    animals[0],animals[1] = (a0,a1)
    for i in range(N-2):
        animals[i+2] = animalOnRight(animals[i],animals[i+1],s[i+1])
        #print(animals)

    if animalOnRight(animals[N-2],animals[N-1],s[N-1]) == animals[0]:
        for char in animals:
            print(char, end='')
        print()
        exit()
print(-1)

Submission status: Wrong Answer

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

# 1週を扱いやすいように
S = S[N-1]+S+S[0]
B = {"S":"W", "W":"S"}
def check(a0, a1):
    A = a1
    for i in range(1, N+1):
        if a1 == "S":
            if S[i] == "o":
                a2 = a0
            else:
                a2 = B[a0]
        else:
            if S[i] == "o":
                a2 = B[a0]
            else:
                a2 = a0
        A += a2
        a0,a1 = a1,a2
    if A[0] == A[N]:
        return A[0:N]
    else:
        return -1

Ans = []
Ans.append(check("S","S"))
Ans.append(check("S","W"))
Ans.append(check("W","S"))
Ans.append(check("W","W"))

for ans in Ans:
    if ans == -1:
        continue
    else:
        print(ans)
        exit()
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python

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

def decide_i_plus_one(p, c, res):
  if c == 'S':
    if res == 'o':
      return p
    else:
      if p == 'S': return 'W'
      else:        return 'S'
  else:
    if res == 'o':
      if p == 'S': return 'W'
      else:        return 'S'
    else:
      return p

possible_pairs = [('S','S'), ('S','W'), ('W','S'), ('W','W')]
for (fst,snd) in possible_pairs:
  animals = []
  animals.append(fst)
  animals.append(snd)

  pi,ci = 0,1

  while 1:
    n = decide_i_plus_one(animals[pi], animals[ci], s[ci])

    if ci == N-1:
      if n == animals[0]:
        print("".join(animals))
        exit(0)
      else:
        break

    animals.append(n)
    pi += 1
    ci += 1

print("-1")

Submission status: Wrong Answer

Solution code:
from itertools import product
N = int(input())
S = input()

C = product("SW", repeat=2)


for c in C:
    ans = list(c)
    for i in range(1, len(S)):
        # 羊
        if ans[-1] == "S":
            # 羊で〇なら同じ
            if S[i] == "o":
                ans.append(ans[-2])
            else:
                # 羊で×ならじゃないほう
                if ans[-2] == "S":
                    ans.append("W")
                else:
                    ans.append("S")
        # 狼
        else:
            # 狼で×なら同じ
            if S[i] == "x":
                ans.append(ans[-2])
            # 狼で〇ならじゃないほう
            else:
                if ans[-2] == "S":
                    ans.append("W")
                else:
                    ans.append("S")

    ans = ans[:-1]
    print(ans)
    for i in range(N):
        if ans[i] == "S" and S[i] == "o":
            if ans[i-1] != ans[(i+1) % N]:
                break
        if ans[i] == "S" and S[i] == "x":
            if ans[i-1] == ans[(i+1) % N]:
                break
        if ans[i] == "W" and S[i] == "x":
            if ans[i-1] != ans[(i+1) % N]:
                break
        if ans[i] == "W" and S[i] == "o":
            if ans[i-1] == ans[(i+1) % N]:
                break
    else:
        print("".join(ans))


else:
    print(-1)

Submission status: Wrong Answer

Solution code:
from itertools import product
N = int(input())
S = input()

C = product("SW", repeat=2)


for c in C:
    ans = list(c)
    for i in range(1, len(S)):
        # 羊
        if ans[-1] == "S":
            # 羊で〇なら同じ
            if S[i] == "o":
                ans.append(c[-2])
            else:
                # 羊で×ならじゃないほう
                if ans[-2] == "S":
                    ans.append("W")
                else:
                    ans.append("S")
        # 狼
        else:
            # 狼で×なら同じ
            if S[i] == "x":
                ans.append(ans[-2])
            # 狼で〇ならじゃないほう
            else:
                if ans[-2] == "S":
                    ans.append("W")
                else:
                    ans.append("S")

    ans = ans[:-1]

    for i in range(N):
        if ans[i] == "S" and S[i] == "o":
            if ans[i-1] != ans[(i+1)%N]:
                break
        if ans[i] == "S" and S[i] == "x":
            if ans[i-1] == ans[(i+1)%N]:
                break
        if ans[i] == "W" and S[i] == "x":
            if ans[i-1] != ans[(i+1)%N]:
                break
        if ans[i] == "W" and S[i] == "o":
            if ans[i-1] == ans[(i+1)%N]:
                break
    else:
        print("".join(ans))
        break

else:
    print(-1)

Submission status: Wrong Answer

Solution code:
from itertools import product
N = int(input())
S = input()

C = product("SW", repeat=2)


for c in C:
    ans = list(c)
    for i in range(1, len(S)):
        # 羊
        if ans[-1] == "S":
            # 羊で〇なら同じ
            if S[i] == "o":
                ans.append(c[-2])
            else:
                # 羊で×ならじゃないほう
                if ans[-2] == "S":
                    ans.append("W")
                else:
                    ans.append("S")
        # 狼
        else:
            # 狼で×なら同じ
            if S[i] == "x":
                ans.append(ans[-2])
            # 狼で〇ならじゃないほう
            else:
                if ans[-2] == "S":
                    ans.append("W")
                else:
                    ans.append("S")

    ans = ans[:-1]
    
    for i in range(N):
        if ans[i] == "S" and S[i] == "o":
            if ans[i-1] != ans[(i+1)%N]:
                break
        if ans[i] == "S" and S[i] == "x":
            if ans[i-1] == ans[(i+1)%N]:
                break
        if ans[i] == "W" and S[i] == "x":
            if ans[i-1] != ans[(i+1)%N]:
                break
        if ans[i] == "W" and S[i] == "o":
            if ans[i-1] == ans[(i+1)%N]:
                break
    else:
        print("".join(ans))

else:
    print(-1)