Problem:


Score : 500 points

Problem Statement

Snuke, who loves animals, built a zoo.

There are N animals in this zoo. They are conveniently numbered 1 through N, and arranged in a circle.
The animal numbered i (2≤i≤N-1) is adjacent to the animals numbered i-1 and i+1. Also, the animal numbered 1 is adjacent to the animals numbered 2 and N, and the animal numbered N is adjacent to the animals numbered N-1 and 1.

There are two kinds of animals in this zoo: honest sheep that only speak the truth, and lying wolves that only tell lies.

Snuke cannot tell the difference between these two species, and asked each animal the following question: "Are your neighbors of the same species?" The animal numbered i answered s_i. Here, if s_i is o, the animal said that the two neighboring animals are of the same species, and if s_i is x, the animal said that the two neighboring animals are of different species.

More formally, a sheep answered o if the two neighboring animals are both sheep or both wolves, and answered x otherwise.
Similarly, a wolf answered x if the two neighboring animals are both sheep or both wolves, and answered o otherwise.

Snuke is wondering whether there is a valid assignment of species to the animals that is consistent with these responses. If there is such an assignment, show one such assignment. Otherwise, print -1.

Constraints

3 ≤ N ≤ 10^{5}

s is a string of length N consisting of o and x.

Input

The input is given from Standard Input in the following format:

N
s

Output

If there does not exist an valid assignment that is consistent with s, print -1.
Otherwise, print an string t in the following format. The output is considered correct if the assignment described by t is consistent with s.

t is a string of length N consisting of S and W.

If t_i is S, it indicates that the animal numbered i is a sheep. If t_i is W, it indicates that the animal numbered i is a wolf.

Sample Input 1

6
ooxoox

Sample Output 1

SSSWWS

For example, if the animals numbered 1, 2, 3, 4, 5 and 6 are respectively a sheep, sheep, sheep, wolf, wolf, and sheep, it is consistent with their responses. Besides, there is another valid assignment of species: a wolf, sheep, wolf, sheep, wolf and wolf.

Let us remind you: if the neiboring animals are of the same species, a sheep answers o and a wolf answers x. If the neiboring animals are of different species, a sheep answers x and a wolf answers o.

Sample Input 2

3
oox

Sample Output 2

-1

Print -1 if there is no valid assignment of species.

Sample Input 3

10
oxooxoxoox

Sample Output 3

SSWWSSSWWS



Sample input:
6
ooxoox


Sample output:
SSSWWS

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
a=['SS','SW','WS','WW']
for j in range(4):
    for i in range(1,n):
        if s[i]=='o':
            if a[j][i]=='S':
                if a[j][i-1]=='S':
                    a[j]+='S'
                else:
                    a[j]+='W'
            else:
                if a[j][i-1]=='S':
                    a[j]+='W'
                else:
                    a[j]+='S'
        else:
            if a[j][i]=='S':
                if a[j][i-1]=='S':
                    a[j]+='W'
                else:
                    a[j]+='S'
            else:
                if a[j][i-1]=='S':
                    a[j]+='S'
                else:
                    a[j]+='W'
ans='-1'
for j in range(4):
    if a[j][0]==a[j][-1]:
        if s[0]=='o' and a[j][-2]==a[j][1]:
            ans=a[j]
        if s[0]=='x' and a[j][-2]!=a[j][1]:
            ans=a[j]
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
s=input()
A=[list("SS"+"?"*(N-2)),list("WS"+"?"*(N-2)),list("SW"+"?"*(N-2)),list("WW"+"?"*(N-2))]
for a in A:
  for i in range(2,N):
    if a[i-2:i]==["S","S"] and s[i-1]=="o":
      a[i]="S"
    elif a[i-2:i]==["S","S"] and s[i-1]=="x":
      a[i]="W"
    elif a[i-2:i]==["W","S"] and s[i-1]=="o":
      a[i]="W"
    elif a[i-2:i]==["W","S"] and s[i-1]=="x":
      a[i]="S"
    elif a[i-2:i]==["S","W"] and s[i-1]=="o":
      a[i]="W"
    elif a[i-2:i]==["S","W"] and s[i-1]=="x":
      a[i]="S"
    elif a[i-2:i]==["W","W"] and s[i-1]=="o":
      a[i]="S"
    elif a[i-2:i]==["W","W"] and s[i-1]=="x":
      a[i]="W"
  if a[0:2]==["S","S"] and s[0]=="o" and a[-1]=="S":
    print("".join(a))
    exit()
  elif a[0:2]==["S","S"] and s[0]=="x" and a[-1]=="W":
    print("".join(a))
    exit()
  elif a[0:2]==["W","S"] and s[0]=="o" and a[-1]=="W":
    print("".join(a))
    exit()
  elif a[0:2]==["W","S"] and s[0]=="x" and a[-1]=="S":
    print("".join(a))
    exit()
  elif a[0:2]==["S","W"] and s[0]=="o" and a[-1]=="S":
    print("".join(a))
    exit()
  elif a[0:2]==["S","W"] and s[0]=="x" and a[-1]=="W":
    print("".join(a))
    exit()
  elif a[0:2]==["W","W"] and s[0]=="o" and a[-1]=="S":
    print("".join(a))
    exit()
  elif a[0:2]==["W","W"] and s[0]=="x" and a[-1]=="W":
    print("".join(a))
    exit()
print(-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
for c in ['SS','SW','WS','WW']:
    for d in range(1,n):
        if c[d] == 'S':
            if s[d] == 'o':
                c += c[d-1]
            elif c[d-1] == 'S':
                c += 'W'
            else:
                c += 'S'
        else:
            if s[d] == 'x':
                c += c[d-1]
            elif c[d-1] == 'S':
                c += 'W'
            else:
                c += 'S'
    if c[0] == 'S':
        if c[0] == c[-1]:
            print(c[:-1])
            exit()
    else:
        if c[0] != c[-1]:
            print(c[:-1])
            exit()
print(-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
for c in ['SS','SW','WS','WW']:
    for d in range(1,n):
        if c[d] == 'S':
            if s[d] == 'o':
                c += c[d-1]
            elif c[d-1] == 'S':
                c += 'W'
            else:
                c += 'S'
        else:
            if s[d] == 'x':
                c += c[d-1]
            elif c[d-1] == 'S':
                c += 'W'
            else:
                c += 'S'
    if c[0] == c[-1]:
        print(c[:-1])
        exit()
print(-1)

Submission status: Wrong Answer

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


def roop(St):
    for i in range(1,N):
        flag = 1
        if S[i] == 'x':
            flag *= -1
        if St[i] == 'W':
            flag *= -1
        if St[i-1] == 'W':
            flag *= -1
        if flag == 1:
            St += 'S'
        else:
            St += 'W'
    return St
ans = '-1'
candidate = ('SS','WS','SW','WW')
for i in candidate:
    a = roop(i)
    if a[0] == a[-1]:
        ans = a[0:N]
        break
print(ans)

Submission status: Wrong Answer

Solution code:
def getSpecies(sw, ox, swAdj):
    if (sw == 'S' and ox == 'o') or (sw == 'W' and ox == 'x'):
        return swAdj
    else:
        return 'SW'[swAdj == 'S']

N = int(input())
ss = input()

for pat in ['SS', 'SW', 'WS', 'WW']:
    anss = list(pat) + [''] * (N - 2)
    for i in range(1, N - 1):
        anss[i + 1] = getSpecies(anss[i], ss[i], anss[i - 1])

    if getSpecies(anss[-1], ss[-1], anss[-2]) == anss[0]:
        print(''.join(anss))
        break
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
def getSpecies(sw, ox, swAdj):
    if (sw == 'S' and ox == 'o') or (sw == 'W' and ox == 'x'):
        return swAdj
    else:
        return 'SW'[swAdj == 'S']

N = int(input())
ss = input()

for pat in ['SS', 'SW', 'WS', 'WW']:
    anss = list(pat) + [''] * (N - 2)
    for i in range(1, N - 1):
        anss[i + 1] = getSpecies(anss[i], ss[i], anss[i - 1])

    if getSpecies(anss[-1], ss[-1], anss[-2]) == anss[0]:
        print(''.join(anss))
        break

Submission status: Wrong Answer

Solution code:
N = int(input())

S = input()

start_set = []
#0番目と1番目を決めてから進める
start_set.append("SS") 
start_set.append("SW")
start_set.append("WS")
start_set.append("WW")
    
goal_set = []
if S[0] == "o":
    goal_set.append("SSS")
    goal_set.append("WSW")
    goal_set.append("WWS")
    goal_set.append("SWW")
else:
    goal_set.append("WSS")
    goal_set.append("SSW")
    goal_set.append("WWW")
    goal_set.append("SWS")
    
isok = False
for st in start_set:
    O = []
    O.append(st[0])
    O.append(st[1])
    for i in range(1,N-1):
        if O[i-1]=="S":
            if O[i]=="S": 
                if S[i]=="o":
                    O.append("S") #SSS
                else:
                    O.append("W") #SSW
            else:
                if S[i]=="o":
                    O.append("W") #SWW
                else:
                    O.append("S") #SWS
                
        if O[i-1]=="W":
            if O[i]=="S":
                if S[i]=="o":
                    O.append("W") #WSW
                else:
                    O.append("S") #WSS
            else:
                if S[i]=="o":
                    O.append("S") #WWS
                else:
                    O.append("W") #WWW
    #print(O)
    goals = O[-1]+O[0]+O[1]
    if goals in goal_set:
        isok = True
        break
                
if isok:
    print("".join(O))
else:
    print("-1")

Submission status: Wrong Answer

Solution code:
N = int(input())

S = input()

start_set = []
#0番目と1番目を決めてから進める
start_set.append("SS") 
start_set.append("SW")
start_set.append("WS")
start_set.append("WW")
    
isok = False
for st in start_set:
    O = []
    O.append(st[0])
    O.append(st[1])
    for i in range(1,N):
        if O[i-1]=="S":
            if O[i]=="S": #SS.
                if S[i]=="o":
                    O.append("S")
                else:
                    O.append("W")
            else: #SW.
                if S[i]=="o":
                    O.append("W")
                else:
                    O.append("S")
                
        if O[i-1]=="W":
            if O[i]=="S": #WS.
                if S[i]=="o":
                    O.append("W")
                else:
                    O.append("S")
            else: #WW.
                if S[i]=="o":
                    O.append("S")
                else:
                    O.append("W")
        if i==N-1:
            #print(O)
            if O[N]==O[0]:
                isok = True
                break
    if isok:break
                
if isok:
    print("".join(O[:-1]))
else:
    print("-1")

Submission status: Wrong Answer

Solution code:
N = int(input())

S = input()

start_set = []
#0番目と1番目を決めてから進める
if S[0] == "o":
    start_set.append("SS") 
    start_set.append("SW")
    start_set.append("WS")
else: #"x"
    start_set.append("SW")
    start_set.append("SS")
    start_set.append("WW")
    
isok = False
for st in start_set:
    goal = st[0]
    O = []
    O.append(st[0])
    O.append(st[1])
    for i in range(1,N):
        if O[i-1]=="S":
            if O[i]=="S": #SS.
                if S[i]=="o":
                    O.append("S")
                else:
                    O.append("W")
            else: #SW.
                if S[i]=="o":
                    O.append("W")
                else:
                    O.append("S")
                
        if O[i-1]=="W":
            if O[i]=="S": #WS.
                if S[i]=="o":
                    O.append("W")
                else:
                    O.append("S")
            else: #WW.
                if S[i]=="o":
                    O.append("S")
                else:
                    O.append("W")
        if i==N-1:
            #print(O)
            if O[N]==goal:
                isok = True
                break
    if isok:break
                
if isok:
    print("".join(O[:-1]))
else:
    print("-1")

Submission status: Wrong Answer

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

patterns=[("S","W"),("W","S"),("S","S"),("W","W")]

def solve(pattern):
  l=[True]*n
  l[0],l[1]=pattern
  for i in range(1,n-1):
    if (s[i]=="o" and l[i]=="S") or (s[i]=="x" and l[i]=="W"):
      l[i+1]=l[i-1]
    elif (s[i]=="x" and l[i]=="S") or (s[i]=="o" and l[i]=="W"):
      if l[i-1]=="S":
        l[i+1]="W"
      else:
        l[i+1]="S"
  if (s[-1]=="o" and l[-1]=="S") or (s[-1]=="x" and l[-1]=="W"):
    return (l[-2]==l[0],l)
  else:
    return (l[-2]!=l[0],l)

for pattern in patterns:
  res,string=solve(pattern)
  if res:
    print(*string,sep="")
    break
else:
  print(-1)

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
import copy

from math import *

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [int(input_raw[0])]
    input_raw = read_func().strip().split()
    [s] = [input_raw[0]]

    S_list = [["*" for i in range(N)] for i in range(4)]
    if s[0] == "o":
        S_list[0][-1] = "s"; S_list[0][0] = "w"; S_list[0][1] = "w"
        S_list[1][-1] = "w"; S_list[1][0] = "w"; S_list[1][1] = "s"
        S_list[2][-1] = "w"; S_list[2][0] = "s"; S_list[2][1] = "w"
        S_list[3][-1] = "s"; S_list[3][0] = "s"; S_list[3][1] = "s"

    else:
        S_list[0][-1] = "s"; S_list[0][0] = "w"; S_list[0][1] = "s"
        S_list[1][-1] = "w"; S_list[1][0] = "w"; S_list[1][1] = "w"
        S_list[2][-1] = "s"; S_list[2][0] = "s"; S_list[2][1] = "w"
        S_list[3][-1] = "w"; S_list[3][0] = "s"; S_list[3][1] = "s"

    rev = lambda x:"s" if x == "w" else "w"
    is_possible = False
    for S in S_list:
        for i in range(1, N - 1):
            R = i
            if s[R] == "o":
                if S[R] == "w":
                    SR = rev(S[R - 1])
                else:
                    SR= S[R - 1]
            else:
                if S[R] == "w":
                    SR = S[R - 1]
                else:
                    SR = rev(S[R - 1])
            if R + 1 < N - 1:
                S[R + 1] = SR
            else:
                if S[N - 1] == SR:
                    if (s[N - 1] == "o" and S[N - 1] == "s") or (s[N - 1] == "x" and S[N - 1] == "w"):
                        if S[N - 2] == S[0]:
                            is_possible = True
                            break;
                    if (s[N - 1] == "o" and S[N - 1] == "w") or (s[N - 1] == "x" and S[N - 1] == "s"):
                        if S[N - 2] != S[0]:
                            is_possible = True
                            break;

        if is_possible == True:
            print "".join(S)
            exit()

    print -1


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

ans = ["" for i in range(n)]


def solve():
    for i in range(n-2):
        if s[i] == "o" and ans[i] == "S" or s[i] == "x" and ans[i] == "W":
            ans[i+1] = ans[i-1]
        elif ans[i-1] == "S":
            ans[i+1] = "W"
        else:
            ans[i+1] = "S"

    if s[n-1] == "o" and ans[n-1] == "S" and ans[n-2] == ans[0]:
        return True
    if s[n-1] == "x" and ans[n-1] == "S" and ans[n-2] != ans[0]:
        return True
    if s[n-1] == "o" and ans[n-1] == "W" and ans[n-2] != ans[0]:
        return True
    if s[n-1] == "x" and ans[n-1] == "W" and ans[n-2] == ans[0]:
        return True

    return False


def main():
    ans[0] = ans[-1] = "S"
    if solve():
        print("".join(ans))
        exit()

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

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

    ans[0] = ans[-1] = "W"
    if solve():
        print("".join(ans))
        exit()

    print(-1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

ans = ["" for i in range(n)]


def solve():
    for i in range(n-2):
        if s[i] == "o" and ans[i] == "S" or s == "x" and ans[i] == "W":
            ans[i+1] = ans[i-1]
        elif ans[i-1] == "S":
            ans[i+1] = "W"
        else:
            ans[i+1] = "S"

    if s[n-1] == "o" and ans[n-1] == "S" and ans[n-2] == ans[0]:
        return True
    if s[n-1] == "x" and ans[n-1] == "S" and ans[n-2] != ans[0]:
        return True
    if s[n-1] == "o" and ans[n-1] == "W" and ans[n-2] != ans[0]:
        return True
    if s[n-1] == "x" and ans[n-1] == "W" and ans[n-2] == ans[0]:
        return True

    return False


def main():
    ans[0] = ans[-1] = "S"
    if solve():
        print("".join(ans))
        exit()

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

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

    ans[0] = ans[-1] = "W"
    if solve():
        print("".join(ans))
        exit()

    print(-1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

ans = ["" for i in range(n)]


def solve():
    for i in range(n-1):
        if s[i] == "o" and ans[i] == "S" or s == "x" and ans[i] == "W":
            ans[i+1] = ans[i-1]
        elif ans[i-1] == "S":
            ans[i+1] = "W"
        else:
            ans[i+1] = "S"

    if s[n-1] == "o" and ans[n-1] == "S" and ans[n-2] == ans[0]:
        return True
    if s[n-1] == "x" and ans[n-1] == "S" and ans[n-2] != ans[0]:
        return True
    if s[n-1] == "o" and ans[n-1] == "W" and ans[n-2] != ans[0]:
        return True
    if s[n-1] == "x" and ans[n-1] == "W" and ans[n-2] == ans[0]:
        return True

    return False


def main():
    ans[0] = ans[-1] = "S"
    if solve():
        print("".join(ans))
        exit()

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

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

    ans[0] = ans[-1] = "W"
    if solve():
        print("".join(ans))
        exit()

    print(-1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
ans = [[True,True],[True,False],[False,True],[False,False]]
for i in range(n):
    c = (s[i] == 'o')
    for j in ans:
        if j[-1] : c = (not c)
        if c:
            j.append(not j[-2])
        else:
            j.append(j[-2])
for j in ans:
    if j[0] == j[n] and j[1] == j[n+1]:
        print("".join(list(map(lambda x: "S" if x else "W", j[1:-1]))))
        break
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
ans = [[True,True],[True,False],[False,True],[False,False]]
for i in range(1,n):
    c = (s[i] == 'o')
    for j in ans:
        if not j[-1] : c = not c
        if c:
            j.append(j[-2])
        else:
            j.append(not j[-2])
c = (s[0] == 'o')
for j in ans:
    '''
    if not j[0]: c = not c
    if c and j[-1] == j[1] or not c and j[-1] != j[1]:
        print("".join(list(map(lambda x: "S" if x else "W", j[:-1]))))
        break
    '''
    if j[0] != j[-1]: continue
    for k in range(1,n):
        flag = False
        if not (j[k] and j[k-1] == j[k+1] and s[k] == 'o' or j[k] and j[k-1] != j[k+1] and s[k] == 'x' or not j[k] and j[k-1] == j[k+1] and s[k] == 'x' or not j[k] and j[k-1] != j[k+1] and s[k] == 'o'):
            flag = True
            break
    if flag:
        continue
    else:
        if ( j[0] and j[n-1] == j[1] and s[0] == 'o' or j[0] and j[n-1] != j[1] and s[0] == 'x' or not j[0] and j[n-1] == j[1] and s[0] == 'x' or not j[0] and j[n-1] != j[1] and s[0] == 'o'):
            print("".join(list(map(lambda x: "S" if x else "W", j[:-1]))))
            break
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
ans = [[True,True],[True,False],[False,True],[True,True]]
for i in range(1,n):
    c = (s[i] == 'o')
    for j in ans:
        if not j[-1] : c = not c
        if c:
            j.append(j[-2])
        else:
            j.append(not j[-2])
c = (s[0] == 'o')
for j in ans:
    '''
    if not j[0]: c = not c
    if c and j[-1] == j[1] or not c and j[-1] != j[1]:
        print("".join(list(map(lambda x: "S" if x else "W", j[:-1]))))
        break
    '''
    if j[0] != j[-1]: continue
    for k in range(1,n):
        flag = False
        if not (j[k] and j[k-1] == j[k+1] and s[k] == 'o' or j[k] and j[k-1] != j[k+1] and s[k] == 'x' or not j[k] and j[k-1] == j[k+1] and s[k] == 'x' or not j[k] and j[k-1] != j[k+1] and s[k] == 'o'):
            flag = True
            break
    if flag:
        continue
    else:
        if ( j[0] and j[n-1] == j[1] and s[0] == 'o' or j[0] and j[n-1] != j[1] and s[0] == 'x' or not j[0] and j[n-1] == j[1] and s[0] == 'x' or not j[0] and j[n-1] != j[1] and s[0] == 'o'):
            print("".join(list(map(lambda x: "S" if x else "W", j[:-1]))))
            break
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
ans = [[True,True],[True,False],[False,True],[True,True]]
for i in range(1,n):
    c = (s[i] == 'o')
    for j in ans:
        if not j[-1] : c = not c
        if c:
            j.append(j[-2])
        else:
            j.append(not j[-2])
c = (s[0] == 'o')
for j in ans:
    '''
    if not j[0]: c = not c
    if c and j[-1] == j[1] or not c and j[-1] != j[1]:
        print("".join(list(map(lambda x: "S" if x else "W", j[:-1]))))
        break
    '''
    if j[0] != j[-1]: continue
    for k in range(1,n):
        flag = False
        if not (j[k] and j[k-1] == j[k+1] and s[k] == 'o' or j[k] and j[k-1] != j[k+1] and s[k] == 'x' or not j[k] and j[k-1] == j[k+1] and s[k] == 'x' or not j[k] and j[k-1] != j[k+1] and s[k] == 'o'):
            flag = True
            break
    if flag:
        continue
    else:
        print("".join(list(map(lambda x: "S" if x else "W", j[:-1]))))
        break
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
ans = [[True,True],[True,False],[False,True],[True,True]]
for i in range(1,n):
    c = (s[i] == 'o')
    for j in ans:
        if not j[-1] : c = not c
        if c:
            j.append(j[-2])
        else:
            j.append(not j[-2])
c = (s[0] == 'o')
for j in ans:
    '''
    if not j[0]: c = not c
    if c and j[-1] == j[1] or not c and j[-1] != j[1]:
        print("".join(list(map(lambda x: "S" if x else "W", j[:-1]))))
        break
    '''
    if j[0] != j[-1]: continue
    for k in range(n):
        flag = False
        if not (j[k] and j[k-1] == j[k+1] and s[k] == 'o' or j[k] and j[k-1] != j[k+1] and s[k] == 'x' or not j[k] and j[k-1] == j[k+1] and s[k] == 'x' or not j[k] and j[k-1] != j[k+1] and s[k] == 'o'):
            flag = True
            break
    if flag:
        continue
    else:
        print("".join(list(map(lambda x: "S" if x else "W", j[:-1]))))
        break
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
ans = [[True,True],[True,False],[False,True],[True,True]]
for i in range(1,n):
    c = (s[i] == 'o')
    for j in ans:
        if not j[-1] : c = not c
        if c:
            j.append(j[-2])
        else:
            j.append(not j[-2])
c = (s[0] == 'o')
for j in ans:
    if j[0] != j[-1] : continue
    if not j[0]: c = not c
    if c and j[-1] == j[1] or not c and j[-1] != j[1]:
        print("".join(list(map(lambda x: "S" if x else "W", j[:-1]))))
        break
else:
    print(-1)

Submission status: Wrong Answer

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

ans = ["SS", "SW", "WS", "WW"]

for i in range(4):
    for j in range(1, n + 1):
        if s[j - 1] == "o":
            if ans[i][j] == "S":
                if ans[i][j - 1] == "S":
                    ans[i] += "S"
                else:
                    ans[i] += "W"
            else:
                if ans[i][j - 1] == "S":
                    ans[i] += "W"
                else:
                    ans[i] += "S"
        else:
            if ans[i][j] == "S":
                if ans[i][j - 1] == "S":
                    ans[i] += "W"
                else:
                    ans[i] += "S"
            else:
                if ans[i][j - 1] == "S":
                    ans[i] += "S"
                else:
                    ans[i] += "W"
    print(ans)

    if ans[i][0] == ans[i][n] and ans[i][1] == ans[i][n + 1]:
        flag = True
    else:
        flag = False

    if flag:
        idx = i
        break

if flag:
    print(ans[idx][1:n + 1])
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
def menagerie_2():
	n = int(raw_input())
	ans = str(raw_input())

	def check_possibility(at, a):
		re = ['#']*len(a)
		re[0] = at[0]
		re[1] = at[1]
		for i in range(1, n-1):
			if a[i]=='o':
				if re[i]==1:
					re[i+1] = re[i-1]
				else:
					re[i+1] = re[i-1]*-1
			else:
				if re[i]==1:
					re[i+1] = re[i-1]*-1
				else:
					re[i+1] = re[i-1]

		c1 = False
		c2 = False
		if a[0]=='o':
			if re[0]==1 and (re[1]*re[-1]==1):
				c1 = True
			elif re[0]==-1 and (re[1]*re[-1]==-1):
				c1 = True
		else:
			if re[0]==1 and (re[1]*re[-1]==-1):
				c1 = True
			elif re[0]==-1 and (re[1]*re[-1]==1):
				c1 = True
		if a[-1]=='o':
			if re[-1]==1 and (re[0]*re[-2]==1):
				c2 = True
			elif re[-1]==-1 and (re[0]*re[-2]==-1):
				c2 = True
		else:
			if re[-1]==1 and (re[0]*re[-2]==-1):
				c2 = True
			elif re[-1]==-1 and (re[0]*re[-2]==1):
				c2 = True
		if c1 and c2:
			return re
		else:
			return None

	if check_possibility([1,1], ans) is not None:
		op = ['s' if x == 1 else 'w' for x in check_possibility([1,1], ans)]
		print''.join(op)
	elif check_possibility([1,-1], ans) is not None:
		op = ['s' if x == 1 else 'w' for x in check_possibility([1,-1], ans)]
		print''.join(op)
	elif check_possibility([-1,1], ans) is not None:
		op = ['s' if x == 1 else 'w' for x in check_possibility([-1,1], ans)]
		print''.join(op)
	elif check_possibility([-1,-1], ans) is not None:
		op = ['s' if x == 1 else 'w' for x in check_possibility([-1,-1], ans)]
		print''.join(op)
	else:
		print -1


if __name__ == "__main__":
	menagerie_2()

Submission status: Wrong Answer

Solution code:
def menagerie():
	# The key idea is that, if we konw the first two animals
	# by input, we could derive all the others
	n = int(raw_input())
	ans = str(raw_input())

	def _check(f, s, ans):
		siz = len(ans)
		re = ['#']*siz
		re[0] = f
		re[1] = s
		for i in range(1, siz-1):
			_temp_ans = ans[i]
			if re[i]==1:
				if _temp_ans=='o':
					re[i+1] = re[i-1]
				else:
					re[i + 1] = re[i - 1]*(-1)
			if re[i]==-1:
				if _temp_ans=='o':
					re[i+1] = re[i-1]*(-1)
				else:
					re[i + 1] = re[i - 1]
		# check ans[0] and ans[-1]
		c1 = False
		c2 = False
		if re[1]*re[-1]==1:
			if re[0]==1 and ans[0]=='o':
				c1 = True
			if re[0]==-1 and ans[0]=='x':
				c1 = True
		else:
			if re[0]==1 and ans[0]=='x':
				c1 = True
			if re[0]==-1 and ans[0]=='o':
				c1 = True

		if re[-2]*re[0]==1:
			if re[-1]==1 and ans[-1]=='o':
				c2 = True
			if re[-1]==-1 and ans[-1]=='x':
				c2 = True
		else:
			if re[-1]==1 and ans[-1]=='x':
				c2 = True
			if re[-1]==-1 and ans[-1]=='o':
				c2 = True
		if c1 and c2:
			return re
		else:
			return -1
	# w:-1; s:1
	re1 = _check(-1, -1, ans)
	re2 = _check(-1, 1, ans)
	re3 = _check(1, 1, ans)
	re4 = _check(1, -1, ans)

	if re1 != -1:
		op = ['s' if x==1 else 'w' for x in re1]
		print ''.join(op)
		return
	if re2 != -1:
		op = ['s' if x==1 else 'w' for x in re2]
		print ''.join(op)
		return
	if re3 != -1:
		op = ['s' if x==1 else 'w' for x in re3]
		print ''.join(op)
		return
	if re4 != -1:
		op = ['s' if x==1 else 'w' for x in re4]
		print ''.join(op)
		return
	print -1

if __name__ == "__main__":
	menagerie()

Submission status: Wrong Answer

Solution code:
def solve(pos0_is_sheep, pos1_is_sheep):
    pre_is_sheep = pos1_is_sheep
    prepre_is_sheep = pos0_is_sheep
    ans = [pos0_is_sheep]
    for is_same_neighbors in s[1:]:
        ans.append(pre_is_sheep)
        if pre_is_sheep:
            pre_is_sheep = is_same_neighbors == prepre_is_sheep
            prepre_is_sheep = True
        else:
            pre_is_sheep = is_same_neighbors != prepre_is_sheep
            prepre_is_sheep = False
    if pos0_is_sheep != pre_is_sheep:
        return False
    if pos0_is_sheep and prepre_is_sheep != pos1_is_sheep:
        return False
    if not pos0_is_sheep and prepre_is_sheep == pos1_is_sheep:
        return False
    return ans


n = int(input())
s = [c == 'o' for c in input().strip()]

for pos0_is_sheep, pos1_is_sheep in ((1, 1), (1, 0), (0, 1), (0, 0)):
    result = solve(pos0_is_sheep, pos1_is_sheep)
    if result:
        print(''.join('WS'[is_sheep] for is_sheep in result))
        break
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
def solve(pos0_is_sheep, pos1_is_sheep):
    pre_is_sheep = pos1_is_sheep
    prepre_is_sheep = pos0_is_sheep
    ans = [pos0_is_sheep]
    for is_same_neighbors in s[1:]:
        ans.append(pre_is_sheep)
        if pre_is_sheep:
            pre_is_sheep = is_same_neighbors == prepre_is_sheep
            prepre_is_sheep = True
        else:
            pre_is_sheep = is_same_neighbors ^ prepre_is_sheep
            prepre_is_sheep = False
    if pos0_is_sheep != pre_is_sheep:
        return False
    if pos0_is_sheep and prepre_is_sheep != pos1_is_sheep:
        return False
    if not pos0_is_sheep and prepre_is_sheep == pos1_is_sheep:
        return False
    return ans


n = int(input())
s = [c == 'o' for c in input().strip()]

for pos0_is_sheep, pos1_is_sheep in ((1, 1), (1, 0), (0, 1), (0, 0)):
    result = solve(pos0_is_sheep, pos1_is_sheep)
    if result:
        print(''.join('WS'[is_sheep] for is_sheep in result))
        break
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
a = int(input())
s = input()
l = len(s)
target = [None for x in s]
target[0] = True
target[1] = True


def fill(b, n, i):
    if s[i] == "o":
        target[b] = target[n] if target[i] else not target[n]
    else:
        target[b] = not target[n] if target[i] else target[n]


def jud(b, n, i):
    if s[i] == "o":
        return target[b] == (target[n] if target[i] else not target[n])
    else:
        return target[b] == (not target[n] if target[i] else target[n])
    

def result(s1, s2):
    global target
    target = [None for x in s]
    target[0] = s1
    target[1] = s2
    for i in range(1, len(s)):
        b, n = i - 1, (i + 1) % l
        fill(n, b, i)
    return jud(-1, 1, 0)

for p in [[True, True], [True, False], [False, True], [False, False]]:
    if result(*p):
        print("".join(["S" if x else "W" for x in target]))
        break
else:
    print(-1)