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 = ['S']*(n)

ani0 = ['S','S','W','W']
ani1 = ['S','W','S','W']
anim1 = ['S','W','W','S']

for i in range(4):
    ans[0] = ani0[i]
    if s[0] == 'o':
        ans[-1] = anim1[i]
        ans[1] = ani1[i]
    else:
        ans[-1] = anim1[3-i]
        ans[1] = ani1[3-i]
        
    #print(ans)
        
    for j in range(1,n):
        #print(j,n-2)
        if j == n-1:
            if s[j] == 'o':
                if ans[j] == 'S':
                    if ans[j-1] == 'S':
                        if ans[0] == 'S':
                            print(*ans,sep='')
                            exit()
                    else:
                        if ans[0] == 'W':
                            print(*ans,sep='')
                            exit()
                else:
                    if ans[j-1] == 'S':
                        if ans[0] == 'W':
                            print(*ans,sep='')
                            exit()
                    else:
                        if ans[0] == 'S':
                            print(*ans,sep='')
                            exit()
            else:
                if ans[j] == 'S':
                    if ans[j-1] == 'S':
                        if ans[0] == 'W':
                            print(*ans,sep='')
                            exit()
                    else:
                        if ans[0] == 'S':
                            print(*ans,sep='')
                            exit()
                else:
                    if ans[j-1] == 'S':
                        if ans[0] == 'S':
                            print(*ans,sep='')
                            exit()
                    else:
                        if ans[0] == 'W':
                            print(*ans,sep='')
                            exit()
            break
        
        if s[j] == 'o':
            if ans[j] == 'S':
                if ans[j-1] == 'S':
                    ans[j+1] = 'S'
                else:
                    ans[j+1] = 'W'
            else:
                if ans[j-1] == 'S':
                    ans[j+1] = 'W'
                else:
                    ans[j+1] = 'S'
        else:
            if ans[j] == 'S':
                if ans[j-1] == 'S':
                    ans[j+1] = 'W'
                else:
                    ans[j+1] = 'S'
            else:
                if ans[j-1] == 'S':
                    ans[j+1] = 'S'
                else:
                    ans[j+1] = 'W'
print(-1)

Submission status: Wrong Answer

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

ans = ['S']*(n)

ans[1] = 'W'

ani0 = ['S','S','W','W']
ani1 = ['S','W','S','W']
anim1 = ['S','W','W','S']

for i in range(4):
    ans[0] = ani0[i]
    if s[0] == 'o':
        ans[-1] = anim1[i]
        ans[1] = ani1[i]
    else:
        ans[-1] = anim1[3-i]
        ans[1] = ani1[3-i]
        
    #print(ans)
        
    for j in range(1,n):
        #print(j,n-2)
        if j == n-1:
            if s[j] == 'o':
                if ans[j] == 'S':
                    if ans[j-1] == 'S':
                        if ans[0] == 'S':
                            print(*ans,sep='')
                            exit()
                    else:
                        if ans[0] == 'W':
                            print(*ans,sep='')
                            exit()
                else:
                    if ans[j-1] == 'S':
                        if ans[0] == 'W':
                            print(*ans,sep='')
                            exit()
                    else:
                        if ans[0] == 'S':
                            print(*ans,sep='')
                            exit()
            else:
                if ans[j] == 'S':
                    if ans[j-1] == 'S':
                        if ans[0] == 'W':
                            print(*ans,sep='')
                            exit()
                    else:
                        if ans[0] == 'S':
                            print(*ans,sep='')
                            exit()
                else:
                    if ans[j-1] == 'S':
                        if ans[0] == 'S':
                            print(*ans,sep='')
                            exit()
                    else:
                        if ans[0] == 'W':
                            print(*ans,sep='')
                            exit()
            break
        
        if s[j] == 'o':
            if ans[j] == 'S':
                if ans[j-1] == 'S':
                    ans[j+1] = 'S'
                else:
                    ans[j+1] = 'W'
            else:
                if ans[j-1] == 'S':
                    ans[j+1] = 'W'
                else:
                    ans[j+1] = 'S'
        else:
            if ans[j] == 'S':
                if ans[j-1] == 'S':
                    ans[j+1] = 'W'
                else:
                    ans[j+1] = 'S'
            else:
                if ans[j-1] == 'S':
                    ans[j+1] = 'S'
                else:
                    ans[j+1] = 'W'
print(-1)

Submission status: Wrong Answer

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
s = input()
def check(res):
    for i in range(1,n):
        if res[-1] == 'S':
            if s[i] == 'o':
                if res[-2] == 'S':
                    res += 'S'
                else:
                    res += 'W'
            else:
                if res[-2] == 'S':
                    res += 'W'
                else:
                    res += 'S'
        else:
            if s[i] == 'o':
                if res[-2] == 'S':
                    res += 'W'
                else:
                    res += 'S'
            else:
                if res[-2] == 'S':
                    res += 'S'
                else:
                    res += 'W'
    return res

ans1 = 'S'
ans2 = 'S'
ans3 = 'S'
ans4 = 'S'
if s[0] == 'o':
    ans1 += 'S'
    ans2 += 'W'
    res1 = check(ans1)
    res2 = check(ans2)
    if res1[-1] == ans1[0]:
        print(res1[:-1])
        quit()
    elif res2[-1] == ans2[0]:
        print(res2[:-1])
        quit()
else:
    ans3 += 'S'
    ans4 += 'W'
    res3 = check(ans3)
    res4 = check(ans4)
    if res3[-1] == ans3[0]:
        print(res3[:-1])
        quit()
    elif res4[-1] == ans4[0]:
        print(res4[:-1])
        quit()

ans5 = 'W'
ans6 = 'W'
ans7 = 'W'
ans8 = 'W'
if s[0] == 'o':
    ans5 += 'S'
    ans6 += 'W'
    res5 = check(ans5)
    res6 = check(ans6)
    if res5[-1] == ans5[0]:
        print(res5[:-1])
        quit()
    elif res6[-1] == ans6[0]:
        print(res6[:-1])
        quit()
else:
    ans7 += 'S'
    ans8 += 'W'
    res7 = check(ans7)
    res8 = check(ans8)
    if res7[-1] == ans7[0]:
        print(res7[:-1])
        quit()
    elif res8[-1] == ans8[0]:
        print(res8[:-1])
        quit()
print(-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
seed1 = ["S","W"]
ans = ["SS","SW","WS","WW"]
for i in s[1:]:
    for k,v in enumerate(ans):
        now = 0 if i == "o" else 1
        now = (now + seed1.index(v[-1]) + seed1.index(v[-2])) % 2
        if now:
            ans[k] += "W"
        else:
            ans[k] += "S"
print(ans)
now = 0 if s[0] == "x" else 1
for i in ans:  
    now2 = (now + seed1.index(i[-2]) + seed1.index(i[1]) + seed1.index(i[0])) % 2
    if (i[0] == i[-1]) and now2:
        print(i[:-1])
        exit()
print(-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
seed1 = ["S","W"]
ans = ["SS","SW","WS","WW"]
for i in s[1:]:
    for k,v in enumerate(ans):
        now = 0 if i == "o" else 1
        now = (now + seed1.index(v[-1]) + seed1.index(v[-2])) % 2
        if now:
            ans[k] += "W"
        else:
            ans[k] += "S"
print(ans)
for i in ans:
    now = 0 if i[0] == "o" else 1
    if (i[0] == i[-1]) and ((i[1] == i[-2]) ^ now):
        print(i[:-1])
        exit()
print(-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
seed1 = ["S","W"]
ans = ["SS","SW","WS","WW"]
for i in s[1:]:
    for k,v in enumerate(ans):
        now = 0 if i == "o" else 1
        now = (now + seed1.index(v[-1]) + seed1.index(v[-2])) % 2
        if now:
            ans[k] += "W"
        else:
            ans[k] += "S"
for i in ans:
    now = 0 if i[0] == "o" else 1
    if (i[0] == i[-1]) and ((i[2] == i[-2]) ^ now):
        print(i[:-1])
        exit()
print(-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
seed1 = ["S","W"]
ans = ["SS","SW","WS","WW"]
for i in s[1:]:
    for k,v in enumerate(ans):
        now = 0 if i == "o" else 1
        now = (now + seed1.index(v[-1]) + seed1.index(v[-2])) % 2
        if now:
            ans[k] += "W"
        else:
            ans[k] += "S"
now = 0 if s[0] == "o" else 1
for i in ans:
    if (i[0] == i[-1]) and ((i[2] == i[-2]) ^ now):
        print(i[:-1])
        exit()
print(-1)

Submission status: Wrong Answer

Solution code:
n=int(input())
s = list(input())
l = list(0 for i in range(n))
l[0]='S'
l[1]='S'
for i in range(1,n-1):
    if l[i]=='S':
        if l[i-1]=='S':
            if (s[i]=='o'):
                s[i+1]='S'
            else:
                s[i+1]='W'
        else:
            if s[i]=='o':
                s[i+1]='W'
            else:
                s[i+1]='S'
    else:
        if l[i-1]=='S':
            if (s[i]=='o'):
                s[i+1]='W'
            else:
                s[i+1]='S'
        else:
            if s[i]=='o':
                s[i+1]='S'
            else:
                s[i+1]='W'
if l[n-1]=='S':
    if l[n-2]=='S':
        if (s[n-1]=='o'):
            if s[0]=='S':
                print(l)
                exit
        else:
            if s[0]=='W':
                print(l)                   
                exit
    else:
        if s[n-1]=='o':
            if s[0]=='W':
                print(l)
                exit
        else:
            if s[0]=='S':
                print(l)
                exit
else:
    if l[n-2]=='S':
        if (s[n-1]=='o'):
            if s[0]=='W':
                print(l)
                exit
        else:
            if s[0]=='S':
                print(l)
                exit
    else:
        if s[n-1]=='o':
            if s[0]=='S':
                print(l)
                exit
        else:
            if s[0]=='W':
                print(l)                    
                exit
l[0]='S'
l[1]='W'
for i in range(1,n-1):
    if l[i]=='S':
        if l[i-1]=='S':
            if (s[i]=='o'):
                s[i+1]='S'
            else:
                s[i+1]='W'
        else:
            if s[i]=='o':
                s[i+1]='W'
            else:
                s[i+1]='S'
    else:
        if l[i-1]=='S':
            if (s[i]=='o'):
                s[i+1]='W'
            else:
                s[i+1]='S'
        else:
            if s[i]=='o':
                s[i+1]='S'
            else:
                s[i+1]='W'
if l[n-1]=='S':
    if l[n-2]=='S':
        if (s[n-1]=='o'):
            if s[0]=='S':
                print(l)
                exit
        else:
            if s[0]=='W':
                print(l)                   
                exit
    else:
        if s[n-1]=='o':
            if s[0]=='W':
                print(l)
                exit
        else:
            if s[0]=='S':
                print(l)
                exit
else:
    if l[n-2]=='S':
        if (s[n-1]=='o'):
            if s[0]=='W':
                print(l)
                exit
        else:
            if s[0]=='S':
                print(l)
                exit
    else:
        if s[n-1]=='o':
            if s[0]=='S':
                print(l)
                exit
        else:
            if s[0]=='W':
                print(l)                    
                exit
l[0]='W'
l[1]='S'
for i in range(1,n-1):
    if l[i]=='S':
        if l[i-1]=='S':
            if (s[i]=='o'):
                s[i+1]='S'
            else:
                s[i+1]='W'
        else:
            if s[i]=='o':
                s[i+1]='W'
            else:
                s[i+1]='S'
    else:
        if l[i-1]=='S':
            if (s[i]=='o'):
                s[i+1]='W'
            else:
                s[i+1]='S'
        else:
            if s[i]=='o':
                s[i+1]='S'
            else:
                s[i+1]='W'
if l[n-1]=='S':
    if l[n-2]=='S':
        if (s[n-1]=='o'):
            if s[0]=='S':
                print(l)
                exit
        else:
            if s[0]=='W':
                print(l)                   
                exit
    else:
        if s[n-1]=='o':
            if s[0]=='W':
                print(l)
                exit
        else:
            if s[0]=='S':
                print(l)
                exit
else:
    if l[n-2]=='S':
        if (s[n-1]=='o'):
            if s[0]=='W':
                print(l)
                exit
        else:
            if s[0]=='S':
                print(l)
                exit
    else:
        if s[n-1]=='o':
            if s[0]=='S':
                print(l)
                exit
        else:
            if s[0]=='W':
                print(l)                    
                exit
l[0]='W'
l[1]='W'
for i in range(1,n-1):
    if l[i]=='S':
        if l[i-1]=='S':
            if (s[i]=='o'):
                s[i+1]='S'
            else:
                s[i+1]='W'
        else:
            if s[i]=='o':
                s[i+1]='W'
            else:
                s[i+1]='S'
    else:
        if l[i-1]=='S':
            if (s[i]=='o'):
                s[i+1]='W'
            else:
                s[i+1]='S'
        else:
            if s[i]=='o':
                s[i+1]='S'
            else:
                s[i+1]='W'
if l[n-1]=='S':
    if l[n-2]=='S':
        if (s[n-1]=='o'):
            if s[0]=='S':
                print(l)
                exit
        else:
            if s[0]=='W':
                print(l)                   
                exit
    else:
        if s[n-1]=='o':
            if s[0]=='W':
                print(l)
                exit
        else:
            if s[0]=='S':
                print(l)
                exit
else:
    if l[n-2]=='S':
        if (s[n-1]=='o'):
            if s[0]=='W':
                print(l)
                exit
        else:
            if s[0]=='S':
                print(l)
                exit
    else:
        if s[n-1]=='o':
            if s[0]=='S':
                print(l)
                exit
        else:
            if s[0]=='W':
                print(l)                    
                exit
print(-1)

Submission status: Wrong Answer

Solution code:
n=int(input())
s = list(input())
l = list(0 for i in range(n))
l[0]='S'
l[1]='S'
for i in range(1,n-1):
    if l[i]=='S':
        if l[i-1]=='S':
            if (s[i]=='○'):
                s[i+1]='S'
            else:
                s[i+1]='W'
        else:
            if s[i]=='○':
                s[i+1]='W'
            else:
                s[i+1]='S'
    else:
        if l[i-1]=='S':
            if (s[i]=='○'):
                s[i+1]='W'
            else:
                s[i+1]='S'
        else:
            if s[i]=='○':
                s[i+1]='S'
            else:
                s[i+1]='W'
if l[n-1]=='S':
    if l[n-2]=='S':
        if (s[n-1]=='○'):
            if s[0]=='S':
                print(l)
                exit
        else:
            if s[0]=='W':
                print(l)                   
                exit
    else:
        if s[n-1]=='○':
            if s[0]=='W':
                print(l)
                exit
        else:
            if s[0]=='S':
                print(l)
                exit
else:
    if l[n-2]=='S':
        if (s[n-1]=='○'):
            if s[0]=='W':
                print(l)
                exit
        else:
            if s[0]=='S':
                print(l)
                exit
    else:
        if s[n-1]=='○':
            if s[0]=='S':
                print(l)
                exit
        else:
            if s[0]=='W':
                print(l)                    
                exit
l[0]='S'
l[1]='W'
for i in range(1,n-1):
    if l[i]=='S':
        if l[i-1]=='S':
            if (s[i]=='○'):
                s[i+1]='S'
            else:
                s[i+1]='W'
        else:
            if s[i]=='○':
                s[i+1]='W'
            else:
                s[i+1]='S'
    else:
        if l[i-1]=='S':
            if (s[i]=='○'):
                s[i+1]='W'
            else:
                s[i+1]='S'
        else:
            if s[i]=='○':
                s[i+1]='S'
            else:
                s[i+1]='W'
if l[n-1]=='S':
    if l[n-2]=='S':
        if (s[n-1]=='○'):
            if s[0]=='S':
                print(l)
                exit
        else:
            if s[0]=='W':
                print(l)                   
                exit
    else:
        if s[n-1]=='○':
            if s[0]=='W':
                print(l)
                exit
        else:
            if s[0]=='S':
                print(l)
                exit
else:
    if l[n-2]=='S':
        if (s[n-1]=='○'):
            if s[0]=='W':
                print(l)
                exit
        else:
            if s[0]=='S':
                print(l)
                exit
    else:
        if s[n-1]=='○':
            if s[0]=='S':
                print(l)
                exit
        else:
            if s[0]=='W':
                print(l)                    
                exit
l[0]='W'
l[1]='S'
for i in range(1,n-1):
    if l[i]=='S':
        if l[i-1]=='S':
            if (s[i]=='○'):
                s[i+1]='S'
            else:
                s[i+1]='W'
        else:
            if s[i]=='○':
                s[i+1]='W'
            else:
                s[i+1]='S'
    else:
        if l[i-1]=='S':
            if (s[i]=='○'):
                s[i+1]='W'
            else:
                s[i+1]='S'
        else:
            if s[i]=='○':
                s[i+1]='S'
            else:
                s[i+1]='W'
if l[n-1]=='S':
    if l[n-2]=='S':
        if (s[n-1]=='○'):
            if s[0]=='S':
                print(l)
                exit
        else:
            if s[0]=='W':
                print(l)                   
                exit
    else:
        if s[n-1]=='○':
            if s[0]=='W':
                print(l)
                exit
        else:
            if s[0]=='S':
                print(l)
                exit
else:
    if l[n-2]=='S':
        if (s[n-1]=='○'):
            if s[0]=='W':
                print(l)
                exit
        else:
            if s[0]=='S':
                print(l)
                exit
    else:
        if s[n-1]=='○':
            if s[0]=='S':
                print(l)
                exit
        else:
            if s[0]=='W':
                print(l)                    
                exit
l[0]='W'
l[1]='W'
for i in range(1,n-1):
    if l[i]=='S':
        if l[i-1]=='S':
            if (s[i]=='○'):
                s[i+1]='S'
            else:
                s[i+1]='W'
        else:
            if s[i]=='○':
                s[i+1]='W'
            else:
                s[i+1]='S'
    else:
        if l[i-1]=='S':
            if (s[i]=='○'):
                s[i+1]='W'
            else:
                s[i+1]='S'
        else:
            if s[i]=='○':
                s[i+1]='S'
            else:
                s[i+1]='W'
if l[n-1]=='S':
    if l[n-2]=='S':
        if (s[n-1]=='○'):
            if s[0]=='S':
                print(l)
                exit
        else:
            if s[0]=='W':
                print(l)                   
                exit
    else:
        if s[n-1]=='○':
            if s[0]=='W':
                print(l)
                exit
        else:
            if s[0]=='S':
                print(l)
                exit
else:
    if l[n-2]=='S':
        if (s[n-1]=='○'):
            if s[0]=='W':
                print(l)
                exit
        else:
            if s[0]=='S':
                print(l)
                exit
    else:
        if s[n-1]=='○':
            if s[0]=='S':
                print(l)
                exit
        else:
            if s[0]=='W':
                print(l)                    
                exit

Submission status: Wrong Answer

Solution code:
N=int(input())
S=list(input().rstrip())
for i in range(N):
  if S[i]=='o': S[i]=True
  else: S[i]=False
S.append(S[0])
A=[True]*(N+2)
for a in [[True,True],[True,False],[False,True],[False,False]]:
  A[0],A[1]=a[0],a[1]
  for j in range(1,N+1):
    if A[j] ^ S[j]:
      A[j+1]=not A[j-1]
    else:
      A[j+1]=A[j-1]
  if A[0]==A[-1]:
    for k in range(N):
      if A[k]: A[k]='S'
      else: A[k]='W'
    print("".join(A[:N]))
    exit()
print(-1)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=list(input().rstrip())
for i in range(N):
  if S[i]=='o': S[i]=True
  else: S[i]=False
A=[True]*(N+1)
for a in [[True,True],[True,False],[False,True],[False,False]]:
  A[0],A[1]=a[0],a[1]
  for j in range(1,N):
    if A[j] ^ S[j]:
      A[j+1]=not A[j-1]
    else:
      A[j+1]=A[j-1]
  if A[0]==A[-1]:
    for k in range(N):
      if A[k]: A[k]='S'
      else: A[k]='W'
    print("".join(A[:N]))
    exit()
print(-1)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
def check(s1,s2):
  ans=[s1,s2]
  for i in range(1,n-1):
    if (ans[i]=='S' and s[i]=='o') or (ans[i]=='W' and s[i]=='x'):
      ans.append(ans[i-1])
    elif ans[i]=='S' and s[i]=='x' and ans[i-1]=='S':
      ans.append('W')
    elif ans[i]=='S' and s[i]=='x' and ans[i-1]=='W':
      ans.append('S')
    elif ans[i]=='W' and s[i]=='o' and ans[i-1]=='S':
      ans.append('W')
    elif ans[i]=='W' and s[i]=='o' and ans[i-1]=='W':
      ans.append('S')
  if ans[-1]=='S':
    if s[-1]=='o' and ans[0]==ans[-2]:
      print(''.join(ans))
      exit()
    if s[-1]=='x' and ans[0]!=ans[-2]:
      print(''.join(ans))
      exit()
  else:
    if s[-1]=='o' and ans[0]!=ans[-2]:
      print(''.join(ans))
      exit()
    if s[-1]=='x' and ans[0]==ans[-2]:
      print(''.join(ans))
      exit()
  return
check('S','S')
check('S','W')
check('W','S')
check('W','W')
print(-1)

Submission status: Wrong Answer

Solution code:
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]

n=int(input())
s=input()
lst=[[0,0],[0,1],[1,0],[1,1]]

for i in range(n-1):
    for j in range(4):
        if lst[j][-1]==0 and s[1+i]=="o":
            lst[j].append(lst[j][-2])
        elif lst[j][-1]==0 and s[1+i]=="x":
            lst[j].append(abs(1-lst[j][-2]))
        elif lst[j][-1]==1 and s[1+i]=="o":
            lst[j].append(abs(1-lst[j][-2]))
        else:
            lst[j].append(lst[j][-2])
# print(lst)

for i in range(4):
    if lst[i][0]==lst[i][-1]:
        if lst[i][0]==0 and lst[i][1]!=lst[i][-2]:
            continue
        if lst[i][0]==1 and lst[i][1]==lst[i][-1]:
            continue
        tmp=[]
        for j in range(n):
            if lst[i][j]==0:
                tmp.append("S")
            else:
                tmp.append("W")
        print("".join(tmp))
        quit()
print(-1)

Submission status: Wrong Answer

Solution code:
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]

n=int(input())
s=input()
lst=[[0,0],[0,1],[1,0],[1,1]]

for i in range(n-1):
    for j in range(4):
        if lst[j][-1]==0 and s[1+i]=="o":
            lst[j].append(lst[j][-2])
        elif lst[j][-1]==0 and s[1+i]=="x":
            lst[j].append(abs(1-lst[j][-2]))
        elif lst[j][-1]==1 and s[1+i]=="o":
            lst[j].append(abs(1-lst[j][-2]))
        else:
            lst[j].append(lst[j][-2])
# print(lst)

for i in range(4):
    if lst[i][0]==lst[i][-1]:
        tmp=[]
        for j in range(n):
            if lst[i][j]==0:
                tmp.append("S")
            else:
                tmp.append("W")
        print("".join(tmp))
        quit()
print(-1)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
for a in [0,1]:
    for b in [0,1]:
        #0 means it's a false speaking animal
        #1 means it's a truth speaking animal
        ass=[-1]*n
        ass[0]=a
        ass[1]=b
        #we know about the assignment of first two animals
        for i in range(1,n-1):
            if ass[i]==0:#false speaking animal
                if s[i]=='o':
                    ass[i+1]=1-ass[i-1]
                else:
                    ass[i+1]=ass[i-1]
            else:#true speaking animal
                if s[i]=='o':
                    ass[i+1]=ass[i-1]
                else:
                    ass[i+1]=1-ass[i-1]
        #print(i)
        if ass[0]==1:
            if (s[0]=='o' and ass[-1]!=ass[1]) or (s[0]=='x' and ass[-1]==ass[1]):
                continue
        else:
            if (s[0]=='o' and ass[-1]==ass[1]) or (s[0]=='x' and ass[-1]!=ass[1]):
                continue
        if ass[-1]==1:
            if (s[-1]=='o' and ass[n-2]!=ass[0]) or (s[-1]=='x' and ass[n-2]==ass[0]):
                continue
        else:
            if (s[-1]=='o' and ass[n-2]==ass[0]) or (s[-1]=='x' and ass[n-2]!=ass[0]):
                continue
        ass=['S' if i==0 else 'W' for i in ass]
        print(''.join(ass))
        exit()
print(-1)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())
#print(s)
for a in [0,1]:
    for b in [0,1]:
        #0 means it's a false speaking animal
        #1 means it's a truth speaking animal
        ass=[-1]*n
        ass[0]=a
        ass[1]=b
        #we know about the assignment of first two animals
        for i in range(1,n-1):
            if ass[i]==0:#false speaking animal
                if s[i]=='o':
                    ass[i+1]=1-ass[i-1]
                else:
                    ass[i+1]=ass[i-1]
            else:#true speaking animal
                if s[i]=='o':
                    ass[i+1]=ass[i-1]
                else:
                    ass[i+1]=1-ass[i-1]
        if ass[0]==1:
            if (s[0]=='o' and ass[-1]!=ass[1]) or (s[i]=='x' and ass[-1]==ass[1]):
                continue
        else:
            if (s[0]=='o' and ass[-1]==ass[1]) or (s[i]=='x' and ass[-1]!=ass[1]):
                continue
        if ass[-1]==1:
            if (s[-1]=='o' and ass[n-2]!=ass[0]) or (s[-1]=='x' and ass[n-2]==ass[0]):
                continue
        else:
            if (s[-1]=='o' and ass[n-2]==ass[0]) or (s[-1]=='x' and ass[n-2]!=ass[0]):
                continue
        ass=['S' if i==0 else 'W' for i in ass]
        print(''.join(ass))
        exit()
print(-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
a = "SS"
ct=1
while ct<6:    
    for i in range(n-1):
        p=a[i]
        q="A"
        if a[i]=="S":
            q="W"
        else:
            q="S"
        if a[i+1]=="S":
            if s[i+1] == "o":
                a=a+a[i]
            else:
                a=a+q
        else:
            if s[i+1] == "o":
                 a=a+q
            else:
                a=a+a[i]
    if a[0]==a[n]:
        print(a[0:n])
        break
    else:
        ct=ct+1
        if ct==2:
            a="SW"
        elif ct==3:
            a="WS"
        elif ct==4:
            a="WW"
        else:
            print(-1)
            break

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
a = "SS"
ct=0
while ct<6:    
    for i in range(n-1):
        p=a[i]
        q="A"
        if a[i]=="S":
            q="W"
        else:
            q="S"
        if a[i+1]=="S":
            if s[i+1] == "o":
                a=a+a[i]
            else:
                a=a+q
        else:
            if s[i+1] == "o":
                 a=a+q
            else:
                a=a+a[i]
    if a[0]==a[n]:
        print(a[0:n])
        break
    else:
        ct=ct+1
        if ct==2:
            a="SW"
        elif ct==3:
            a="WS"
        elif ct==4:
            a="WW"
        else:
            print(-1)
            break