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 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():

    n = int(input())
    s = input()
    s += s[0]

    def case1(cur, ans):
        if cur == n-1:
            if ans[0] == ans[-1]:

                print(ans)
                exit()
            else:
                case2(0, 'SW')

        elif (s[cur] == 'o' and s[cur+1] == 'o'):
            cur += 1
            ans += 'S'
            case1(cur, ans)
        elif (s[cur] == 'o' and s[cur+1] == 'x'):
            cur += 1
            ans += 'W'
            case2(cur, ans)
        elif (s[cur] == 'x' and s[cur+1] == 'o'):
            cur += 1
            ans += 'S'
            case1(cur, ans)
        else:
            cur += 1
            ans += 'W'
            case2(cur, ans)

    def case2(cur, ans):

        if cur == n-1:
            if ans[0] == ans[-1]:

                print(ans)
                exit()
            else:
                case3(0, 'WS')

        elif (s[cur] == 'o' and s[cur+1] == 'o'):
            cur += 1
            ans += 'W'
            case4(cur, ans)
        elif (s[cur] == 'o' and s[cur+1] == 'x'):
            cur += 1
            ans += 'S'
            case3(cur, ans)
        elif (s[cur] == 'x' and s[cur+1] == 'o'):
            cur += 1
            ans += 'W'
            case4(cur, ans)
        else:
            cur += 1
            ans += 'S'
            case3(cur, ans)

    def case3(cur, ans):

        if cur == n-1:
            if ans[0] == ans[-1]:

                print(ans)
                exit()
            else:
                case4(0, 'WW')

        elif (s[cur] == 'o' and s[cur+1] == 'o'):
            cur += 1
            ans += 'W'
            case2(cur, ans)
        elif (s[cur] == 'o' and s[cur+1] == 'x'):
            cur += 1
            ans += 'S'
            case1(cur, ans)
        elif (s[cur] == 'x' and s[cur+1] == 'o'):
            cur += 1
            ans += 'W'
            case2(cur, ans)
        else:
            cur += 1
            ans += 'S'
            case1(cur, ans)

    def case4(cur, ans):

        if cur == n-1:
            if ans[0] == ans[-1]:

                print(ans)
                exit()
            else:
                print(-1)
                exit()

        if (s[cur] == 'o' and s[cur+1] == 'o'):
            cur += 1
            ans += 'S'
            case3(cur, ans)
        elif (s[cur] == 'o' and s[cur+1] == 'x'):
            cur += 1
            ans += 'W'
            case4(cur, ans)
        elif (s[cur] == 'x' and s[cur+1] == 'o'):
            cur += 1
            ans += 'S'
            case3(cur, ans)
        else:
            cur += 1
            ans += 'W'
            case4(cur, ans)

    case1(0, 'SS')


resolve()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():

    n = int(input())
    s = input()
    s += s[0]

    def case1(cur, ans):
        if cur == n-1:
            print(ans)
            exit()
        elif (s[cur] == 'o' and s[cur+1] == 'o'):
            cur += 1
            ans += 'S'
            case1(cur, ans)
        elif (s[cur] == 'o' and s[cur+1] == 'x'):
            cur += 1
            ans += 'W'
            case2(cur, ans)
        elif (s[cur] == 'x' and s[cur+1] == 'o'):
            cur += 1
            ans += 'S'
            case1(cur, ans)
        else:
            cur += 1
            ans += 'W'
            case2(cur, ans)

    def case2(cur, ans):

        if cur == n-1:
            print(ans)
            exit()

        elif (s[cur] == 'o' and s[cur+1] == 'o'):
            cur += 1
            ans += 'W'
            case4(cur, ans)
        elif (s[cur] == 'o' and s[cur+1] == 'x'):
            cur += 1
            ans += 'S'
            case3(cur, ans)
        elif (s[cur] == 'x' and s[cur+1] == 'o'):
            cur += 1
            ans += 'W'
            case4(cur, ans)
        else:
            cur += 1
            ans += 'S'
            case3(cur, ans)

    def case3(cur, ans):

        if cur == n-1:
            print(ans)
            exit()

        elif (s[cur] == 'o' and s[cur+1] == 'o'):
            cur += 1
            ans += 'W'
            case2(cur, ans)
        elif (s[cur] == 'o' and s[cur+1] == 'x'):
            cur += 1
            ans += 'S'
            case1(cur, ans)
        elif (s[cur] == 'x' and s[cur+1] == 'o'):
            cur += 1
            ans += 'W'
            case2(cur, ans)
        else:
            cur += 1
            ans += 'S'
            case1(cur, ans)

    def case4(cur, ans):

        if cur == n-1:
            print(ans)
            exit()

        if (s[cur] == 'o' and s[cur+1] == 'o'):
            cur += 1
            ans += 'S'
            case3(cur, ans)
        elif (s[cur] == 'o' and s[cur+1] == 'x'):
            cur += 1
            ans += 'W'
            case4(cur, ans)
        elif (s[cur] == 'x' and s[cur+1] == 'o'):
            cur += 1
            ans += 'S'
            case3(cur, ans)
        else:
            cur += 1
            ans += 'W'
            case4(cur, ans)

    while True:
        val=case1(0, 'SS')
        if val[0]==val[-1]:
            print(val)
            break
        val=case2(0, 'SW')
        if val[0]==val[-1]:
            print(val)
            break
        val=case3(0, 'WS')
        if val[0]==val[-1]:
            print(val)
            break
        val=case4(0, 'WW')
        if val[0]==val[-1]:
            print(val)
            break


    else:
        print(-1)


resolve()

Submission status: Wrong Answer

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

assignable = False

for k in range(4):
    res = [None for _ in range(N)]
    res[0] = k % 2
    res[-1] = k // 2
    for i in range(N - 1):
        if S[i] == 'o':
            if res[i] == 0:
                res[i + 1] = res[i - 1]
            else:
                res[i + 1] = 1 - res[i - 1]
        else:
            if res[i] == 0:
                res[i + 1] = 1 - res[i - 1]
            else:
                res[i + 1] = res[i - 1]
    if S[-1] == 'o':
        if res[-1] == 0:
            if res[0] == res[-2]:
                assignable = True
        else:
            if res[0] == 1 - res[-2]:
                assignable = True
    else:
        if res[-1] == 0:
            if res[0] == 1 - res[-2]:
                assignable = True
        else:
            if res[0] == res[-2]:
                assignable = True
    if assignable:
        for i in range(N):
            if res[i]:
                print('W', end='')
            else:
                print('S', end='')
        break
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    read = sys.stdin.buffer.read
    readline = sys.stdin.buffer.readline
    readlines = sys.stdin.buffer.readlines
    sys.setrecursionlimit(10 ** 7)

    def check(m):
        for bf, c, af, ss in zip(m, m[1:], m[2:], s):
            if ss == 'o':
                if (c == 'S' and bf != af) or (c == 'W' and bf == af):
                    return False
            else:
                if (c == 'S' and bf == af) or (c == 'W' and bf != af):
                    return False
        return True

    n = int(readline())
    s = readline().rstrip().decode()
    check1 = ''
    flag = True
    for ss in s:
        if ss == 'x':
            check1 += 'S'
            if flag:
                flag = False
            else:
                flag = True
        else:
            if flag:
                check1 += 'S'
            else:
                check1 += 'W'
    check1 = check1[-1] + check1 + check1[0]
    if check(check1):
        print(check1[1:-1])
    else:
        check2 = ''
        flag = {'S': 'W', 'W': 'S'}
        for c in check1:
            check2 += flag[c]
        if check(check2):
            print(check2[1:-1])
        else:
            print(-1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

N = ini()
S = ins()


def flip(x):
    if x == "S":
        return "W"
    else:
        return "S"


def solve():
    for p in ["SS", "SW", "WS", "WW"]:
        buf = list(p)
        for i in range(1, N):
            if (buf[i] == "S" and S[i] == "o") or (buf[i] == "W" and S[i] == "x"):
                buf.append(buf[i - 1])
            else:
                buf.append(flip(buf[i - 1]))
        assert len(buf) == N + 1
        if buf[0] != buf[-1]:
            continue
        buf.pop()
        if S[1] == S[-1]:
            if (buf[0] == "S" and S[0] == "x") or (buf[0] == "W" and S[0] == "o"):
                continue
        else:
            if (buf[0] == "S" and S[0] == "o") or (buf[0] == "W" and S[0] == "x"):
                continue
        return "".join(buf)
    return -1


print(solve())

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

N = ini()
S = ins()


def flip(x):
    if x == "S":
        return "W"
    else:
        return "S"


def solve():
    for p in ["SS", "SW", "WS", "WW"]:
        buf = list(p)
        for i in range(1, N):
            if (buf[i] == "S" and S[i] == "o") or (buf[i] == "W" and S[i] == "x"):
                buf.append(buf[i - 1])
            else:
                buf.append(flip(buf[i - 1]))
        assert len(buf) == N + 1
        if buf[0] == buf[-1]:
            buf.pop()
            return "".join(buf)
    return -1


print(solve())

Submission status: Wrong Answer

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
s = input()
t = []
for i in range(n):
    if s[i] == 'o':
        t.append(0)
    else:
        t.append(1)
def chk():
    if res[n-1] ^ t[n-1] != res[0] ^ res[n-2]:
        return False
    if res[n-2] ^ t[n-2] != res[n-1] ^ res[n-3]:
        return False
    return True
for zero,one in itertools.product(range(2),repeat=2):
    # 0:S 1:W
    res = [0] * n
    res[0] = zero; res[1] = one
    for i in range(2,n):
        if res[i-1] == t[i-1]:
            res[i] = res[i-2]
        else:
            res[i] = res[i-2]^1
    if chk():
        ans = []
        for i in range(n):
            ans.append('W' if res[i] else 'S')
        print(''.join(ans))
        quit()
print(-1)

Submission status: Wrong Answer

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
s = input()
t = []
for i in range(n):
    if s[i] == 'o':
        t.append(0)
    else:
        t.append(1)
def chk():
    ok = False
    if res[n-1] == t[n-1]:
        if res[0] == res[n-2]:
            ok = True
    else:
        if res[0] != res[n-2]:
            ok = True
    return ok
for zero,one in itertools.product(range(2),repeat=2):
    # 0:S 1:W
    res = [None] * n
    res[0] = zero; res[1] = one
    for i in range(2,n):
        if res[i-1] == t[i-1]:
            res[i] = res[i-2]
        else:
            res[i] = res[i-2]^1
    if chk():
        ans = []
        for i in range(n):
            ans.append('W' if res[i] else 'S')
        print(''.join(ans))
        quit()
print(-1)

Submission status: Wrong Answer

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
s = input()
check1 = [None] * n
check1[0] = 'S'
check1[1] = 'S'
check2 = [None] * n
check2[0] = 'S'
check2[1] = 'W'
check3 = [None] * n
check3[0] = 'W'
check3[1] = 'S'
check4 = [None] * n
check4[0] = 'W'
check4[1] = 'W'
def check(lst):
    for i in range(1,n):
        if lst[i] == 'S':
            if s[i] == 'o':
                if i + 1 == n:
                    if lst[0] != lst[i-1]:
                        return False, lst
                else:
                    lst[i+1] = lst[i-1]
            else:
                if i + 1 == n:
                    if lst[0] == lst[i-1]:
                        return False, lst
                else:
                    if lst[i-1] == 'S':
                        lst[i+1] = 'W'
                    else:
                        lst[i+1] = 'S'
        else:
            if s[i] == 'o':
                if i + 1 == n:
                    if lst[0] == lst[i-1]:
                        return False, lst
                else:
                    if lst[i-1] == 'S':
                        lst[i+1] = 'W'
                    else:
                        lst[i+1] = 'S'
            else:
                if i + 1 == n:
                    if lst[0] != lst[i-1]:
                        return False, lst
                else:
                    lst[i+1] = lst[i-1]
    else:
        if s[0] == 'o' and lst[0] == 'S':
            if lst[-1] != lst[1]:
                return False, lst
        elif s[0] == 'o' and lst[0] == 'W':
            if lst[-1] == lst[1]:
                return False, lst
        elif s[0] == 'x' and lst[0] == 'S':
            if lst[-1] == lst[0]:
                return False, lst
        elif s[0] == 'x' and lst[0] == 'W':
            if lst[-1] != lst[0]:
                return False, lst
        return True, lst

f1, check1 = check(check1)
if f1:
    print(''.join(check1))
    quit()
f2, check2 = check(check2)
if f2:
    print(''.join(check2))
    quit()
f3, check3 = check(check3)
if f3:
    print(''.join(check3))
    quit()
f4, check4 = check(check4)
if f4:
    print(''.join(check4))
    quit()
print(-1)

Submission status: Wrong Answer

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
s = input()
check1 = [None] * n
check1[0] = 'S'
check1[1] = 'S'
check2 = [None] * n
check2[0] = 'S'
check2[1] = 'W'
check3 = [None] * n
check3[0] = 'W'
check3[1] = 'S'
check4 = [None] * n
check4[0] = 'W'
check4[1] = 'W'
def check(lst):
    for i in range(1, n):
        if lst[i] == 'S':
            if s[i] == 'o':
                if i + 1 == n:
                    if lst[0] != lst[i-1]:
                        return False, lst
                else:
                    lst[i+1] = lst[i-1]
            else:
                if i + 1 == n:
                    if lst[0] == lst[i-1]:
                        return False, lst
                else:
                    if lst[i-1] == 'S':
                        lst[i+1] = 'W'
                    else:
                        lst[i+1] = 'S'
        else:
            if s[i] == 'o':
                if i + 1 == n:
                    if lst[0] == lst[i-1]:
                        return False, lst
                else:
                    if lst[i-1] == 'S':
                        lst[i+1] = 'W'
                    else:
                        lst[i+1] = 'S'
            else:
                if i + 1 == n:
                    if lst[0] != lst[i-1]:
                        return False, lst
                else:
                    lst[i+1] = lst[i-1]
    else:
        return True, lst

f1, check1 = check(check1)
if f1:
    print(''.join(check1))
    quit()
f2, check2 = check(check2)
if f2:
    print(''.join(check2))
    quit()
f3, check3 = check(check3)
if f3:
    print(''.join(check3))
    quit()
f4, check4 = check(check4)
if f4:
    print(''.join(check4))
    quit()
print(-1)

Submission status: Wrong Answer

Solution code:
def resolve():
    n = int(input())
    s = list(input())
    init = [["S","S"], ["S","W"], ["W","S"], ["W","W"]]
    def addsheep (prev, now):
        if s[now] == "o":
            if ans[now] == "S" and ans[prev] == "S":
                return "S"
            elif ans[now] == "S" and ans[prev] == "W":
                return "W"
            elif ans[now] == "W" and ans[prev] == "S":
                return "W"
            elif ans[now] == "W" and ans[prev] == "W":
                return "S"
        if s[now] == "x":
            if ans[now] == "S" and ans[prev] == "S":
                return "W"
            elif ans[now] == "S" and ans[prev] == "W":
                return "S"
            elif ans[now] == "W" and ans[prev] == "S":
                return "S"
            elif ans[now] == "W" and ans[prev] == "W":
                return "W"

    OK = False
    for i in init:
        ans = i
        for j in range(n-3):
            ans.append(addsheep(j, j+1))
        ans.append(addsheep(n-3, n-2))

        if addsheep(n-2, n-1) == ans[0]:
            OK = True
            break
    if OK:
        print("".join(ans))
    else:
        print(-1)
resolve()

Submission status: Wrong Answer

Solution code:
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
import re

n = ii()
s = input()

#最初2つがSS/SW/WS/WWの状態で、前から決めてく
#S=1,W=0
l = [[1,1],[1,0],[0,1],[0,0]]
'''
ss = [1,1]
sw = [1,0]
ws = [0,1]
ww = [0,0]
'''

def nextAnimal(lis,st):
    if st == 'o':
        lis.append(lis[-2]^(lis[-1]^1))
    else:
        lis.append(lis[-2]^(lis[-1]))
#    print(lis)


for i in s[1:]:
    for item in l:
        nextAnimal(item,i)

#print(l)
for item in l:
    if item[0] == item[-1]:
        ans = ''
        for i in item[:n]:
            if i == 0:
                ans += 'W'
            else:
                ans += 'S'
        print(ans)
        exit()
print(-1)

Submission status: Wrong Answer

Solution code:
N = int(input())
s = input().strip()
flag = 0
A = [0 for _ in range(N)]
for a in range(2):
    for b in range(2):
        A[0]=a
        A[1]=b
        for i in range(1,N-1):
            if A[i]==0 and s[i]=="o":
                A[i+1]=A[i-1]
            elif A[i]==0 and s[i]=="x":
                A[i+1]=1-A[i-1]
            elif A[i]==1 and s[i]=="o":
                A[i+1]=1-A[i-1]
            elif A[i]==1 and s[i]=="x":
                A[i+1]=A[i-1]
        if A[N-1]==0 and s[N-1]=="o":
            if A[0]==A[N-2]:
                flag = 0
            else:
                flag = 1
        elif A[N-1]==0 and s[N-1]=="x":
            if A[0]==1-A[N-2]:
                flag = 0
            else:
                flag = 1
        elif A[N-1]==1 and s[N-1]=="o":
            if A[0]==1-A[N-2]:
                flag = 0
            else:
                flag = 1
        elif A[N-1]==1 and s[N-1]=="x":
            if A[0]==A[N-2]:
                flag = 0
            else:
                flag =1
        if A[0]==0 and s[0]=="o":
            if A[1]==A[N-1]:
                flag = 0
            else:
                flag =1
        elif A[0]==0 and s[0]=="x":
            if A[1]==1-A[N-1]:
                flag = 0
            else:
                flag = 1
        elif A[0]==1 and s[0]=="o":
            if A[1]==1-A[N-1]:
                flag = 0
            else:
                flag = 1
        elif A[0]==1 and s[0]=="x":
            if A[1]==A[N-1]:
                flag = 0
            else:
                flag = 1
        if flag==0:
            B = []
            for i in range(N):
                if A[i]==0:
                    B.append("S")
                else:
                    B.append("W")
            break
if flag==1:
    print(-1)
else:
    print("".join(B))

Submission status: Wrong Answer

Solution code:
N = int(input())
s = str(input())
s = list(s)
start = "S"
ans = ["S","S"]
for i in range(len(s)):
  if ans[-2] == "S" and ans[-1] == "S":
    if s[i] == "o":
      temp = "S"
    else:
      temp = "W"
  elif ans[-2] == "W" and ans[-1] == "S":
    if s[i] == "o":
      temp = "W"
    else:
      temp = "S"
  elif ans[-2] == "S" and ans[-1] == "W":
    if s[i] == "o":
      temp = "W"
    else:
      temp = "S" 
  else:
    if s[i] == "o":
      temp = "S"
    else:
      temp = "W"
  ans.append(temp)
#print(ans)
if ans[0] != ans[-2] or ans[1] != ans[-1]:
  print(-1)
else:
  answer = ans[1:-1]
  t = "".join(answer)
  print(t)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
for ans in ('SS', 'SW', 'WS', 'WW'):
    for i in range(1, n):
        if (s[i] == 'o') ^ (ans[i] == 'S'):
            if ans[i - 1] == 'S':
                ans += 'W'
            else:
                ans += 'S'
        else:
            ans += ans[i - 1]
    if ans[0] == ans[-1]:
        print(ans[:-1])
        break
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
for ans in ('SS', 'SW', 'WS', 'WW'):
    ans = 'SS'
    for i in range(1, n):
        if (s[i] == 'o') ^ (ans[i] == 'S'):
            if ans[i - 1] == 'S':
                ans += 'W'
            else:
                ans += 'S'
        else:
            ans += ans[i - 1]
    if ans[0] == ans[-1]:
        print(ans[:-1])
        break
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
print(-1)

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10**9)
mod = 10**9+7

N = i()
S = s()
a = 'S'
b = 'W'
kouho = [[a,a],[a,b],[b,a],[b,b]]
for a,b in kouho:
    S1 = [a,b]
    for i in range(1,N):
        if S[i] == 'o':
            if S1[i] == 'S':
                if S1[i-1] == 'S':
                    S1.append('S')
                else:
                    S1.append('W')
            else:
                if S1[i-1] == 'S':
                    S1.append('W')
                else:
                    S1.append('S')
        else:
            if S1[i] == 'S':
                if S1[i-1] == 'S':
                    S1.append('W')
                else:
                    S1.append('S')
            else:
                if S1[i-1] == 'S':
                    S1.append('S')
                else:
                    S1.append('W')
    if S1[-1] != a:
        continue
    S1 = S1[:N]
    if a == 'S' and b == 'S':
        if S[0] == 'o':
            if S1[-1] == 'S':
                print(''.join(S1))
                exit()
        else:
            if S1[-1] == 'W':
                print(''.join(S1))
                exit()
    elif a == 'S' and b == 'W':
        if S[0] == 'o':
            if S1[-1] == 'W':
                print(''.join(S1))
                exit()
        else:
            if S1[-1] == 'S':
                print(''.join(S1))
                exit()
    elif a == 'W' and b == 'S':
        if S[0] == 'o':
            if S1[-1] == 'S':
                print(''.join(S1))
                exit()
        else:
            if S1[-1] == 'W':
                print(''.join(S1))
                exit()
    else:
        if S[0] == 'o':
            if S1[-1] == 'W':
                print(''.join(S1))
                exit()
        else:
            if S1[-1] == 'S':
                print(''.join(S1))
                exit()
print(-1)

Submission status: Wrong Answer

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

def sheep(a,b):
    l=[0]*(n+1)
    l[0]=a
    l[1]=b
    m=[]
    for i in range(1,n):
        if s[i]=="o":
            if l[i]==0:
                l[i+1]=l[i-1]
            else:
                l[i+1]=(l[i-1]+1)%2
        else:
            if l[i]==0:
                l[i+1]=(l[i-1]+1)%2
            else:
                l[i+1]=l[i-1]
    if l[n]==l[0]:
        for i in range(n):
            if l[i]==0:
                m.append("S")
            else:
                m.append("W")
        print("".join(m))
        exit()


sheep(0,0)
sheep(0,1)
sheep(1,0)
sheep(1,1)
print("-1")

Submission status: Wrong Answer

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

def sheep(a,b):
    l=[0]*(n+1)
    l[0]=a
    l[1]=b
    for i in range(1,n):
        if s[i]=="o":
            if l[i]==0:
                l[i+1]=l[i-1]
            else:
                l[i+1]=(l[i-1]+1)%2
        else:
            if l[i]==0:
                l[i+1]=(l[i-1]+1)%2
            else:
                l[i+1]=l[i-1]
    if l[n]==l[0]:
        for i in range(n):
            if l[i]==0:
                print("S")
            else:
                print("W")
        exit()


sheep(0,0)
sheep(0,1)
sheep(1,0)
sheep(1,1)
print("-1")

Submission status: Wrong Answer

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
s = input()

out = None
for a0, a1 in (("W", "S"), ("S", "W"), ("S","S"), ("W", "W")):
    ans = [None]*n
    ans[0] = a0
    ans[-1] = a1
    for i in range(n-1):
        v = int(s[i]=="o") + int(ans[i-1]=="S") + int(ans[i]=="S")
        if v%2==1:
            ans[i+1] = "S"
        else:
            ans[i+1] = "W"
    v = int(s[n-1]=="o") + int(ans[n-2]=="S") + int(ans[0]=="S") + int(ans[n-1]=="S")
    if v%2==0:
        out = ans
if out is not None:
    write("".join(out))
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
s = input()

out = None
for a0, a1 in (("W", "S"), ("S", "W"), ("S","S"), ("W", "W")):
    ans = [None]*n
    ans[0] = a0
    ans[-1] = a1
    for i in range(n-1):
        v = (s[i]=="o") + (ans[i-1]=="S") + (ans[i]=="S")
        if v%2==1:
            ans[i+1] = "S"
        else:
            ans[i+1] = "W"
    v = (s[n-1]=="o") + (ans[n-2]=="S") + (ans[0]=="S") + (ans[n-1]=="S")
    if v%2==0:
        out = ans
if out is not None:
    write("".join(out))
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
s = input()


for a0, a1 in (("W", "S"), ("S", "W"), ("S","S"), ("W", "W")):
    ans = [None]*n
    ans[0] = a0
    ans[-1] = a1
    for i in range(n-1):
        v = (s[i]=="o") + (ans[i-1]=="S") + (ans[i]=="S")
        if v%2==1:
            ans[i+1] = "S"
        else:
            ans[i+1] = "W"
    v = (s[n-1]=="o") + (ans[n-2]=="S") + (ans[0]=="S") + (ans[n-1]=="S")
    if v%2==0:
        write("".join(ans))
        break
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
s = input()

import itertools
for a0, a1 in itertools.product(("W", "S"), ("S", "W")):
    ans = [None]*n
    ans[0] = a0
    ans[-1] = a1
    for i in range(n-1):
        v = (s[i]=="o") + (ans[i-1]=="S") + (ans[i]=="S")
        if v%2==1:
            ans[i+1] = "S"
        else:
            ans[i+1] = "W"
    v = (s[n-1]=="o") + (ans[n-2]=="S") + (ans[0]=="S") + (ans[n-1]=="S")
    if v%2==0:
        write("".join(ans))
        break
else:
    print(-1)