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()
animals=["#"]*len(s)

def oppositeAnimal(animal):
  if animal=="S":
    return "W"
  else:
    return "S"

def getNextAnimal(animal,answer,pastanimal):
  if animal=="S":
    if answer=="o":
      return pastanimal
    else:
      return oppositeAnimal(pastanimal)
  else:
    if answer=="o":
      return oppositeAnimal(pastanimal)
    else:
      return pastanimal

# [0]を羊とする
animals[0]="S"

if s[0]=="o":
  animals[len(s)-1]="S"
  animals[1]="S"
else:
  animals[len(s)-1]="S"
  animals[1]="W"

for i in range(2,len(s)-1):
  animals[i]=getNextAnimal(animals[i-1],s[i-1],animals[i-2])

if getNextAnimal(animals[len(s)-2],s[len(s)-2],animals[len(s)-3])==animals[len(s)-1]:
  if getNextAnimal(animals[len(s)-1],s[len(s)-1],animals[len(s)-2])==animals[0]:
    print("".join(animals))
    exit(0)

animals[0]="S"

if s[0]=="o":
  animals[len(s)-1]="W"
  animals[1]="W"
else:
  animals[len(s)-1]="S"
  animals[1]="W"

for i in range(2,len(s)-1):
  animals[i]=getNextAnimal(animals[i-1],s[i-1],animals[i-2])

if getNextAnimal(animals[len(s)-2],s[len(s)-2],animals[len(s)-3])==animals[len(s)-1]:
  if getNextAnimal(animals[len(s)-1],s[len(s)-1],animals[len(s)-2])==animals[0]:
    print("".join(animals))
    exit(0)

# [0]をオオカミとする
animals[0]="W"
if s[0]=="o":
  animals[len(s)-1]="S"
  animals[1]="W"
else:
  animals[len(s)-1]="S"
  animals[1]="S"
  
for i in range(2,len(s)-1):
  animals[i]=getNextAnimal(animals[i-1],s[i-1],animals[i-2])

if getNextAnimal(animals[len(s)-2],s[len(s)-2],animals[len(s)-3])==animals[len(s)-1]:
  if getNextAnimal(animals[len(s)-1],s[len(s)-1],animals[len(s)-2])==animals[0]:
    print("".join(animals))
    exit(0)

animals[0]="W"
if s[0]=="o":
  animals[len(s)-1]="S"
  animals[1]="W"
else:
  animals[len(s)-1]="W"
  animals[1]="W"
  
for i in range(2,len(s)-1):
  animals[i]=getNextAnimal(animals[i-1],s[i-1],animals[i-2])

if getNextAnimal(animals[len(s)-2],s[len(s)-2],animals[len(s)-3])==animals[len(s)-1]:
  if getNextAnimal(animals[len(s)-1],s[len(s)-1],animals[len(s)-2])==animals[0]:
    print("".join(animals))
    exit(0)

print(-1)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
animals=["#"]*len(s)

def oppositeAnimal(animal):
  if animal=="S":
    return "W"
  else:
    return "S"

def getNextAnimal(animal,answer,pastanimal):
  if animal=="S":
    if answer=="o":
      return pastanimal
    else:
      return oppositeAnimal(pastanimal)
  else:
    if answer=="o":
      return oppositeAnimal(pastanimal)
    else:
      return pastanimal

# [0]を羊とする
animals[0]="S"

if s[0]=="o":
  animals[len(s)-1]="S"
  animals[1]="S"
else:
  animals[len(s)-1]="S"
  animals[1]="W"

for i in range(2,len(s)-1):
  animals[i]=getNextAnimal(animals[i-1],s[i-1],animals[i-2])

if getNextAnimal(animals[len(s)-2],s[len(s)-2],animals[len(s)-3])==animals[len(s)-1]:
  if getNextAnimal(animals[len(s)-1],s[len(s)-1],animals[len(s)-2])==animals[0]:
    print("".join(animals))
    exit(0)

# [0]をオオカミとする
animals[0]="W"
if s[0]=="o":
  animals[len(s)-1]="S"
  animals[1]="W"
else:
  animals[len(s)-1]="S"
  animals[1]="S"
  
for i in range(2,len(s)-1):
  animals[i]=getNextAnimal(animals[i-1],s[i-1],animals[i-2])

if getNextAnimal(animals[len(s)-2],s[len(s)-2],animals[len(s)-3])==animals[len(s)-1]:
  if getNextAnimal(animals[len(s)-1],s[len(s)-1],animals[len(s)-2])==animals[0]:
    print("".join(animals))
    exit(0)

print(-1)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
s = input()
pats = [('S', 'W'), ('W', 'S'), ('S', 'S'), ('W', 'W')]

def predict(current_animal, prev_animal, judge):
    if current_animal == 'S':
        if judge == 'o':
            return prev_animal
        else:
            return 'S' if prev_animal == 'W' else 'W'

    else:
        if judge == 'o':
            return 'S' if prev_animal == 'W' else 'W'
        else:
            return prev_animal


for pat in pats:
    ans = ['' for _ in range(N)]
    ans[0], ans[1] = pat

    for i in range(1, N-1):
        ans[i+1] = predict(ans[i], ans[i-1], s[i])

    if ans[0] != predict(ans[N-1], ans[N-2], s[N-1]):
        continue

    print(''.join(ans))
    # print(predict(ans[N - 1], ans[N - 2], s[N - 1]))
    # print(ans[0])
    exit()

print(-1)

Submission status: Wrong Answer

Solution code:
N = int(input())
s = list(input())
ans = ["S"] * N
for i in range(1, N - 1):
    left = ans[i - 1]
    now = ans[i]
    TF = s[i]
    if now == "S":
        if TF == "o":
            if left == "W":
                ans[i + 1] = "W"
        elif TF == "x":
            if left == "S":
                ans[i + 1] = "W"
    else:
        if TF == "o":
            if left == "S":
                ans[i + 1] = "W"
        elif TF == "x":
            if left == "W":
                ans[i + 1] = "W"

left = ans[-2]
now = ans[-1]
TF = s[-1]
if now == "S":
    if TF == "o":
        if left == "W":
            ans[0] = "W"
    elif TF == "x":
        if left == "S":
            ans[0] = "W"
else:
    if TF == "o":
        if left == "S":
            ans[0] = "W"
    elif TF == "x":
        if left == "W":
            ans[0] = "W"

left = ans[-1]
now = ans[0]
TF = s[0]
if now == "S":
    if TF == "o":
        if left == "W":
            ans[1] = "W"
    elif TF == "x":
        if left == "S":
            ans[1] = "W"
else:
    if TF == "o":
        if left == "S":
            ans[1] = "W"
    elif TF == "x":
        if left == "W":
            ans[1] = "W"

if ans[1] == "S":
    print("".join(ans))
else:
    """
    うんち
    """
    ans = ["W"] * N
    for i in range(1, N - 1):
        left = ans[i - 1]
        now = ans[i]
        TF = s[i]
        if now == "S":
            if TF == "o":
                if left == "W":
                    ans[i + 1] = "S"
            elif TF == "x":
                if left == "W":
                    ans[i + 1] = "S"
        else:
            if TF == "o":
                if left == "W":
                    ans[i + 1] = "S"
            elif TF == "x":
                if left == "S":
                    ans[i + 1] = "S"

    left = ans[-2]
    now = ans[-1]
    TF = s[-1]
    if now == "S":
        if TF == "o":
            if left == "S":
                ans[0] = "S"
        elif TF == "x":
            if left == "W":
                ans[0] = "S"
    else:
        if TF == "o":
            if left == "W":
                ans[0] = "S"
        elif TF == "x":
            if left == "S":
                ans[0] = "S"
    left = ans[-1]
    now = ans[0]
    TF = s[0]
    if now == "S":
        if TF == "o":
            if left == "S":
                ans[1] = "S"
        elif TF == "x":
            if left == "W":
                ans[1] = "S"
    else:
        if TF == "o":
            if left == "W":
                ans[1] = "S"
        elif TF == "x":
            if left == "S":
                ans[1] = "S"
    if ans[1] == "W":
        print("".join(ans))
    else:
        print(-1)

Submission status: Wrong Answer

Solution code:
N = int(input())
s = list(input())
ans = ["S"] * N
for i in range(1, N - 1):
    left = ans[i - 1]
    now = ans[i]
    TF = s[i]
    if now == "S":
        if TF == "o":
            if left == "W":
                ans[i + 1] = "W"
        elif TF == "x":
            if left == "S":
                ans[i + 1] = "W"
    else:
        if TF == "o":
            if left == "S":
                ans[i + 1] = "W"
        elif TF == "x":
            if left == "W":
                ans[i + 1] = "W"

left = ans[-2]
now = ans[-1]
TF = s[-1]
if now == "S":
    if TF == "o":
        if left == "W":
            ans[0] = "W"
    elif TF == "x":
        if left == "S":
            ans[0] = "W"
else:
    if TF == "o":
        if left == "S":
            ans[0] = "W"
    elif TF == "x":
        if left == "W":
            ans[0] = "W"
if ans[0] == "S":
    print("".join(ans))
else:
    """
    うんち
    """
    ans = ["W"] * N
    for i in range(1, N - 1):
        left = ans[i - 1]
        now = ans[i]
        TF = s[i]
        if now == "S":
            if TF == "o":
                if left == "W":
                    ans[i + 1] = "S"
            elif TF == "x":
                if left == "W":
                    ans[i + 1] = "S"
        else:
            if TF == "o":
                if left == "W":
                    ans[i + 1] = "S"
            elif TF == "x":
                if left == "S":
                    ans[i + 1] = "S"

    left = ans[-2]
    now = ans[-1]
    TF = s[-1]
    if now == "S":
        if TF == "o":
            if left == "S":
                ans[0] = "S"
        elif TF == "x":
            if left == "W":
                ans[0] = "S"
    else:
        if TF == "o":
            if left == "W":
                ans[0] = "S"
        elif TF == "x":
            if left == "S":
                ans[0] = "S"
    if ans[0] == "W":
        print("".join(ans))
    else:
        print(-1)

Submission status: Wrong Answer

Solution code:
N = int(input())
s = list(input())
first_x = s.index("x")
ans = ["S"] * N
for i in range(first_x, N - 1):
    left = ans[i - 1]
    now = ans[i]
    TF = s[i]
    if now == "S":
        if TF == "o":
            if left == "W":
                ans[i + 1] = "W"
        elif TF == "x":
            if left == "S":
                ans[i + 1] = "W"
    else:
        if TF == "o":
            if left == "S":
                ans[i + 1] = "W"
        elif TF == "x":
            if left == "W":
                ans[i + 1] = "W"

left = ans[-2]
now = ans[-1]
TF = s[-1]
if now == "S":
    if TF == "o":
        if left == "W":
            ans[0] = "W"
    elif TF == "x":
        if left == "S":
            ans[0] = "W"
else:
    if TF == "o":
        if left == "S":
            ans[0] = "W"
    elif TF == "x":
        if left == "W":
            ans[0] = "W"

for i in range(1, first_x):
    left = ans[i - 1]
    now = ans[i]
    TF = s[i]
    if now == "S":
        if TF == "o":
            if left == "W":
                ans[i + 1] = "W"
        elif TF == "x":
            if left == "S":
                ans[i + 1] = "W"
    else:
        if TF == "o":
            if left == "S":
                ans[i + 1] = "W"
        elif TF == "x":
            if left == "W":
                ans[i + 1] = "W"
if ans[first_x] == "S":
    print("".join(ans))
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
N = int(input())
s = input().replace("xoox", "xAAx")
if "A" in s:
    for char in s:
        if char in {"o", "x"}:
            print("S", end="")
        else:
            print("W", end="")
    print()
else:
    print(-1)
# s = list(input())

# ans = ["S"] * N
# for i in range(1, N - 1):
#     left = ans[i - 1]
#     now = ans[i]
#     TF = s[i]
#     if now == "S":
#         if TF == "o":
#             if left == "W":
#                 ans[i + 1] = "W"
#         elif TF == "x":
#             if left == "S":
#                 ans[i + 1] = "W"
#     else:
#         if TF == "o":
#             if left == "S":
#                 ans[i + 1] = "W"
#         elif TF == "x":
#             if left == "W":
#                 ans[i + 1] = "W"
# 
# left = ans[-2]
# now = ans[-1]
# TF = s[-1]
# if now == "S":
#     if TF == "o":
#         if left == "W":
#             ans[0] = "W"
#     elif TF == "x":
#         if left == "S":
#             ans[0] = "W"
# else:
#     if TF == "o":
#         if left == "S":
#             ans[0] = "W"
#     elif TF == "x":
#         if left == "W":
#             ans[0] = "W"
# 
# 
# if ans[0] == "S":
#     print("".join(ans))
# else:
#     print(-1)

Submission status: Wrong Answer

Solution code:
from copy import deepcopy
N = int(input())
s = list(input())

ans = ["S"] * N
for i in range(1, N - 1):
    left = ans[i - 1]
    now = ans[i]
    TF = s[i]
    if now == "S":
        if TF == "o":
            if left == "W":
                ans[i + 1] = "W"
        elif TF == "x":
            if left == "S":
                ans[i + 1] = "W"
    else:
        if TF == "o":
            if left == "S":
                ans[i + 1] = "W"
        elif TF == "x":
            if left == "W":
                ans[i + 1] = "W"

left = now
now = ans[-1]
TF = s[-1]
if now == "S":
    if TF == "o":
        if left == "W":
            ans[0] = "W"
    elif TF == "x":
        if left == "S":
            ans[0] = "W"
else:
    if TF == "o":
        if left == "S":
            ans[0] = "W"
    elif TF == "x":
        if left == "W":
            ans[0] = "W"
first = deepcopy(ans)

for i in range(1, N - 1):
    left = ans[i - 1]
    now = ans[i]
    TF = s[i]
    if now == "S":
        if TF == "o":
            if left == "W":
                ans[i + 1] = "W"
        elif TF == "x":
            if left == "S":
                ans[i + 1] = "W"
    else:
        if TF == "o":
            if left == "S":
                ans[i + 1] = "W"
        elif TF == "x":
            if left == "W":
                ans[i + 1] = "W"

left = now
now = ans[-1]
TF = s[-1]
if now == "S":
    if TF == "o":
        if left == "W":
            ans[0] = "W"
    elif TF == "x":
        if left == "S":
            ans[0] = "W"
else:
    if TF == "o":
        if left == "S":
            ans[0] = "W"
    elif TF == "x":
        if left == "W":
            ans[0] = "W"

if ans == first:
    print("".join(ans))
else:
    print(-1)

Submission status: Wrong Answer

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

ans = ["S"] * N
for i in range(1, N - 1):
    left = ans[i - 1]
    now = ans[i]
    TF = s[i]
    if now == "S":
        if TF == "o":
            if left == "W":
                ans[i + 1] = "W"
        elif TF == "x":
            if left == "S":
                ans[i + 1] = "W"
    else:
        if TF == "o":
            if left == "S":
                ans[i + 1] = "W"
        elif TF == "x":
            if left == "W":
                ans[i + 1] = "W"

left = now
now = ans[-1]
TF = s[-1]
if now == "S":
    if TF == "o":
        if left == "W":
            ans[0] = "W"
    elif TF == "x":
        if left == "S":
            ans[0] = "W"
else:
    if TF == "o":
        if left == "S":
            ans[0] = "W"
    elif TF == "x":
        if left == "W":
            ans[0] = "W"
# print(ans)
if ans[0] == "S":
    print("".join(ans))
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
import copy

def sol(animals):
  for i, rep in enumerate(reps[:N-1]):
    if i == 0: continue
    if animals[i] == 1:animals[i+1] = rep*animals[i-1]
    else:animals[i+1] = -rep*animals[i-1]

  if animals[-1] == 1 and animals[0] != reps[-1]*animals[-2]: return False
  elif animals[-1] == -1 and animals[0] != -reps[-1]*animals[-2]: return False
  else: return animals

N = int(input())
reps = [1 if s=='o' else -1 for s in input()]
animals = [0 for _ in range(N)]

if reps[0] == 1:
  cases = [[1,1,1], [-1,1,-1],[1,-1,-1],[-1,-1,1]]
else:
  cases = [[-1,1,1],[1,1,-1],[1,-1,1],[-1,-1,-1]]
  
for case in cases:
  animals1 = copy.deepcopy(animals)
  animals1[-1],animals1[0],animals1[1] = case #1,1,1
  res = sol(animals1)
  if res is not False:
    print(''.join(['S' if s==1 else 'W' for s in res]))
    exit()
print(-1)

Submission status: Wrong Answer

Solution code:
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    s = [True if s == "o" else False for s in list(str(input().rstrip('\n')))]
    ls = [[0] * n for _ in range(4)]
    ls[0][0] = False
    ls[0][1] = False
    ls[1][0] = False
    ls[1][1] = True
    ls[2][0] = True
    ls[2][1] = False
    ls[3][0] = True
    ls[3][1] = True
    for i in range(1, n-1):
        ls[0][i+1] = (s[i] == ls[0][i]) == ls[0][i-1]
        ls[1][i+1] = (s[i] == ls[1][i]) == ls[1][i-1]
        ls[2][i+1] = (s[i] == ls[2][i]) == ls[2][i-1]
        ls[3][i+1] = (s[i] == ls[3][i]) == ls[3][i-1]
    for i in range(4):
        if s[-1] == ls[i][-1]:
            if ls[i][0] == ls[i][-2]:
                print("".join(["S" if ls[i][j] else "W" for j in range(n)]))
                exit()
        else:
            if ls[i][0] != ls[i][-2]:
                print("".join(["S" if ls[i][j] else "W" for j in range(n)]))
                exit()
    print(-1)


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

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

  arr = ['']*N
  for i in range(N):
    if s[i] == 'x':
      arr[i] = 'S'
  
  cur = 'S'
  ind = 0
  while ind < N:
    while ind < N and s[ind] != 'x':
      arr[ind] = cur
      ind += 1
    if cur == 'S':
      cur = 'W'
    else:
      cur = 'S'

    if ind >= N:
      break
    
    if s[ind] == 'x':
      ind += 1

    while ind < N and s[ind] == 'x':
      arr[ind] = cur
      if cur == 'S':
        cur = 'W'
      else:
        cur = 'S'
      ind += 1
    
    arr[ind-1] = 'S'
    if arr[ind-2] == 'S':
      cur = 'W'
    else:
      cur = 'S'
    if ind >= N:
      break

  if s[N-1] =='o':
    if arr[N-1] == 'S' and arr[N-2] == arr[0]:
      print(''.join(arr))
    elif arr[N-1] == 'W' and arr[N-2] != arr[0]:
      print(''.join(arr))
    else:
      print('-1')
  else:
    if arr[N-1] == 'W' and arr[N-2] == arr[0]:
      print(''.join(arr))
    elif arr[N-1] == 'S' and arr[N-2] != arr[0]:
      print(''.join(arr))
    else:
      print('-1')
main()

Submission status: Wrong Answer

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

  arr = ['']*N
  for i in range(N):
    if s[i] == 'x':
      arr[i] = 'S'
  
  cur = 'S'
  ind = 0
  while ind < N:
    while ind < N and s[ind] != 'x':
      arr[ind] = cur
      ind += 1
    if cur == 'S':
      cur = 'W'
    else:
      cur = 'S'

    if ind >= N:
      break
    
    if s[ind] == 'x':
      ind += 1

    subcur = 'W'
    while ind < N and s[ind] == 'x':
      arr[ind] = subcur
      if subcur == 'S':
        subcur = 'W'
      else:
        subcur = 'S'
      ind += 1
    
    arr[ind-1] = 'S'
    if ind >= N:
      break

  if s[N-1] =='o':
    if arr[N-1] == 'S' and arr[N-2] == arr[0]:
      print(''.join(arr))
    elif arr[N-1] == 'W' and arr[N-2] != arr[0]:
      print(''.join(arr))
    else:
      print('-1')
  else:
    if arr[N-1] == 'W' and arr[N-2] == arr[0]:
      print(''.join(arr))
    elif arr[N-1] == 'S' and arr[N-2] != arr[0]:
      print(''.join(arr))
    else:
      print('-1')
main()

Submission status: Wrong Answer

Solution code:
global opposite
opposite = {"S": "W",
            "W": "S"}

def generate(ans,s,N):
  global opposite
  for i in range(1,N-1):
    if ans[i] == "S" and s[i] == "o":
      ans += ans[i-1]
    elif ans[i] == "S" and s[i] == "x":
      ans += opposite[ans[i-1]]
    elif ans[i] == "W" and s[i] == "o":
      ans += opposite[ans[i-1]]
    elif ans[i] == "W" and s[i] == "x":
      ans += ans[i-1]
  
  if ans[-1] == "S":
    if (s[-1] == "o" and ans[-2] != ans[0]) or (s[-1] == "x" and ans[-2] == ans[0]):
      return True
  if ans[-1] == "W":
    if (s[-1] == "o" and ans[-2] == ans[0]) or (s[-1] == "x" and ans[-2] != ans[0]):
      return True
  print(ans)

N = int(input())
S = input()
if generate("SS",S,N):
  if generate("SW",S,N):
    if generate("WS",S,N):
      if generate("WW",S,N):
        print(-1)

Submission status: Wrong Answer

Solution code:
global opposite
opposite = {"S": "W",
            "W": "S"}

def generate(ans,s,N):
  global opposite
  for i in range(1,N-1):
    if ans[i] == "S" and s[i] == "o":
      ans += ans[i-1]
    elif ans[i] == "S" and s[i] == "x":
      ans += opposite[ans[i-1]]
    elif ans[i] == "W" and s[i] == "o":
      ans += opposite[ans[i-1]]
    else:
      ans += ans[i-1]
  
  if ans[-1] == "S":
    if (s[-1] == "o" and ans[-2] != ans[0]) or (s[-1] == "x" and ans[-2] == ans[0]):
      return True
  if ans[-1] == "W":
    if (s[-1] == "o" and ans[-2] == ans[0]) or (s[-1] == "x" and ans[-2] != ans[0]):
      return True
  print(ans)

N = int(input())
S = input()
if generate("SS",S,N):
  if generate("SW",S,N):
    if generate("WS",S,N):
      if generate("WW",S,N):
        print(-1)

Submission status: Wrong Answer

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

  arr = ['']*N
  for i in range(N):
    if s[i] == 'x':
      arr[i] = 'S'
  
  cur = 'S'
  ind = 0
  while ind < N:
    while ind < N and s[ind] != 'x':
      arr[ind] = cur
      ind += 1
    if cur == 'S':
      cur = 'W'
    else:
      cur = 'S'

    if ind >= N:
      break
    
    if arr[ind] == 'x':
      ind += 1

    subcur = 'W'
    while ind < N and s[ind] == 'x':
      arr[ind] = subcur
      if subcur == 'S':
        subcur = 'W'
      else:
        subcur = 'S'
      ind += 1
    
    arr[ind-1] = 'S'
    if ind >= N:
      break

  if s[N-1] =='o':
    if arr[N-1] == 'S' and arr[N-2] == arr[0]:
      print(''.join(arr))
    elif arr[N-1] == 'W' and arr[N-2] != arr[0]:
      print(''.join(arr))
    else:
      print('-1')
  else:
    if arr[N-1] == 'W' and arr[N-2] == arr[0]:
      print(''.join(arr))
    elif arr[N-1] == 'S' and arr[N-2] != arr[0]:
      print(''.join(arr))
    else:
      print('-1')
main()

Submission status: Wrong Answer

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

def loop():
    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'

ans = ['S'] + ['Unknown'] * (n-2) + ['S']
if s[0]  == 'x':
    ans[1] = 'W'
else:
    ans[1] = 'S'
loop()
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'):
        print(''.join(ans))
        exit()

ans = ['W'] + ['Unknown'] * (n-2) + ['S']
if s[0]  == 'x':
    ans[1] = 'S'
else:
    ans[1] = 'W'
loop()
if ans[n-1] == 'S':
    if (s[n-1] == 'x' and ans[n-2] == 'S') or (s[n-1] == 'o' and ans[n-2] == 'W'):
        print(''.join(ans))
        exit()

ans = ['W'] + ['Unknown'] * (n-2) + ['W']
if s[0]  == 'x':
    ans[1] = 'W'
else:
    ans[1] = 'S'
loop()
if ans[n-1] == 'W':
    if (s[n-1] == 'x' and ans[n-2] == 'W') or (s[n-1] == 'o' and ans[n-2] == 'S'):
        print(''.join(ans))
        exit()

# ans = ['S'] + ['Unknown'] * (n-2) + ['W']
# if s[0]  == 'x':
#     ans[1] = 'S'
# else:
#     ans[1] = 'W'
# loop()
# if ans[n-1] == 'W':
#     if (s[n-1] == 'x' and ans[n-2] == 'S') or (s[n-1] == 'o' and ans[n-2] == 'W'):
#         print(''.join(ans))
#         exit()

print(-1)

Submission status: Wrong Answer

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

def loop():
    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'

ok = False

ans = ['S'] + ['Unknown'] * (n-2) + ['S']
if s[0]  == 'x':
    ans[1] = 'W'
else:
    ans[1] = 'S'
loop()
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) + ['S']
        if s[0]  == 'x':
            ans[1] = 'S'
        else:
            ans[1] = 'W'
        loop()
        if ans[n-1] == 'S':
            if (s[n-1] == 'x' and ans[n-2] == 'S') or (s[n-1] == 'o' 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'
    loop()
    if ans[n-1] == 'W':
        if (s[n-1] == 'x' and ans[n-2] == 'W') or (s[n-1] == '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'
            loop()
            if ans[n-1] == 'W':
                if (s[n-1] == 'x' and ans[n-2] == 'S') or (s[n-1] == '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()

def loop():
    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'

ok = False

ans = ['S'] + ['Unknown'] * (n-2) + ['S']
if s[0]  == 'x':
    ans[1] = 'W'
else:
    ans[1] = 'S'
loop()
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) + ['S']
        if s[0]  == 'x':
            ans[1] = 'S'
        else:
            ans[1] = 'W'
        loop()
        if ans[n-1] == 'S':
            if (s[n-1] == 'x' and ans[n-2] == 'S') or (s[n-1] == 'o' 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'
    loop()
    if ans[n-1] == 'W':
        if (s[n-1] == 'x' and ans[n-2] == 'W') or (s[n-1] == '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'
        loop()
        if ans[n-1] == 'W':
            if (s[n-1] == 'x' and ans[n-2] == 'S') or (s[n-1] == '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()

def loop():
    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'

ok = False

ans = ['S'] + ['Unknown'] * (n-2) + ['S']
if s[0]  == 'x':
    ans[1] = 'W'
else:
    ans[1] = 'S'
loop()

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

    if ans[n-1] == 'W':
        if (s[n-1] == 'x' and ans[n-2] == 'W') or (s[n-1] == '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'
        loop()
        
        if ans[n-1] == 'W':
            if (s[n-1] == 'x' and ans[n-2] == 'S') or (s[n-1] == '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'
            loop()
            
            if ans[n-1] == 'S':
                if (s[n-1] == 'x' and ans[n-2] == 'S') or (s[n-1] == 'o' and ans[n-2] == 'W'):
                    ok = True

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