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:
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(c[-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:
def check(listx,s):
	num = (listx[-2]+listx[1])%2
	if num!=listx[0] and s[0]=="o": return True
	elif num==listx[0] and s[0]=="x": return True
	else: return False
n = int(input())
s = input()
x,flag,ans = [[1,1],[1,0],[0,1],[1,0]],False,""
for i in range(4):
	for j in range(1,n):
		if (s[j]=="o" and x[i][-1]==1) or (s[j]=="x" and x[i][-1]==0): x[i].append(x[i][-2])
		else: x[i].append(1-x[i][-2])
	if x[i][0]==x[i][-1] and check(x[i],s):
		flag = True
		break
if flag:
	for k in x[i][:n]:
		if k==1: ans+="S"
		else: ans+="W"
	print(ans)
else: print(-1)

Submission status: Wrong Answer

Solution code:
def check(listx,s):
	num = (listx[-2]+listx[1])%2
	if num!=listx[0] and s[0]=="o": return True
	elif num==listx[0] and s[0]=="x": return True
	else: return False
n = int(input())
s = input()
x,flag,ans = [[1,1],[1,0],[0,1],[1,0]],False,""
for i in range(4):
	for j in range(1,n):
		if (s[j]=="o" and x[i][-1]==1) or (s[j]=="x" and x[i][-1]==0): x[i].append(x[i][-2])
		else: x[i].append(1-x[i][-2])
	print(x[i])
	if x[i][0]==x[i][-1] and check(x[i],s):
		flag = True
		break
if flag:
	for k in x[i][:n]:
		if k==1: ans+="S"
		else: ans+="W"
	print(ans)
else: print(-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
x,flag,ans = [[1,1],[1,0],[0,1],[1,0]],False,""
for i in range(4):
	for j in range(1,n):
		if (s[j]=="o" and x[i][-1]==1) or (s[j]=="x" and x[i][-1]==0): x[i].append(x[i][-2])
		else: x[i].append(1-x[i][-2])
	if x[i][0]==x[i][-1]:
		flag = True
		break
if flag:
	for k in x[i][:n]:
		if k==1: ans+="S"
		else: ans+="W"
	print(ans)
else: print(-1)

Submission status: Wrong Answer

Solution code:
N = int(input())
s = list(input())
zoo = [0] * N
# 1: sheep, -1:wolf
zoo[0] = 1
zoo[-1] = 1
flag = 0
for i, c in enumerate(s):
    if (c == 'o' and zoo[i] == 1) or (c == 'x' and zoo[i] == -1):
        if i != N - 1 and zoo[i+1] == 0:
            zoo[i+1] = zoo[i-1]
    if (c == 'x' and zoo[i] == 1) or (c == 'o' and zoo[i] == -1):
        if i != N - 1 and zoo[i+1] == 0:
            zoo[i+1] = -1 * zoo[i-1]
if ((s[-1] == 'o' and zoo[-1] == 1) or (s[-1] == 'x' and zoo[-1] == -1)) and zoo[0] != zoo[-2]:
    flag = 1
elif ((s[-1] == 'x' and zoo[-1] == 1) or (s[-1] == 'o' and zoo[-1] == -1)) and zoo[0] == zoo[-2]:
    flag = 1
elif ((s[0] == 'o' and zoo[0] == 1) or (s[0] == 'x' and zoo[0] == -1)) and zoo[1] != zoo[-1]:
    flag = 1
elif ((s[0] == 'x' and zoo[0] == 1) or (s[0] == 'o' and zoo[0] == -1)) and zoo[1] == zoo[-1]:
    flag = 1
if flag == 0: 
    zoo = ['S' if i == 1 else 'W' for i in zoo]
    print(''.join(zoo))
else: print(-1)

Submission status: Wrong Answer

Solution code:
N = int(input())
s = list(input())
zoo = [0] * N
# 1: sheep, -1:wolf
zoo[0] = 1
zoo[-1] = 1
flag = 0
for i, c in enumerate(s):
    if (c == 'o' and zoo[i] == 1) or (c == 'x' and zoo[i] == -1):
        if i != N - 1 and zoo[i+1] == 0:
            zoo[i+1] = zoo[i-1]
    if (c == 'x' and zoo[i] == 1) or (c == 'o' and zoo[i] == -1):
        if i != N - 1 and zoo[i+1] == 0:
            zoo[i+1] = -1 * zoo[i-1]
if ((s[-1] == 'o' and zoo[-1] == 1) or (s[-1] == 'x' and zoo[-1] == -1)) and zoo[0] != zoo[-2]:
    flag = 1
elif ((s[-1] == 'x' and zoo[-1] == 1) or (s[-1] == 'o' and zoo[i] == -1)) and zoo[0] == zoo[-2]:
    flag = 1
if flag == 0: 
    zoo = ['S' if i == 1 else 'W' for i in zoo]
    print(''.join(zoo))
else: print(-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
t = [0] * n
# 0=sheep, 1=wolf

def check(one, two):
    t[0: 2] = [one, two]
    for i in range(n - 2):
        if (s[i + 1] == "o" and t[i + 1] == 0) or (s[i + 1] == "x" and t[i + 1] == 1):
            t[i + 2] = t[i]
        else:
            t[i + 2] = 1 - t[i]
    # print(t)
    if ((s[-1] == "o" and t[-1] == 0) or (s[-1] == "x" and t[-1] == 1)) and t[-2] == t[0]:
        return t
    elif ((s[-1] == "o" and t[-1] == 1) or (s[-1] == "x" and t[-1] == 0)) and t[-2] != t[0]:
        return t
    else:
        return None
    
def sw(t):
    ans = []
    for i in range(n):
        if t[i] == 0:
            ans.append("S")
        else:
            ans.append("W")
    return("".join(ans))

# print(check(0, 0))
# print(check(0, 1))
# print(check(1, 0))
# print(check(1, 1))
if check(0, 0) is not None:
    print(sw(check(0, 0)))
elif check(0, 1) is not None:
    print(sw(check(0, 1)))
elif check(1, 0) is not None:
    print(sw(check(1, 0)))
elif check(1, 1) is not None:
    print(sw(check(1, 1)))
else:
    print(-1)

Submission status: Wrong Answer

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

N = int(input())
statements = list(str(input()))
patterns = [['S', 'S'], ['S', 'W'], ['W', 'S'], ['W', 'W']]
null_flg = 1

for pattern in patterns:
    animals = pattern
    for index in range(1, N-1):
        rule = statements[index] + animals[index]
        if rule == 'oS':
            animals.append(animals[index - 1])
        elif rule == 'xS':
            if animals[index - 1] == 'S':
                animals.append('W')
            else:
                animals.append('S')
        elif rule == 'oW':
            if animals[index - 1] == 'S':
                animals.append('W')
            else:
                animals.append('S')
        elif rule == 'xW':
            animals.append(animals[index - 1])
        else:
            raise ValueError

    last = statements[-1] + animals[-1]
    if last == 'oS':
        if animals[0] == animals[-2] and animals[1] == animals[-1]:
            print(''.join(animals))
            null_flg = 0
            break
    elif last == 'xS':
        if animals[0] != animals[-2] and animals[1] != animals[-1]:
            print(''.join(animals))
            null_flg = 0
            break
    elif last == 'oW':
        if animals[0] != animals[-2] and animals[1] != animals[-1]:
            print(''.join(animals))
            null_flg = 0
            break
    elif last == 'xW':
        if animals[0] == animals[-2] and animals[1] == animals[-1]:
            print(''.join(animals))
            null_flg = 0
            break
    else:
        raise ValueError

if null_flg:
    print('-1')

Submission status: Wrong Answer

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

N = int(input())
statements = list(str(input()))
patterns = [['S', 'S'], ['S', 'W'], ['W', 'S'], ['W', 'W']]
null_flg = 1

for pattern in patterns:
    animals = pattern
    for index in range(1, N-1):
        rule = statements[index] + animals[index]
        if rule == 'oS':
            animals.append(animals[index - 1])
        elif rule == 'xS':
            if animals[index - 1] == 'S':
                animals.append('W')
            else:
                animals.append('S')
        elif rule == 'oW':
            if animals[index - 1] == 'S':
                animals.append('W')
            else:
                animals.append('S')
        elif rule == 'xW':
            animals.append(animals[index - 1])
        else:
            raise ValueError

    print('candidate: ', animals, 'last:', statements[-1] + animals[-1])
    last = statements[-1] + animals[-1]
    if last == 'oS':
        if animals[0] == animals[-2] and animals[1] == animals[-1]:
            print(''.join(animals))
            null_flg = 0
            break
    elif last == 'xS':
        if animals[0] != animals[-2] and animals[1] != animals[-1]:
            print(''.join(animals))
            null_flg = 0
            break
    elif last == 'oW':
        if animals[0] != animals[-2] and animals[1] != animals[-1]:
            print(''.join(animals))
            null_flg = 0
            break
    elif last == 'xW':
        if animals[0] == animals[-2] and animals[1] == animals[-1]:
            print(''.join(animals))
            null_flg = 0
            break
    else:
        raise ValueError

if null_flg:
    print('-1')

Submission status: Wrong Answer

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

N = int(input())
s = list(str(input()))
patterns = [['S', 'S'], ['S', 'W'], ['W', 'S'], ['W', 'W']]
rules = ['oS', 'xS', 'oW', 'xW']
null_flg = 1

for pattern in patterns:
    result = pattern
    for index in range(1, N-1):
        rule = s[index] + result[index]
        if rule == 'oS':
            result.append(result[index - 1])
        elif rule == 'xS':
            if result[index - 1] == 'S':
                result.append('W')
            else:
                result.append('S')
        elif rule == 'oW':
            if result[index - 1] == 'S':
                result.append('W')
            else:
                result.append('S')
        elif rule == 'xW':
            result.append(result[index - 1])

    # print('candidate: ', result)
    # print('last:', s[-1] + result[-1])
    last = s[-1] + result[-1]
    if last == 'oS':
        if result[0] == result[-2]:
            print(''.join(result))
            null_flg = 0
            break
    elif last == 'xS':
        if result[0] != result[-2]:
            print(''.join(result))
            null_flg = 0
            break
    elif last == 'oW':
        if result[0] != result[-2]:
            print(''.join(result))
            null_flg = 0
            break
    elif last == 'xW':
        if result[0] == result[-2]:
            print(''.join(result))
            null_flg = 0
            break

if null_flg:
    print('-1')

Submission status: Wrong Answer

Solution code:
N = int(input())
ori1 = [0 for x in  range(N)]
fini = 0
s = input()

init = [[1,1],[1,-1],[-1,1],[-1,-1]]


for it in init:
    flag = 0
    ori = ori1.copy()
    ori[0] = it[0]
    ori[1] = it[1]
    for i in range(N):
        #print(ori)
        #print(i)
        if i == 0:
            continue
        if ori[i] == 1:
            if s[i] == "o":
                if i == N-1:
                    if ori[0] != ori[i-1]:
                        flag = 1

                else:
                    ori[i+1] = ori[i-1]
            else:
                if i == N-1:
                    if ori[0] != -ori[i-1]:
                        flag = 1
                else:
                    ori[i+1] = -ori[i-1]
        else:
            if s[i] == "x":
                if i == N-1:
                    if ori[0] != ori[i-1]:
                        flag = 1
                else:
                    ori[i+1] = ori[i-1]
            else:
                if i == N-1:
                    if ori[0] != -ori[i-1]:
                        flag = 1
                else:
                    ori[i+1] = -ori[i-1]

    if flag == 0:
        ori = ["S" if x == 1 else "W" for x in ori]
        out = ""
        for o in ori:
            out += o
        print(out)
        fini = 1
        break
    else:
        continue

if fini == 0:
    print(-1)

Submission status: Wrong Answer

Solution code:
n =int(input())
s = input()
cir = ['']*n
judge = ''
def convertSW(x):
  if x == 'S':
    return 'W'
  elif x == 'W':
    return 'S'
for i in range(4):
  if i == 0:
    cir[0],cir[1] = 'S','S'
  if i == 1:
    cir[0],cir[1] = 'S','W'
  if i == 2:
    cir[0],cir[1] = 'W','W'
  else:
    cir[0],cir[1] = 'W','S'
  if s[0] == 'o' and cir[0] == 'S' or s[0] == 'x' and cir[0] == 'W':
    judge = cir[1]
  else:
    judge = convertSW(cir[1])    
  for j in range(2,n):
    if s[j-1] == 'o' and cir[j-1] == 'S' or s[j-1] == 'x' and cir[j-1] == 'W':
      cir[j] = cir[j-2]
    else:
      cir[j] = convertSW(cir[j-2])
  if (s[-1] == 'o' and cir[-1] == 'S') or (s[-1] == 'x' and cir[-1] == 'W'):
    if cir[0] == cir[-2]:
      print(''.join(cir))
      exit()
  else:
    if cir[0] == convertSW(cir[-2]):
      print(''.join(cir))
      exit()
print(-1)

Submission status: Wrong Answer

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

def judge(a,b):
	t=[]
	t.append(a)
	t.append(b)

	for ind, i in enumerate(s):
		if ind==0:
			continue

		if i=="o" and t[ind]=="S":
			t.append(t[ind-1])
		elif i=="o" and t[ind]=="W":
			if t[ind-1]=="S":
				t.append("W")
			elif t[ind-1]=="W":
				t.append("S")
		elif i=="x" and t[ind]=="S":
			if t[ind-1]=="S":
				t.append("W")
			elif t[ind-1]=="W":
				t.append("S")
		elif i=="x" and t[ind]=="W":
			t.append(t[ind-1])

	if t[0]==t[-1]:
		print "".join(t[:-1])
		quit()
	else:
		return False

judge("S","S")
judge("S","W")
judge("W","S")
judge("W","W")
print -1

Submission status: Wrong Answer

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

def judge(a,b):
	t=[]
	t.append(a)
	t.append(b)

	for ind, i in enumerate(s):
		if ind==0:
			continue
		else:
			if i=="o" and t[ind]=="S":
				t.append(t[ind-1])
			elif i=="o" and t[ind]=="W":
				if t[ind-1]=="S":
					t.append("W")
				elif t[ind-1]=="W":
					t.append("S")
			elif i=="x" and t[ind]=="S":
				if t[ind-1]=="S":
					t.append("W")
				elif t[ind-1]=="W":
					t.append("S")
			elif i=="x" and t[ind]=="W":
				t.append(t[ind-1])

	if t[0]==t[-1]:
		print "".join(t[:-1])
		quit()
	else:
		return False

judge("S","S")
judge("S","W")
judge("W","S")
judge("W","W")
print -1

Submission status: Wrong Answer

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

pat1 = [-1] * N
pat2 = [-1] * N
pat3 = [-1] * N
pat4 = [-1] * N

pat1[1] = pat2[1] = 1
pat3[1] = pat4[1] = 0

pat1[0] = pat1[2] = 0
pat2[0] = pat2[2] = 1
pat3[0] = pat4[2] = 0
pat3[2] = pat4[0] = 1

#print([pat1,pat2,pat3,pat4])

for i in range(2,N-1):
	for lis in [pat1,pat2,pat3,pat4]:
		if lis[i] == 1:
			if s[i] == 'o':
				lis[i+1] = lis[i-1]

			else:
				lis[i+1] = (lis[i-1] + 1)%2
		else:
			if s[i] == 'x':
				lis[i+1] = lis[i-1]

			else:
				lis[i+1] = (lis[i-1] + 1)%2

#print([pat1,pat2,pat3,pat4])

flg = []
for lis in [pat1,pat2,pat3,pat4]:
	if lis[N-1] == 1:
		if s[N-1] == 'o' and lis[N-2] == lis[0]:
			flg = lis
			break
		elif s[N-1] == 'x' and lis[N-2] != lis[0]:
			flg = lis
			break

	else:
		if s[N-1] == 'x' and lis[N-2] == lis[0]:
			flg = lis
			break
		elif s[N-1] == 'o' and lis[N-2] != lis[0]:
			flg = lis
			break

ans = ""
if flg != []:
	for num in flg:
		if num ==  0:
			ans += 'W'
		else:
			ans += 'S'

	print(ans)

else:
	print(-1)

Submission status: Wrong Answer

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

def addleave(p):
    for i in range(1, n-1):
        if s[i]=="o":
            if p[i]=="S":
                p += "S" if p[i-1]=="S" else "W"
            else:
                p += "W" if p[i-1]=="S" else "S"
        else:
            if p[i]=="S":
                p += "W" if p[i-1]=="S" else "S"
            else:
                p += "S" if p[i-1]=="S" else "W"
    return p
def solve():
    result = addleave("SS")
    if check(result):
        return result[:-1]
    result = addleave("SW")
    if check(result):
        return result[:-1]
    result = addleave("WS")
    if check(result):
        return result[:-1]
    result = addleave("WW")
    if check(result):
        return result[:-1]
    return -1

def check(res):
    res = res + res + res
    flag = True
    for i in range(n):
        if res[n + i - 1] == res[n + i + 1] and res[n + i]=="S" and s[i]=="o":
            pass
        elif res[n + i - 1] != res[n + i + 1] and res[n + i]=="S" and s[i]=="x":
            pass
        elif res[n + i - 1] == res[n + i + 1] and res[n + i]=="W" and s[i]=="x":
            pass
        elif res[n + i - 1] != res[n + i + 1] and res[n + i]=="W" and s[i]=="o":
            pass
        else:
            flag = False
    return flag
print(solve())

Submission status: Wrong Answer

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

def addleave(p):
    for i in range(1,n):
        if s[i]=="o":
            if p[i]=="S":
                p += "S" if p[i-1]=="S" else "W"
            else:
                p += "W" if p[i-1]=="S" else "S"
        else:
            if p[i]=="S":
                p += "W" if p[i-1]=="S" else "S"
            else:
                p += "S" if p[i-1]=="S" else "W"
    return p
def solve():
    result = addleave("SS")
    if result[-1] == result[0]:
        if check(result):
            return result[:-1]
    result = addleave("SW")
    if result[-1] == result[0]:
        if check(result):
            return result[:-1]
    result = addleave("WS")
    if result[-1] == result[0]:
        if check(result):
            return result[:-1]

    result = addleave("WW")
    if result[-1] == result[0]:
        if check(result):
            return result[:-1]

def check(res):
    res = res[:-1] + res[:-1] + res[:-1]
    flag = True
    for i in range(n):
        if res[n + i - 1] == res[n + i + 1] and res[n + i]=="S" and s[i]=="o":
            pass
        elif res[n + i - 1] != res[n + i + 1] and res[n + i]=="S" and s[i]=="x":
            pass
        elif res[n + i - 1] == res[n + i + 1] and res[n + i]=="W" and s[i]=="x":
            pass
        elif res[n + i - 1] != res[n + i + 1] and res[n + i]=="W" and s[i]=="o":
            pass
        else:
            flag = False
    return flag
print(solve())

Submission status: Wrong Answer

Solution code:
def judge():
    for i in range(1, n):
        before = list[i-1]
        l = s[i]
        if l == 'o':
            if list[i] == 'S':
                if before == 'S':
                    list.append('S')
                else:
                    list.append('W')
            else:
                if before == 'S':
                    list.append('W')
                else:
                    list.append('S')
        else:
            if list[i] == 'S':
                if before == 'S':
                    list.append('W')
                else:
                    list.append('S')
            else:
                if before == 'S':
                    list.append('S')
                else:
                    list.append('W')
    if list[0] == list[n]:
        if s[0] == 'o' and list[1] == list[n-1] or s[0] == 'x' and list[1] != list[n-1]:
            list.pop()
            print("".join(list))
            exit()

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

list = ['S', 'S']
judge()
list.clear()
list = ['S', 'W']
judge()
list.clear()
list = ['W', 'S']
judge()
list.clear()
list = ['W', 'W']
judge()
list.clear()
print('-1')

Submission status: Wrong Answer

Solution code:
def judge():
    for i in range(1, n):
        before = list[i-1]
        l = s[i]
        print(i, l)
        if l == 'o':
            if list[i] == 'S':
                if before == 'S':
                    list.append('S')
                else:
                    list.append('W')
            else:
                if before == 'S':
                    list.append('W')
                else:
                    list.append('S')
        else:
            if list[i] == 'S':
                if before == 'S':
                    list.append('W')
                else:
                    list.append('S')
            else:
                if before == 'S':
                    list.append('S')
                else:
                    list.append('W')
    if list[0] == list[n]:
        if s[0] == 'o' and list[1] == list[n-1] or s[0] == 'x' and list[1] != list[n-1]:
            list.pop()
            print("".join(list))
            exit()

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

list = ['S', 'S']
judge()
list.clear()
list = ['S', 'W']
judge()
list.clear()
list = ['W', 'S']
judge()
list.clear()
list = ['W', 'W']
judge()
list.clear()
print('-1')

Submission status: Wrong Answer

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

n = int(input())
s = input()
t = []
l = []
for i in range(n):
    t.append("S")

for i in range(n):
    if i+1 <= n-1 and i != 0:
        if (s[i] == "x" and t[i] == "S") or (s[i] == "o" and t[i] == "W"):
            if t[i-1] == "S":
                t[i+1] = "W"

            else:
                t[i+1] = "S"

        else:
            t[i+1] = t[i]
    elif i == 0:
        pass
    else:
        if ((s[i] == "x" and t[i] == "S") or (s[i] == "o" and t[i] == "W")) and t[0] == t[i-1]: t = "-1"
        elif ((s[i] == "x" and t[i] == "W") or (s[i] == "o" and t[i] == "S")) and t[0] != t[i-1]: t = "-1"
        elif ((s[0] == "o" and t[0] == "S") or (s[0] == "x" and t[0] == "W")) and t[1] != t[i]: t = "-1"
        elif ((s[0] == "o" and t[0] == "W") or (s[0] == "x" and t[0] == "S")) and t[1] == t[i]: t = "-1"
for i in range(n):
    l.append("W")

for i in range(n):
    if i+1 <= n-1 and i != 0:
        if (s[i] == "x" and l[i] == "S") or (s[i] == "o" and l[i] == "W"):
            if l[i-1] == "S":
                l[i+1] = "W"

            else:
                l[i+1] = "S"

        else:
            l[i+1] = l[i]
            
    elif i == 0:
        pass
    else:
        if(s[i] == "x" and l[i] == "S") or (s[i] == "o" and l[i] == "W") and l[0] == l[i-1]: l = "-1"
        elif (s[i] == "x" and l[i] == "W") or (s[i] == "o" and l[i] == "S") and l[0] != l[i-1]: l = "-1"
        elif ((s[0] == "o" and l[0] == "S") or (s[0] == "x" and l[0] == "W")) and l[1] != l[i]: l = "-1"
        elif ((s[0] == "o" and l[0] == "W") or (s[0] == "x" and l[0] == "S")) and l[1] == l[i]: l = "-1"
if t != "-1" and l == "-1":
    for i in t:
        print(i,end ="")

elif t == "-1" and l != "-1":
    for i in l:
        print(i,end ="")

elif t == l:print("-1")
else:
    for i in t:
        print(i,end ="")

Submission status: Wrong Answer

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

def addleave(p):
    for i in range(1,n):
        if s[i]=="o":
            if p[i]=="S":
                p += "S" if p[i-1]=="S" else "W"
            else:
                p += "W" if p[i-1]=="S" else "S"
        else:
            if p[i]=="S":
                p += "W" if p[i-1]=="S" else "S"
            else:
                p += "S" if p[i-1]=="S" else "W"
    return p
def solve():
    result = addleave("SS")
    if result[-1] == result[0]:
        return (result[:-1])
    result = addleave("SW")
    if result[-1] == result[0]:
        return (result[:-1])
    result = addleave("WS")
    if result[-1] == result[0]:
        return (result[:-1])
    result = addleave("WW")
    if result[-1] == result[0]:
        return (result[:-1])
    return -1

print(solve())

Submission status: Wrong Answer

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

n = int(input())
s = input()
t = []
l = []
for i in range(n):
    t.append("S")

for i in range(n):
    if i+1 <= n-1 and i != 0:
        if (s[i] == "x" and t[i] == "S") or (s[i] == "o" and t[i] == "W"):
            if t[i-1] == "S":
                t[i+1] = "W"

            else:
                t[i+1] = "S"

        else:
            t[i+1] = t[i]
    elif i == 0:
        pass
    else:
        if ((s[i] == "x" and t[i] == "S") or (s[i] == "o" and t[i] == "W")) and t[0] == t[i-1]: t = "-1"
        elif ((s[i] == "x" and t[i] == "W") or (s[i] == "o" and t[i] == "S")) and t[0] != t[i-1]: t = "-1"
        
for i in range(n):
    l.append("W")

for i in range(n):
    if i+1 <= n-1 and i != 0:
        if (s[i] == "x" and l[i] == "S") or (s[i] == "o" and l[i] == "W"):
            if l[i-1] == "S":
                l[i+1] = "W"

            else:
                l[i+1] = "S"

        else:
            l[i+1] = l[i]
            
    elif i == 0:
        pass
    else:
        if(s[i] == "x" and l[i] == "S") or (s[i] == "o" and l[i] == "W") and t[0] == l[i-1]: l = "-1"
        elif (s[i] == "x" and l[i] == "W") or (s[i] == "o" and l[i] == "S") and t[0] != l[i-1]: l = "-1"
if t != "-1" and l == "-1":
    for i in t:
        print(i,end ="")

elif t == "-1" and l != "-1":
    for i in l:
        print(i,end ="")

elif t == l:print("-1")
else:
    for i in t:
        print(i,end ="")

Submission status: Wrong Answer

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

def addleave(p):
    for i in range(1,n):
        if s[i]=="o":   #i匹目が一緒だと言っている
            if p[i]=="S":   #i匹目が羊である
                p += "S" if p[i-1]=="S" else "W"
            else:           #i匹目が狼である
                p += "W" if p[i-1]=="S" else "S"
        else:   #i匹目が違うと言っている
            if p[i]=="S":   #i匹目が羊である
                p += "W" if p[i-1]=="S" else "S"
            else:           #i匹目が狼である
                p += "S" if p[i-1]=="S" else "W"
    return p
def solve():
    # 1番目を羊だと仮定する(2番目とn番目は同じ！)
    # 2番目を羊だと仮定する(n番目が羊)
    p = "SS"
    result = addleave(p)
    if result[-1] == result[0]:
        return result[:-1]

    # 2番目を狼だと仮定する(n番目が狼)
    p = "SW"
    result = addleave(p)
    if result[-1] == result[0]:
        return result[:-1]

    # 1番目を狼だと仮定する(2番目とn番目は違う！)
    # 2番目を羊だと仮定する(n番目が狼)
    p = "WS"
    result = addleave(p)
    if result[-1] == result[0]:
        return result[:-1]
    # 2番目を狼だと仮定する(n番目が羊)
    p = "WW"
    result = addleave(p)
    if result[-1] == result[0]:
        return result[:-1]
    return -1

print(solve())

Submission status: Wrong Answer

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

n = int(input())
s = input()
t = []
l = []
for i in range(n):
    t.append("S")

for i in range(n):
    if i+1 <= n-1:
        if (s[i] == "x" and t[i] == "S") or (s[i] == "o" and t[i] == "W"):
            if t[i-1] == "S":
                t[i+1] = "W"

            else:
                t[i+1] = "S"

        else:
            t[i+1] = t[i]
    else:
        if ((s[i] == "x" and t[i] == "S") or (s[i] == "o" and t[i] == "W")) and t[0] == t[i-1]: t = "-1"
        elif ((s[i] == "x" and t[i] == "W") or (s[i] == "o" and t[i] == "S")) and t[0] != t[i-1]: t = "-1"
        
for i in range(n):
    l.append("W")

for i in range(n):
    if i+1 <= n-1:
        if (s[i] == "x" and l[i] == "S") or (s[i] == "o" and l[i] == "W"):
            if l[i-1] == "S":
                l[i+1] = "W"

            else:
                l[i+1] = "S"

        else:
            l[i+1] = l[i]

    else:
        if(s[i] == "x" and l[i] == "S") or (s[i] == "o" and l[i] == "W") and t[0] == l[i-1]: l = "-1"
        elif (s[i] == "x" and l[i] == "W") or (s[i] == "o" and l[i] == "S") and t[0] != l[i-1]: l = "-1"
if t != "-1" and l == "-1":
    for i in t:
        print(i,end ="")

elif t == "-1" and l != "-1":
    for i in l:
        print(i,end ="")

elif t == l:print("-1")
else:
    for i in t:
        print(i,end ="")

Submission status: Wrong Answer

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

n = int(input())
s = input()
t = []
l = []
for i in range(n):
    t.append("S")

for i in range(n):
    if i+1 <= n-1:
        if (s[i] == "x" and t[i] == "S") or (s[i] == "o" and t[i] == "W"):
            if t[i-1] == "S":
                t[i+1] = "W"

            else:
                t[i+1] = "S"

        else:
            t[i+1] = t[i]
    else:
        if ((s[i] == "x" and t[i] == "S") or (s[i] == "o" and t[i] == "W")) and t[0] == t[i-1]: t = "-1"
        elif ((s[i] == "x" and t[i] == "W") or (s[i] == "o" and t[i] == "S")) and t[0] != t[i-1]: t = "-1"
        
for i in range(n):
    l.append("W")

for i in range(n):
    if i+1 <= n-1:
        if (s[i] == "x" and l[i] == "S") or (s[i] == "o" and l[i] == "W"):
            if l[i-1] == "S":
                l[i+1] = "W"

            else:
                l[i+1] = "S"

        else:
            l[i+1] = l[i]

    else:
        if(s[i] == "x" and l[i] == "S") or (s[i] == "o" and l[i] == "W") and t[0] == l[i-1]: l = "-1"
        elif (s[i] == "x" and l[i] == "W") or (s[i] == "o" and l[i] == "S") and t[0] != l[i-1]: l = "-1"
if t != "-1" and l == "-1":
    for i in t:
        print(i,end ="")

elif t == "-1" and l != "-1":
    for i in l:
        print(i,end ="")

elif t == l:print("-1")
else:
    for i in t:
        print(i,end ="")