Problem: 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`.

Submission attempts (in order):
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

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


def dfs(now,ans):

    if now == n-1:
        if s[now] == 'o' and ans[now] == 'S':
            if ans[now-1] == ans[0]:
                return ans
            else: return '-1'
        elif s[now] == 'o' and ans[now] == 'W':
            if ans[now-1] != ans[0]:
                return ans
            else: return '-1'
        elif s[now] == 'x' and ans[now] == 'S':
            if ans[now-1] != ans[0]:
                return ans
            else: return '-1'
        elif s[now] == 'x' and ans[now] == 'W':
            if ans[now-1] == ans[0]:
                return ans
            else: return '-1'
        else:
            return '-1'

    if s[now] == 'o' and ans[now] == 'S':
        if ans[now-1] == 'S':
            ans[now+1]= 'S'
            return dfs(now+1,ans)
        else:
            ans[now+1]= 'W'
            return dfs(now+1,ans)
    elif s[now] == 'o' and ans[now] == 'W':
        if ans[now-1] == 'S':
            ans[now+1]= 'W'
            return dfs(now+1,ans)
        else:
            ans[now+1]= 'S'
            return dfs(now+1,ans)
    elif s[now] == 'x' and ans[now] == 'S':
        if ans[now-1] == 'S':
            ans[now+1]= 'W'
            return dfs(now+1,ans)
        else:
            ans[now+1]= 'S'
            return dfs(now+1,ans)
    elif s[now] == 'x' and ans[now] == 'W':
        if ans[now-1] == 'S':
            ans[now+1]= 'S'
            return dfs(now+1,ans)
        else:
            ans[now+1]= 'W'
            return dfs(now+1,ans)

ans = ['A']*n
ANS= ['a']*4

if s[0]=='o':
    ans[:2]=['S','W']
    ans[-1]='W'
    ANS[0] = dfs(0,ans)[:]

    ans[:2]=['S','S']
    ans[-1]='S'
    ANS[1] = dfs(0,ans)[:]

    ans[:2]=['W','S']
    ans[-1]='W'
    ANS[2] = dfs(0,ans)[:]

    ans[:2]=['W','W']
    ans[-1]='S'
    ANS[3] = dfs(0,ans)[:]

else:
    ans[:2]=['S','S']
    ans[-1]='W'
    ANS[0] = dfs(0,ans)

    ans[:2]=['S','W']
    ans[-1]='S'
    ANS[1] = dfs(0,ans)

    ans[:2]=['W','S']
    ans[-1]='S'
    ANS[2] = dfs(0,ans)

    ans[:2]=['W','W']
    ans[-1]='W'
    ANS[3] = dfs(0,ans)

for i in range(4):
    if ANS[i] != '-1':
        print(*ANS[i],sep='')
        exit()

print(-1)


import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

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


def dfs(now,ans):

    if now == n-1:
        if s[now] == 'o' and ans[now] == 'S':
            if ans[now-1] == ans[0]:
                return ans
            else: return '-1'
        elif s[now] == 'o' and ans[now] == 'W':
            if ans[now-1] != ans[0]:
                return ans
            else: return '-1'
        elif s[now] == 'x' and ans[now] == 'S':
            if ans[now-1] != ans[0]:
                return ans
            else: return '-1'
        elif s[now] == 'x' and ans[now] == 'W':
            if ans[now-1] == ans[0]:
                return ans
            else: return '-1'
        else:
            return '-1'

    if s[now] == 'o' and ans[now] == 'S':
        if ans[now-1] == 'S':
            ans[now+1]= 'S'
            return dfs(now+1,ans)
        else:
            ans[now+1]= 'W'
            return dfs(now+1,ans)
    elif s[now] == 'o' and ans[now] == 'W':
        if ans[now-1] == 'S':
            ans[now+1]= 'W'
            return dfs(now+1,ans)
        else:
            ans[now+1]= 'S'
            return dfs(now+1,ans)
    elif s[now] == 'x' and ans[now] == 'S':
        if ans[now-1] == 'S':
            ans[now+1]= 'W'
            return dfs(now+1,ans)
        else:
            ans[now+1]= 'S'
            return dfs(now+1,ans)
    elif s[now] == 'x' and ans[now] == 'W':
        if ans[now-1] == 'S':
            ans[now+1]= 'S'
            return dfs(now+1,ans)
        else:
            ans[now+1]= 'W'
            return dfs(now+1,ans)

ans = ['A']*n
ANS= ['a']*4

if s[0]=='o':
    ans[:2]=['S','W']
    ans[-1]='W'
    ANS[0] = dfs(0,ans)[:]

    ans[:2]=['S','S']
    ans[-1]='S'
    ANS[1] = dfs(0,ans)[:]

    ans[:2]=['W','S']
    ans[-1]='W'
    ANS[2] = dfs(0,ans)[:]

    ans[:2]=['W','W']
    ans[-1]='S'
    ANS[3] = dfs(0,ans)[:]

else:
    ans[:2]=['S','S']
    ans[-1]='W'
    ANS[0] = dfs(0,ans)[:]

    ans[:2]=['S','W']
    ans[-1]='S'
    ANS[1] = dfs(0,ans)[:]

    ans[:2]=['W','S']
    ans[-1]='S'
    ANS[2] = dfs(0,ans)[:]

    ans[:2]=['W','W']
    ans[-1]='W'
    ANS[3] = dfs(0,ans)[:]

for i in range(4):
    if ANS[i] != '-1':
        print(*ANS[i],sep='')
        exit()

print(-1)



n = int(input())
s = input() 
s=s+s[0]

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

ans[0] = 'S'
ans[1] = 'S'

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

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

print(-1)


Verdicts: Wrong Answer

Wrong Answer

Accepted