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:
# -*- coding: utf-8 -*-

import sys
import os


N = int(input())
s = input().strip()


def judge(zero, one):
    predict = [None] * N
    # ひつじ 0
    # おおかみ 1とする

    # 最初の２つを仮定する
    predict[0] = zero
    predict[1] = one

    for i in range(1, N - 1):
        # sheep
        if predict[i] == 0:
            if s[i] == 'o':
                predict[i+1] = predict[i-1]
            else:
                predict[i+1] = 1 - predict[i-1]
        # wolf
        else:
            if s[i] == 'o':
                predict[i+1] = 1 - predict[i-1]
            else:
                predict[i+1] = predict[i-1]

    is_consistent = None

    # sheep
    if predict[-1] == 0:
        if s[-1] == 'o':
            if predict[-2] == predict[0]:
                is_consistent = True
            else:
                is_consistent = False
        else:
            if predict[-2] != predict[0]:
                is_consistent = True
            else:
                is_consistent = False
    # wolf
    else:
        if s[-1] == 'o':
            if predict[-2] != predict[0]:
                is_consistent = True
            else:
                is_consistent = False
        else:
            if predict[-2] == predict[0]:
                is_consistent = True
            else:
                is_consistent = False

    return is_consistent, predict


# 判定
results = []
results.append(judge(0, 0))
results.append(judge(1, 0))
results.append(judge(1, 1))
results.append(judge(0, 1))

# 1つでもTrueがあればいい
trues = [x for x in results if x[0] is True]

if trues:
    # 例示
    result = trues[0]
    example = result[1]
    for v in example:
        if v == 0:
            print('S', end='')
        else:
            print('W', end='')
    print()
else:
    print(-1)

Submission status: Wrong Answer

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

import sys
import os


N = int(input())
s = input().strip()


def judge(zero, one):
    predict = [None] * N
    # ひつじ 0
    # おおかみ 1とする

    # 最初の２つを仮定する
    predict[0] = zero
    predict[1] = one

    for i in range(1, N - 1):

        # 羊ならばこう動く
        if s[i] == 'o':
            predict[i+1] = predict[i-1]
        else:
            predict[i+1] = 1 - predict[i-1]

        # オオカミなら上記をひっくり返す
        if predict[i] == 1:
            predict[i + 1] = 1 - predict[i+1]

    exist = None
    # 羊ならこう動く
    if predict[-1] == 0:
        if s[-1] == 'o':
            if predict[-2] == predict[0]:
                exist = True
            else:
                exist = False
        else:
            if predict[-2] != predict[0]:
                exist = True
            else:
                exist = False
    else:
        if s[-1] == 'o':
            if predict[-2] != predict[0]:
                exist = True
            else:
                exist = False
        else:
            if predict[-2] == predict[0]:
                exist = True
            else:
                exist = False

    # オオカミなら
    #if predict[-1] == 1:
        # 反転
    #    exist = not exist

    return exist, predict


# 判定
results = []
results.append(judge(0, 0))
results.append(judge(1, 0))
results.append(judge(0, 1))
results.append(judge(1, 1))

# 1つでもTrueがあればいい
trues = [x for x in results if x[0] is True]

if trues:
    # 例示
    result = trues[0]
    example = result[1]
    for v in example:
        if v == 0:
            print('S', end='')
        else:
            print('W', end='')
    print()
else:
    print(-1)

Submission status: Wrong Answer

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

import sys
import os


N = int(input())
s = input().strip()


def judge(zero, one):
    predict = [None] * N
    # ひつじ 0
    # おおかみ 1とする

    # 最初の２つを仮定する
    predict[0] = zero
    predict[1] = one
    for i in range(1, N - 1):

        # 羊ならばこう動く
        if s[i] == 'o':
            predict[i+1] = predict[i-1]
        else:
            predict[i+1] = 1 - predict[i-1]

        # オオカミなら上記をひっくり返す
        if predict[i] == 1:
            predict[i + 1] = 1 - predict[i+1]

    exist = None
    # 羊ならこう動く
    if s[-1] == 'o':
        if predict[-2] == predict[0]:
            exist = True
        else:
            exist = False
    else:
        if predict[-2] != predict[0]:
            exist = True
        else:
            exist = False
    # オオカミなら
    if predict[-1] == 1:
        # 反転
        exist = not exist
    return exist, predict


# 判定
results = []
results.append(judge(0, 0))
results.append(judge(1, 0))
results.append(judge(0, 1))
results.append(judge(1, 1))

# 1つでもTrueがあればいい
trues = [x for x in results if x[0] is True]

if trues:
    # 例示
    result = trues[0]
    example = result[1]
    for v in example:
        if v == 0:
            print('S', end='')
        else:
            print('W', end='')
    print()
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
N = int(input())
s = list(input())
check_SW = True
X = ["S"]

for i in range(1,N):
    if check_SW:
        if s[i-1] == "o":
            X.append("S")
            check_SW = True
        else:
            X.append("W")
            check_SW = False
    else:
        if s[i-1] =="×":
            X.append("S")
            check_SW = False
        else:
            X.append("W")
            check_SW = True

print("".join(X))

Submission status: Wrong Answer

Solution code:
N = int(input())
s = list(input())
check_SW = True
X = ["S"]

for i in range(1,N):
    if check_SW:
        if s[i-1] == "o":
            X.append("S")
            check_SW = True
        else:
            X.append("W")
            check_SW = False
    else:
        if s[i-1] =="×":
            X.append("S")
            check_SW = False
        else:
            X.append("W")
            check_SW = True

print(X)

Submission status: Wrong Answer

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

a = False
b = False

sw = [None] * n

sw[0] = False
sw[1] = False

def next(s,sw,i,j):
    if s[i] == 'o':
        return not (sw[j] ^ sw[i])
    else:
        return sw[j] ^ sw[i]

def printsw(sw,n):
    s = ''
    for i in range(n):
        if sw[i]:
            s += 'S'
        else:
            s += 'W'
    print(s)

flag = True

for j in range(4):
    for i in range(2,n):
        sw[i] = next(s,sw,i-2,i-1)

    zero = next(s,sw,n-2,n-1)
    one = next(s,sw,n-1,0)
    if zero == sw[0]:
        if one == sw[1]:
            printsw(sw,n)
            flag = False
            break

    sw[0] = not sw[0]
    if j == 1:
        sw[1] = True

if flag:
    print(-1)

Submission status: Wrong Answer

Solution code:
N = int(input())
s = list(input())
S = [0]*N
for i in range(N):
    if s[i]=='o':
        S[i]=1
    else:
        S[i]=-1

P = [[1]*N,[1]*N,[-1]*N,[-1]*N]

if S[0]==1:
    P[0][1]=1
    P[0][N-1]=1
    P[1][1] = -1
    P[1][N - 1] = -1
    P[2][1] = 1
    P[2][N - 1] = -1
    P[3][1] = -1
    P[3][N - 1] = 1
else:
    P[0][1] = 1
    P[0][N - 1] = -1
    P[1][1] = -1
    P[1][N - 1] = 1
    P[2][1] = 1
    P[2][N - 1] = 1
    P[3][1] = -1
    P[3][N - 1] = -1

result = -1
for i in range(1,N-1):
    for j in range(4):
        if S[i]*P[j][i]==1:
            P[j][i+1]=P[j][i-1]
        else:
            P[j][i + 1] = - P[j][i - 1]
    if i == N-2:
        for j in range(4):
            if S[i] * P[j][i] == 1:
                if P[j][i + 1] == P[j][i - 1]:
                    if S[i+1] * P[j][i+1] == 1:
                        if P[j][0] == P[j][i]:
                            result = j
                            break
                    else:
                        if P[j][0] == - P[j][i]:
                            result = j
                            break
            else:
                if P[j][i + 1] == - P[j][i - 1]:
                    if S[i+1] * P[j][i+1] == 1:
                        if P[j][0] == P[j][i]:
                            result = j
                            break
                    else:
                        if P[j][0] == - P[j][i]:
                            result = j
                            break

if result == -1:
    print(result)
else:
    for i in range(N):
        if P[result][i]==1:
            print('S',end="")
        else:
            print('W',end="")

Submission status: Wrong Answer

Solution code:
# -*- coding:utf-8 -*-
n = int(input())
m = input()

class Queue:
    def __init__(self):
        self.animal_list = []

    def enqueue(self, animal):
        self.animal_list.append(animal)

class Animal:
    def __init__(self, say, tp, before):
        self.tp = tp
        self.say = say
        if not before:
            pass
        else:
            self.before = before
        if (self.say == 'o' and self.tp == 'S') or (self.say=='x' and self.tp == 'W'):
            self.next = self.before
        else:
            self.next = 'W' if self.before == 'S' else 'S'

q = Queue()
for i,l in enumerate(m):
    if i == 0:
        pass
    elif i == 1:
        q.enqueue(Animal(m[1],'S', 'S'))
    else:
        q.enqueue(Animal(l,q.animal_list[-1].next,q.animal_list[-1].tp))

output = 'S'
for anim in q.animal_list:
    output += anim.tp

la = q.animal_list[-1]
if la.tp == 'S':
    if la.say == 'o' and la.before == 'S':
        pass
    elif la.say == 'x' and la.before == 'W':
        pass
    else:
        output = -1
else:
    if la.say == 'o' and la.before == 'W':
        pass
    elif la.say == 'x' and la.before == 'S':
        pass
    else:
        output = -1
if output == -1:
    q = Queue()
    for i,l in enumerate(m):
        if i == 0:
            pass
        elif i == 1:
            q.enqueue(Animal(m[1],'S', 'W'))
        else:
            q.enqueue(Animal(l,q.animal_list[-1].next,q.animal_list[-1].tp))

        if la.tp == 'S':
            if la.say == 'o' and la.before == 'W':
                pass
            elif la.say == 'x' and la.before == 'S':
                pass
            else:
                output = -1
        else:
            if la.say == 'o' and la.before == 'S':
                pass
            elif la.say == 'x' and la.before == 'W':
                pass
            else:
                output = -1
print (output)

Submission status: Wrong Answer

Solution code:
# -*- coding:utf-8 -*-
n = int(input())
m = input()

class Queue:
    def __init__(self):
        self.animal_list = []

    def enqueue(self, animal):
        self.animal_list.append(animal)

class Animal:
    def __init__(self, say, tp, before):
        self.tp = tp
        self.say = say
        if not before:
            pass
        else:
            self.before = before
        if (self.say == 'o' and self.tp == 'S') or (self.say=='x' and self.tp == 'W'):
            self.next = self.before
        else:
            self.next = 'W' if self.before == 'S' else 'S'

q = Queue()
for i,l in enumerate(m):
    if i == 0:
        pass
    elif i == 1:
        q.enqueue(Animal(m[1],'S', 'S'))
    else:
        q.enqueue(Animal(l,q.animal_list[-1].next,q.animal_list[-1].tp))

output = 'S'
for anim in q.animal_list:
    output += anim.tp

la = q.animal_list[-1]
if la.tp == 'S':
    if la.say == 'o' and la.before == 'S':
        print(output)
    elif la.say == 'x' and la.before == 'W':
        print(output)
    else:
        print(-1)
else:
    if la.say == 'o' and la.before == 'W':
        print(output)
    elif la.say == 'x' and la.before == 'S':
        print(output)
    else:
        print(-1)

Submission status: Wrong Answer

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

n=int(raw_input().strip())
s=str(raw_input().strip())
WS=['']*(n+1)

def next(ani_b,ani_c,rep):
    # type: (object, object) -> object
    if ani_c==True:
        if rep=='o':
            ani_next=ani_b
        else:
            ani_next=not(ani_b)
    else:
        if rep=='o':
            ani_next=not(ani_b)
        else:
            ani_next=ani_b

    return ani_next


def prep_last_ani(init_prep):
    if init_prep==True:
        if s[0]=='o':
            prep_last=True
        else:
            prep_last=False
    else:
        if s[0]=='o':
            prep_last=False
        else:
            prep_last=True
    return  prep_last

#prep_last=prep_last_ani(WS[0])
def determin(init_ani):
    for i in range(n):
        WS[i+1]=next(WS[i-1],WS[i],s[i])
        #print "i:"+str(i)+"   WS["+str(i-1)+"]:"+str(WS[i-1])+\
        #       "   WS["+str(i)+"]:"+str(WS[i])+"   s["+str(i)+"]:"+str(s[i])+\
        #        "   WS["+str(i+1)+"]:"+str(WS[i+1])
    if WS[-1]==WS[0]:
        S_list=[i*'S' for i in WS]
        W_list=[i*'W' for i in [not(j) for j in WS]]
        return "".join([x+y for x,y in zip(S_list,W_list)])
    else:
        return "NG"


WS[0]=True
WS[-1]=prep_last_ani(WS[0])
#print "WS[-1]:"+str(WS[-1])
#print "init WS(True):"+str(WS[0])
ans=determin(WS[0])
if ans=="NG":
    #print ans
    WS[0]=False
    WS[-1]=prep_last_ani(WS[0])
    #print "init WS(False)"
    ans=determin(WS[0])
    if ans=="NG":
        print -1
    else:
        print ans[:-1]
else:
    print ans[:-1]

Submission status: Wrong Answer

Solution code:
def my_func(resp, n_animal, p_animal):
    if resp == "o":
        if n_animal == "S":
            return p_animal
        else:
            return "S" if p_animal == "W" else "W"
    elif resp == "x":
        if n_animal == "S":
            return "S" if p_animal == "W" else "W"
        else:
            return p_animal

def my_func2(N, s, first, second):
    row =  [first, second] + [None] * (N-2)
    for i in range(1,N-1):
        row[i+1] = my_func(s[i], row[i], row[i-1])
    if my_func(s[0], row[0], row[1]) == row[-1] and my_func(s[-1], row[-1], row[-2]) == row[0]:
        return "".join(row)
    else:
        return ""


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

ans = my_func2(N,s,"W","W")
ans = my_func2(N,s,"W","S")
ans = my_func2(N,s,"S","W")
ans = my_func2(N,s,"S","S")
if ans != "":
    print(ans)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
def my_func(resp, n_animal, p_animal):
    if resp == "o":
        if n_animal == "S":
            return p_animal
        else:
            return "S" if p_animal == "W" else "W"
    elif resp == "x":
        if n_animal == "S":
            return "S" if p_animal == "W" else "W"
        else:
            return p_animal

def my_func2(N, s, first, second):
    row =  [first, second] + [None] * (N-2)
    for i in range(1,N-1):
        row[i+1] = my_func(s[i], row[i], row[i-1])
    return "".join(row) if my_func(s[0], row[0], row[1]) == row[-1] else ""


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

ans = my_func2(N,s,"W","W")
ans = my_func2(N,s,"W","S")
ans = my_func2(N,s,"S","W")
ans = my_func2(N,s,"S","S")
if ans != "":
    print(ans)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
def my_func(resp, n_animal, p_animal):
    if resp == "o":
        if n_animal == "S":
            return p_animal
        else:
            return "S" if p_animal == "W" else "W"
    elif resp == "x":
        if n_animal == "S":
            return "S" if p_animal == "W" else "W"
        else:
            return p_animal

def my_func2(N, s, first, second):
    row =  [first, second] + [None] * (N-1)
    for i in range(1,N):
        row[i+1] = my_func(s[i], row[i], row[i-1])
    return "".join(row[:-1]) if my_func(s[0], row[0], row[1]) == row[-1] else "" 


N = int(input())
s = input()
ans = ""
ans = my_func2(N,s,"W","W")
ans = my_func2(N,s,"W","S")
ans = my_func2(N,s,"S","W")
ans = my_func2(N,s,"S","S")
if ans != "":
    print(ans)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
import sys
a = int(input())
b = list(input())
frag = 0
parks = [list("SS"),list("SW"),list("WS"),list("WW")]
for park in parks:
    for i in range(len(b)-2):
        if b[i+1] == "o":
            if park[i]=="S" and park[i+1]=="S":
                park.append("S")
            elif park[i]=="S" and park[i+1]=="W":
                park.append("W")
            elif park[i]=="W" and park[i+1]=="S":
                park.append("W")
            elif park[i]=="W" and park[i+1]=="W":
                park.append("S")
        elif b[i+1] == "x":
            if park[i]=="S" and park[i+1]=="S":
                park.append("W")
            elif park[i]=="S" and park[i+1]=="W":
                park.append("S")
            elif park[i]=="W" and park[i+1]=="S":
                park.append("S")
            elif park[i]=="W" and park[i+1]=="W":
                park.append("W")
    if b[-1]=="o":
        if park[-1] == "S":
            if park[0]==park[-2]:
                print (''.join(park))
                frag = 1
                break
        if park[-1] == "W":
            if park[0]!=park[-2]:
                print (''.join(park))
                frag = 1
                break
    if b[-1]=="x":
        if park[-1] == "S":
            if park[0]!=park[-2]:
                print (''.join(park))
                frag = 1
                break
        if park[-1] == "W":
            if park[0]==park[-2]:
                print (''.join(park))
                frag = 1
                break
if frag == 0:
    print(-1)

Submission status: Wrong Answer

Solution code:
import sys
a = int(input())
b = list(input())
frag = 0
parks = [list("ss"),list("sw"),list("ws"),list("ww")]
for park in parks:
    for i in range(len(b)-2):
        if b[i+1] == "o":
            if park[i]=="s" and park[i+1]=="s":
                park.append("s")
            elif park[i]=="s" and park[i+1]=="w":
                park.append("w")
            elif park[i]=="w" and park[i+1]=="s":
                park.append("w")
            elif park[i]=="w" and park[i+1]=="w":
                park.append("s")
        elif b[i+1] == "x":
            if park[i]=="s" and park[i+1]=="s":
                park.append("w")
            elif park[i]=="s" and park[i+1]=="w":
                park.append("s")
            elif park[i]=="w" and park[i+1]=="s":
                park.append("s")
            elif park[i]=="w" and park[i+1]=="w":
                park.append("w")
    if b[-1]=="o":
        if park[-1] == "s":
            if park[0]==park[-2]:
                print (''.join(park))
                frag = 1
                break
        if park[-1] == "w":
            if park[0]!=park[-2]:
                print (''.join(park))
                frag = 1
                break
    if b[-1]=="x":
        if park[-1] == "s":
            if park[0]!=park[-2]:
                print (''.join(park))
                frag = 1
                break
        if park[-1] == "w":
            if park[0]==park[-2]:
                print (''.join(park))
                frag = 1
                break
if frag == 0:
    print(-1)

Submission status: Wrong Answer

Solution code:
def check(s,ans_d):
	for i in range(1,len(s)):
		if ans_d[i]=="S":
			if s[i]=="o":
				ans_d+=ans_d[i-1]
			else:
				if ans_d[i-1]=="S":
					ans_d+="W"
				else:
					ans_d+="S"
		else:
			if s[i]=="x":
				ans_d+=ans_d[i-1]
			else:
				if ans_d[i-1]=="S":
					ans_d+="W"
				else:
					ans_d+="S"
	#check index=-1
	if ans_d[-1]==ans_d[0]:
		if ans_d[0]=="S":
			if s[0]=="o":
				if s[1]==s[-1]:
					return ans_d
			else:
				if s[1]!=s[-1]:
					return ans_d
		else:
			if s[0]=="x":
				if s[1]==s[-1]:
					return ans_d
			else:
				if s[1]!=s[-1]:
					return ans_d
	return False

N=int(input())
s=input()
flag=False

ans=check(s,"SS")
if ans==False and flag==False:
	ans=check(s,"SW")
else:
	flag=True
if ans==False and flag==False:
	ans=check(s,"WS")
else:
	flag=True
if ans==False and flag==False:
	ans=check(s,"WW")
else:
	flag=True

if flag==False:
	print("-1")
else:
	print(ans[0:-1])

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N = input()
S = raw_input()
Ans = ''
StartString = ['SS','SW','WS','WW']
CheckFlag = 0
for i in range(4):
    Ans += StartString[i]
    for j in range(N-1):
        if(Ans[j+1]=='S' and S[j+1]=='o'):
            Ans += Ans[j]
        elif(Ans[j+1]=='S' and S[j+1]=='x'):
            if(Ans[j]=='S'):
                Ans += 'W'
            else:
                Ans += 'S'
        elif(Ans[j+1]=='W' and S[j+1]=='o'):
            if(Ans[j]=='S'):
                Ans += 'W'
            else:
                Ans += 'S'
        elif(Ans[j+1]=='W' and S[j+1]=='x'):
            Ans += Ans[j]
    if(Ans[0]==Ans[N]):
        if(Ans[0]=='S' and S[0]=='o'):
            if(Ans[1]==Ans[N-1]):
                print(Ans[:N])
                CheckFlag = 1
                break
        elif(Ans[0]=='S' and S[0]=='x'):
            if(Ans[1]!=Ans[N-1]):
                print(Ans[:N])
                CheckFlag = 1
                break
        elif(Ans[0]=='W' and S[0]=='o'):
            if(Ans[1]!=Ans[N-1]):
                print(Ans[:N])
                CheckFlag = 1
                break
        elif(Ans[0]=='W' and S[0]=='x'):
            if(Ans[1]==Ans[N-1]):
                print(Ans[:N])
                CheckFlag = 1
                break
        else:
            Ans = ''
    else:
        Ans = ''
        
if(CheckFlag == 0):
    print('-1')

Submission status: Wrong Answer

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

N = input()
S = raw_input()
Ans = ''
StartString = ['SS','SW','WS','WW']
CheckFlag = 0
for i in range(4):
    Ans += StartString[i]
    for j in range(N-1):
        if(Ans[j+1]=='S' and S[j+1]=='o'):
            Ans += Ans[j]
        elif(Ans[j+1]=='S' and S[j+1]=='x'):
            if(Ans[j]=='S'):
                Ans += 'W'
            else:
                Ans += 'S'
        elif(Ans[j+1]=='W' and S[j+1]=='o'):
            if(Ans[j]=='S'):
                Ans += 'W'
            else:
                Ans += 'S'
        elif(Ans[j+1]=='W' and S[j+1]=='x'):
            Ans += Ans[j]
    if(Ans[0]==Ans[N]):
        print(Ans[:N])
        CheckFlag = 1
        break
    else:
        Ans = ''
        
if(CheckFlag == 0):
    print('-1')

Submission status: Wrong Answer

Solution code:
_ = input()
s = input()

cands = ['SSS', 'WSW'] if s[0] == 'o' else ['WSS', 'SSW']

d = {
    'o':{'SS': 'S', 'SW': 'W', 'WW': 'S', 'WS': 'W'},
    'x':{'SS': 'W', 'SW': 'S', 'WW': 'W', 'WS': 'S'}
}

for char in s[1:]:
    for i in range(len(cands)):
        cands[i] += d[char][cands[i][-2:]]

for cand in cands:
    if cand[:2] == cand[-2:]:
        print(cand[1:-1])
        break
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
d={"o":1,"x":-1}
N=int(raw_input())
s=raw_input()
def ans(a):
    for i in range(1,N):
        a=a+[a[i]*a[i-1]*d[s[i]]]
    if a[0]==a[N]:
        return a[:-1]
    else:
        return []
for ini in [[1,1],[1,-1],[-1,1],[-1,-1]]:
    a=ans(ini)
    if a:
        print "".join(['S' if x>0 else 'W' for x in a])
        break
else:
    print "-1"

Submission status: Wrong Answer

Solution code:
n = int(input())
s = str(input())
ans = -1
ss = [1, 1]
sw = [1, -1]
ws = [-1, 1]
ww = [-1, -1]
line = [ss, sw, ws, ww]

for c in s[1:]:
    for s in line:
        if c == "o":
            if s[-1] == 1:
                s.append(s[-2])
            else:
                s.append(s[-2] * -1)
        else:
            if s[-1] == -1:
                s.append(s[-2])
            else:
                s.append(s[-2] * -1)

for s in line:
    if s[0] == s[-1]:
        if (s[0] == 1 and s[1] == s[-2]) or (s[0] == -1 and s[1] != s[-2]):
            ans = ""
            for i in s[:-1]:
                if i == 1:
                    ans += "S"
                else:
                    ans += "W"
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = str(input())
ans = -1
ss = [1, 1]
sw = [1, -1]
ws = [-1, 1]
ww = [-1, -1]
line = [ss, sw, ws, ww]

for c in s[1:]:
    for s in line:
        if c == "o":
            if s[-1] == 1:
                s.append(s[-2])
            else:
                s.append(s[-2] * -1)
        else:
            if s[-1] == -1:
                s.append(s[-2])
            else:
                s.append(s[-2] * -1)

for s in line:
    if s[0] == s[-1]:
        if s[0] == 1 and s[1] == s[-2] or s[0] == -1 and s[1] != s[-2]:
            ans = ""
            for i in s[:-1]:
                if i == 1:
                    ans += "S"
                else:
                    ans += "W"
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = str(input())
ans = -1
ss = [1, 1]
sw = [1, -1]
ws = [-1, 1]
ww = [-1, -1]
line = [ss, sw, ws, ww]

for c in s[1:]:
    for s in line:
        if c == "o":
            if s[-1] == 1:
                s.append(s[-2])
            else:
                s.append(s[-2] * -1)
        else:
            if s[-1] == -1:
                s.append(s[-2])
            else:
                s.append(s[-2] * -1)

for s in line:
    if s[-1] == s[0]:
        ans = ""
        for i in s[:-1]:
            if i == 1:
                ans += "S"
            else:
                ans += "W"
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
def point(main_animal,main_animal_answer,previous_animal):
    next_animal=''
    if main_animal=='S':
        if main_animal_answer=='o':
            next_animal=previous_animal
        else:
            if previous_animal=='W':
                next_animal='S'
            else:
                next_animal='W'
    else:
        if main_animal_answer=='x':
            next_animal=previous_animal
        else:
            if previous_animal=='W':
                next_animal='S'
            else:
                next_animal='W'
        

    
    
    return next_animal

def cheacker(main_animal,main_animal_answer,previous_animal,next_animal):
    if (main_animal=="S" and main_animal_answer=="o")or(main_animal=='W' and main_animal_answer=='x' ):
        if(previous_animal==next_animal):
            return True
        else:
            return False
    elif (main_animal=="S"and main_animal_answer=="x")or(main_animal=="W" and main_animal_answer=="o"):
        if(previous_animal!=next_animal):
            return True
        else:
            return False
    else:
        return False

def cheack_list(animal_list,answer_list):
    final_ans=True
    for i in range(1,len(animal_list)-2):
        if i==1:
            ans=cheacker(animal_list[i],answer_list[i],animal_list[len(animal_list)-1],animal_list[i+1])
        else:
            ans=cheacker(animal_list[i],answer_list[i],animal_list[i-1],animal_list[i+1])
        if ans==False:
            final_ans=False
        else:
            pass
    return final_ans

N=input()
str=input()
answer_list=[]
animal_list=[]
flag=True
final_answer=""
for i in str:
    answer_list.append(i)

animal_list.append("S")
animal_list.append("S")

for i in range(1,len(answer_list)-1):
    animal_list.append(point(animal_list[i],answer_list[i],animal_list[i-1]))

ans=cheack_list(animal_list,answer_list)
if ans:
    if flag:
        for i in range(0,len(answer_list)):
            final_answer+=animal_list[i]
    flag=False
del animal_list[:]

animal_list.append("S")
animal_list.append("W")

for i in range(1,len(answer_list)-1):
    animal_list.append(point(animal_list[i],answer_list[i],animal_list[i-1]))

ans=cheack_list(animal_list,answer_list)
if ans:
    if flag:
        for i in range(0,len(answer_list)):
            final_answer+=animal_list[i]
    flag=False
del animal_list[:]

animal_list.append("W")
animal_list.append("S")

for i in range(1,len(answer_list)-1):
    animal_list.append(point(animal_list[i],answer_list[i],animal_list[i-1]))

ans=cheack_list(animal_list,answer_list)
if ans:
    if flag:
        for i in range(0,len(answer_list)):
            final_answer+=animal_list[i]
    flag=False
del animal_list[:]

animal_list.append("W")
animal_list.append("W")

for i in range(1,len(answer_list)-1):
    animal_list.append(point(animal_list[i],answer_list[i],animal_list[i-1]))

ans=cheack_list(animal_list,answer_list)
if ans:
    if flag:
        for i in range(0,len(answer_list)):
            final_answer+=animal_list[i]
    flag=False
del animal_list[:]

if flag:
    print(-1)

else:
    print(final_answer)