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 = input()
s += s[0]
ans = [''] * (n+1)
rev_dic = {'S':'W', 'W':'S'}
for a0,a1 in zip('SSWW','SWSW'):
    ans[0] = a0
    ans[1] = a1
    for i in range(1,n):
        if(ans[i] == 'S')&(s[i] == 'o'):
            ans[i+1] = ans[i-1]
        elif(ans[i] == 'S')&(s[i] == 'x'):
            ans[i+1] = rev_dic[ans[i-1]]
        elif(ans[i] == 'W')&(s[i] == 'o'):
            ans[i+1] = rev_dic[ans[i-1]]
        elif(ans[i] == 'W')&(s[i] == 'x'):
            ans[i+1] = ans[i-1]
    if(ans[0] == ans[-1]):
        if(ans[0]=='S')&(s[0]=='o')&(ans[n-1]==ans[1]):
            print(''.join(ans[:-1]))
            exit()
        if(ans[0]=='S')&(s[0]=='x')&(ans[n-1]!=ans[1]):
            print(''.join(ans[:-1]))
            exit()
        if(ans[0]=='W')&(s[0]=='o')&(ans[n-1]!=ans[1]):
            print(''.join(ans[:-1]))
            exit()
        if(ans[0]=='W')&(s[0]=='x')&(ans[n-1]==ans[1]):
            print(''.join(ans[:-1]))
            exit()
print(-1)

Solution (Python):
N = int(input())
s = input()
s += s[0]
L = ["SS","SW","WS","WW"]

for e in L:
    for k in range(1,N+1):
        if s[k] == "o" and e[-1] == "S":
            e += e[-2]
        elif (s[k] == "x" and e[-1] == "S") or (s[k] == "o" and e[-1] == "W"):
            if e[-2] == "S":
                e += "W"
            else:
                e += "S"
        elif s[k] == "o" and e[-1] == "W":
            if e[-2] == "W":
                e += "S"
            else:
                e += "W"
        else:
            e += e[-2]
    if e[:2] == e[-2:]:
        print(e[:-2])
        exit(0)
print(-1)

Solution (Python):


from collections import deque

N = int(input())
S = input()


def valid(ans):
    
    for i in range(1, N - 1):
        if S[i] == 'o':
            if ans[i] == 0:
                ans[i + 1] = ans[i - 1]
            else:
                ans[i + 1] = 1 - ans[i - 1]
        else:
            if ans[i] == 0:
                ans[i + 1] = 1 - ans[i - 1]
            else:
                ans[i + 1] = ans[i - 1]

    flag1 = False
    if ans[-1] == 0:
        if S[-1] == 'o':
            flag1 = ans[-2] == ans[0]
        else:
            flag1 = ans[-2] != ans[0]
    else:
        if S[-1] == 'o':
            flag1 = ans[-2] != ans[0]
        else:
            flag1 = ans[-2] == ans[0]

    flag2 = False
    if ans[0] == 0:
        if S[0] == 'o':
            flag2 = ans[1] == ans[-1]
        else:
            flag2 = ans[1] != ans[-1]
    else:
        if S[0] == 'o':
            flag2 = ans[1] != ans[-1]
        else:
            flag2 = ans[1] == ans[-1]
    return flag1 and flag2

for (v0, v1) in [(0, 0), (0, 1), (1, 0), (1, 1)]:
    ans = [-1] * N
    ans[0] = v0
    ans[1] = v1
    flag = valid(ans)
    
    if flag:
        for ch in ans:
            print('S' if ch == 0 else 'W', end='')
        print()
        exit()

print("-1")

Solution (Python):
from itertools import product

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

for bfo2, bfo1 in product(['S', 'W'], repeat=2):
    ans = [bfo2, bfo1]
    for i in s:
        if ((bfo1 == 'S' and i == 'o')
                or (bfo1 == 'W' and i == 'x')):
            ans.append(bfo2)
        elif ((bfo1 == 'S' and i == 'x')
                or (bfo1 == 'W' and i == 'o')):
            ans.append(*({'S', 'W'} - {bfo2}))
        bfo1, bfo2 = ans[-1], bfo1
    if ans[:2] == ans[-2:]:
        print(*ans[1:-1], sep='')
        break
else:
    print(-1)

Solution (Python):
from itertools import product


def solve(bfo2, bfo1):
    ANS = [bfo2, bfo1]
    for i in s:
        if ((bfo1 == 'S' and i == 'o')
                or (bfo1 == 'W' and i == 'x')):
            ANS.append(bfo2)
        elif ((bfo1 == 'S' and i == 'x')
                or (bfo1 == 'W' and i == 'o')):
            ANS.append(*({'S', 'W'} - {bfo2}))
        bfo1, bfo2 = ANS[-1], bfo1
    return ANS


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

for i, j in product(['S', 'W'], repeat=2):
    ans = solve(i, j)
    if ans[:2] == ans[-2:]:
        print(*ans[1:-1], sep='')
        break
else:
    print(-1)

Solution (Python):
def solve(bfo2, bfo1):
    ans = [bfo2, bfo1]
    for i in s:
        if ((bfo1 == 'S' and i == 'o')
                or (bfo1 == 'W' and i == 'x')):
            ans.append(bfo2)
        elif ((bfo1 == 'S' and i == 'x')
                or (bfo1 == 'W' and i == 'o')):
            ans.append(*({'S', 'W'} - {bfo2}))
        bfo1, bfo2 = ans[-1], bfo1
    if ans[:2] == ans[-2:]:
        print(*ans[1:-1], sep='')
        exit()


n, s = int(input()), input()
for i in ['S', 'W']:
    for j in ['S', 'W']:
        solve(i, j)
print(-1)

Solution (Python):
def solve(bfo2, bfo1):
    ans = [bfo2, bfo1]
    for i in s:
        if ((bfo1 == 'S' and i == 'o')
                or (bfo1 == 'W' and i == 'x')):
            ans.append(bfo2)
        else:
            ans.append('S' if bfo2 == 'W' else 'W')
        bfo1, bfo2 = ans[-1], bfo1
    if ans[:2] == ans[-2:]:
        print(*ans[1:-1], sep='')
        exit()


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

for i in ['S', 'W']:
    for j in ['S', 'W']:
        solve(i, j)
print(-1)

Solution (Python):
n=int(input())
s=input()
ans=''
for ft in {'o':['SSS','WSW','SWW','WWS'],'x':['SSW','WSS','SWS','WWW'],}[s[0]]:
    a=ft
    for l in s[1:-1]:
        if l=='o':
            if a[-1]=='S':a=a+('S' if a[-2]=='S' else 'W')
            else:         a=a+('W' if a[-2]=='S' else 'S')
        if l=='x':
            if a[-1]=='S':a=a+('W' if a[-2]=='S' else 'S')
            else:         a=a+('S' if a[-2]=='S' else 'W')
    else:
        if a[0]==a[-1] and s[-1]=='o':
            if (a[-1]=='S' and a[1]==a[-2]) or (a[-1]=='W' and a[1]!=a[-2]):
                print(a[1:]);exit()
        if a[0]==a[-1] and s[-1]=='x':
            if (a[-1]=='S' and a[1]!=a[-2]) or (a[-1]=='W' and a[1]==a[-2]):
                print(a[1:]);exit()
print(-1)

Solution (Python):
N=int(input())
S=input()
A=["SS","SW","WS","WW"]

X=""
for a in A:
    T=a
    for i in range(1,N-1):
        if T[-1]=="S":
            if S[i]=="o":
                T+=T[-2]
            else:
                if T[-2]=="S":
                    T+="W"
                else:
                    T+="S"
        else:
            if S[i]=="o":
                if T[-2]=="S":
                    T+="W"
                else:
                    T+="S"
            else:
                T+=T[-2]

    F=True
    if (T[0]=="S") and not((S[0]=="o")^(T[1]==T[-1])):
        pass
    elif (T[0]=="W") and not((S[0]=="x")^(T[1]==T[-1])):
        pass
    else:
        F=False

    if (T[-1]=="S") and not((S[-1]=="o")^(T[0]==T[-2])):
        pass
    elif (T[-1]=="W") and not((S[-1]=="x")^(T[0]==T[-2])):
        pass
    else:
        F=False

    if F:
        X=T

if X:
    print(X)
else:
    print(-1)

Solution (Python):
N=int(input())
S=input()
A=["SS","SW","WS","WW"]

X=""
for a in A:
    T=a
    for i in range(1,N-1):
        if T[-1]=="S":
            if S[i]=="o":
                T+=T[-2]
            else:
                if T[-2]=="S":
                    T+="W"
                else:
                    T+="S"
        else:
            if S[i]=="o":
                if T[-2]=="S":
                    T+="W"
                else:
                    T+="S"
            else:
                T+=T[-2]

    F=True
    if (T[0]=="S") and not((S[0]=="o")^(T[1]==T[-1])):
        pass
    elif (T[0]=="W") and not((S[0]=="x")^(T[1]==T[-1])):
        pass
    else:
        F=False

    if (T[-1]=="S") and not((S[-1]=="o")^(T[0]==T[-2])):
        pass
    elif (T[-1]=="W") and not((S[-1]=="x")^(T[0]==T[-2])):
        pass
    else:
        F=False

    if F:
        X=T

if X:
    print(X)
else:
    print(-1)

Solution (Python):
import sys,math,collections,itertools
input = sys.stdin.readline

def solve(n0,n1):
    
    ws = [-1]*len(s)
    ws[0]=n0
    ws[1]=n1
    for i in range(1,len(s)-1):
        if s[i]=='o' and ws[i]==0:
            ws[i+1]=ws[i-1]
        elif  s[i]=='x' and ws[i]==0:
            ws[i+1]=(ws[i-1]+1)%2
        elif s[i]=='o' and ws[i]==1:
            ws[i+1]=(ws[i-1]+1)%2
        elif s[i]=='x' and ws[i]==1:
            ws[i+1]=ws[i-1]
    if ws[0] == ws[-2] and ws[1]==ws[-1]:
        return ws[1:-1]
    else:
        return 0

N=int(input())
s=input().rstrip()
s=s[-1]+s+s[0]

for i in range(2):
    for j in range(2):
        ws = solve(i,j)
        if ws:
            for w in ws:
                if w==0:
                    print('S',end='')
                else:
                    print('W',end='')
            exit()
print(-1)

Solution (Python):
'''
研究室PCでの解答
'''
import math

import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit


ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7 
dir = [(-1,0),(1,0),(0,-1),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"


def main():
    n = int(ipt())
    s = input()
    da = {"S":1,"W":-1}
    dq = {"o":1,"x":-1}
    rda = {1:"S",-1:"W"}
    kh = ("SS","WW","SW","WS")

    for i in kh:
        anim = i
        for j in s:
            anim += rda[da[anim[-1]]*dq[j]*da[anim[-2]]]
        if anim[-1] == anim[1] and anim[-2] == anim[0]:
            print(anim[1:-1:])
            return None

    print(-1)

    return None

if __name__ == '__main__':
    main()

Solution (Python):
def check(i,j):
  if s[j-1]=='o':
    if a[j-1]=='S':return a[i]==a[j]
    else:return a[i]!=a[j]
  else:
    if a[j-1]=='S':return a[i]!=a[j]
    else:return a[i]==a[j]
n=int(input())
s=input()
sw='SW'
for i in 'SS','SW','WS','WW':
  a=i
  for i,j in enumerate(s[1:n-1],1):
    if j=='o':
      if a[-1]=='S':a+=a[-2]
      else:a+=sw[a[-2]=='S']
    else:
      if a[-1]=='S':a+=sw[a[-2]=='S']
      else:a+=a[-2]
  if check(-1,1) and check(-2,0):
    flag=1
    break
  else:flag=0
print([-1,a][flag])

Solution (Python):
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n = int(input())
s = input()
for S in ["SS","SW","WS","WW"]:
  st = S
  for i in range(1,n):
    if s[i] == "o":
      if st[i] == "S":
        st += st[i-1]
      else:
        st += ("W" if st[i-1] == "S" else "S")
    else:
      if st[i] == "S":
        st += ("W" if st[i-1] == "S" else "S")
      else:
        st += st[i-1]
  
  if st[0] == st[-1]:
    ok = False
    if s[0] == "o":
      if st[0] == "S":
        if st[1] == st[-2]:
          ok = True
      else:
        if st[1] != st[-2]:
          ok = True
    else:
      if st[0] == "W":
        if st[1] == st[-2]:
          ok = True
      else:
        if st[1] != st[-2]:
          ok = True
    if ok:
      print(*st[:n],sep = "")
      exit()
print(-1)

Solution (Python):
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007



def other_kind(k):
	if k == 'S':
		return 'W'
	elif k == 'W':
		return 'S'
	else:
		return 1/0



def mk_next(kind, say, pre_kind):
	if kind == 'S':
		if say == 'o':
			return pre_kind
		else:
			return other_kind(pre_kind)
	else:
		if say == 'o':
			return other_kind(pre_kind)
		else:
			return pre_kind


def main():
	n = int(input())
	
	s = input()
	for pre in ['W','S']:
		for cc in ['W','S']:
			ret = [0]*n
			pk = pre
			kind = cc
			for i, c in enumerate(s):
				next = mk_next(kind, c, pk)
				
				ret[i] = kind
				pk = kind
				kind = next
			if pre == ret[-1] and cc == mk_next(ret[-1], s[-1], ret[-2]):
				
				print(''.join(ret))
				return
	return -1
	
	
	

isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		
			
	ret = main()
	if ret is not None:
		print(ret)

Solution (Python):
from itertools import product
n = int(input())
s = input()

for a, b in product('SW', repeat=2):
    ls = [None]*n
    ls[0] = a
    ls[-1] = b
    for i in range(n-2):
        if ls[i] == 'S':
            if s[i] == 'o':
                ls[i+1] = ls[i-1]
            else:
                ls[i+1] = 'W' if ls[i-1] == 'S' else 'S'
        else:
            if s[i] == 'o':
                ls[i+1] = 'W' if ls[i-1] == 'S' else 'S'
            else:
                ls[i+1] = ls[i-1]

    def is_ok(i):
        if ls[i] == 'S':
            if s[i] == 'o':
                if ls[i-1] != ls[i+1]:
                    return False
            else:
                if ls[i-1] == ls[i+1]:
                    return False
        else:
            if s[i] == 'o':
                if ls[i-1] == ls[i+1]:
                    return False
            else:
                if ls[i-1] != ls[i+1]:
                    return False
        return True

    if not is_ok(-2):
        continue
    elif not is_ok(-1):
        continue
    print(''.join(ls))
    break
else:
    print(-1)

Solution (Python):
import sys
import math
import collections
import bisect
import itertools

import numpy as np

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7


ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))




def main():
    n = ni()
    s = list(input())

    table = [[-1 for _ in range(n)] for __ in range(4)]
    flg = [True] * 4

    init = []
    if s[0] == "o":
        init = [[1, 1, 1], [0, 1, 0], [1, 0, 0], [0, 0, 1]]
        for i in range(4):
            table[i][-1], table[i][0], table[i][1] = init[i]
    else:
        init = [[1, 1, 0], [0, 1, 1], [1, 0, 1], [0, 0, 0]]
        for i in range(4):
            table[i][-1], table[i][0], table[i][1] = init[i]

    for i in range(1, n):
        for j in range(4):
            if s[i] == "o":
                if table[j][(i + 1) % n] == -1:
                    if table[j][i] == 1:
                        table[j][(i + 1) % n] = table[j][i - 1]
                    else:
                        table[j][(i + 1) % n] = table[j][i - 1] ^ 1
                else:
                    if table[j][i] == 1:
                        if table[j][(i + 1) % n] != table[j][i - 1]:
                            flg[j] = False
                    else:
                        if table[j][(i + 1) % n] != table[j][i - 1] ^ 1:
                            flg[j] = False
            else:
                if table[j][(i + 1) % n] == -1:
                    if table[j][i] == 1:
                        table[j][(i + 1) % n] = table[j][i - 1] ^ 1
                    else:
                        table[j][(i + 1) % n] = table[j][i - 1]
                else:
                    if table[j][i] == 1:
                        if table[j][(i + 1) % n] == table[j][i - 1]:
                            flg[j] = False
                    else:
                        if table[j][(i + 1) % n] == table[j][i - 1] ^ 1:
                            flg[j] = False

    for i in range(4):
        if flg[i]:
            s = ""
            for ti in table[i]:
                if ti:
                    s += "S"
                else:
                    s += "W"
            print(s)
            exit()

    print(-1)


if __name__ == '__main__':
    main()

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

def calc():
  global ans
  for i in range(1, n-1):
    temp = s[i]
    if ans[i]=="S":
      if temp=="o":
        ans[i+1]=ans[i-1]
      else:
        if ans[i-1]=="S":
          ans[i+1]="W"
        else:
          ans[i+1]="S"
    else:
      if temp=="o":
        if ans[i-1]=="S":
          ans[i+1]="W"
        else:
          ans[i+1]="S"
      else:
        ans[i+1]=ans[i-1]

def judge():
  global ans
  global last
  if ans[n-1]!=last:
    return False
  else:
    if ans[n-1]=="S":
      if s[n-1]=="o":
        if ans[n-2]==ans[0]:
          return True
        else:
          return False
      else:
        if ans[n-2]==ans[0]:
          return False
        else:
          return True
    else:
      if s[n-1]=="o":
        if ans[n-2]==ans[0]:
          return False
        else:
          return True
      else:
        if ans[n-2]==ans[0]:
          return True
        else:
          return False


ans = ["a"]*n
ans[0]="S"
ans[1]="S"
if s[0]=="o":
  last = "S"
else:
  last = "W"

calc()

if judge():
  print("".join(ans))
  quit()
  

ans = ["a"]*n
ans[0]="S"
ans[1]="W"
if s[0]=="o":
  last = "W"
else:
  last = "S"
  
calc()

if judge():
  print("".join(ans))
  quit()
  


ans = ["a"]*n
ans[0]="W"
ans[1]="S"
if s[0]=="o":
  last = "W"
else:
  last = "S"

calc()

if judge():
  print("".join(ans))
  quit()

ans = ["a"]*n
ans[0]="W"
ans[1]="W"
if s[0]=="o":
  last = "S"
else:
  last = "W"
  
calc()

if judge():
  print("".join(ans))
  quit()
print(-1)

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

d = ['S','W']
for i in d:
    for j in d:
        ans = [i,j]
        for k in range(2,N):
            if s[k-1] == 'o':
                if ans[-1] == ans[-2]:
                    ans.append('S')
                else:
                    ans.append('W')
            else:
                if ans[-1] == ans[-2]:
                    ans.append('W')
                else:
                    ans.append('S')

        

        cans = [ans[-2],ans[-1],ans[0],ans[1]]
        cs = [s[-2],s[-1],s[0],s[1]]
        
        
        flg = True
        for k in range(1,3):
            if (cans[k] == 'S' and cs[k] == 'o') or (cans[k] == 'W' and cs[k] == 'x'):
                if cans[k-1] != cans[k+1]:
                    flg = False
            else:
                if cans[k-1] == cans[k+1]:
                    flg = False
        if flg == True:
            print(''.join(ans))
            exit()



print(-1)

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

d = ['S','W']
for i in d:
    for j in d:
        ans = [i,j]
        for k in range(2,N):
            if s[k-1] == 'o':
                if ans[-1] == ans[-2]:
                    ans.append('S')
                else:
                    ans.append('W')
            else:
                if ans[-1] == ans[-2]:
                    ans.append('W')
                else:
                    ans.append('S')

        
        if s[0] == 'o':
            if ans[0] == ans[1]:
                val1 = 'S'
            else:
                val1 = 'W'
        else:
            if ans[0] == ans[1]:
                val1 = 'W'
            else:
                val1 = 'S'
        if s[-1] == 'o':
            if ans[-1] == ans[-2]:
                val2 = 'S'
            else:
                val2 = 'W'
        else:
            if ans[-2] == ans[-1]:
                val2 = 'W'
            else:
                val2 = 'S'
        if val1 == ans[-1] and val2 == ans[0]:
            print(''.join(ans))
            exit()



print(-1)

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

d = ['S','W']
for i in d:
    for j in d:
        ans = [i,j]
        for k in range(2,N):
            if s[k-1] == 'o':
                if ans[-1] == 'S':
                    ans.append(ans[-2])
                else:
                    if ans[-2] == 'S':
                        ans.append('W')
                    else:
                        ans.append('S')
            else:
                if ans[-1] == 'S':
                    if ans[-2] == 'S':
                        ans.append('W')
                    else:
                        ans.append('S')
                else:
                    ans.append(ans[-2])
        
        flg = True
        if ans[-1] == 'S':
            if s[-1] == 'o':
                if ans[-2] != ans[0]:
                    flg = False
            else:
                if ans[-2] == ans[0]:
                    flg = False
        else:
            if s[-1] == 'x':
                if ans[-2] != ans[0]:
                    flg = False
            else:
                if ans[-2] == ans[0]:
                    flg = False
        if ans[0] == 'S':
            if s[0] == 'o':
                if ans[-1] != ans[1]:
                    flg = False
            else:
                if ans[-1] == ans[1]:
                    flg = False
        else:
            if s[0] == 'x':
                if ans[-1] != ans[1]:
                    flg = False
            else:
                if ans[-1] == ans[1]:
                    flg = False
        if flg == True:
            print(''.join(ans))
            exit()

print(-1)

Solution (Python):
n = int(input())
s = input()
l = ["SS", "WS", "SW", "WW"]
for i in range(n):
    for j in range(4):
        if s[i] == "o":
            if l[j][i] == l[j][i + 1]:
                l[j] += "S"
            else:
                l[j] += "W"
        else:
            if l[j][i] == l[j][i + 1]:
                l[j] += "W"
            else:
                l[j] += "S"
for i in range(4):
    if l[i][1] == l[i][n + 1] and l[i][0] == l[i][n]:
        exit(print(l[i][1:n + 1]))
print(-1)

Solution (Python):
n=int(input());s=input()
for p in range(4):
  l=[p//2,p%2]+[0]*(n-2)
  for i in range(1,n):l[(i+1)%n]=[l[i-1],1-l[i-1]][::(-1)**(s[i]=="o")][l[i]]
  for i in range(n):
    if s[i]!="ox"[int(l[(i-1)%n]==l[(i+1)%n])-l[i]]:break
  else:print("".join("WS"[x]for x in l));exit()
print(-1)

Solution (Python):
n=int(input());s=input()
for p in range(4):
  l=[p//2,p%2]+[0]*(n-2)
  for i in range(1,n):l[(i+1)%n]=[l[i-1],1-l[i-1]][::(-1)**(s[i]=="o")][l[i]]
  for i in range(n):
    if s[i]!="ox"[int(l[(i-1)%n]==l[(i+1)%n])-l[i]]:break
  else:print("".join("WS"[x]for x in l));exit()
print(-1)

Solution (Python):
n=int(input())
s=input()
f=0
for i in [[0,0],[0,1],[1,0],[1,1]]:
  d=[i[0],i[1]]
  for j in range(2,n):
    d.append((d[-2]+d[-1]+int(s[j-1]=="x"))%2)
  if (int(d[-2]==d[0])+d[-1]+int(s[-1]=="x"))%2 and (int(d[-1]==d[1])+d[0]+int(s[0]=="x"))%2:
    f=1
    break
if f:
  for i in d:
    if i:
      print("W",end="")
    else:
      print("S",end="")
  print()
else:
  print(-1)

Solution (Python):
def main():
    N = int(input())
    s = list(input())
    for t0,t1 in [('S','S'),('S','W'),('W','S'),('W','W')]:
        T = ['S'] * (N + 1)

        T[0] = t0
        T[1] = t1

        for i in range(1,N):
            if s[i] == 'o':
                if T[i] == 'S':
                    T[i+1] = T[i-1]
                else:
                    if T[i-1] == 'W':
                        T[i+1] = 'S'
                    else:
                        T[i+1] = 'W'
            else:
                if T[i] == 'W':
                    T[i+1] = T[i-1]
                else:
                    if T[i-1] == 'W':
                        T[i+1] = 'S'
                    else:
                        T[i+1] = 'W'

        if T[-1] == T[0]:
            if T[0] == 'S':
                if s[0] == 'o' and T[-2] == T[1]:
                    T.pop(-1)
                    print(''.join(T))
                    exit()
                elif s[0] == 'x' and T[-2] != T[1]:
                    T.pop(-1)
                    print(''.join(T))
                    exit()
            else:
                if s[0] == 'x' and T[-2] == T[1]:
                    T.pop(-1)
                    print(''.join(T))
                    exit()
                elif s[0] == 'o' and T[-2] != T[1]:
                    T.pop(-1)
                    print(''.join(T))
                    exit()


    print(-1)



if __name__ == "__main__":
    main()

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

dic = {('S','S','o'):'S', ('S','S','x'):'W', ('S','W','o'):'W', ('S','W','x'):'S', \
       ('W','S','o'):'W', ('W','S','x'):'S', ('W','W','o'):'S', ('W','W','x'):'W'}

cnd = [['S','S'], ['S','W'], ['W','S'], ['W','W']]

for h in cnd:
  rlt = h
  l = dic[(h[0],h[1],S[0])]
  for i in range(1,N-1):
    rlt.append(dic[(rlt[i], rlt[i-1], S[i])])
  if l == rlt[-1] and dic[(rlt[-1], rlt[-2], S[-1])] == rlt[0]:
    print(''.join(rlt))
    exit()

print(-1)

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

dic = {('S','S','o'):'S', ('S','S','x'):'W', ('S','W','o'):'W', ('S','W','x'):'S', \
       ('W','S','o'):'W', ('W','S','x'):'S', ('W','W','o'):'S', ('W','W','x'):'W'}

cnd = ['SS', 'SW', 'WS', 'WW']

for h in cnd:
  rlt = h
  l = dic[(h[0],h[1],S[0])]
  for i in range(1,N-1):
    rlt += dic[(rlt[i], rlt[i-1], S[i])]
  if l == rlt[-1] and dic[(rlt[-1], rlt[-2], S[-1])] == rlt[0]:
    print(rlt)
    exit()

print(-1)

Solution (Python):
from itertools import product

n = int(input())
s = [c == "o" for c in input()]


def is_consistent(is_sheep_0, is_sheep_1):
    list_is_sheep = [None] * (n + 2)
    list_is_sheep[0] = is_sheep_0
    list_is_sheep[1] = is_sheep_1
    for i in range(2, n + 2):
        is_sheep = list_is_sheep[i - 2]
        if not s[(i - 1) % n]:
            is_sheep = not is_sheep
        if not list_is_sheep[i - 1]:
            is_sheep = not is_sheep
        list_is_sheep[i] = is_sheep
    c = list_is_sheep[0] == list_is_sheep[-2] and list_is_sheep[1] == list_is_sheep[-1]
    return c, list_is_sheep


def answer():
    for is_sheep_0, is_sheep_1 in product([True, False], repeat=2):
        c, list_is_sheep = is_consistent(is_sheep_0, is_sheep_1)
        if c:
            return list_is_sheep
    return -1


answer = answer()

if answer == -1:
    print(answer)
else:
    print("".join(["S" if is_sheep else "W" for is_sheep in answer[:-2]]))

Solution (Python):

N=int(input())
S=input()


def solve(N, start, end):
    memory=[-1]*N
    memory[0]=start
    for i in range(1,N):
        pre=memory[i-2]
        if i==1:
            pre=end
        if memory[i-1]==0:
            if S[i-1]=="o":
                now=pre
            else:
                now=(pre+1)%2
        else:
            if S[i-1]=="o":
                now=(pre+1)%2
            else:
                now=pre
        if i==N-1:
            if now!=end:
                return False
        memory[i]=now
    ok=True
    if memory[-1]==0:
        if S[-1]=="o" and memory[0]!=memory[-2]:
            ok=False
        if S[-1]=="x" and memory[0]==memory[-2]:
            ok=False
    else:
        if S[-1]=="o" and memory[0]==memory[-2]:
            ok=False
        if S[-1]=="x" and memory[0]!=memory[-2]:
            ok=False

    if ok:
        return memory
    else:
        return False
        




ans1=solve(N, 0, 0)
ans2=solve(N, 0, 1)
ans3=solve(N, 1, 0)
ans4=solve(N, 1, 1)

for ans in [ans1, ans2, ans3, ans4]:
    if ans:
        for a in ans:
            if a==0:
                print("S", end="")
            else:
                print("W", end="")

        exit()

print(-1)