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:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    S=ST()
    S+=S[0]
    def is_ok():
        for i,s in enumerate(S[1:-1],start=1):
            if ans[i]==(s=="o"):
                ans[i+1]=ans[i-1]
            else:
                ans[i+1]=ans[i-1]^1
        return ans[0]==ans[-1]
    for bit in range(1<<2):
        ans=[0]*(N+1)
        for i in range(2):
            ans[i] = bit>>i&1
        if is_ok():
            ans="".join(map(str,ans[:-1]))
            print(ans.replace("1","S").replace("0","W"))
                
            return
    print(-1)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    S=ST()
    S+=S[0]
    def is_ok():
        for i,s in enumerate(S[1:-1],start=1):
            print(i,s)
            if ans[i]==(s=="o"):
                ans[i+1]=ans[i-1]
            else:
                ans[i+1]=ans[i-1]^1
        return ans[0]==ans[-1]
    for bit in range(1<<2):
        ans=[0]*(N+1)
        for i in range(2):
            ans[i] = bit>>i&1
        if is_ok():
            ans="".join(map(str,ans[:-1]))
            print(ans.replace("1","S").replace("0","W"))
                
            return
    print(-1)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    S=ST()
    S+=S[0]
    def is_ok():
        for i,s in enumerate(S[1:-1],start=1):
            print(i,s)
            if ans[i]==(s=="o"):
                ans[i+1]=ans[i-1]
            else:
                ans[i+1]=ans[i-1]^1
        return ans[0]==ans[-1]
    for bit in range(1<<2):
        ans=[0]*(N+1)
        for i in range(2):
            ans[i] = bit>>i&1
        if is_ok():
            ans="".join(map(str,ans))
            print(ans.replace("1","S").replace("0","W"))
                
            return
    print(-1)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

    def checker(S0, S1):
        rec = S0+S1
        for i in range(1, N-1):
            if S[i] == "o" and rec[i] == "S":
                rec = rec + rec[i-1]
            elif S[i] == "o" and rec[i] == "W":
                if rec[i-1] == "S":
                    rec = rec + "W"
                else:
                    rec = rec + "S"
            elif S[i] == "x" and rec[i] == "S":
                if rec[i-1] == "S":
                    rec = rec + "W"
                else:
                    rec = rec + "S"
            elif S[i] == "x" and rec[i] == "W":
                rec = rec + rec[i-1]

        if S[N-1] == "o" and rec[N-1] == "S":
            return (rec[N-2] == rec[0], rec)
        elif S[N-1] == "o" and rec[N-1] == "W":
            return (rec[N-2] != rec[0], rec)
        elif S[N-1] == "x" and rec[N-1] == "S":
            return (rec[N-2] != rec[0], rec)
        elif S[N-1] == "x" and rec[N-1] == "W":
            return (rec[N-2] == rec[0], rec)

    for S0, S1 in (("S", "S"), ("S", "W"), ("W", "S"), ("W", "W")):
        flag, rec = checker(S0, S1)
        if flag:
            print(rec)
            break
    else:
        print(-1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
from itertools import product

n = int(sys.stdin.readline().rstrip())
s = sys.stdin.readline().rstrip()
resp = s
resp = resp.replace('o', '1')
resp = resp.replace('x', '0')
resp = [None] + [int(x) for x in resp]

def restore(pattern):
    for i in range(1, n):
        if resp[i] ^ pattern[i]:
            pattern[i+1] = 1 if pattern[i-1] ^ 1 else 0
        else:
            pattern[i+1] = pattern[i-1]
    return pattern

def contradicting(pattern):
    if pattern[0] != pattern[-1]:
        return True
    return False

def main():
    res = [None] * (n + 1)
    for i in range(4):
        pattern = res.copy()
        pattern[0] = i >> 0 & 1
        pattern[1] = i >> 1 & 1
        ans = restore(pattern)
        if not contradicting(ans):
            t = ''
            for i in range(1, n+1):
                t += 'S' if ans[i] & 1 else 'W'
            return t
    return -1

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
for key in ['SS', 'SW', 'WS', 'WW']:
    animals = key
    for i in range(N):
        if i < 1:
            continue
        if animals[i] == 'S':
            if S[i] == 'o':
                animals += animals[-2]
            else:
                animals += 'S' if animals[-2] == 'W' else 'W'
        else:
            if S[i] == 'x':
                animals += animals[-2]
            else:
                animals += 'S' if animals[-2] == 'W' else 'W'
    if animals[0] == animals[-1]:
        print(animals[:-1])
        exit(0)
print(-1)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from itertools import product

def main():
    n = int(input())
    s = input()
    ans = "-1"

    ls = list(product("SW", repeat = 2))

    for tpl in ls:
        flag = False
        anss = str(tpl[0]) + str(tpl[0])
        for i in range(1,n+1):
            if anss[-1] == "S":
                if s[i-1] == "o":
                    anss += anss[-2]
                else:
                    if anss[-2] == "S":
                        anss += "W"
                    else:
                        anss += "S"
            else:
                if s[i-1] == "x":
                    anss += anss[-2]
                else:
                    if anss[-2] == "S":
                        anss += "W"
                    else:
                        anss += "S"
        if anss[:2] == anss[-2:]:
            ans = anss[1:-1]
            break
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from itertools import product

def main():
    n = int(input())
    s = input()
    ans = "-1"

    ls = list(product("SW", repeat = 2))

    for tpl in ls:
        flag = False
        anss = str(tpl[0]) + str(tpl[0])
        for i in range(1,n+1):
            if anss[-1] == "S":
                if s[i-1] == "o":
                    anss += anss[-2]
                else:
                    if anss[-2] == "S":
                        anss += "W"
                    else:
                        anss += "S"
            else:
                if s[i-1] == "x":
                    anss += anss[-2]
                else:
                    if anss[-2] == "S":
                        anss += "W"
                    else:
                        anss += "S"
        if anss[:2] == anss[-2:]:
            flag = True
            
        if flag:
            ans = anss[1:-1]
            break
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from itertools import product

def main():
    n = int(input())
    s = input()
    ans = "-1"

    ls = list(product("SW", repeat = 2))

    for tpl in ls:
        flag = False
        anss = str(tpl[0]) + str(tpl[0])
        for i in range(1,n):
            if anss[-1] == "S":
                if s[i-1] == "o":
                    anss += anss[-2]
                else:
                    if anss[-2] == "S":
                        anss += "W"
                    else:
                        anss += "S"
            else:
                if s[i-1] == "x":
                    anss += anss[-2]
                else:
                    if anss[-2] == "S":
                        anss += "W"
                    else:
                        anss += "S"
        if anss[0] == anss[-1]:
            if anss[-1] == "S":
                if s[-1] == "o":
                    if anss[-2] == anss[1]:
                        flag = True
                else:
                    if anss[-2] != anss[1]:
                        flag = True
            else:
                if s[-1] == "x":
                    if anss[-2] == anss[1]:
                        flag = True
                else:
                    if anss[-2] != anss[1]:
                        flag = True
        if flag:
            ans = anss[1:]
            break
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from itertools import product

def main():
    n = int(input())
    s = input()
    ans = -1

    ls = list(product("SW", repeat = 2))

    for tpl in ls:
        flag = False
        anss = str(tpl[0]) + str(tpl[0])
        for i in range(1,n):
            if anss[-1] == "S":
                if s[i-1] == "o":
                    anss += anss[-2]
                else:
                    if anss[-2] == "S":
                        anss += "W"
                    else:
                        anss += "S"
            else:
                if s[i-1] == "x":
                    anss += anss[-2]
                else:
                    if anss[-2] == "S":
                        anss += "W"
                    else:
                        anss += "S"
        if anss[0] == anss[-1]:
            if anss[-1] == "S":
                if s[-1] == "o":
                    if anss[-2] == anss[1]:
                        ans = anss[1:]
                        flag = True
                else:
                    if anss[-2] != anss[1]:
                        ans = anss[1:]
                        flag = True
            else:
                if s[-1] == "x":
                    if anss[-2] == anss[1]:
                        ans = anss[1:]
                        flag = True
                else:
                    if anss[-2] != anss[1]:
                        ans = anss[1:]
                        flag = True
        if flag:
            break
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

def output(lst):
    map_lst = map(str, lst[:-1])
    s = ''.join(map_lst)
    print (s.replace('0', 'S').replace('1', 'W'))
    return

# 0: 羊、1: 狼
for a in range(2):
    for b in range(2):
        lst = [-1] * (N + 1)
        lst[0] = a
        lst[1] = b
        for i in range(1, N):
            if S[i] == 'o':
                flag = True
            else:
                flag = False

            if flag == (lst[i] == 0):
                lst[i + 1] = lst[i - 1]
            else:
                lst[i + 1] = 1 - lst[i - 1]
        if lst[0] == lst[-1]:
            output(lst)
            exit()

        #     print ('OK')
        #     print (lst)
        # # else:
        #     print ('NG')

print (-1)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys

def convert(ss):
    if ss == 0:
        return "S"
    else:
        return "W"


def solve(N: int, s: str):
    animals = [0]*N
    ## 0 がひつじ 1が狼を表す
    init = [(0,1),(1,0),(0,0),(1,1)]

    for first,second in init:
        animals[0] = first
        animals[1] = second

        for j in range(1,N):
            ## 最後にたどり着いたとき
            if j == N-1:
                if animals[j] == 0:
                    if s[j] == "o":
                        if animals[j-1] == animals[0]:
                            print(''.join(list(map(convert,animals))))
                            return 
                    else:
                       if animals[j-1] != animals[0]:
                            print(''.join(list(map(convert,animals))))
                            return

                elif animals[j] == 1:
                    if s[j] == "o":
                        if animals[j-1] != animals[0]:
                            print(''.join(list(map(convert,animals))))
                            return
                    else:
                       if animals[j-1] == animals[0]:
                            print(''.join(list(map(convert,animals))))
                            return 
                break


            if animals[j] == 0:
                if s[j] == "o":
                    animals[j+1] = animals[j-1]
                else:
                    animals[j+1] = 1^animals[j-1]
            elif animals[j] == 1:
                if s[j] == "o":
                    animals[j+1] = 1^animals[j-1]
                else:
                    animals[j+1] = animals[j-1]    

    print(-1)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    s = next(tokens)  # type: str
    solve(N, s)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys

def convert(ss):
    if ss == 0:
        return "S"
    else:
        return "W"


def solve(N: int, s: str):
    animals = [0]*N
    ## 0 がひつじ 1が狼を表す
    init = [(0,1),(1,0),(0,0),(1,1)]

    for first,second in init:
        animals[0] = first
        animals[1] = second

        for j in range(1,N):
            ## 最後にたどり着いたとき
            if j == N-1:
                if animals[j] == 0:
                    if s[j] == "o":
                        if animals[j-1] == animals[0]:
                            print(''.join(list(map(convert,animals))))
                            return 
                    else:
                       if animals[j-1] != animals[0]:
                            print(''.join(list(map(convert,animals))))
                            return

                elif animals[j] == 1:
                    if s[j] == "o":
                        if animals[j-1] != animals[0]:
                            print(''.join(list(map(convert,animals))))
                            return
                    else:
                       if animals[j-1] == animals[0]:
                            print(''.join(list(map(convert,animals))))
                            return 
                break


            if animals[j] == 0:
                if s[j] == "o":
                    animals[j+1] = animals[j-1]
                else:
                    animals[j+1] = ~animals[j-1]
            elif animals[j] == 1:
                if s[j] == "o":
                    animals[j+1] = ~animals[j-1]
                else:
                    animals[j+1] = animals[j-1]    

    print(-1)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    s = next(tokens)  # type: str
    solve(N, s)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from itertools import product
n = int(input())
s = input()
s_dict = {"o":1, "x":-1}
flg = False
for combi in product([-1,1], repeat=2):
    state = list(combi)
    for i, _s in enumerate(s[1:], 1):
        cur = state[i]
        res = s_dict[_s] * cur * state[i-1]
        state.append(res)
    if state[0] == state[-1]:
        flg = True
        break
res = "".join(["S" if i == 1 else "W" for i in state])
if flg:
    print(res[:-1])
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
from itertools import product
n = int(input())
s = input()
s_dict = {"o":1, "x":-1}
flg = False
for combi in product([1,-1], repeat=2):
    state = list(combi)
    for i, _s in enumerate(s[1:], 1):
        cur = state[i]
        res = s_dict[_s] * cur * state[i-1]
        state.append(res)
    if state[0] == state[-1]:
        flg = True
        break
res = "".join(["S" if i == 1 else "W" for i in state])
if flg:
    print(res[:-1])
else:
    print(-1)

Submission status: Wrong Answer

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

l = [0] * n
l2 = [0 if s[i]=='o' else 1 for i in range(n)]
def f(x,y):
    l[0]=x
    l[1]=y
    for i in range(2,n):
        l[i]=l[i-2]^l[i-1]^l2[i-1]
    if l[0] == l[n-2]^l[n-1]^l2[n-1]:
        return True
    else: return False

if f(0,0):
    print(''.join(['S' if not l[i] else 'W' for i in range(n)]))
elif f(0,1):
    print(''.join(['S' if not l[i] else 'W' for i in range(n)]))
elif f(1,0):
    print(''.join(['S' if not l[i] else 'W' for i in range(n)]))
elif f(1,1):
    print(''.join(['S' if not l[i] else 'W' for i in range(n)]))
else:print(-1)

Submission status: Wrong Answer

Solution code:
import random
import sys

sys.setrecursionlimit(500000)

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:
        comp = s[position] + animal + animal_list[position-1]
        if comp == 'oSS' or comp == 'oWW' or comp == 'xSW' or comp == 'xWS':
            animal_list.append('S')
        else:
            animal_list.append('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
    for j in range(1, n):
        checker(animal_list[j])

print(-1)

Submission status: Wrong Answer

Solution code:
import random
import sys



n = int(input())
sys.setrecursionlimit(200000)
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('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: Wrong Answer

Solution code:
N=int(input())
S=input()
L='SS'

for i in range(1,N-1):
    if S[i]+L[i-1]+L[i] in ['oSS','oWW','xSW','xWS']:
        L+='S'
    else:
        L+='W'

T=['oSSS','oWSW','oSWW','oWWS','xWSS','xSSW','xSWS','xWWW']
if S[0]+L[-1]+L[0]+L[1] in T and S[-1]+L[-2]+L[-1]+L[0] in T:
    print(L)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
n=int(input())
sw=[0 for i in range(n)]
ox=list(input())

def who(x):
    if sw[x-1]=="S":
        a=1
    else:
        a=-1
        
    if sw[x]=="S":
        b=1
    else:
        b=-1
    
    if ox[x]=="o":
        c=1
    else:
        c=-1
    
    if a*b*c==1:
        return "S"
    else:
        return "W"
   
        
start=[["S","S"],["S","W"],["W","S"],["W","W"]]
ans=-1

for i in range(4):
    sw[0],sw[-1]=start[i]
    tmp=sw[0]

    for j in range(n):
        sw[(j+1)%n]=who(j)

    if tmp==sw[0]:
        ans="".join(sw)
    
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    S=list(map(lambda x:(x=='o')-0,input()))
    ans=[None]*n
    ans[0]=1; ans[1]=1

    for i in range(2,n):
        if(S[i-1]==ans[i-1]): ans[i]=ans[i-2]
        else: ans[i]=1-ans[i-2]

    if((S[0]==ans[0])^(ans[1]==ans[-1])):
        print(-1)
        return
    if((S[-1]==ans[-1])^(ans[0]==ans[-2])):
        print(-1)
        return

    for s in ans: print('S' if(s) else 'W',end='')
    print()
resolve()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    S=list(map(lambda x:(x=='o')-0,input()))
    ans=[None]*n
    ans[0]=1; ans[1]=1

    for i in range(2,n):
        if(S[i-1]==ans[i-1]): ans[i]=ans[i-2]
        else: ans[i]=1-ans[i-2]

    if((S[0]==ans[0])^(ans[1]==ans[-1])):
        print(-1)
        return
    if((S[-1]==ans[-1])^(ans[0]==ans[-2])):
        print(-1)
        return

    for s in S: print('S' if(s) else 'W',end='')
    print()
resolve()

Submission status: Wrong Answer

Solution code:
import sys


def main():
    N = int(input())
    s = list(input())
    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: 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=["#"]*len(s)
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=["#"]*len(s)
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=["#"]*len(s)
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)