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

ok = False

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

if ans[n-1] == 'S':
    if (s[n-1] == 'o' and ans[n-2] == 'S') or (s[n-1] == 'x' and ans[n-2] == 'W'):
        ok = True
else: # 最初と最後の一匹が羊と仮定していたことに矛盾する
    ans = ['W'] + ['Unknown'] * (n-2) + ['W']
    if s[0]  == 'x':
        ans[1] = 'W'
    else:
        ans[1] = 'S'
    for i in range(1, n-1):
        if ans[i] == 'S':
            if s[i] == 'x':
                if ans[i-1] == 'S':         
                    ans[i+1] = 'W'
                else:
                    ans[i+1] = 'S'
            else:
                if ans[i-1] == 'W':
                    ans[i+1] = 'W'
                else:
                    ans[i+1] = 'S'
        else:
            if s[i] == 'o':
                if ans[i-1] == 'S':
                    ans[i+1] = 'W'
                else:
                    ans[i+1] = 'S'
            else:
                if ans[i-1] == 'W':
                    ans[i+1] = 'W'
                else:
                    ans[i+1] = 'S'

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



if ok:
    print(''.join(ans))
else:
    print(''.join(ans))
    # print(-1)

Submission status: Wrong Answer

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

ok = False

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

if ans[n-1] == 'S':
    if (s[n-1] == 'o' and ans[n-2] == 'S') or (s[n-1] == 'x' and ans[n-2] == 'W'):
        ok = True
else: # 最初と最後の一匹が羊と仮定していたことに矛盾する
    ans = ['W'] + ['Unknown'] * (n-2) + ['W']
    if s[0]  == 'x':
        ans[1] = 'W'
    else:
        ans[1] = 'S'
    for i in range(1, n-1):
        if ans[i] == 'S':
            if s[i] == 'x':
                if ans[i-1] == 'S':         
                    ans[i+1] = 'W'
                else:
                    ans[i+1] = 'S'
            else:
                if ans[i-1] == 'W':
                    ans[i+1] = 'W'
                else:
                    ans[i+1] = 'S'
        else:
            if s[i] == 'o':
                if ans[i-1] == 'S':
                    ans[i+1] = 'W'
                else:
                    ans[i+1] = 'S'
            else:
                if ans[i-1] == 'W':
                    ans[i+1] = 'W'
                else:
                    ans[i+1] = 'S'

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



if ok:
    print(''.join(ans))
else:
    print(-1)

Submission status: Wrong Answer

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

ok = False

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

if ans[n-1] == 'S':
    if (s[n-1] == 'o' and ans[n-2] == 'S') or (s[n-1] == 'x' and ans[n-2] == 'W'):
        ok = True
else: # 最初と最後の一匹が羊と仮定していたことに矛盾する
    ans = ['W'] + ['Unknown'] * (n-2) + ['W']
    if s[0]  == 'x':
        ans[1] = 'W'
    else:
        ans[1] = 'S'
    for i in range(1, n-1):
        if ans[i] == 'S':
            if s[i] == 'x':
                if ans[i-1] == 'S':         
                    ans[i+1] = 'W'
                else:
                    ans[i+1] = 'S'
            else:
                if ans[i-1] == 'W':
                    ans[i+1] = 'W'
                else:
                    ans[i+1] = 'S'
        else:
            if s[i] == 'o':
                if ans[i-1] == 'S':
                    ans[i+1] = 'W'
                else:
                    ans[i+1] = 'S'
            else:
                if ans[i-1] == 'W':
                    ans[i+1] = 'W'
                else:
                    ans[i+1] = 'S'

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



if ok:
    print(''.join(ans))
else:
    print(-1)

Submission status: Wrong Answer

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

ok = False

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

if ans[n-1] == 'S':
    if (s[n-1] == 'o' and ans[n-2] == 'S') or (s[n-1] == 'x' and ans[n-2] == 'W'):
        ok = True
else: # 最初と最後の一匹が羊と仮定していたことに矛盾する
    ans = ['W'] + ['Unknown'] * (n-2) + ['W']
    if s[0]  == 'x':
        ans[1] = 'W'
    else:
        ans[1] = 'S'
    for i in range(1, n-1):
        if ans[i] == 'S':
            if s[i] == 'x':
                if ans[i-1] == 'S':         
                    ans[i+1] = 'W'
                else:
                    ans[i+1] = 'S'
            else:
                if ans[i-1] == 'W':
                    ans[i+1] = 'W'
                else:
                    ans[i+1] = 'S'
        else:
            if s[i] == 'o':
                if ans[i-1] == 'S':
                    ans[i+1] = 'W'
                else:
                    ans[i+1] = 'S'
            else:
                if ans[i-1] == 'W':
                    ans[i+1] = 'W'
                else:
                    ans[i+1] = 'S'

    if ans[n-1] == 'W':
        if (s[n-1] == 'x' and ans[n-2] == 'W') or (s[n-i] == 'o' and ans[n-2] == 'S'):
            ok = True

if ok:
    print(''.join(ans))
else:
    print(-1)

Submission status: Wrong Answer

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

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

print(ans)
ok = False
if ans[n-1] == 'S':
    if (s[n-1] == 'o' and ans[n-2] == 'S') or (s[n-1] == 'x' and ans[n-2] == 'W'):
        ok = True
else:
    if (s[n-1] == 'x' and ans[n-2] == 'S') or (s[n-i] == 'o' and ans[n-2] == 'W'):
        ok = True

if ok:
    print(''.join(ans))
else:
    print(-1)

Submission status: Wrong Answer

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

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

print(ans)
ok = False
if ans[n-1] == 'S':
    if (s[n-1] == 'o' and ans[n-2] == 'S') or (s[n-1] == 'x' and ans[n-2] == 'W'):
        ok = True
else:
    if (s[n-1] == 'x' and ans[n-2] == 'S') or (s[n-i] == 'o' and ans[n-2] == 'W'):
        ok = True

if ok:
    print(''.join(ans))
else:
    print(-1)

Submission status: Wrong Answer

Solution code:

def reset(n):
    a = [0 for i in range(n+2)]
    return a
    
n = int(input())
s = list(input())

dt = [[1,1],[-1,1],[1,-1],[-1,-1]] #1→sheep,-1→wlf

ans = False
for i in range(4):
    li = reset(n)
    li[0] = dt[i][0]
    li[1] = dt[i][1]

    for j in range(1,len(s)):
        if s[j] =='o':
            li[j+1] = li[j]*li[j-1]
        elif s[j] =='x':
            li[j+1] = li[j]*li[j-1]*(-1)
    if li[0]==li[n] and li[1]==li[n+1]:
        ans = True
        break

if (ans):
    for i in range(n):
        if li[i] == 1:
            print('S',end="")
        else:
            print('W',end="")
    print('')

else:
    print(-1)

Submission status: Wrong Answer

Solution code:

def reset(n):
    a = [0 for i in range(n+1)]
    return a
    
n = int(input())
s = list(input())

dt = [[1,1],[-1,1],[1,-1],[-1,-1]] #1→sheep,-1→wlf

ans = False
for i in range(4):
    li = reset(n)
    li[0] = dt[i][0]
    li[1] = dt[i][1]

    for j in range(1,len(s)):
        if s[j] =='o':
            li[j+1] = li[j]*li[j-1]
        elif s[j] =='x':
            li[j+1] = li[j]*li[j-1]*(-1)
    if li[0] ==li[n]:
        ans = True
        break

if (ans):
    for i in range(n):
        if li[i] == 1:
            print('S',end="")
        else:
            print('W',end="")
    print('')

else:
    print(-1)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
chk=["SS","SW","WS","WW"]
for i in chk:
    x=i
    for j in range(len(s)):
        j=(j+1)%len(s)
        if j==len(s)-1:
            if (s[0]=="o" and x[0]=="S" and x[1]==x[-1]) or (s[0]=="x" and x[0]=="S" and x[1]!=x[-1]) or (s[0]=="o" and x[0]=="W" and x[-1]!=x[1]) or (s[0]=="x" and x[0]=="W" and x[-1]==x[1]):
                print(x)
                exit()
        if s[j]=="o" and x[j]=="S":
            x+=x[j-1]
        elif s[j]=="o" and x[j]=="W":
            x+=["S","W"][x[j-1]=="S"]
        elif s[j]=="x" and x[j]=="S":
            x+=["S","W"][x[j-1]=="S"]
        elif s[j]=="x" and x[j]=="W":
            x+=x[j-1]

print(-1)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
animal=["S","W"]
ans=[[0 for i in range(n)] for j in range(4)]
ans[0][0]="S";ans[0][1]="S"
ans[1][0]="S";ans[1][1]="W"
ans[2][0]="W";ans[2][1]="S"
ans[3][0]="W";ans[3][1]="W"
for i in range(4):
    for j in range(1,n-1):
        if ans[i][j]=="S":
            if s[j]=="o":
                ans[i][j+1]=ans[i][j-1]
            else:
                ans[i][j+1]=animal[1^animal.index(ans[i][j-1])]
        if ans[i][j]=="W":
            if s[j]=="x":
                ans[i][j+1]=ans[i][j-1]
            else:
                ans[i][j+1]=animal[1^animal.index(ans[i][j-1])]
    if (ans[i][-2]==ans[i][0] and ((ans[i][-1]=="S" and s[-1]=="o") or (ans[i][-1]=="W" and s[-1]=="x"))) or (ans[i][-2]!=ans[i][0] and ((ans[i][-1]=="S" and s[-1]=="x") or (ans[i][-1]=="W" and s[-1]=="o"))):
        print("".join(map(str,ans[i])));exit()
print(-1)

Submission status: Wrong Answer

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


def main():
    n = int(input())
    s = list(input())

    # 1番目と2番目を決め打ち
    # SS，SW，WW，WS
    # 1文字目とn + 1文字目が一致するかどうか
    for pair in ['SS', 'SW', 'WW', 'WS']:
        ans = ['' for _ in range(n + 1)]

        for index, p in enumerate(pair):
            ans[index] = p

            for j in range(1, n):
                if s[j] == 'o':
                    if ans[j] == 'S':
                        ans[j + 1] = ans[j - 1]
                    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:
                        ans[j + 1] = ans[j - 1]

        if ans[0] == ans[-1]:
            print(''.join(ans[:-1]))
            exit()

    print(-1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())

S = input()
s = []
#返答
for i in range(n):
    if S[i] == "o":
        s.append(0)
    else:
        s.append(1)
Test = [[0,0],[0,1],[1,0],[1,1]]
#00,01,10,11/0が羊
flag = False
ans = []
for t in Test:
    for i in range(1,n):
        t.append(t[-2]^s[i]^t[-1])
    if t[-1] == t[0]  and not t[-2]^s[0]^t[1]:###
        flag = True
        ans = t
        break

if flag:
    #print(S)
    for i in range(n):
        if ans[i] == 0:
            print("S",end = "")
        else:
            print("W",end = "")
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
n = int(input())

S = input()
s = []
#返答
for i in range(n):
    if S[i] == "o":
        s.append(0)
    else:
        s.append(1)
Test = [[0,0],[0,1],[1,0],[1,1]]
#00,01,10,11/0が羊
flag = False
ans = []
for t in Test:
    for i in range(1,n):
        t.append(t[-2]^s[i]^t[-1])
    if t[-1] == t[0]  and not t[-1]^s[0]^t[1]:
        flag = True
        ans = t
        break

if flag:
    #print(S)
    for i in range(n):
        if ans[i] == 0:
            print("S",end = "")
        else:
            print("W",end = "")
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
list_pat = [["S", "S"], ["S", "W"], ["W", "S"], ["W", "W"]]
for one_s in s[1:]:
  if one_s == "o":
    for i, one_pat in enumerate(list_pat):
      if one_pat[-1] == "S":
        if one_pat[-2] == "S":
          list_pat[i].append("S")
        else:
          list_pat[i].append("W")
      else:
        if one_pat[-2] == "S":
          list_pat[i].append("W")
        else:
          list_pat[i].append("S")
  else:
    for i, one_pat in enumerate(list_pat):
      if one_pat[-1] == "S":
        if one_pat[-2] == "S":
          list_pat[i].append("W")
        else:
          list_pat[i].append("S")
      else:
        if one_pat[-2] == "S":
          list_pat[i].append("S")
        else:
          list_pat[i].append("W")

for one_pat in list_pat:
  if one_pat[0] == one_pat[-1]:
    print("".join(one_pat[:-1]))
    exit()
print("-1")

Submission status: Wrong Answer

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]

n=int(input())
s=input()
tmp=["SS","WW","SW","WS"]
for j in range(4):
    ans=tmp[j]
    for i in range(n-1):
        if ans[i+1]=="S":
            if s[i+1]=="o":
                if ans[i]=="S":
                    ans+="S"
                else:
                    ans+="W"
            else:
                if ans[i]=="S":
                    ans+="W"
                else:
                    ans+="S"
        else:
            if s[i+1]=="o":
                if ans[i]=="S":
                    ans+="W"
                else:
                    ans+="S"
            else:
                if ans[i]=="S":
                    ans+="S"
                else:
                    ans+="W"
    if ans[0]==ans[-1]:
        print(ans[:-1])
        quit()
print(-1)

Submission status: Wrong Answer

Solution code:
N = int(input())
s = input()
s_num = s.replace("o", "1").replace("x", "0")
ans = [True] * N

# s[0]が"o"なら羊三匹、"x"なら狼三匹を確定
if s_num[0]:
    ans[0] = ans[1] = last = True
else:
    ans[0] = ans[1] = last = False

# i番目が羊か狼か決めた前提で"o" or "x"でi+1番目を決める
for i in range(1, N - 1):
    if int(s_num[i]) == ans[i]:
        ans[i + 1] = ans[i - 1]
    else:
        ans[i + 1] = not ans[i - 1]

# 1周回ってlastが羊か狼かを決める
if int(s_num[N - 1]) == ans[N - 1]:
    last = ans[N - 2]
else:
    last = not ans[N - 2]

# ans[0]とlastが一致していたら並びを出す
if ans[0] == last:
    answer = ""
    for a in ans:
        answer += str(a)
    answer = answer.replace("True", "S").replace("False", "W")
    print(answer)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
for p in (('S', 'S'), ('S', 'W'), ('W', 'S'), ('W', 'W')):
    t = [None] * n
    t[0], t[1] = p
    for i in range(1, n - 1):
        if (s[i] == 'o') == (t[i] == 'S'):t[i + 1] = t[i - 1]
        else:t[i + 1] = 'S' if t[i - 1] == 'W' else 'W'
    con1,con2 = ((s[0] == 'o') == (t[0] == 'S')) == (t[n - 1] == t[1]),((s[n - 1] == 'o') == (t[n - 1] == 'S')) == (t[n - 2] == t[0])
    if con1 and con2:
        print(''.join(t))
        exit()
    print(-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
s_list = list(input())
def main():
  animal_list = [None] * n
  sonzai = False
  #SS
  if not sonzai:
    animal_list[0] = True
    animal_list[1] = True
    animal_list = create_animal_list(animal_list)
    sonzai = is_valid_list(animal_list)
  if not sonzai:
    animal_list[0] = True
    animal_list[1] = False
    animal_list = create_animal_list(animal_list)
    sonzai = is_valid_list(animal_list)
  if not sonzai:
    animal_list[0] = False
    animal_list[1] = False
    animal_list = create_animal_list(animal_list)
    sonzai = is_valid_list(animal_list)
  if not sonzai:
    animal_list[0] = False
    animal_list[1] = True
    animal_list = create_animal_list(animal_list)
    sonzai = is_valid_list(animal_list)
  if not sonzai:
    print(-1)
  else:
    animal_list2 = []
    for animal in animal_list:
      if animal:
        animal_list2.append("S")
      else:
        animal_list2.append("W")
    animal_list2 = "".join(animal_list2)
    print(animal_list2)
def is_valid_list(animal_list):
  return is_ok(animal_list, 0) and is_ok(animal_list,-1)
  
def is_ok(animal_list, index):
  if animal_list[index%n]:
    if s_list[index%n] == "o":
      return s_list[(index+1)%n] == s_list[index-1]
    else:
      return not (s_list[(index+1)%n] == s_list[index-1])
  else:
    if s_list[index%n] == "o":
      return not (s_list[(index+1)%n] == s_list[index-1])
    else:
      return (s_list[(index+1)%n] == s_list[index-1])
def create_animal_list(animal_list):
  for index in range(2, len(animal_list)):
    if animal_list[index-1]:
      if s_list[index-1] == "o":
        animal_list[index] = animal_list[index-2]
      else:
        animal_list[index] = not animal_list[index-2]
    else:
      if s_list[index-1] == "o":
        animal_list[index] = not animal_list[index-2]
      else:
        animal_list[index] = animal_list[index-2]
  return animal_list
main()

Submission status: Wrong Answer

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

def sheep(): #一番左の動物が羊(1)の時をチェック
    for i in range(2):
        animal = [-1]*(n+2)
        animal[1] = 1 
        if s[1]=="o":
            animal[0] = 1-i
            animal[2] = 1-i
        else:
            animal[0] = i
            animal[2] = 1-i
        for x in range(2, n+1):
            if animal[x] == 1:
                animal[x+1] = animal[x-1] if s[x]=="o" else 1-animal[x-1]
            elif animal[x] == 0:
                animal[x+1] = 1-animal[x-1] if s[x]=="o" else animal[x-1]
        if animal[0] == animal[-2] and animal[1] == animal[-1]:
            return True, animal[1:n+1]
    return False, []


def wolf(): #一番左の動物が狼(0)の時をチェック
    for i in range(2):
        animal = [-1]*(n+2)
        animal[1] = 1 
        if s[1]=="x":
            animal[0] = 1-i
            animal[2] = 1-i
        else:
            animal[0] = i
            animal[2] = 1-i
        for x in range(2, n+1):
            if animal[x] == 1:  #hitsuji
                animal[x+1] = animal[x-1] if s[x]=="o" else 1-animal[x-1]
            elif animal[x] == 0:    #ookami
                animal[x+1] = 1-animal[x-1] if s[x]=="o" else animal[x-1]
        if animal[0] == animal[-2] and animal[1] == animal[-1]:
            return True, animal[1:n+1]
    return False, []

def solve():
    isFound, animal = sheep()
    if isFound:
        animal=["S" if i == 1 else "W" for i in animal] 
        return "".join(animal)
    isFound, animal = wolf()
    if isFound:
        animal=["S" if i == 1 else "W" for i in animal] 
        return "".join(animal)
    return -1
    

print(solve())

Submission status: Wrong Answer

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

for ss in [[0, 0], [0, 1], [1, 0], [1, 1]]:
    for i in range(1, n):
        if (ss[i] == 0 and s[i] == 'o') or (ss[i] == 1 and s[i] == 'x'):
            ss.append(ss[i - 1])
        else:
            ss.append(1 - ss[i - 1])
    if ss[-1] == ss[0]:
        res = ''.join(['SW' [i] for i in ss[:-1]])
        print(res)
        break
else:
    print(-1)

Submission status: Wrong Answer

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

l = ['SS', 'SW', 'WS', 'WW']

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