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:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000


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

def step(first,second,rep):
    ls = [first,second]
    if ls == [0,0]:
        if rep == "o":
            third = 0
        else:
            third = 1
    elif ls == [0,1]:
        if rep == "o":
            third = 1
        else:
            third = 0
    elif ls == [1,0]:
        if rep == "o":
            third = 1
        else:
            third = 0
    else:
        if rep == "o":
            third = 0
        else:
            third = 1
    return second,third

def check(animals):
    first,second = step(animals[-1],animals[0],s[0])
    if second == animals[1]:
        return True
    else:
        return False

primes = [[0,0],[0,1],[1,0],[1,1]]
for first,second in primes:
    animals = [first]
    for i in range(N-1):
        animals += [second]
        rep = s[i+1]
        first,second = step(first,second,rep)
    if check(animals):
        ans = ["S" if i == 0 else "W" for i in animals]
        ans = "".join(ans)
        print(ans)
        exit()

print(-1)

Submission status: Wrong Answer

Solution code:
inputa = int(input())
inputb = input()
flag = 0
res = ""

for c in inputb:
  if c == "o":
    if flag % 2 == 0:
      res += "S"
    else:
      res += "W"
  else:
    res += "S"
    flag += 1

if inputb[0] == "o":
  if flag % 2 != 0:
    print(-1)
  else:
    print(res)
elif inputb[0] == "x":
  if flag % 2 != 1:
    print(-1)
  else:
    print(res)
else:
  print(res)

Submission status: Wrong Answer

Solution code:
N=int(input())
s=input()
ans = ["X"]*N
end = False
for c0 in "SW":
    ans[0] = c0
    for cN in "SW":
        ans[-1] = cN
        for i,c in enumerate(s[:-2]):
            if (ans[i]=="S")^(c=="x"):
                ans[i+1] = ans[i-1]
            else:
                ans[i+1] = {"S":"W","W":"S"}[ans[i-1]]
        if ((ans[-1]=="S")^(s[-1]=="x")):
            end = ans[0]==ans[-2]
        else:
            end = ans[0]!=ans[-2]
        if end:break
    if end:break
if end:print("".join(ans))
else:print(-1)

Submission status: Wrong Answer

Solution code:
N=int(input())
s=input()
ans = ["X"]*N
end = False
for c0 in "SW":
    ans[0] = c0
    for cN in "SW":
        ans[-1] = cN
        for i,c in enumerate(s[:-1]):
            if (ans[i]=="S")^(c=="x"):
                ans[i+1] = ans[i-1]
            else:
                ans[i+1] = {"S":"W","W":"S"}[ans[i-1]]
        end = ((ans[-1]=="S")^(s[-1]=="x"))^(ans[0]!=ans[-2])
        if end:break
    if end:break
if end:print("".join(ans))
else:print(-1)

Submission status: Wrong Answer

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

ans = ['SS', 'SW', 'WS', 'WW']
s += s[0]
for i in range(4):
    for j in range(1, N+1):
        if ans[i][j] == 'S':
            if s[j] == 'o':
                ans[i] += ans[i][j-1]
            else:
                if ans[i][j-1] == 'S':
                    ans[i] += 'W'
                else:
                    ans[i] += 'S'
        else:
            if s[j] == 'x':
                ans[i] += ans[i][j-1]
            else:
                if ans[i][j-1] == 'S':
                    ans[i] += 'W'
                else:
                    ans[i] += 'S'

    if ans[i][0:2] == ans[i][-3:-1]:
        print(ans[i][:-2])
        exit()

print(-1)

Submission status: Wrong Answer

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

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

for i in range(4):
    for j in range(1, N):
        if ans[i][j] == 'S':
            if s[j] == 'o':
                ans[i] += ans[i][j-1]
            else:
                if ans[i][j-1] == 'S':
                    ans[i] += 'W'
                else:
                    ans[i] += 'S'
        else:
            if s[j] == 'x':
                ans[i] += ans[i][j-1]
            else:
                if ans[i][j-1] == 'S':
                    ans[i] += 'W'
                else:
                    ans[i] += 'S'

    if ans[i][0] == ans[i][-1]:
        print(ans[i][:-1])
        exit()
print(-1)

Submission status: Wrong Answer

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

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

for i in range(4):
    for j in range(1, N):
        if ans[i][j] == 'S':
            if s[j] == 'o':
                ans[i] += ans[i][j-1]
            else:
                if ans[i][j-1] == 'S':
                    ans[i] += 'W'
                else:
                    ans[i] += 'S'
        else:
            if s[j] == 'x':
                ans[i] += ans[i][j-1]
            else:
                if ans[i][j-1] == 'S':
                    ans[i] += 'W'
                else:
                    ans[i] += 'S'

    if ans[i][0] == ans[i][-1]:
        print(ans[i][:-1])
        exit()
print(-1)

Submission status: Wrong Answer

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

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

for i in range(4):
    for j in range(1, N):
        if ans[i][-1] == 'S':
            if s[j] == 'o':
                ans[i] += ans[i][-2]
            else:
                if ans[i][-2] == 'S':
                    ans[i] += 'W'
                else:
                    ans[i] += 'S'
        else:
            if s[j] == 'x':
                ans[i] += ans[i][-2]
            else:
                if ans[i][-2] == 'S':
                    ans[i] += 'W'
                else:
                    ans[i] += 'S'

    if ans[i][0] == ans[i][-1]:
        print(ans[i][:-1])
        exit()
print(-1)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(map(int, input().replace('o', '0').replace('x', '1')))

for p in [[0, 0], [0, 1], [1, 0], [1, 1]]:
    for s in S[1:]:
        if p[-1] ^ p[-2] ^ s == 1:
            p.append(1)
        else:
            p.append(0)
    
    if (p[0] == p[-1]) and (p[-2] ^ p[-3] ^ p[0] ^ S[-1] == 0):
        print(''.join(map(str, p[:-1])).replace('0', 'S').replace('1', 'W'))
        break
else:
    print(-1)

Submission status: Wrong Answer

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


for p in [[0, 0], [0, 1], [1, 0], [1, 1]]:
    for s in S[1:]:
        if p[-1] == 0 and s == 'o':
            p.append(p[-2])

        elif p[-1] == 0 and s == 'x':
            p.append(abs(p[-2] - 1))

        elif p[-1] == 1 and s == 'o':
            p.append(abs(p[-2] - 1))

        elif p[-1] == 1 and s == 'x':
            p.append(p[-2])

    if p[0] == p[-1]:
        print(''.join(map(str, p[:-1])).replace('0', 'S').replace('1', 'W'))
        break
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
if N == 3:
    if S == "ooo":
        print("SSS")
    elif S == "xxx":
        print("SSW")
    else:
        print(-1)
    exit()
def solve(first, second):
    R = [None] * N
    R[0] = first
    if (S[0] == "o" and R[0] == "S") or (S[0] == "x" and R[0] == "W"):
        R[1] = R[-1] = second
    else:
        R[1] = second
        R[-1] = "S" if second != "S" else "W"
    for i, s in enumerate(S):
        if i == 0:
            continue
        if (s == "o" and R[i] == "S") or (s == "x" and R[i] == "W"):
            new = R[i - 1]
        else:
            new = "W" if R[i - 1] != "W" else "S"
        if i == N - 2:
            if new == R[i + 1]:
                return True, R
            else:
                return False, None
        R[i + 1] = new
for f, s in [("S", "S"), ("S", "W"), ("W", "S"), ("W", "W")]:
    ok, result = solve(f, s)
    if ok:
        print("".join(result))
        break
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
import sys

def make_pos(pos, S):
    """Sheep: 0, Wolf: 1"""
    N = len(S)
    for i in range(1, N-1):
        if pos[i] == 0:
            if S[i] == 'o':
                pos[i+1] = pos[i-1]
            else:
                pos[i+1] = (pos[i-1] + 1) % 2

        else:
            if S[i] == 'o':
                pos[i+1] = (pos[i-1] + 1) % 2
            else:
                pos[i+1] = pos[i-1]

    if pos[N-1] == 0:
        if S[N-1] == 'o':
            if pos[0] == pos[N-2]:
                return pos
            else:
                return False
        else:
            if pos[0] != pos[N-2]:
                return pos
            else:
                return False
    else:
        if S[N-1] == 'o':
            if pos[0] != pos[N-2]:
                return pos
            else:
                return False
        else:
            if pos[0] == pos[N-2]:
                return pos
            else:
                return False


def main():
    input = sys.stdin.readline
    N = int(input())
    S = str(input().strip())

    # Case 1: SSxxx
    pos = [-1 for _ in range(N)]
    pos[0] = 0
    pos[1] = 0
    pos = make_pos(pos, S)
    if pos:
        ans = ['S' if n == 0 else 'W' for n in pos]
        return ''.join(ans)

    # Case 2: SWxxx
    pos = [-1 for _ in range(N)]
    pos[0] = 0
    pos[1] = 1
    pos = make_pos(pos, S)
    if pos:
        ans = ['S' if n == 0 else 'W' for n in pos]
        return ''.join(ans)

    # Case 3: WSxxx
    pos = [-1 for _ in range(N)]
    pos[0] = 1
    pos[1] = 0
    pos = make_pos(pos, S)
    if pos:
        ans = ['S' if n == 0 else 'W' for n in pos]
        return ''.join(ans)

    # Case 4: WWxxx
    pos = [-1 for _ in range(N)]
    pos[0] = 1
    pos[1] = 1
    pos = make_pos(pos, S)
    if pos:
        ans = ['S' if n == 0 else 'W' for n in pos]
        return ''.join(ans)

    return -1


if __name__ == '__main__':
    print(main())

Submission status: Wrong Answer

Solution code:
import sys

def make_pos(pos, S):
    N = len(S)
    for i in range(1, N-1):
        if pos[i] == 'S':
            if S[i] == 'o':
                pos[i+1] = pos[i-1]
            else:
                if pos[i-1] == 'S':
                    pos[i+1] = 'W'
                else:
                    pos[i+1] = 'S'

        else:
            if S[i] == 'o':
                if pos[i-1] == 'S':
                    pos[i+1] = 'W'
                else:
                    pos[i+1] = 'S'
            else:
                pos[i+1] = pos[i-1]

    if pos[N-1] == 'S':
        if S[N-1] == 'o':
            if pos[0] == pos[N-2]:
                return pos
            else:
                return False
        else:
            if pos[0] != pos[N-2]:
                return pos
            else:
                return False
    else:
        if S[N-1] == 'o':
            if pos[0] != pos[N-2]:
                return pos
            else:
                return False
        else:
            if pos[0] == pos[N-2]:
                return pos
            else:
                return False


def main():
    input = sys.stdin.readline
    N = int(input())
    S = str(input().strip())

    if S[0] == 'o':
        # Case 1 pos 0 is Sheep and neighbors are Wolves.
        pos = [0 for _ in range(N)]
        pos[0] = 'S'
        pos[1] = 'W'
        pos[N-1] = 'W'

        pos = make_pos(pos, S)
        if pos:
            return ''.join(pos)

        # Case 2: pos0 is Sheep ans neighbors are Sheeps.
        pos = [0 for _ in range(N)]
        pos[0] = 'S'
        pos[1] = 'S'
        pos[N-1] = 'S'

        pos = make_pos(pos, S)
        if pos:
            return ''.join(pos)

        # Case 3: pos0 is wolf and neibors are Sheep-Wolf.
        pos = [0 for _ in range(N)]
        pos[0] = 'W'
        pos[1] = 'S'
        pos[N-1] = 'W'

        pos = make_pos(pos, S)
        if pos:
            return ''.join(pos)

        # Case 4: pos0 is wolf and neibors are Wolf-Sheep.
        pos = [0 for _ in range(N)]
        pos[0] = 'W'
        pos[1] = 'W'
        pos[N-1] = 'S'

        pos = make_pos(pos, S)
        if pos:
            return ''.join(pos)

    else:
        # Case 1 pos 0 is Sheep and neighbors are Sheep-Wolf.
        pos = [0 for _ in range(N)]
        pos[0] = 'S'
        pos[1] = 'S'
        pos[N-1] = 'W'

        pos = make_pos(pos, S)
        if pos:
            return ''.join(pos)

        # Case 2: pos0 is Sheep ans neighbors are Wolf-Sheep.
        pos = [0 for _ in range(N)]
        pos[0] = 'S'
        pos[1] = 'W'
        pos[N-1] = 'S'

        pos = make_pos(pos, S)
        if pos:
            return ''.join(pos)

        # Case 3: pos0 is wolf and neibors are Sheeps.
        pos = [0 for _ in range(N)]
        pos[0] = 'W'
        pos[1] = 'S'
        pos[N-1] = 'S'

        pos = make_pos(pos, S)
        if pos:
            return ''.join(pos)

        # Case 4: pos0 is wolf and neibors are Wolves.
        pos = [0 for _ in range(N)]
        pos[0] = 'W'
        pos[1] = 'W'
        pos[N-1] = 'W'

        pos = make_pos(pos, S)
        if pos:
            return ''.join(pos)

    return -1


if __name__ == '__main__':
    print(main())

Submission status: Wrong Answer

Solution code:
import sys

def make_pos(pos, S):
    N = len(S)
    for i in range(1, N-1):
        if pos[i] == 'S':
            if S[i] == 'o':
                pos[i+1] = pos[i-1]
            else:
                if pos[i-1] == 'S':
                    pos[i+1] = 'W'
                else:
                    pos[i+1] = 'S'

        else:
            if S[i] == 'o':
                if pos[i-1] == 'S':
                    pos[i+1] = 'W'
                else:
                    pos[i+1] = 'S'
            else:
                pos[i+1] = pos[i-1]

    if pos[0] == 'S':
        if S[0] == 'o':
            if pos[1] == pos[N-1]:
                return pos
            else:
                return False
        else:
            if pos[1] != pos[N-1]:
                return pos
            else:
                return False
    else:
        if S[0] == 'o':
            if pos[1] != pos[N-1]:
                return pos
            else:
                return False


def main():
    input = sys.stdin.readline
    N = int(input())
    S = str(input().strip())

    if S[0] == 'o':
        # Case 1 pos 0 is Sheep and neighbors are Wolves.
        pos = [0 for _ in range(N)]
        pos[0] = 'S'
        pos[1] = 'W'
        pos[N-1] = 'W'

        pos = make_pos(pos, S)
        if pos:
            return ''.join(pos)

        # Case 2: pos0 is Sheep ans neighbors are Sheeps.
        pos = [0 for _ in range(N)]
        pos[0] = 'S'
        pos[1] = 'S'
        pos[N-1] = 'S'

        pos = make_pos(pos, S)
        if pos:
            return ''.join(pos)

        # Case 3: pos0 is wolf and neibors are Sheep-Wolf.
        pos = [0 for _ in range(N)]
        pos[0] = 'W'
        pos[1] = 'S'
        pos[N-1] = 'W'

        pos = make_pos(pos, S)
        if pos:
            return ''.join(pos)

        # Case 4: pos0 is wolf and neibors are Wolf-Sheep.
        pos = [0 for _ in range(N)]
        pos[0] = 'W'
        pos[1] = 'W'
        pos[N-1] = 'S'

        pos = make_pos(pos, S)
        if pos:
            return ''.join(pos)

    else:
        # Case 1 pos 0 is Sheep and neighbors are Sheep-Wolf.
        pos = [0 for _ in range(N)]
        pos[0] = 'S'
        pos[1] = 'S'
        pos[N-1] = 'W'

        pos = make_pos(pos, S)
        if pos:
            return ''.join(pos)

        # Case 2: pos0 is Sheep ans neighbors are Wolf-Sheep.
        pos = [0 for _ in range(N)]
        pos[0] = 'S'
        pos[1] = 'W'
        pos[N-1] = 'S'

        pos = make_pos(pos, S)
        if pos:
            return ''.join(pos)

        # Case 3: pos0 is wolf and neibors are Sheeps.
        pos = [0 for _ in range(N)]
        pos[0] = 'W'
        pos[1] = 'S'
        pos[N-1] = 'S'

        pos = make_pos(pos, S)
        if pos:
            return ''.join(pos)

        # Case 4: pos0 is wolf and neibors are Wolves.
        pos = [0 for _ in range(N)]
        pos[0] = 'W'
        pos[1] = 'W'
        pos[N-1] = 'W'

        pos = make_pos(pos, S)
        if pos:
            return ''.join(pos)

    return -1


if __name__ == '__main__':
    print(main())

Submission status: Wrong Answer

Solution code:
n=int(input())
a=input()
s="SW"
for d in range(2):
    for c in range(2):
        k=s[d]+s[c]
        for i in range(2,n+1):
            if k[i-1]=="S":
                if a[i-1]=="o":
                    k+=k[i-2]
                else:
                    k+=("W" if k[i-2]=="S" else "S")
            else:
                if a[i-1]=="o":
                    k+=("W" if k[i-2]=="S" else "S")
                else:
                    k+=k[i-2]
        else:
            if k[0]==k[-1]:
                print(k[:-1])
                exit()
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
def menagerie(N: int, s: str) -> str:
    # Sheep: True, Wolf: False

    # 0 番目と 1 番目の道具ぶつの組み合わせだけ全探索。
    # その 2 頭が決まればあとは一意に決まる。
    is_sheeps = [[None] * N for _ in range(4)]

    is_sheeps[0][:2] = True, True
    is_sheeps[1][:2] = True, False
    is_sheeps[2][:2] = False, True
    is_sheeps[3][:2] = False, False

    for n in range(1, N):
        for is_sheep in is_sheeps:
            if (s[n] == 'o') == is_sheep[n]:
                is_sheep[(n + 1) % N] = is_sheep[n - 1]
            else:
                is_sheep[(n + 1) % N] = not is_sheep[n - 1]

    for i, is_sheep in enumerate(is_sheeps):
        # if ((s[-1] == 'o') == is_sheep[-1]) and is_sheep[0] == is_sheep[-2]:
        #     return ''.join('S' if b else 'W' for b in is_sheep)
        # if ((s[-1] == 'o') != is_sheep[-1]) and is_sheep[0] != is_sheep[-2]:
        #     return ''.join('S' if b else 'W' for b in is_sheep)
        if is_sheep[0] == (i // 2 == 0):
            return ''.join('S' if b else 'W' for b in is_sheep)

    return '-1'


if __name__ == "__main__":
    N = int(input())
    s = input()
    ans = menagerie(N, s)
    print(ans)

Submission status: Wrong Answer

Solution code:
def menagerie(N: int, s: str) -> str:
    # Sheep: True, Wolf: False

    # 0 番目と 1 番目の道具ぶつの組み合わせだけ全探索。
    # その 2 頭が決まればあとは一意に決まる。
    is_sheeps = [[None] * N for _ in range(4)]

    is_sheeps[0][:2] = True, True
    is_sheeps[1][:2] = True, False
    is_sheeps[2][:2] = False, True
    is_sheeps[3][:2] = False, False

    for n in range(1, N):
        for is_sheep in is_sheeps:
            if (s[n] == 'o') == is_sheep[n]:
                is_sheep[(n + 1) % N] = is_sheep[n - 1]
            else:
                is_sheep[(n + 1) % N] = not is_sheep[n - 1]

    for i, is_sheep in enumerate(is_sheeps):
        # if ((s[-1] == 'o') == is_sheep[-1]) and is_sheep[0] == is_sheep[-2]:
        #     return ''.join('S' if b else 'W' for b in is_sheep)
        # if ((s[-1] == 'o') != is_sheep[-1]) and is_sheep[0] != is_sheep[-2]:
        #     return ''.join('S' if b else 'W' for b in is_sheep)
        print(is_sheep)
        if is_sheep[0] == (i // 2 == 0):
            return ''.join('S' if b else 'W' for b in is_sheep)

    return '-1'


if __name__ == "__main__":
    N = int(input())
    s = input()
    ans = menagerie(N, s)
    print(ans)

Submission status: Wrong Answer

Solution code:
def menagerie(N: int, s: str) -> str:
    # Sheep: True, Wolf: False

    # 0 番目と 1 番目の道具ぶつの組み合わせだけ全探索。
    # その 2 頭が決まればあとは一意に決まる。
    is_sheeps = [[None] * N for _ in range(4)]

    is_sheeps[0][0], is_sheeps[0][1] = True, True
    is_sheeps[1][0], is_sheeps[1][1] = True, False
    is_sheeps[2][0], is_sheeps[2][1] = False, True
    is_sheeps[3][0], is_sheeps[3][1] = False, False

    for n in range(1, N - 1):
        for is_sheep in is_sheeps:
            if (s[n] == 'o') == is_sheep[n]:
                is_sheep[n + 1] = is_sheep[n - 1]
            else:
                is_sheep[n + 1] = not is_sheep[n - 1]

    for is_sheep in is_sheeps:
        if ((s[-1] == 'o') == is_sheep[-1]) and is_sheep[0] == is_sheep[-2]:
            return ''.join('S' if b else 'W' for b in is_sheep)
        if ((s[-1] == 'o') != is_sheep[-1]) and is_sheep[0] != is_sheep[-2]:
            return ''.join('S' if b else 'W' for b in is_sheep)

    return '-1'


if __name__ == "__main__":
    N = int(input())
    s = input()
    ans = menagerie(N, s)
    print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())
s.append(s[0])
f=0
l=['S','S']
for j in range(4):
  for i in range(1,n+1):
    if l[i]=='S':
      if l[i-1]=='S':
        if s[i]=='o':
          l.append('S')
        else:
          l.append('W')
      else:
        if s[i]=='o':
          l.append('W')
        else:
          l.append('S')
    else:
      if l[i-1]=='S':
        if s[i]=='o':
          l.append('W')
        else:
          l.append('S')
      else:
        if s[i]=='o':
          l.append('S')
        else:
          l.append('W')
  if l[n+1]==l[1]:
    f=1
    break
  else:
    if j==0:
      l=['S','W']
    elif j==1:
      l=['W','S']
    elif j==2:
      l=['W','W']
    else:
      break
if f==0:
  print(-1)
else:
  l.pop()
  l.pop()
  print(''.join(l))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
f=0
l=['S','S']
for j in range(4):
  for i in range(1,n):
    if l[i]=='S':
      if l[i-1]=='S':
        if s[i]=='o':
          l.append('S')
        else:
          l.append('W')
      else:
        if s[i]=='o':
          l.append('W')
        else:
          l.append('S')
    else:
      if l[i-1]=='S':
        if s[i]=='o':
          l.append('W')
        else:
          l.append('S')
      else:
        if s[i]=='o':
          l.append('S')
        else:
          l.append('W')
  if l[n]==l[0]:
    f=1
    break
  else:
    if j==0:
      l=['S','W']
    elif j==1:
      l=['W','S']
    elif j==2:
      l=['W','W']
    else:
      break
if f==0:
  print(-1)
else:
  l.pop()
  print(''.join(l))

Submission status: Wrong Answer

Solution code:
def check(S, offset):
    S = S[:]
    N = len(S)
    ret = ['S'] * N
    for i in range(N):
        if S[(offset+i) % N] == False:
            ret[(offset+i+1) % N] = 'W'
            for j in range(i, i+3):
                S[(offset+j) % N] = not S[(offset+j) % N]
    if S == [True]*N:
        return ret
    else:
        return False


def main():
    N = int(input())
    S = [c == 'o' for c in input()]
    offset = S.index(False)
    c1 = check(S, offset)
    c2 = check(S, offset+1)
    if c1:
        print("".join(c1))
    elif c2:
        print("".join(c2))
    else:
        print(-1)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

def main():
	n = int(input())
	tmp = input()
	ans = list(tmp)
	
	ans_Q = []
	case = [["x" for _ in range(n)] for _ in range(4)]
	case[0][0] = "S"
	case[0][1] = "S"
	case[1][0] = "W"
	case[1][1] = "W"
	case[2][0] = "S"
	case[2][1] = "W"
	case[3][0] = "W"
	case[3][1] = "S"
	
	for case_o in case:
		for i in range(1, n-1):
			if case_o[i] == "S" and ans[i] == "o":
				case_o[i+1] = case_o[i-1]
				continue
			if case_o[i] == "S" and ans[i] == "x":
				case_o[i+1] = run(case_o[i-1])
				continue
			if case_o[i] == "W" and ans[i] == "o":
				case_o[i+1] = run(case_o[i-1])
				continue
			if case_o[i] == "W" and ans[i] == "x":
				case_o[i+1] = case_o[i-1]
				continue
		if case_o[n-1] == "S" and ans[n-1] == "o":
			if case_o[0] == case_o[n-2]:
				ans_Q = case_o
				break
		if case_o[n-1] == "S" and ans[n-1] == "x":
			if case_o[0] != case_o[n-2]:
				ans_Q = case_o
				break
		if case_o[n-1] == "W" and ans[n-1] == "o":
			if case_o[0] != case_o[n-2]:
				ans_Q = case_o
				break
		if case_o[n-1] == "W" and ans[n-1] == "x":
			if case_o[0] == case_o[n-2]:
				ans_Q = case_o
				break
	
	if len(ans_Q) == 0:
		print(-1)
	else:
		word = ""
		for w in ans_Q:
			word = word + w
		print(word)
	
def run(cher):
	if cher == "W":
		return "S"
	else:
		return "W"

if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A

#B

#C
"""
n,m = LI()
if m <= 2*n:print(m//2)
else:
    ans = n
    m -= 2*n
    ans += m//4
    print(ans)
"""

#D
def f(a,b,c):
    k = a^b
    if c == "x":
        k = 1-k
    return k
n = I()
s = S()
s.append(s[0])
na = ["S","W"]
pre = [0,0]
for i in range(1,n):
    pre.append(f(pre[-2],pre[-1],s[i]))
if pre[0] == pre[-1]:
    for i in range(n-1):
        print(na[pre[i]],end = "")
    print(na[pre[n]])
    quit()
pre = [0,1]
for i in range(1,n):
    pre.append(f(pre[-2],pre[-1],s[i]))
if pre[0] == pre[-1]:
    for i in range(n-1):
        print(na[pre[i]],end = "")
    print(na[pre[n]])
    quit()
pre = [1,0]
for i in range(1,n):
    pre.append(f(pre[-2],pre[-1],s[i]))
if pre[0] == pre[-1]:
    for i in range(n-1):
        print(na[pre[i]],end = "")
    print(na[pre[n]])
    quit()
pre = [1,1]
for i in range(1,n):
    pre.append(f(pre[-2],pre[-1],s[i]))
if pre[0] == pre[-1]:
    for i in range(n-1):
        print(na[pre[i]],end = "")
    print(na[pre[n]])
    quit()
print(-1)
#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A

#B

#C
"""
n,m = LI()
if m <= 2*n:print(m//2)
else:
    ans = n
    m -= 2*n
    ans += m//4
    print(ans)
"""

#D
def f(a,b,c):
    k = a^b
    if c == "x":
        k = 1-k
    return k
n = I()
s = S()
s.append(s[1])
s.append(s[-2])
na = ["S","W"]
pre = [0,0]
for i in range(1,n):
    pre.append(f(pre[-2],pre[-1],s[i]))
if pre[0] == pre[-1]:
    for i in range(n-1):
        print(na[pre[i]],end = "")
    print(na[pre[n]])
    quit()
pre = [0,1]
for i in range(1,n):
    pre.append(f(pre[-2],pre[-1],s[i]))
if pre[0] == pre[-1]:
    for i in range(n-1):
        print(na[pre[i]],end = "")
    print(na[pre[n]])
    quit()
pre = [1,0]
for i in range(1,n):
    pre.append(f(pre[-2],pre[-1],s[i]))
if pre[0] == pre[-1]:
    for i in range(n-1):
        print(na[pre[i]],end = "")
    print(na[pre[n]])
    quit()
pre = [1,1]
for i in range(1,n):
    pre.append(f(pre[-2],pre[-1],s[i]))
if pre[0] == pre[-1]:
    for i in range(n-1):
        print(na[pre[i]],end = "")
    print(na[pre[n]])
    quit()
print(-1)
#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T

Submission status: Wrong Answer

Solution code:
def solver(array):
    for index in range(1, n+1):
        if index == n:
            index = 0
        if array[index] == "S" and s[index]:
            if index == n - 1:
                if array[index-1] != array[0]:
                    return False
                else:
                    continue
            array[index + 1] = array[index - 1]
        elif array[index] == "S" and not s[index]:
            if index == n - 1:
                if array[index-1] == array[0]:
                    return False
                else:
                    continue
            if array[index - 1] == "W":
                array[index + 1] = "S"
            else:
                array[index + 1] = "W"
        elif array[index] == "W" and s[index]:
            if index == n - 1:
                if array[index-1] == array[0]:
                    return False
                else:
                    continue
            if array[index - 1] == "W":
                array[index + 1] = "S"
            else:
                array[index + 1] = "W"
        elif array[index] == "W" and not s[index]:
            if index == n - 1:
                if array[index-1] != array[0]:
                    return False
                else:
                    continue
            array[index + 1] = array[index - 1]
    return array


n = int(input())
s = [True if x == "o" else False for x in list(input())]
ws = ["W", "S"] + ["*" for x in range(n - 2)]
sw = ["S", "W"] + ["*" for x in range(n - 2)]
ss = ["S", "S"] + ["*" for x in range(n - 2)]
ww = ["W", "W"] + ["*" for x in range(n - 2)]

for array in [ws, sw, ss, ww]:
    res = solver(array)
    if not res:
        continue
    else:
        print("".join(res))
        exit()
else:
    print(-1)