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: Runtime Error

Solution code:
n=int(input())
s=str(input())
l=[0]*n
flag=1
if s[0]=='x':
  flag=0
def check(i,l):
  if i==0:
    l11=[0]*n
    l12=[0]*n
    l21=[0]*n
    l22=[0]*n
    if s[i]=='o':
      l11[0]='S'
      l11[1]=l11[n-1]='S'
      l12[0]='S'
      l12[1]=l12[n-1]='W'
      tmp1=check(i+1,l11)
      tmp2=check(i+1,l12)
      l21[0]=l21[n-1]='W'
      l21[1]='S'
      l22[0]=l22[1]='W'
      l22[n-1]='S'
      tmp3=check(i+1,l21)
      tmp4=check(i+1,l22)
      if tmp1==tmp2==tmp3==tmp4==-1:
        return -1
      else:
        if tmp1!=-1:
          return tmp1
        if tmp2!=-1:
          return tmp2
        if tmp3!=-1:
          return tmp3
        if tmp4!=-1:
          return tmp4
    else:
      for j in range(n):
        if s[j]=='x':
          s[j]='o'
        else:
          s[j]='x'
      return check(0,l)      # このときは出力が−１でなければ’W'と'S'を入れ替える
  elif 1<=i<=n-2:
    if s[i]=='o':
      if l[i]=='S':
        l[i+1]=l[i-1]
        return check(i+1,l)
      else:
        if l[i-1]=='W':
          l[i+1]='S'
          return check(i+1,l)
        else:
          l[i+1]='W'
          return check(i+1,l)
    else:
      if l[i]=='W':
        l[i+1]=l[i-1]
        return check(i+1,l)
      else:
        if l[i-1]=='S':
          l[i+1]='W'
          return check(i+1,l)
        else:
          l[i+1]='S'
          return check(i+1,l)
  else:
    if s[i]=='o':
      if l[i]=='S':
        if l[i-1]==l[0]:
          return l
        else:
          return -1
      else:
        if l[i-1]!=l[0]:
          return l
        else:
          return -1
    else:
      if l[i]=='S':
        if l[i-1]!=l[0]:
          return l
        else:
          return -1
      else:
        if l[i-1]==l[0]:
          if l[0]=='W' and l[i]==l[1]:
            return -1
          else:
            return l
        else:
          return -1      
ans=check(0,l)
if ans==-1:
  print(-1)
else:
  if flag:
    print(''.join(ans))
  else:
    for i in range(n):
      if ans[i]=='S':
        ans[i]='W'
      else:
        ans[i]='S'
    print(''.join(ans))

Submission status: Runtime Error

Solution code:
#始めの2匹が決まるとあとは自動的に決まるので矛盾していないかどうか判定

def main():
    import sys
    #input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations
    #from itertools import accumulate, product
    from bisect import bisect_left,bisect_right
    from math import floor, ceil
    #from operator import itemgetter

    #mod = 1000000007

    N = int(input())
    s = list(input())
    s += s[0]

    def check(p):
        for i in range(1, N):
            if s[i]=='o' and p[i]=='S':
                p += p[i-1]
            elif s[i]=='o' and p[i]=='W':
                if p[i-1]=='S':
                    p += 'W'
                else:
                    p += 'S'
            elif s[i]=='x' and p[i]=='S':
                if p[i-1]=='S':
                    p += 'W'
                else:
                    p += 'S'
            else:
                p += p[i-1]
        if p[0]==p[N] and p[1]==p[N+1]:
            print(p[:-2])
            exit()

    for i in ['SS', 'SW', 'WS', 'WW']:
        check(i)
    print(-1)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
n = int(input())
l = list(input())


check = [[1,1],[1,-1],[-1,1],[-1,-1]]
for j,k in check:
    ans = [0]*n
    ans[0] = j
    ans[1] = k
    
    for i in range(1,n):
        if ans[i] == 1:
            if l[i] == "o":
                ans[(i+1)%n] = ans[i-1]
            else:
                ans[(i+1)%n] = -ans[i-1]

        else:
            if l[i] == "o":
                ans[(i+1)%n] = -ans[i-1]
            else:
                ans[(i+1)%n] = ans[i-1]
        
    if j == ans[0]:  
        if l[0]=="o":
            if k == ans[-1]:
                for i in ans:
                    if i == 1:
                        print("S",end="")
                    else:
                        print("W",end="")
            exit()
        else:
            if k == -ans[-1]:
                for i in ans:
                    if i == 1:
                        print("S",end="")
                    else:
                        print("W",end="")

			exit()
        
        
        
            
print(-1)

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
def f(n):
    if n == 'S':
        return 'W'
    if n == 'W':
        return 'S'
A = ['S','S']
fa = 1
B = ['S','W']
fb = 1
C = [W,W]
fc = 1
D = [W,S]
fd = 1
s = fa + fb + fc + fd
for i in range(1,N-1):
    x = S[i]
    if x == 'o':
        if A[i] == 'S':
            A.append(A[i-1])
        else:
            A.append(f(A[i-1]))
        if B[i] == 'S':
            B.append(B[i-1])
        else:
            B.append(f(B[i-1]))
        if C[i] == 'S':
            C.append(C[i-1])
        else:
            C.append(f(C[i-1]))
        if D[i] == 'S':
            D.append(D[i-1])
        else:
            D.append(f(D[i-1]))
    else:
        if A[i] == 'S':
            A.append(f(A[i-1]))
        else:
            A.append(A[i-1])
        if B[i] == 'S':
            B.append(f(B[i-1]))
        else:
            B.append(B[i-1])
        if C[i] == 'S':
            C.append(f(C[i-1]))
        else:
            C.append(C[i-1])
        if D[i] == 'S':
            D.append(f(D[i-1]))
        else:
            D.append(D[i-1])
if S[0] == 'o':
    if A[0] == 'S':
        if A[1] != A[-1]:
            fa = 0
    else:
        if A[1] == A[-1]:
            fa = 0
else:
    if A[0] == 'S':
        if A[1] == A[-1]:
            fa = 0
    else:
        if A[1] != A[-1]:
            fa = 0
if S[-1] == 'o':
    if A[-1] == 'S':
        if A[-2] != A[0]:
            fa = 0
    else:
        if A[-2] == A[0]:
            fa = 0
else:
    if A[-1] == 'S':
        if A[-2] == A[0]:
            fa = 0
    else:
        if A[-2] != A[0]:
            fa = 0
if fa == 1:
    x = A[0]
    for i in range(1,N):
        x += A[i]
    print(x)
    quit()
if S[0] == 'o':
    if A[0] == 'S':
        if A[1] != A[-1]:
            fa = 0
    else:
        if A[1] == A[-1]:
            fa = 0
else:
    if B[0] == 'S':
        if B[1] == B[-1]:
            fb = 0
    else:
        if B[1] != B[-1]:
            fb = 0
if S[-1] == 'o':
    if B[-1] == 'S':
        if B[-2] != B[0]:
            fb = 0
    else:
        if B[-2] == B[0]:
            fb = 0
else:
    if B[-1] == 'S':
        if B[-2] == B[0]:
            fb = 0
    else:
        if B[-2] != B[0]:
            fb = 0
if fb == 1:
    x = B[0]
    for i in range(1,N):
        x += B[i]
    print(x)
    quit()
if S[0] == 'o':
    if C[0] == 'S':
        if C[1] != C[-1]:
            fc = 0
    else:
        if C[1] == C[-1]:
            fc = 0
else:
    if C[0] == 'S':
        if C[1] == C[-1]:
            fc = 0
    else:
        if C[1] != C[-1]:
            fc = 0
if S[-1] == 'o':
    if C[-1] == 'S':
        if C[-2] != C[0]:
            fa = 0
    else:
        if A[-2] == A[0]:
            fc = 0
else:
    if C[-1] == 'S':
        if C[-2] == C[0]:
            fc = 0
    else:
        if C[-2] != C[0]:
            fc = 0
if fc == 1:
    x = C[0]
    for i in range(1,N):
        x += C[i]
    print(x)
    quit()
if S[0] == 'o':
    if D[0] == 'S':
        if D[1] != D[-1]:
            fd = 0
    else:
        if D[1] == D[-1]:
            fd = 0
else:
    if D[0] == 'S':
        if D[1] == D[-1]:
            fd = 0
    else:
        if D[1] != D[-1]:
            fd = 0
if S[-1] == 'o':
    if D[-1] == 'S':
        if D[-2] != D[0]:
            fd = 0
    else:
        if D[-2] == D[0]:
            fd = 0
else:
    if D[-1] == 'S':
        if D[-2] == D[0]:
            fd = 0
    else:
        if D[-2] != D[0]:
            fd = 0
if fd == 1:
    x = D[0]
    for i in range(1,N):
        x += D[i]
    print(x)
    quit()
if s == 0:
    print(-1)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
n=int(input())
s=input()
def solve():
    for i in range(1,n):
        if (ans[i]=="S" and s[i]=="o") or (ans[i]=="W" and s[i]=="x"):
            ans[i+1]=ans[i-1]
        else:
            if ans[i-1]=="S":
                ans[i+1]="W"
            else:
                ans[i+1]="S"

        if (ans[0]=="S" and s[0]=="o") or (ans[0]=="W" and s[0]=="x"):
            sl=ans[1]
        else:
            if a[1]=="S":
                sl="W"
            else:
                sl="S"
    if ans[0]==ans[-1] and sl==ans[n-1]:
        return True
    else:
        return False

ans=[0]*(n+1)

for i in ["S","W"]:
    for j in ["S","W"]:
        ans[0]=i
        ans[1]=j
        if solve():
            print("".join(ans[:-1]))
            exit()
print(-1)

Submission status: Runtime Error

Solution code:
n=int(input())
s=input()
x=["SS","SW","WS","WW"]

def check(i,j):
    if j==0:
        l=0
    else:
        l=1
    if x[i][l]=="S":
        if s[l]=="o":
            if x[i][l-1]=="S":
                return x[i][l+1]=="S"
            else:
                return x[i][l+1]=="W"
        else:
            if x[i][-1]=="S":
                return x[i][l+1]=="W"
            else:
                return x[i][l+1]=="S"
    else:
        if s[l]=="o":
            if x[i][-l1]=="S":
                return x[i][l+1]=="W"
            else:
                return x[i][l+1]=="S"
        else:
            if x[i][-1]=="S":
                return x[i][l+1]=="S"
            else:
                return x[i][l+1]=="W"

a=["S","W"]
for i in range(4):
    for j in range(n-2):
        if x[i][j+1]=="S":
            if s[j+1]=="o":
                x[i]+=a[x[i][j]!="S"]
            else:
                x[i]+=a[x[i][j]=="S"]
        else:
            if s[j+1]=="o":
                x[i]+=a[x[i][j]=="S"]
            else:
                x[i]+=a[x[i][j]!="S"]
    if check(i,0) and check(i,1):
        print(x[i])
        break
else:
    print(-1)

Submission status: Runtime Error

Solution code:
n=int(input())
s=input()
x=["SS","SW","WS","WW"]

def check(i,j):
    if j==0:
        l=0
    else:
        l=1
    if x[i][l]=="S":
        if s[l]=="o":
            if x[i][l-1]=="S":
                return x[i][l+1]=="S"
            else:
                return x[i][l+1]=="W"
        else:
            if x[i][-1]=="S":
                return x[i][l+1]=="W"
            else:
                return x[i][l+1]=="S"
    else:
        if s[l]=="o":
            if x[i][-l1]=="S":
                return x[i][l+1]=="W"
            else:
                return x[i][l+1]=="S"
        else:
            if x[i][-1]=="S":
                return x[i][l+1]=="S"
            else:
                return x[i][l+1]=="W"

a=["S","W"]
for i in range(4):
    for j in range(n-2):
        if x[i][j+1]=="S":
            if s[j+1]=="o":
                x[i]+=a[x[i][j]!="S"]
            else:
                x[i]+=a[x[i][j]=="S"]
        else:
            if s[j+1]=="o":
                x[i]+=a[x[i][j]=="S"]
            else:
                x[i]+=a[x[i][j]!="S"]
    if check(i,0) and check1(i,-1):
        print(x[i])
        break
else:
    print(-1)

Submission status: Runtime Error

Solution code:
#55d
from functools import lru_cache

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

#深さ優先探索
def dfs(ans_list):
    if len(ans_list) == N:
        if ((is_contradiction(ans_list[-2],ans_list[-1],ans_list[0],s[-1]) == 0)
            and (is_contradiction(ans_list[-1],ans_list[0],ans_list[1],s[0]) == 0)):
            return ans_list
        else:
            return []
    else:
        #末尾にSとWを追加し、矛盾していないかを調べる
        #矛盾していなければ深堀する
        if is_contradiction(ans_list[-2],ans_list[-1],"S",s[len(ans_list)-1]) == 0:
            ans_S = dfs(ans_list + ["S"])
        else:
            ans_S = []
        if is_contradiction(ans_list[-2],ans_list[-1],"W",s[len(ans_list)-1]) == 0:
            ans_W = dfs(ans_list + ["W"])
        else:
            ans_W = []
            
        if len(ans_S) >= len(ans_W):
            return ans_S
        else:
            return ans_W

#矛盾しているかを検査
@lru_cache(maxsize=1000)
def is_contradiction(a,b,c,o_or_x):
    #print(a,b,c,o_or_x,end="")
    if ((b == "S" and o_or_x == "o" and a == c)
        or (b == "S" and o_or_x == "x" and a != c)
        or (b == "W" and o_or_x == "o" and a != c)
        or (b == "W" and o_or_x == "x" and a == c)):
        #print(" OK")
        return 0
    else:
        #print(" NG")
        return 1
    
for first_two_list in [["S","S"],["S","W"],["W","S"],["W","W"]]:
    ans = dfs(first_two_list)
    if len(ans) == N:
        print(''.join(map(str,ans)))
        break
else:
    print(-1)

Submission status: Runtime Error

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


def print_animal():
    for k in animal_list:
        print(k, end='')
    exit()


def checker(animal):
    # print(animal_list)
    global position
    position += 1
    # print(s[position])
    if position != n-1:
        if s[position] == 'o' and animal == 'S' and animal_list[position-1] == 'S':
            animal_list.append('S')
            checker('S')
        elif s[position] == 'o' and animal == 'S' and animal_list[position-1] == 'W':
            animal_list.append('W')
            checker('W')
        elif s[position] == 'o' and animal == 'W' and animal_list[position-1] == 'S':
            animal_list.append('W')
            checker('W')
        elif s[position] == 'o' and animal == 'W' and animal_list[position-1] == 'W':
            animal_list.append('S')
            checker('S')
        elif s[position] == 'x' and animal == 'S' and animal_list[position-1] == 'S':
            animal_list.append('W')
            checker('W')
        elif s[position] == 'x' and animal == 'S' and animal_list[position-1] == 'W':
            animal_list.append('S')
            checker('S')
        elif s[position] == 'x' and animal == 'W' and animal_list[position-1] == 'S':
            animal_list.append('S')
            checker('S')
        elif s[position] == 'x' and animal == 'W' and animal_list[position-1] == 'W':
            animal_list.append('W')
            checker('W')
    else:
        if s[position] == 'o' and animal == 'S' and animal_list[0] == animal_list[position-1]:
            print_animal()
        elif s[position] == 'o' and animal == 'W' and animal_list[0] != animal_list[position-1]:
            print_animal()
        elif s[position] == 'x' and animal == 'S' and animal_list[0] != animal_list[position-1]:
            print_animal()
        elif s[position] == 'x' and animal == 'W' and animal_list[0] == animal_list[position-1]:
            print_animal()

for i in [['S', 'S'], ['S', 'W'], ['W', 'W'], ['W', 'S']]:
    animal_list = i
    position = 0
    checker(animal_list[1])

print(-1)

Submission status: Runtime Error

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

def print_animal():
    for k in animal_list:
        print(k, end='')
    exit()


def checker(animal):
    global position
    position += 1
    if position != n-1:
        if s[position] == 'o' and animal == 'S' and animal_list[position-1] == 'S':
            animal_list.append('S')
            checker('S')
        elif s[position] == 'o' and animal == 'S' and animal_list[position-1] == 'W':
            animal_list.append('W')
            checker('W')
        elif s[position] == 'o' and animal == 'W' and animal_list[position-1] == 'S':
            animal_list.append('W')
            checker('W')
        elif s[position] == 'o' and animal == 'W' and animal_list[position-1] == 'W':
            animal_list.append('S')
            checker('S')
        elif s[position] == 'x' and animal == 'S' and animal_list[position-1] == 'S':
            animal_list.append('W')
            checker('W')
        elif s[position] == 'x' and animal == 'S' and animal_list[position-1] == 'W':
            animal_list.append('S')
            checker('S')
        elif s[position] == 'x' and animal == 'W' and animal_list[position-1] == 'S':
            animal_list.append('W')
            checker('W')
        elif s[position] == 'x' and animal == 'W' and animal_list[position-1] == 'W':
            animal_list.append('W')
            checker('S')
    else:
        if s[position] == 'o' and animal == 'S' and animal_list[0] == animal_list[position-1]:
            print_animal()
        elif s[position] == 'o' and animal == 'W' and animal_list[0] != animal_list[position-1]:
            print_animal()
        elif s[position] == 'x' and animal == 'S' and animal_list[0] != animal_list[position-1]:
            print_animal()
        elif s[position] == 'x' and animal == 'W' and animal_list[0] == animal_list[position-1]:
            print_animal()

for i in [['S', 'S'], ['S', 'W'], ['W', 'W'], ['W', 'S']]:
    animal_list = i
    position = 0
    checker(animal_list[1])

print(-1)

Submission status: Runtime Error

Solution code:
import sys

readline = sys.stdin.buffer.readline


def main():
    N = int(input())
    s = readline()
    s = list(s.decode('UTF-8').rstrip("\n"))
    s.append(s[0])
    s.insert(0, s[-2])

    init = ((1, 1), (0, 1), (1, 0), (0, 0))
    # init = ((0, 0), (0, 1), (1, 0), (1, 1))
    for i in init:
        p = [0] * (N+2)
        p[0] = i[0]
        p[1] = i[1]
        for j in range(1, N+1):
            if s[j] == "o":
                if p[j] == 0:
                    p[j+1] = p[j-1] ^ p[j]
                else:
                    p[j+1] = p[j-1] ^ 1
            else:
                if p[j] == 0:
                    p[j+1] = p[j-1] ^ 1
                else:
                    p[j+1] = p[j-1] ^ p[j]

        if p[0] == p[-2] and p[1] == p[-1]:
            ss = list(map(lambda x: "W" if x == 1 else "S", p[1:N+1]))
            print(''.join(ss))
            sys.exit()
    else:
        print(-1)


main()

Submission status: Runtime Error

Solution code:
n = int(input())
s = input()
pattern = ["SS", "SW", "WS", "WW"]
dict_s = {"S":"W", "W":"S"}
not_clear = True
for p in pattern:
    ans = p
    for i in range(1, n - 1):
        if s[i] == "o":
            if ans[i] == "W":
                ans += dict_s[ans[i-1]]
            else:
                ans += ans[i-1]
        else:
            if ans[i] == "S":
                ans += dict_s[ans[i-1]]
            else:
                ans += ans[i-1]
    if s[n - 1] == "o":
        if ans[n - 1] == "S":
            if ans[0] == ans[n - 2]:
                print(ans)
                exit()
            else:
                continue
        else:
            if ans[0] != ans[n - 2]:
                print(ans)
                exit()
            else:
                continue
        else:
            continue
    if s[n - 1] == "x":
        if ans[n - 1] == "W":
            if ans[0] == ans[n - 2]:
                print(ans)
                exit()
            else:
                continue
        else:
            if ans[0] != ans[n - 2]:
                print(ans)
                exit()
            else:
                continue            
if not_clear:
    print(-1)

Submission status: Runtime Error

Solution code:
""" abc055_a """

import sys

H = pow(10, 9) + 7

def _main():
    n_s, n_c = map(int, sys.stdin.readline().split(' '))

    if 2 * n_s <= n_c:
        result = n_s + int((n_c - n_s * 2) / 4)
    else:
        result = int(n_c / 2)

    print(result)

if __name__ == '__main__':
    _main()

Submission status: Runtime Error

Solution code:
n = int(input())
s = input()
l = ['SS','WS','SW','WW']

for i in range(n):
  for j in range(len(l)):
    l[j] += 'SW'[::-1 if s[i]=='o' else 1][l[j][i]==l[j][i+1]]
for i in range(n):
  if l[i][1]==l[i][n+1] and l[i][0]==l[i][n]:
    print(l[i][1:n+1])
    exit()
print(-1)

Submission status: Runtime Error

Solution code:
    n = int(input())
    s = [1 if si == 'o' else 0 for si in list(input())]
    t0 = [[1, 1], [1, 0], [0, 1], [0, 0]]
    for ti in t0:
        flag = True
        for i in range(1, n - 1):
            if ti[i] * (1 - s[i]) or (1 - ti[i]) * s[i]:
                ti.append(1 - ti[i - 1])
            else:
                ti.append(ti[i - 1])
        for i in range(2):
            if ti[i - 1]:
                if (s[i - 1] and not ti[i - 2] == ti[i]) or (1 - s[i - 1] and ti[i - 2] == ti[i]):
                    flag = False
            else:
                if (s[i - 1] and ti[i - 2] == ti[i]) or (1 - s[i - 1] and not ti[i - 2] == ti[i]):
                    flag = False
        if flag:
            ans = ['S' if x else 'W' for x in ti]
            print(''.join(ans))
            exit()
    print(-1)

Submission status: Runtime Error

Solution code:
s = [1 if si == 'o' else 0 for si in list(input())]
t0 = [[1, 1], [1, 0], [0, 1], [0, 0]]
for ti in t0:
    flag = True
    for i in range(1, n - 1):
        if ti[i] * (1 - s[i]) or (1 - ti[i]) * s[i]:
            ti.append(1 - ti[i - 1])
        else:
            ti.append(ti[i - 1])
    for i in range(2):
        if ti[i - 1]:
            if (s[i - 1] and not ti[i - 2] == ti[i]) or (1 - s[i - 1] and ti[i - 2] == ti[i]):
                flag = False
        else:
            if (s[i - 1] and ti[i - 2] == ti[i]) or (1 - s[i - 1] and not ti[i - 2] == ti[i]):
                flag = False
    if flag:
        ans = ['S' if x else 'W' for x in ti]
        print(''.join(ans))
        exit()
print(-1)

Submission status: Runtime Error

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)
    return
if inputb[0] == "x":
  if flag % 2 != 1:
    print(-1)
    return
print(res)

Submission status: Runtime Error

Solution code:
from itertools import product

N = int(input())
S = [0 if i == 'o' else 1 for i in input()]

for i, j in product(range(2), repeat=2):
	pattern = [i, j] + [0] * (N - 2) 
	for k in range(2, N):
		pattern[k] = ( S[k-1] - (pattern[k - 1] + pattern[k - 2] )) % 2
	if S[-1] != (pattern[-2] + pattern[-1] + pattern[0]) % 2 : 
		continue
	if S[0] != (pattern[-1] + pattern[0] + pattern[1]) % 2 :
		continue 	
	answer = [ 'S' if pattern[k] == 0 else 'W' for k in range(N)]
	print(''.join(answer))
	return None
print(-1)

Submission status: Runtime Error

Solution code:
!/usr/bin/python3
from itertools import product
 
def solve():
	N = int(input())
	S = [0 if i == 'o' else 1 for i in input()]
 
	for i, j in product(range(2), repeat=2):
		pattern = [i, j] + [0] * (N - 2) 
		for k in range(2, N):
			pattern[k] = (pattern[k - 1] + pattern[k - 2] + S[k] ) % 2
		if S[-1] != (pattern[-2] + pattern[-1] + pattern[0]) % 2 : 
			continue
		if S[0] != (pattern[-1] + pattern[0] + pattern[1]) % 2 :
			continue 	
		answer = [ 'S' if pattern[k] == 0 else 'W' for k in range(N)]
		print(''.join(answer))
		return None
	print(-1)
 
if __name__ == '__main__':
	solve()

Submission status: Runtime Error

Solution code:
!/usr/bin/python3
from itertools import product

def solve():
	N = int(input())
	S = [0 if i == 'o' else 1 for i in input()]

	for i, j in product(range(2), repeat=2):
		pattern = [i, j] + [0] * (N - 2) 
		for k in range(2, N):
			pattern[k] = (pattern[k - 1] + pattern[k - 2] + S[k] ) % 2
		if S[-1] != (pattern[-2] + pattern[-1] + pattern[0]) % 2 : 
			continue
		if S[0] != (pattern[-1] + pattern[0] + pattern[1]) % 2 :
			continue 	
		answer = [ 'S' if pattern[k] == 0 else 'W' for k in range(N)]
		print(''.join(answer))
		return None;
	print(-1);

if __name__ == '__main__':
	solve()

Submission status: Runtime Error

Solution code:
def solve():
    N = int(input())
    S = [0 if i == 'o' else 1 for i in input()]
    
    for i, j in product(range(2), repeat=2):
        pat = [i, j] + [0]*(N - 2)
        for k in range(2, N):
            pat[k] = (S[k - 1] - (pat[k - 1] + pat[k - 2])) % 2

        if S[-1] != (pat[0] + pat[-1] + pat[-2]) % 2:
            continue
        if S[0] != (pat[1] + pat[0] + pat[-1]) % 2:
            continue

        ans = ['S' if pat[k] == 0 else 'W' for k in range(N)]
        print(''.join(ans))
        return None

    print(-1)

if __name__ == '__main__':
    solve()

Submission status: Runtime Error

Solution code:
n = int(input())
s = input()
animal = [0]*n #0が羊、1が狼
f = [False]
def dfs(v,animal):    
    if f[0]== True:
        return 
    if v == n-1:
        if s[v]=='o':
            if animal[v]==0:
                if ((animal[v-1]==0)and(animal[0]==0))or((animal[v-1]==1)and(animal[0]==1)):
                    # print("True!")
                    f[0]= True
                    return 
            else:
                if ((animal[v-1]==0)and(animal[0]==1))or((animal[v-1]==1)and(animal[0]==0)):
                    # print("True!")
                    f[0]= True
                    return 
        else:
            if animal[v]==0:
                if ((animal[v-1]==0)and(animal[0]==1))or((animal[v-1]==1)and(animal[0]==0)):
                    # print("True!")
                    f[0]= True
                    return 
                
            else:
                if ((animal[v-1]==0)and(animal[0]==0))or((animal[v-1]==1)and(animal[0]==1)):
                    # print("True!")
                    f[0]= True
                    return 
        if f[0]==False:
            # print("False!")
            return
        
        
    if s[v]=='o':
        if animal[v]==0:
            if animal[v-1]==0:
                animal[v+1]=0
                dfs(v+1,animal)
            else:
                animal[v+1]+=1
                dfs(v+1,animal)
            
        else:
            if animal[v-1]==0:
                animal[v+1]+=1
                dfs(v+1,animal)
            else:
                animal[v+1]=0
                dfs(v+1,animal)
            

    else:
        if animal[v]==0:
            if animal[v-1]==0:
                animal[v+1]+=1
                dfs(v+1,animal)
            else:
                animal[v+1]=0
                dfs(v+1,animal)
            
        else:
            if animal[v-1]==0:
                animal[v+1]=0
                dfs(v+1,animal)
            else:
                animal[v+1]+=1
                dfs(v+1,animal)
            

dfs(0,animal)
animal1 = animal
f1 = f[0]

animal = [0]*n #0が羊、1が狼
f = [False]

dfs(1,animal)
animal2 = animal
f2 = f[0]

if (f1==False) and (f2==False):
    print(-1)
if f1 == True:
    u = ''
    for i in range(0,n):
        if animal1[i]==0:
            u = u+'S'
        else:
            u = u + 'W'
    print(u)

if (f1 != True) and (f2 ==True):
    u = ''
    for i in range(0,n):
        if animal2[i]==0:
            u = u+'S'
        else:
            u = u + 'W'
    print(u)

Submission status: Runtime Error

Solution code:
n = int(input())
s = input()
animal = [0]*n #0が羊、1が狼
f = [False]
def dfs(v,animal):
    if v == 0:
        dfs(1,animal)
        animal[0]+=1
        dfs(1,animal)
        
        
    if f[0]== True:
        return 
    if v == n-1:
        if s[v]=='o':
            if animal[v]==0:
                if ((animal[v-1]==0)and(animal[0]==0))or((animal[v-1]==1)and(animal[0]==1)):
                    # print("True!")
                    f[0]= True
                    return 
            else:
                if ((animal[v-1]==0)and(animal[0]==1))or((animal[v-1]==1)and(animal[0]==0)):
                    # print("True!")
                    f[0]= True
                    return 
        else:
            if animal[v]==0:
                if ((animal[v-1]==0)and(animal[0]==1))or((animal[v-1]==1)and(animal[0]==0)):
                    # print("True!")
                    f[0]= True
                    return 
                
            else:
                if ((animal[v-1]==0)and(animal[0]==0))or((animal[v-1]==1)and(animal[0]==1)):
                    # print("True!")
                    f[0]= True
                    return 
        if f[0]==False:
            # print("False!")
            return
        
        
    if s[v]=='o':
        if animal[v]==0:
            if animal[v-1]==0:
                animal[v+1]=0
                dfs(v+1,animal)
            else:
                animal[v+1]+=1
                dfs(v+1,animal)
            
        else:
            if animal[v-1]==0:
                animal[v+1]+=1
                dfs(v+1,animal)
            else:
                animal[v+1]=0
                dfs(v+1,animal)
            

    else:
        if animal[v]==0:
            if animal[v-1]==0:
                animal[v+1]+=1
                dfs(v+1,animal)
            else:
                animal[v+1]=0
                dfs(v+1,animal)
            
        else:
            if animal[v-1]==0:
                animal[v+1]=0
                dfs(v+1,animal)
            else:
                animal[v+1]+=1
                dfs(v+1,animal)
            

dfs(0,animal)
if f[0]==False:
    print(-1)
if f[0]==True:
    u = ''
    for i in range(0,n):
        if animal[i]==0:
            u = u+'S'
        else:
            u = u + 'W'
    print(u)