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):
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def print_sw(a):
    for i in a[:-1]:
        if i == '0':
            print('S',end = '')
        else:
            print('W', end = '')

def solve():
    n = f()[0]
    s = input()

    for i in [ 0, 1]:
        for j in [0, 1]:
            a = str(i) + str(j)
            for k in range(2, n+1):
                if a[k-1] == '0':
                    if s[k-1] == 'o':
                        a += a[k-2]
                    else:
                        a += str(int(a[k-2])^1)
                else:
                    if s[k-1] == 'x':
                        a += a[k-2]
                    else:
                        a += str(int(a[k-2])^1)

            if a[0] != a[n]:
                continue
            
            if a[0] == '0':
                if a[1] == a[n-1] and s[0] == 'o':
                    print_sw(a)
                    return
                elif a[1] != a[n-1] and s[0] == 'x':
                    print_sw(a)
                    return
            else:
                if a[1] == a[n-1] and s[0] == 'x':
                    print_sw(a)
                    return
                elif a[1]!=a[n-1] and s[0] == 'o':
                    print_sw(a)
                    return
    
    print(-1)


solve()

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

def d(r):
	for i in range(1, n):
		if r[i] == "S":
			if s[i] == "o":
				r += r[i-1]
			else:
				r += "S" if r[i-1] == "W" else "W"
		else:
			if s[i] == "o":
				r += "S" if r[i-1] == "W" else "W"
			else:
				r += r[i-1]
	if r[0] != r[-1]:
		return False
	else:
		if r[0] == "S":
			if s[0] == "o":
				if r[1] != r[-2]:
					return False
			else:
				if r[1] == r[-2]:
					return False
		else:
			if s[0] == "o":
				if r[1] == r[-2]:
					return False
			else:
				if r[1] != r[-2]:
					return False

	return r[:-1]

def main():
	r1 = "SS"
	r2 = "SW"
	r3 = "WS"
	r4 = "WW"
	a = d(r1)
	if a:
		print a
		return
	a = d(r2)
	if a:
		print a
		return
	a = d(r3)
	if a:
		print a
		return
	a = d(r4)
	if a:
		print a
		return
	print -1

main()

Solution (Python):





def gen(start, s):
	for i in xrange(1, len(s)+1):
		c = start[i]
		h = s[i] if i < len(s) else s[0]
		if h == 'o':
			if c == 'S':
				start += start[i-1]
			else:
				start += 'S' if start[i-1] == 'W' else 'W'
		else:
			if c == 'S':
				start += 'S' if start[i-1] == 'W' else 'W'
			else:
				start += start[i-1]

	if start[:2] == start[-2:]:
		return start[:-2]
	return ''


def main():
	n = int(raw_input())
	s = raw_input()

	for x in ('SS', 'SW', 'WW', 'WS'):
		ans = gen(x, s)
		if ans:
			print ans
			return
	print -1

if __name__ == '__main__':
	main()

Solution (Python):





def gen(start, s):
	for i in xrange(1, len(s)+1):
		c = start[i]
		h = s[i] if i < len(s) else s[0]
		if h == 'o':
			if c == 'S':
				start += start[i-1]
			else:
				start += 'S' if start[i-1] == 'W' else 'W'
		else:
			if c == 'S':
				start += 'S' if start[i-1] == 'W' else 'W'
			else:
				start += start[i-1]

	if start[:2] == start[-2:]:
		return start[:-2]
	return ''


def main():
	n = int(raw_input())
	s = raw_input()

	for x in ('SS', 'SW', 'WW', 'WS'):
		ans = gen(x, s)
		if ans:
			print ans
			return
	print -1

if __name__ == '__main__':
	main()

Solution (Python):





def gen(start, s):
	for i in xrange(1, len(s)+1):
		c = start[i]
		h = s[i] if i < len(s) else s[0]
		if h == 'o':
			if c == 'S':
				start += start[i-1]
			else:
				start += 'S' if start[i-1] == 'W' else 'W'
		else:
			if c == 'S':
				start += 'S' if start[i-1] == 'W' else 'W'
			else:
				start += start[i-1]

	if start[:2] == start[-2:]:
		return start[:-2]
	return ''


def main():
	n = int(raw_input())
	s = raw_input()

	for x in ('SS', 'SW', 'WW', 'WS'):
		ans = gen(x, s)
		if ans:
			print ans
			return
	print -1

if __name__ == '__main__':
	main()

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

is_zoo = False
start = 'SS'
for _s in s[1:-1]:
  if start[-1] == 'S':
    if _s == 'o':
      start += start[-2]
    else:
      start += 'S' if start[-2] == 'W' else 'W'
  else:
    if _s == 'x':
      start += start[-2]
    else:
      start += 'S' if start[-2] == 'W' else 'W'
if (start[-1] == 'S' and s[-1] == 'o' and start[-2] == 'S' and s[0] == 'o') or \
  (start[-1] == 'S' and s[-1] == 'x' and start[-2] == 'W' and s[0] == 'o') or \
  (start[-1] == 'W' and s[-1] == 'o' and start[-2] == 'W' and s[0] == 'x') or \
  (start[-1] == 'W' and s[-1] == 'x' and start[-2] == 'S' and s[0] == 'x'):
  print(start)
  is_zoo = True

start = 'SW'
if not is_zoo:
  for _s in s[1:-1]:
    if start[-1] == 'S':
      if _s == 'o':
        start += start[-2]
      else:
        start += 'S' if start[-2] == 'W' else 'W'
    else:
      if _s == 'x':
        start += start[-2]
      else:
        start += 'S' if start[-2] == 'W' else 'W'
  if (start[-1] == 'S' and s[-1] == 'o' and start[-2] == 'S' and s[0] == 'x') or \
    (start[-1] == 'S' and s[-1] == 'x' and start[-2] == 'W' and s[0] == 'x') or \
    (start[-1] == 'W' and s[-1] == 'o' and start[-2] == 'W' and s[0] == 'o') or \
    (start[-1] == 'W' and s[-1] == 'x' and start[-2] == 'S' and s[0] == 'o'):
    print(start)
    is_zoo = True

start = 'WS'
if not is_zoo:
  for _s in s[1:-1]:
    if start[-1] == 'S':
      if _s == 'o':
        start += start[-2]
      else:
        start += 'S' if start[-2] == 'W' else 'W'
    else:
      if _s == 'x':
        start += start[-2]
      else:
        start += 'S' if start[-2] == 'W' else 'W'
  if (start[-1] == 'S' and s[-1] == 'o' and start[-2] == 'W' and s[0] == 'x') or \
    (start[-1] == 'S' and s[-1] == 'x' and start[-2] == 'S' and s[0] == 'x') or \
    (start[-1] == 'W' and s[-1] == 'o' and start[-2] == 'S' and s[0] == 'o') or \
    (start[-1] == 'W' and s[-1] == 'x' and start[-2] == 'W' and s[0] == 'o'):
    print(start)
    is_zoo = True

start = 'WW'
if not is_zoo:
  for _s in s[1:-1]:
    if start[-1] == 'S':
      if _s == 'o':
        start += start[-2]
      else:
        start += 'S' if start[-2] == 'W' else 'W'
    else:
      if _s == 'x':
        start += start[-2]
      else:
        start += 'S' if start[-2] == 'W' else 'W'
  if (start[-1] == 'S' and s[-1] == 'o' and start[-2] == 'W' and s[0] == 'o') or \
    (start[-1] == 'S' and s[-1] == 'x' and start[-2] == 'S' and s[0] == 'o') or \
    (start[-1] == 'W' and s[-1] == 'o' and start[-2] == 'S' and s[0] == 'x') or \
    (start[-1] == 'W' and s[-1] == 'x' and start[-2] == 'W' and s[0] == 'x'):
    print(start)
    is_zoo = True

if not is_zoo:
  print(-1)

Solution (Python):
n = int(input())
s = input()
s = list(map(lambda x:1 if x=="o" else -1,list(s)))
flag = False
for start in [[1,1], [1,-1], [-1, 1], [-1, -1]]:
    circle = start + [0]*(n-2)
    for i in range(1,n-1):
        circle[i+1] = circle[i]*s[i]*circle[i-1]
    
    if circle[-2] == circle[-1]*s[-1]*circle[0] and circle[-1] == circle[0]*s[0]*circle[1]:
        flag = True
        break
if flag:
    ans = ""
    for i in circle:
        if i == 1:
            ans += "S"
        else:
            ans += "W"
    print(ans)
else:
    print(-1)

Solution (Python):

N=int(input())
S=input()
def NoSW(a):
	if a=='S':
		return 'W'
	else: 
		return 'S'
def NoOX(a):
	if a=='o':
		return 'x'
	else: 
		return 'o'
C=['' for i in range(N)]
for a in ['S','W']: 
	for b in ['S','W']:
		C[0]=a
		C[1]=b
		for i in range(1,N-1):
			boo=0 if C[i]=='W' else 1
			if boo==(S[i]=='o'):
				C[i+1]=C[i-1]
			else:
				C[i+1]=NoSW(C[i-1])
		
		boo=1 if (S[0]=='o') == (C[0]=='S') else 0
		if boo != (C[N-1]==C[1]):
			continue
		boo=1 if (S[N-1]=='o') == (C[N-1]=='S') else 0
		if boo != (C[N-2]==C[0]):
			continue
		print(''.join(C))
		exit()
print(-1)

Solution (Python):

import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
s = input()[:-1]
ans = [1]*(N+2)


def print_ans(l: list):
    ret = ""
    for a in l[1:-1]:
        ret += "S" if a else "W"
    print(ret)


def next(ind: int, isSame: bool, isSheep: bool)->bool:
    return isSame ^ isSheep ^ ans[ind-1]


def check(first: bool, last: bool)->list:
    ans[0] = last
    ans[1] = first
    for i in range(1, N+1):
        ans[i+1] = next(i, s[i-1] == "o", ans[i])

    return ans[0] == ans[N] and ans[1] == ans[N+1]


for first in [True, False]:
    for last in [True, False]:
        if check(first, last):
            print_ans(ans)
            exit()
print("-1")

Solution (Python):

import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
s = input()[:-1]
ans = [1]*(N+2)


def print_ans(l: list):
    ret = ""
    for a in l[1:-1]:
        ret += "S" if a else "W"
    print(ret)


def next(ind: int, isSame: bool, isSheep: bool)->bool:
    if isSame:
        if isSheep:
            return ans[ind-1]
        else:
            return not ans[ind-1]
    else:
        if isSheep:
            return not ans[ind-1]
        else:
            return ans[ind-1]

    return isSame ^ isSheep ^ ans[ind-1]


def check(first: bool, last: bool)->list:
    ans[0] = last
    ans[1] = first
    for i in range(1, N+1):
        ans[i+1] = next(i, s[i-1] == "o", ans[i])

    return ans[0] == ans[N] and ans[1] == ans[N+1]


for first in [True, False]:
    for last in [True, False]:
        if check(first, last):
            print_ans(ans)
            exit()
print("-1")

Solution (Python):

import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
s = input()[:-1]
ans = [1]*(N+2)


def print_ans(l: list):
    """
    T,Fからなる配列を受け取る
    T->S
    F->Wに変えて出力する
    """
    ret = ""
    for a in l[1:-1]:
        ret += "S" if a else "W"
    print(ret)


def next(ind: int, isSame: bool, isSheep: bool)->bool:
    """
    ind+1の動物を決める
    """
    if isSame:
        if isSheep:
            return ans[ind-1]
        else:
            return not ans[ind-1]
    else:
        if isSheep:
            return not ans[ind-1]
        else:
            return ans[ind-1]


def check(first: bool, last: bool)->list:
    """
    Lは動物の並び
    True;羊
    False:狼
    L=[L[-1],L[0],...]として、sの情報に従って隣を決めていく。
    最後まで行ったときに、最後の値がlastと一致するならok
    番兵的な
    """
    ans[0] = last
    ans[1] = first
    for i in range(1, N+1):
        ans[i+1] = next(i, s[i-1] == "o", ans[i])

    return ans[0] == ans[N] and ans[1] == ans[N+1]


for first in [True, False]:
    for last in [True, False]:
        if check(first, last):
            print_ans(ans)
            exit()
print("-1")

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



def f(k):
    if s[k] == 'o' and a[k] == 1:
        a[k+1] = a[k-1]
    elif s[k] == 'o' and a[k] == -1:
        a[k+1] = a[k-1]*(-1)
    elif s[k] == 'x' and a[k] == 1:
        a[k+1] = a[k-1]*(-1)
    else:
        a[k+1] = a[k-1]
judge = -1
for e in [[1,1],[1,-1],[-1,1],[-1,-1]]:
    if judge == -1:
        a = [0]*n
        a[0] = e[0]
        a[1] = e[1]
        for j in range(1,n-1):
            f(j)
        if s[0] == 'o' and a[0] == 1:
            if a[1] ==  a[-1]:
                judge = 1
        elif s[0] == 'o' and a[0] == -1:
            if a[1] == a[-1]*(-1):
                judge = 1
        elif s[0] == 'x' and a[0] == 1:
            if a[+1] == a[-1]*(-1):
                judge = 1
        else:
            if a[1] == a[-1]:
                judge = 1
        if judge == 1:
            if s[n-1] == 'o' and a[n-1] == 1:
                if a[0] != a[n-2]:
                    judge = -1
            elif s[n-1] == 'o' and a[n-1] == -1:
                if a[0] != a[n-2]*(-1):
                    judge = -1
            elif s[n-1] == 'x' and a[n-1] == 1:
                if a[0] != a[n-2]*(-1):
                    judge = -1
            else:
                if a[0] != a[n-2]:
                    judge = -1
if judge == -1:
    print(-1)
else:
    ans = ''
    for i in range(n):
        if a[i] == 1:
            ans += 'S'
        else:
            ans += 'W'
    print(ans)

Solution (Python):


def main():
    n = int(input())
    s = input()
    s = list(s)
    s.append(s[0])
    for d0 in ["S", "W"]:
        for d1 in ["S", "W"]:
            pat = wrap(n, s, d0, d1)
            if pat[0] == pat[n] and pat[1] == pat[n + 1]:
                res = "".join(pat[:n])
                print(res)
                return
    print("-1")

def wrap(n, s, d0, d1):
    ds = [d0, d1]
    for i in range(2, n + 2):
        d = get_dnext(ds[i - 2], ds[i - 1], s[i - 1])
        ds.append(d)
    assert len(ds) == n + 2
    return ds

def get_dnext(dpre, di, si):
    if di == "S" and si == "o":
        dnext = dpre
    elif di == "S" and si == "x":
        dnext = inv(dpre)
    elif di == "W" and si == "o":
        dnext = inv(dpre)
    elif di == "W" and si == "x":
        dnext = dpre
    else:
        raise Exception
    return dnext

def inv(d):
    return "W" if d == "S" else "S"

main()

Solution (Python):

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

bool_list = [[True,True],[True,False],[False,True],[False,False]]

flag=False
for boo in bool_list:
    ans_list = list(boo)
    for i in range(1,N):

        if S[i]=="o":
            if ans_list[i]:
                if ans_list[i-1]:
                    ans_list.append(True)
                else:
                    ans_list.append(False)
            else:
                if ans_list[i-1]:
                    ans_list.append(False)
                else:
                    ans_list.append(True)
        else:
            if not ans_list[i]:
                if ans_list[i-1]:
                    ans_list.append(True)
                else:
                    ans_list.append(False)
            else:
                if ans_list[i-1]:
                    ans_list.append(False)
                else:
                    ans_list.append(True)
    
    if S[0]=="o":
        if ans_list[0]:
            if ans_list[1]:
                N_cand=True
            else:
                N_cand=False
        else:
            if ans_list[1]:
                N_cand=False
            else:
                N_cand=True
    else:
        if not ans_list[0]:
            if ans_list[1]:
                N_cand=True
            else:
                N_cand=False
        else:
            if ans_list[1]:
                N_cand=False
            else:
                N_cand=True
    
    if ans_list[0]==ans_list[N] and N_cand==ans_list[N-1]:
        flag=True
        break

if flag:
    ans=""
    for a in ans_list[:-1]:
        if a:
            ans+="S"
        else:
            ans+="W"
    print(ans)
else:
    print(-1)

Solution (Python):
def p(w,r,m,c=1):
    n=d.index(w[r])+d.index(w[r-c])+x.index(m)
    return d[n%2]

a=['SS','SW','WS','WW']
d=['S','W']
x=['o','x']

n=int(input())
s=input()
for j in range(4):
    for i in range(1,n):
        a[j]+=p(a[j],i,s[i])
    a[j]=p(a[j],0,s[0],-1)+a[j]

ans=-1
for w in a:
    if w[0]==w[-2] and w[1]==w[-1]:
        ans=w[1:-1]
print(ans)

Solution (Python):
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':
            if a[j][0]=='S' and a[j][-2]==a[j][1]:
                ans=a[j][:-1]
                break
            if a[j][0]=='W' and a[j][-2]!=a[j][1]:
                ans=a[j][:-1]
                break
        if s[0]=='x':
            if  a[j][0]=='S' and a[j][-2]!=a[j][1]:
                ans=a[j][:-1]
                break
            if  a[j][0]=='W' and a[j][-2]==a[j][1]:
                ans=a[j][:-1]
                break
print(ans)

Solution (Python):
N=int(input())
s=list(input())
s.append(s[0])
A=[list("SS"+"?"*(N)),list("WS"+"?"*(N)),list("SW"+"?"*(N)),list("WW"+"?"*(N))]
for a in A:
  for i in range(2,N+2):
    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]==a[N] and a[1]==a[N+1]:
    print("".join(a[:N]))
    exit()
    
print(-1)

Solution (Python):
n = int(input())
s = input()
for c in ['SS','SW','WS','WW']:
    for d in range(1,n-1):
        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'
    res = ''
    for i in range(len(c)):
        if c[i-1] == c[(i+1)-len(c)]:
            if c[i] == 'S':
                res += 'o'
            else:
                res += 'x'
        else:
            if c[i] == 'S':
                res += 'x'
            else:
                res += 'o'
    if res == s:
        print(c)
        exit()
print(-1)

Solution (Python):

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

def check(l):
    if s[0]=="o":
        if l[0]=="S":
            if l[-1]!=l[1]:
                return False
        else:
            if l[-1]==l[1]:
                return False
    else:
        if l[0]=="S":
            if l[-1]==l[1]:
                return False
        else:
            if l[-1]!=l[1]:
                return False
    for i in range(1,n-1):
        if s[i]=="o":
            if l[i]=="S":
                if l[i-1]!=l[i+1]:
                    return False
            else:
                if l[i-1]==l[i+1]:
                    return False
        else:
            if l[i]=="S":
                if l[i-1]==l[i+1]:
                    return False
            else:
                if l[i-1]!=l[i+1]:
                    return False
    if s[n-1]=="o":
        if l[n-1]=="S":
            if l[n-2]!=l[0]:
                return False
        else:
            if l[n-2]==l[0]:
                return False
    else:
        if l[n-1]=="S":
            if l[n-2]==l[0]:
                return False
        else:
            if l[n-2]!=l[0]:
                return False
    return True

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

def fill(s0,s1):
    ret = [None for _ in range(n)]
    ret[0] = s0
    ret[1] = s1
    for i in range(1,n-1):
        if ret[i]=="S" and s[i]=="o":
            ret[i+1] = ret[i-1]
        elif ret[i]=="S" and s[i]=="x":
            ret[i+1] = flip(ret[i-1])
        elif ret[i]=="W" and s[i]=="o":
            ret[i+1] = flip(ret[i-1])
        elif ret[i]=="W" and s[i]=="x":
            ret[i+1] = ret[i-1]
    
    if check(ret):
        return ret
    else:
        return None

ret = fill("S","S")
if ret is not None:
    print("".join(ret))
    exit()

ret = fill("S","W")
if ret is not None:
    print("".join(ret))
    exit()

ret = fill("W","S")
if ret is not None:
    print("".join(ret))
    exit()

ret = fill("W","W")
if ret is not None:
    print("".join(ret))
    exit()
print(-1)

Solution (Python):
N = int(input())
S = input()
S += S[0]

def roop(St):
    for i in range(1,N+1):
        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[-2] and a[1] == a[-1] :
        ans = a[0:N]
        break
print(ans)

Solution (Python):
N=int(input())
s=input()
S=[1 if i=="o" else -1 for i in s]

X=[[0 for i in range(N)] for i in range(4)]
X[0][0]=1
X[0][1]=1
X[1][0]=1
X[1][1]=-1
X[2][0]=-1
X[2][1]=1
X[3][0]=-1
X[3][1]=-1
for k in range(4):
    for i in range(2,N):
        if S[i-1]*X[k][i-1]==1:
            X[k][i]=X[k][i-2]
        else:
            X[k][i]=-X[k][i-2]
    flag=0
    for i in range(2):
        if S[i-1]*X[k][i-1]==1:
            if X[k][i]!=X[k][i-2]:
                flag=1
        else:
            if X[k][i]!=-X[k][i-2]:
                flag=1
    if flag==0:
        T=""
        for i in range(N):
            if X[k][i]==1:
                T=T+"S"
            else:
                T=T+"W"
        print(T)
        exit()
print(-1)

Solution (Python):
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]) \
        and (getSpecies(anss[0], ss[0], anss[-1]) == anss[1]):
        print(''.join(anss))
        break
else:
    print(-1)

Solution (Python):
def assign(s,ans,n):
    for i in range(1,n-1):
        if s[i] == "o":
            if ans[i] == "S":
                if ans[i-1] == "S":
                    ans[i+1] = "S"
                else:
                    ans[i+1] = "W"
            else:
                if ans[i-1] == "S":
                    ans[i+1] = "W"
                else:
                    ans[i+1] = "S"
        else:
            if ans[i] == "S":
                if ans[i-1] == "S":
                    ans[i+1] = "W"
                else:
                    ans[i+1] = "S"
            else:
                if ans[i-1] == "W":
                    ans[i+1] = "W"
                else:
                    ans[i+1] = "S"
    return ans

def judge(s,ans):
    check = True
    if s[0] == "o":
        if ans[0] == "S":
            if ans[1] != ans[-1]:
                check = False
        else:
            if ans[1] == ans[-1]:
                check = False
    else:
        if ans[0] == "S":
            if ans[1] == ans[-1]:
                check = False
        else:
            if ans[1] != ans[-1]:
                check = False

    if s[-1] == "o":
        if ans[-1] == "S":
            if ans[-2] != ans[0]:
                check = False
        else:
            if ans[-2] == ans[0]:
                check = False
    else:
        if ans[-1] == "S":
            if ans[-2] == ans[0]:
                check = False
        else:
            if ans[-2] != ans[0]:
                check = False
    return check


n = int(input())
s = list(input())
whole = False
for i in range(4):
    ans = [1 for i in range(n)]
    if i == 0:
        ans[0] = "S"
        ans[1] = "S"
    elif i == 1:
        ans[0] = "S"
        ans[1] = "W"
    elif i == 2:
        ans[0] = "W"
        ans[1] = "S"
    elif i == 3:
        ans[0] = "W"
        ans[1] = "W"
    ans = assign(s,ans,n)
    check = judge(s,ans)
    if check:
        for i in range(n):
            if i != n-1:
                print(ans[i],end = "")
            else:
                print(ans[i])
        whole = True
        break
if whole == False:
    print("-1")

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

S = input()

start_set = []

start_set.append("SS") 
start_set.append("SW")
start_set.append("WS")
start_set.append("WW")

def listed_goal_set(i):
    goal_set = []
    if S[i] == "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")
    return goal_set
    
goal_set1 = listed_goal_set(0)
goal_set2 = listed_goal_set(-1)
    
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") 
                else:
                    O.append("W") 
            else:
                if S[i]=="o":
                    O.append("W") 
                else:
                    O.append("S") 
                
        if O[i-1]=="W":
            if O[i]=="S":
                if S[i]=="o":
                    O.append("W") 
                else:
                    O.append("S") 
            else:
                if S[i]=="o":
                    O.append("S") 
                else:
                    O.append("W") 
    
    goals1 = O[-1]+O[0]+O[1]
    goals2 = O[-2]+O[-1]+O[0]
    if goals1 in goal_set1 and goals2 in goal_set2:
        isok = True
        break
                
if isok:
    print("".join(O))
else:
    print("-1")

Solution (Python):
N = int(input())
s = input()
s = s[1:] + s[0]
ans = []
for i, j in [('S', 'S'), ('S', 'W'), ('W', 'S'), ('W', 'W')]:
    ans = [i, j]
    for si in s:
        if ans[-1] == 'S':
            if si == 'o':
                ans.append(ans[-2])
            else:
                ans.append('W' if ans[-2] == 'S' else 'S')
        else:
            if si == 'o':
                ans.append('W' if ans[-2] == 'S' else 'S')
            else:
                ans.append(ans[-2])
    if ans[:2] == ans[-2:]:
        print(''.join(ans[:-2]))
        break
else:
    print(-1)

Solution (Python):
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]
    else:
      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"):
    va=(l[-2]==l[0])
  else:
    va=(l[-2]!=l[0])
  if (s[0]=="o" and l[0]=="S") or (s[0]=="x" and l[0]=="W"):
    vb=(l[1]==l[-1])
  else:
    vb=(l[1]!=l[-1])
  return va&vb,l

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

Solution (Python):
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import *
from bisect import bisect

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

N = read()
s = [1 if x == 'o' else 0 for x in input()]

MAP = ['W', 'S']
def dump(res):
  return "".join(MAP[x] for x in res)

for p0, p1 in product(range(2), range(2)):
  res = [p0, p1] + [0] * (N - 2)
  for i in range(2, N):
    res[i] = res[i-2] ^ res[i-1] ^ s[i-1]
  if res[0] == res[-2] ^ res[-1] ^ s[-1] and res[1] == res[-1] ^ res[0] ^ s[0]:
    print(dump(res)); exit()

print(-1)