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

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

Solution (Python):
N = int(input())
S = input()
if N == 3:
    if S == "ooo":
        print("SSS")
    elif S == "xxx":
        print("SSW")
    else:
        print(-1)
    exit()
def solve(first, second):
    R = [None] * N
    R[0] = first
    if (S[0] == "o" and R[0] == "S") or (S[0] == "x" and R[0] == "W"):
        R[1] = R[-1] = second
    else:
        R[1] = second
        R[-1] = "S" if second != "S" else "W"
    for i, s in enumerate(S):
        if i == 0:
            continue
        if (s == "o" and R[i] == "S") or (s == "x" and R[i] == "W"):
            new = R[i - 1]
        else:
            new = "W" if R[i - 1] != "W" else "S"
        if i == N - 2:
            if new != R[i + 1]:
                return False, None
        if i == N - 1:
            if new != R[0]:
                return False, None
            else:
                return True, R
        R[i + 1] = new
for f, s in [("S", "S"), ("S", "W"), ("W", "S"), ("W", "W")]:
    ok, result = solve(f, s)
    if ok:
        print("".join(result))
        break
else:
    print(-1)

Solution (Python):


N=input()
s=raw_input()

def f(i):
    return i%len(s)

def ok(buf):
    for i in range(len(buf)):
        if buf[i]:
            if s[i] == "o":
                if buf[f(i-1)] != buf[f(i+1)]: return False
            else:
                if buf[f(i-1)] == buf[f(i+1)]: return False
        else:
            if s[i] == "o":
                if buf[f(i-1)] == buf[f(i+1)]: return False
            else:
                if buf[f(i-1)] != buf[f(i+1)]: return False            
    return True

OK=[]

for b in range(1<<3):
    buf=[None] * N
    if b&0b001:buf[0]=True
    else:buf[0]=False
    if (b&0b010)>>1:buf[1]=True
    else:buf[1]=False
    if (b&0b100)>>2:buf[-1]=True
    else:buf[-1]=False

    for i in range(2, N-1):
        if s[i-1] == "o":
            if buf[i-1]:
                buf[i]=buf[i-2]
            else:
                buf[i]=not buf[i-2]
        else:
            if buf[i-1]:
                buf[i]=not buf[i-2]
            else:
                buf[i]=buf[i-2]
    if ok(buf):
        OK.append("".join("S" if b else "W" for b in buf))
if len(OK)==0:
    print(-1)
else:
    print(OK[0])

Solution (Python):
import sys

def check(pos, S, index):
    N = len(S)
    right = (index + 1) % N
    left = (index + (N - 1)) % N

    if pos[index] == 0:
        if S[index] == 'o':
            return pos[left] == pos[right]
        else:
            return pos[left] != pos[right]
    else:
        if S[index] == 'o':
            return pos[left] != pos[right]
        else:
            return pos[left] == pos[right]


def make_pos(pos, S):
    """Sheep: 0, Wolf: 1"""
    N = len(S)
    for i in range(1, N-1):
        if pos[i] == 0:
            if S[i] == 'o':
                pos[i+1] = pos[i-1]
            else:
                pos[i+1] = (pos[i-1] + 1) % 2

        else:
            if S[i] == 'o':
                pos[i+1] = (pos[i-1] + 1) % 2
            else:
                pos[i+1] = pos[i-1]

    if check(pos, S, 0) and check(pos, S, N-1):
        return pos
    else:
        return False


def main():
    input = sys.stdin.readline
    N = int(input())
    S = str(input().strip())

    
    pos = [-1 for _ in range(N)]
    pos[0] = 0
    pos[1] = 0
    pos = make_pos(pos, S)
    if pos:
        ans = ['S' if n == 0 else 'W' for n in pos]
        return ''.join(ans)

    
    pos = [-1 for _ in range(N)]
    pos[0] = 0
    pos[1] = 1
    pos = make_pos(pos, S)
    if pos:
        ans = ['S' if n == 0 else 'W' for n in pos]
        return ''.join(ans)

    
    pos = [-1 for _ in range(N)]
    pos[0] = 1
    pos[1] = 0
    pos = make_pos(pos, S)
    if pos:
        ans = ['S' if n == 0 else 'W' for n in pos]
        return ''.join(ans)

    
    pos = [-1 for _ in range(N)]
    pos[0] = 1
    pos[1] = 1
    pos = make_pos(pos, S)
    if pos:
        ans = ['S' if n == 0 else 'W' for n in pos]
        return ''.join(ans)

    return -1


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

Solution (Python):
n=int(input())
a=input()
s="SW"
for d in range(2):
    for c in range(2):
        k=s[d]+s[c]
        for i in range(2,n+2):
            if k[i-1]=="S":
                if a[(i-1)%n]=="o":
                    k+=k[i-2]
                else:
                    k+=("W" if k[i-2]=="S" else "S")
            else:
                if a[(i-1)%n]=="o":
                    k+=("W" if k[i-2]=="S" else "S")
                else:
                    k+=k[i-2]
        else:
            if k[0]==k[-2] and k[1]==k[-1]:
                print(k[:-2])
                exit()
else:
    print(-1)

Solution (Python):
def menagerie(N: int, s: str) -> str:
    

    
    
    is_sheeps = [[None] * N for _ in range(4)]

    
    is_sheeps[0][:2] = True, True
    
    is_sheeps[1][:2] = True, False
    
    is_sheeps[2][:2] = False, True
    
    is_sheeps[3][:2] = False, False

    for n in range(1, N):
        for is_sheep in is_sheeps:
            if (s[n] == 'o') == is_sheep[n]:
                
                
                is_sheep[(n + 1) % N] = is_sheep[n - 1]
            else:
                
                
                is_sheep[(n + 1) % N] = not is_sheep[n - 1]

    for i, is_sheep in enumerate(is_sheeps):
        if is_sheep[0] != (i // 2 == 0):
            
            
            continue
        if ((s[0] == 'o') == is_sheep[0]) != (is_sheep[1] == is_sheep[-1]):
            
            
            continue
        return ''.join('S' if b else 'W' for b in is_sheep)

    return '-1'


if __name__ == "__main__":
    N = int(input())
    s = input()
    ans = menagerie(N, s)
    print(ans)

Solution (Python):
def menagerie(N: int, s: str) -> str:
    

    
    
    is_sheeps = [[None] * N for _ in range(4)]

    
    is_sheeps[0][:2] = True, True
    
    is_sheeps[1][:2] = True, False
    
    is_sheeps[2][:2] = False, True
    
    is_sheeps[3][:2] = False, False

    for n in range(1, N):
        for is_sheep in is_sheeps:
            if (s[n] == 'o') == is_sheep[n]:
                
                
                is_sheep[(n + 1) % N] = is_sheep[n - 1]
            else:
                
                
                is_sheep[(n + 1) % N] = not is_sheep[n - 1]

    for i, is_sheep in enumerate(is_sheeps):
        if is_sheep[0] == (i // 2 == 0) and ((s[0] == 'o') == is_sheep[0]) == (is_sheep[1] == is_sheep[-1]):
            return ''.join('S' if b else 'W' for b in is_sheep)

    return '-1'


if __name__ == "__main__":
    N = int(input())
    s = input()
    ans = menagerie(N, s)
    print(ans)

Solution (Python):
def is_ok(idx):
    flg = False
    bf = (idx - 1) % N
    af = (idx + 1) % N

    if t[idx] == 'S':
        if s[idx] == 'o':
            if t[af] == t[bf]:
                flg = True
        else:
            if t[af] != t[bf]:
                flg = True
    else:
        if s[idx] == 'x':
            if t[af] == t[bf]:
                flg = True
        else:
            if t[af] != t[bf]:
                flg = True
    return flg


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

ans = ['-1']
flg = False
for first in 'SW':
    for second in 'SW':
        t = [None for _ in range(N)]
        t[0] = first
        t[1] = second
        for i, ss in enumerate(s):
            if i <= 1: continue

            if t[i - 1] == 'S':
                if s[i - 1] == 'o':
                    t[i] = t[i - 2]
                else:
                    t[i] = 'W' if t[i - 2] == 'S' else 'S'
            else:
                if s[i - 1] == 'o':
                    t[i] = 'W' if t[i - 2] == 'S' else 'S'
                else:
                    t[i] = t[i - 2]
            
        

        if is_ok(0) and is_ok(N - 1):
            flg = True
            ans = t
            break

    if flg: break

print(''.join(ans))

Solution (Python):
n=int(input())
s=list(input())
s.append(s[0])
f=0
l=['S','S']
for j in range(4):
  for i in range(1,n+1):
    if l[i]=='S':
      if l[i-1]=='S':
        if s[i]=='o':
          l.append('S')
        else:
          l.append('W')
      else:
        if s[i]=='o':
          l.append('W')
        else:
          l.append('S')
    else:
      if l[i-1]=='S':
        if s[i]=='o':
          l.append('W')
        else:
          l.append('S')
      else:
        if s[i]=='o':
          l.append('S')
        else:
          l.append('W')
  if l[n+1]==l[1] and l[n]==l[0]:
    f=1
    break
  else:
    if j==0:
      l=['S','W']
    elif j==1:
      l=['W','S']
    elif j==2:
      l=['W','W']
    else:
      break
if f==0:
  print(-1)
else:
  l.pop()
  l.pop()
  print(''.join(l))

Solution (Python):
N = int(input())
s = input()
for t in ["SS","SW","WS","WW"]:
    for i in range(1,N-1):
        if (s[i] =="o" and t[i]=="S") or (s[i]=="x" and t[i]=="W"):
            t += t[i-1]
        else:
            if t[i-1] =="S":
              t += "W"
            else:
              t +="S"
    if (t[N-2]==t[0] and ((s[N-1]=="o" and t[N-1]=="S") or (s[N-1]=="x" and t[N-1]=="W"))) or (t[N-2]!=t[0] and ((s[N-1]=="o" and t[N-1]=="W") or (s[N-1]=="x" and t[N-1]=="S"))):
         if (t[N-1]==t[1] and ((s[0]=="o" and t[0]=="S") or (s[0]=="x" and t[0]=="W"))) or (t[N-1]!=t[1] and ((s[0]=="o" and t[0]=="W") or (s[0]=="x" and t[0]=="S"))):
             print(t)
             break
else:
    print(-1)

Solution (Python):
def check(N, S, ans):
    for i in range(N):
        if (ans[i] == "S") ^ (S[i] == "o"):
            if ans[(i-1) % N] == ans[(i+1) % N]:
                return False
        else:
            if ans[(i-1) % N] != ans[(i+1) % N]:
                return False
    return True


def main():
    N = int(input())
    S = input()
    initials = ["SS", "SW", "WS", "WW"]
    for init in initials:
        ans = [""] * N
        ans[0] = init[0]
        ans[1] = init[1]
        for i in range(1, N-1):
            if (ans[i] == "S") ^ (S[i] == "o"):
                ans[i+1] = "W" if ans[i-1] == "S" else "S"
            else:
                ans[i+1] = ans[i-1]
        if check(N, S, ans):
            print("".join(ans))
            return
    print(-1)


if __name__ == "__main__":
    main()

Solution (Python):
N=int(input())
s=input()
flag=False
def check(s,bef,now,nex):
    if s=='o':
        if now=='S':
            if bef==nex:return True
        elif now=='W':
            if bef!=nex:return True
    elif s=='x':
        if now=='S':
            if bef!=nex:return True
        elif now=='W':
            if bef==nex:return True
    return False

for x in ['SS','SW','WS','WW']:
    if flag==True:break
    ans=x
    bef,now=x[0],x[1]
    for i in range(2,N):
        if s[i-1]=='o':
            if bef==now:
                ans+='S'
                bef,now=now,'S'
            elif bef!=now:
                ans+='W'
                bef,now=now,'W'
        elif s[i-1]=='x':
            if bef!=now:
                ans+='S'
                bef,now=now,'S'
            elif bef==now:
                ans+='W'
                bef,now=now,'W'
    if check(s[N-1],ans[N-2],ans[N-1],ans[0])==True and check(s[0],ans[N-1],ans[0],ans[1])==True:
        flag=True
        break
if flag==False:print('-1')
else:print(ans)

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

for fs in ["SS","SW","WW","WS"]:
    ANS=["A"]*N
    ANS[0],ANS[1]=fs[0],fs[1]
    for i in range(2,N):
        if ANS[i-1]=="S":
            if S[i-1]=="o":
                if ANS[i-2]=="S":
                    ANS[i]="S"

                else:
                    ANS[i]="W"

            else:
                if ANS[i-2]=="S":
                    ANS[i]="W"

                else:
                    ANS[i]="S"

        else:
            if S[i-1]=="o":
                if ANS[i-2]=="S":
                    ANS[i]="W"

                else:
                    ANS[i]="S"

            else:
                if ANS[i-2]=="S":
                    ANS[i]="S"

                else:
                    ANS[i]="W"

    if ANS[0]=="S":
        if S[0]=="o":
            if ANS[-1]!=ANS[1]:
                continue
        else:
            if ANS[-1]==ANS[1]:
                continue
    else:
        if S[0]=="o":
            if ANS[-1]==ANS[1]:
                continue
        else:
            if ANS[-1]!=ANS[1]:
                continue

    if ANS[-1]=="S":
        if S[-1]=="o":
            if ANS[-2]!=ANS[0]:
                continue
        else:
            if ANS[-2]==ANS[0]:
                continue
    else:
        if S[-1]=="o":
            if ANS[-2]==ANS[0]:
                continue
        else:
            if ANS[-2]!=ANS[0]:
                continue

    print("".join(ANS))
    break
else:
    print(-1)

Solution (Python):

import sys

def main():
	n = int(input())
	tmp = input()
	ans = list(tmp)
	
	ans_Q = []
	case = [["." for _ in range(n)] for _ in range(4)]
	case[0][0] = "S"
	case[0][1] = "S"
	case[1][0] = "W"
	case[1][1] = "W"
	case[2][0] = "S"
	case[2][1] = "W"
	case[3][0] = "W"
	case[3][1] = "S"
	
	for case_o in case:
		for i in range(1, n-1):
			if case_o[i] == "S" and ans[i] == "o":
				case_o[i+1] = case_o[i-1]
				continue
			if case_o[i] == "S" and ans[i] == "x":
				case_o[i+1] = run(case_o[i-1])
				continue
			if case_o[i] == "W" and ans[i] == "o":
				case_o[i+1] = run(case_o[i-1])
				continue
			if case_o[i] == "W" and ans[i] == "x":
				case_o[i+1] = case_o[i-1]
				continue
				
		if case_o[n-1] == "S" and ans[n-1] == "o":
			if case_o[0] == case_o[n-2]:
				if case_o[0] == "S" and ans[0] == "o":
					if case_o[1] == case_o[n-1]:
						ans_Q = case_o
						break
				if case_o[0] == "S" and ans[0] == "x":
					if case_o[1] != case_o[n-1]:
						ans_Q = case_o
						break
				if case_o[0] == "W" and ans[0] == "o":
					if case_o[1] != case_o[n-1]:
						ans_Q = case_o
						break
				if case_o[0] == "W" and ans[0] == "x":
					if case_o[1] == case_o[n-1]:
						ans_Q = case_o
						break
		if case_o[n-1] == "S" and ans[n-1] == "x":
			if case_o[0] != case_o[n-2]:
				if case_o[0] == "S" and ans[0] == "o":
					if case_o[1] == case_o[n-1]:
						ans_Q = case_o
						break
				if case_o[0] == "S" and ans[0] == "x":
					if case_o[1] != case_o[n-1]:
						ans_Q = case_o
						break
				if case_o[0] == "W" and ans[0] == "o":
					if case_o[1] != case_o[n-1]:
						ans_Q = case_o
						break
				if case_o[0] == "W" and ans[0] == "x":
					if case_o[1] == case_o[n-1]:
						ans_Q = case_o
						break
		if case_o[n-1] == "W" and ans[n-1] == "o":
			if case_o[0] != case_o[n-2]:
				if case_o[0] == "S" and ans[0] == "o":
					if case_o[1] == case_o[n-1]:
						ans_Q = case_o
						break
				if case_o[0] == "S" and ans[0] == "x":
					if case_o[1] != case_o[n-1]:
						ans_Q = case_o
						break
				if case_o[0] == "W" and ans[0] == "o":
					if case_o[1] != case_o[n-1]:
						ans_Q = case_o
						break
				if case_o[0] == "W" and ans[0] == "x":
					if case_o[1] == case_o[n-1]:
						ans_Q = case_o
						break
		if case_o[n-1] == "W" and ans[n-1] == "x":
			if case_o[0] == case_o[n-2]:
				if case_o[0] == "S" and ans[0] == "o":
					if case_o[1] == case_o[n-1]:
						ans_Q = case_o
						break
				if case_o[0] == "S" and ans[0] == "x":
					if case_o[1] != case_o[n-1]:
						ans_Q = case_o
						break
				if case_o[0] == "W" and ans[0] == "o":
					if case_o[1] != case_o[n-1]:
						ans_Q = case_o
						break
				if case_o[0] == "W" and ans[0] == "x":
					if case_o[1] == case_o[n-1]:
						ans_Q = case_o
						break
	
	if len(ans_Q) == 0:
		print(-1)
	else:
		word = ""
		for w in ans_Q:
			word = word + w
		print(word)
	
def run(cher):
	if cher == "W":
		return "S"
	else:
		return "W"
		
if __name__ == "__main__":
	main()

Solution (Python):

from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007






"""
n,m = LI()
if m <= 2*n:print(m//2)
else:
    ans = n
    m -= 2*n
    ans += m//4
    print(ans)
"""


def f(a,b,c):
    k = a^b
    if c == "x":
        k = 1-k
    return k
n = I()
s = S()
s.append(s[0])
na = ["S","W"]
pre = [0,0]
for i in range(1,n+1):
    pre.append(f(pre[-2],pre[-1],s[i]))
if pre[0] == pre[-2] and pre[1] == pre[-1]:
    for i in range(n-1):
        print(na[pre[i]],end = "")
    print(na[pre[n-1]])
    quit()
pre = [0,1]
for i in range(1,n+1):
    pre.append(f(pre[-2],pre[-1],s[i]))
if pre[0] == pre[-2] and pre[1] == pre[-1]:
    for i in range(n-1):
        print(na[pre[i]],end = "")
    print(na[pre[n-1]])
    quit()
pre = [1,0]
for i in range(1,n+1):
    pre.append(f(pre[-2],pre[-1],s[i]))
if pre[0] == pre[-2] and pre[1] == pre[-1]:
    for i in range(n-1):
        print(na[pre[i]],end = "")
    print(na[pre[n-1]])
    quit()
pre = [1,1]
for i in range(1,n+1):
    pre.append(f(pre[-2],pre[-1],s[i]))
if pre[0] == pre[-2] and pre[1] == pre[-1]:
    for i in range(n-1):
        print(na[pre[i]],end = "")
    print(na[pre[n-1]])
    quit()
print(-1)

Solution (Python):
def solver(array):
    for index in range(1, n+1):
        if index == n:
            index = 0
        if array[index] == "S" and s[index]:
            if index == n - 1:
                if array[index-1] != array[0]:
                    return False
                else:
                    continue
            if index == 0:
                if array[-1] != array[1]:
                    return False
                else:
                    continue
            array[index + 1] = array[index - 1]
        elif array[index] == "S" and not s[index]:
            if index == n - 1:
                if array[index-1] == array[0]:
                    return False
                else:
                    continue
            if index == 0:
                if array[-1] == array[1]:
                    return False
                else:
                    continue
            if array[index - 1] == "W":
                array[index + 1] = "S"
            else:
                array[index + 1] = "W"
        elif array[index] == "W" and s[index]:
            if index == n - 1:
                if array[index-1] == array[0]:
                    return False
                else:
                    continue
            if index == 0:
                if array[-1] == array[1]:
                    return False
                else:
                    continue
            if array[index - 1] == "W":
                array[index + 1] = "S"
            else:
                array[index + 1] = "W"
        elif array[index] == "W" and not s[index]:
            if index == n - 1:
                if array[index-1] != array[0]:
                    return False
                else:
                    continue
            if index == 0:
                if array[-1] != array[1]:
                    return False
                else:
                    continue
            array[index + 1] = array[index - 1]
    return array


n = int(input())
s = [True if x == "o" else False for x in list(input())]
ws = ["W", "S"] + ["*" for x in range(n - 2)]
sw = ["S", "W"] + ["*" for x in range(n - 2)]
ss = ["S", "S"] + ["*" for x in range(n - 2)]
ww = ["W", "W"] + ["*" for x in range(n - 2)]

for array in [ws, sw, ss, ww]:
    res = solver(array)
    if not res:
        continue
    else:
        print("".join(res))
        exit()
else:
    print(-1)

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


ans = "-1"

for animals in ["SS","SW","WS","WW"]:
    for say in s:
        if (animals[-1] == "S" and say == "o" ) or (animals[-1] == "W" and say == "x"):
            animals += animals[-2]
        elif (animals[-1] == "S" and say == "x"):
            if animals[-2] == "S":
                animals += "W"
            else:
                animals += "S"
        elif (animals[-1] == "W" and say == "o"):
            if animals[-2] == "S":
                animals += "W"
            else:
                animals += "S"
    if animals[:2] == animals[-2:]:
        ans  =animals[1:-1]
print(ans)

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

li = ["N"]*(n+1)

li[0] = "W"
li[1] = "W"

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

  elif li[i]=="S" and s[i]=="x":
    if li[i-1] == "W":
      li[i+1] = "S"
    else:
      li[i+1] = "W"
     
if li[0]==li[n]:
  if s[0]=="o" and li[1]!=li[n-1]:
    print(str(li[0:n]).replace("[","").replace("]","").replace(",","").replace("'","").replace(" ",""))
    exit()
  if s[0]=="x" and li[1]==li[n-1]:
    print(str(li[0:n]).replace("[","").replace("]","").replace(",","").replace("'","").replace(" ",""))
    exit()

li[0] = "W"
li[1] = "S"

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

  elif li[i]=="S" and s[i]=="x":
    if li[i-1] == "W":
      li[i+1] = "S"
    else:
      li[i+1] = "W"
      
if li[0]==li[n]:     
  if s[0]=="o" and li[1]!=li[n-1]:
    print(str(li[0:n]).replace("[","").replace("]","").replace(",","").replace("'","").replace(" ",""))
    exit()
  if s[0]=="x" and li[1]==li[n-1]:
    print(str(li[0:n]).replace("[","").replace("]","").replace(",","").replace("'","").replace(" ",""))
    exit()

li[0] = "S"
li[1] = "W"

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

  elif li[i]=="S" and s[i]=="x":
    if li[i-1] == "W":
      li[i+1] = "S"
    else:
      li[i+1] = "W"
      
if li[0]==li[n]:     
  if s[0]=="o" and li[1]==li[n-1]:
    print(str(li[0:n]).replace("[","").replace("]","").replace(",","").replace("'","").replace(" ",""))
    exit()
  if s[0]=="x" and li[1]!=li[n-1]:
    print(str(li[0:n]).replace("[","").replace("]","").replace(",","").replace("'","").replace(" ",""))
    exit()

li[0] = "S"
li[1] = "S"

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

  elif li[i]=="S" and s[i]=="x":
    if li[i-1] == "W":
      li[i+1] = "S"
    else:
      li[i+1] = "W"
      
if li[0]==li[n]:     
  if s[0]=="o" and li[1]==li[n-1]:
    print(str(li[0:n]).replace("[","").replace("]","").replace(",","").replace("'","").replace(" ",""))
    exit()
  if s[0]=="x" and li[1]!=li[n-1]:
    print(str(li[0:n]).replace("[","").replace("]","").replace(",","").replace("'","").replace(" ",""))
    exit()
    
print(-1)

Solution (Python):
N=int(input())
S=list(input())
S.append(S[0])
S.append(S[1])

L1=["S","S"]
L2=["S","W"]
L3=["W","S"]
L4=["W","W"]

flag=0

for i in range(1,len(S)-1):
    if L1[i]=="S":
        if S[i]=="o" and L1[i-1]=="S":
            L1.append("S")
        elif S[i]=="o" and L1[i-1]=="W":
            L1.append("W")
        elif S[i]=="x" and L1[i-1]=="S":
            L1.append("W")
        elif S[i]=="x" and L1[i-1]=="W":
            L1.append("S")
    else:
        if S[i]=="o" and L1[i-1]=="S":
            L1.append("W")
        elif S[i]=="o" and L1[i-1]=="W":
            L1.append("S")
        elif S[i]=="x" and L1[i-1]=="S":
            L1.append("S")
        elif S[i]=="x" and L1[i-1]=="W":
            L1.append("W")
if L1[0]==L1[len(L1)-2] and L1[1]==L1[len(L1)-1]:
    L1=L1[:N]
    print("".join(L1))
    exit()
    
for i in range(1,len(S)-1):
    if L2[i]=="S":
        if S[i]=="o" and L2[i-1]=="S":
            L2.append("S")
        elif S[i]=="o" and L2[i-1]=="W":
            L2.append("W")
        elif S[i]=="x" and L2[i-1]=="S":
            L2.append("W")
        elif S[i]=="x" and L2[i-1]=="W":
            L2.append("S")
    else:
        if S[i]=="o" and L2[i-1]=="S":
            L2.append("W")
        elif S[i]=="o" and L2[i-1]=="W":
            L2.append("S")
        elif S[i]=="x" and L2[i-1]=="S":
            L2.append("S")
        elif S[i]=="x" and L2[i-1]=="W":
            L2.append("W")
if L2[0]==L2[len(L2)-2] and L2[1]==L2[len(L2)-1]:
    L2=L2[:N]
    print("".join(L2))
    exit()
    
for i in range(1,len(S)-1):
    if L3[i]=="S":
        if S[i]=="o" and L3[i-1]=="S":
            L3.append("S")
        elif S[i]=="o" and L3[i-1]=="W":
            L3.append("W")
        elif S[i]=="x" and L3[i-1]=="S":
            L3.append("W")
        elif S[i]=="x" and L3[i-1]=="W":
            L3.append("S")
    else:
        if S[i]=="o" and L3[i-1]=="S":
            L3.append("W")
        elif S[i]=="o" and L3[i-1]=="W":
            L3.append("S")
        elif S[i]=="x" and L3[i-1]=="S":
            L3.append("S")
        elif S[i]=="x" and L3[i-1]=="W":
            L3.append("W")
if L3[0]==L3[len(L3)-2] and L3[1]==L3[len(L3)-1]:
    L3=L3[:N]
    print("".join(L3))
    exit()
    
for i in range(1,len(S)-1):
    if L4[i]=="S":
        if S[i]=="o" and L4[i-1]=="S":
            L4.append("S")
        elif S[i]=="o" and L4[i-1]=="W":
            L4.append("W")
        elif S[i]=="x" and L4[i-1]=="S":
            L4.append("W")
        elif S[i]=="x" and L4[i-1]=="W":
            L4.append("S")
    else:
        if S[i]=="o" and L4[i-1]=="S":
            L4.append("W")
        elif S[i]=="o" and L4[i-1]=="W":
            L4.append("S")
        elif S[i]=="x" and L4[i-1]=="S":
            L4.append("S")
        elif S[i]=="x" and L4[i-1]=="W":
            L4.append("W")
if L4[0]==L4[len(L4)-2] and L4[1]==L4[len(L4)-1]:
    L4=L4[:N]
    print("".join(L4))
    exit()

print(-1)

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

ans = '-1'

for animals in ['SS', 'SW', 'WS', 'WW']:
    for say in s:
        if (animals[-1] == 'S') != ((say == 'o') != (animals[-2] == 'S')):
            animals += 'S'
        else:
            animals += 'W'
    if animals[:2] == animals[-2:]:
        ans = animals[1:-1]

print(ans)

Solution (Python):
def another(t):
    if t == "W":
        return "S"
    else:
        return "W"


def ok(t1, t2, t3, op):
    if (op == "o" and t2 == "S") or (op == "x" and t2 == "W"):
        return t1 == t3
    else:
        return t1 != t3

def check(ans):
    for i in range(n - 2):
        c = s[i]
        t = ans[i]
        if (c == "o" and t == "S") or (c == "x" and t == "W"):
            ans[i + 1] = ans[i - 1]
        else:
            ans[i + 1] = another(ans[i - 1])
    t1, t2, t3, t4 = ans[-3], ans[-2], ans[-1], ans[0]
    return ok(t1, t2, t3, s[-2]) and ok(t2, t3, t4, s[-1])

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

for head, tail in (("S", "S"), ("S", "W"), ("W", "S"), ("W", "W")):
    ans = [""] * n
    ans[0] = head
    ans[-1] = tail
    if check(ans):
        print(*ans, sep="")
        break
else:
    print(-1)