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()

Ans = [[0] * N for _ in range(4)]
Ans[0][0] = 1
Ans[0][1] = 1
Ans[1][0] = 1
Ans[1][1] = 2
Ans[2][0] = 2
Ans[2][1] = 1
Ans[3][0] = 2
Ans[3][1] = 2

def isok(a):
    for i, s in enumerate(S):
        if i + 2 < N:
            if s == 'o':
                if a[i + 1] == 1:
                    a[i + 2] = a[i]
                else:
                    a[i + 2] = 3 - a[i]
            else:
                if a[i + 1] == 1:
                    a[i + 2] = 3 - a[i]
                else:
                    a[i + 2] = a[i]
        else:
            if s == 'o':
                if a[(i + 1) % N] == 1:
                    if a[(i + 2) % N] != a[i]:
                        return False
                else:
                    if a[(i + 2) % N] + a[i] != 3:
                        return False
            else:
                if a[(i + 1) % N] == 1:
                    if a[(i + 2) % N] + a[i] != 3:
                        return False
                else:
                    if a[(i + 2) % N] != a[i]:
                        return False
    return True

flag = True
num = -1
for i in range(4):
    if isok(Ans[i]):
        num = i
        flag = False
        break
if flag:
    print(-1)
else:
    for a in Ans[num][1:]:
        if a == 1:
            print('S', end='')
        else:
            print('W',end='')
    if Ans[num][0] == 1:
        print('S')
    else:
        print('W')

Solution (Python):
import copy
n = int(input())
s = input()
s += s[0]+s[1]

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

for x in kouho:
    ans = copy.deepcopy(x)
    for i in range(1,n+1):
        if (s[i]=='o' and ans[i]=='S') or (s[i]=='x' and ans[i]=='W'):
            if ans[i-1]=='S':
                ans+= 'S'
            else:
                ans+='W'
        else:
            if ans[i-1]=='S':
                ans+='W'
            else:
                ans+='S'
    
    if ans[-2:]==x:
       print(ans[:n])
       exit()
print(-1)

Solution (Python):
n = int(input())
s = input()
s += s[0]+s[1]
case = ["SS","SW","WS","WW"]
for x in case:
    animal = x
    for i in range(1,n+1):
        if (s[i] == "o" and animal[i] == "S") or (s[i] == "x" and animal[i] == "W"):
            if animal[i-1] == "S": 
                animal += "S"
            else: 
                animal += "W"
        elif animal[i-1] == "S": 
                animal += "W"
        else: 
            animal += "S"
    if animal[-2:] == x:
        print(animal[:n])
        exit()
print(-1)

Solution (Python):
import itertools
n = int(input())
s = input()
t = [''] * n
for p in itertools.product(['o', 'x'], repeat=2):
  t[-1] = p[0]
  t[0] = p[1]
  for i in range(1, n - 1):
    if (t[i - 2] + t[i - 1] + s[i - 1]).count('x') % 2 == 0:
      t[i] = 'o'
    else:
      t[i] = 'x'
  if (t[-3] + t[-2] + t[-1] + s[-2]).count('x') % 2 == 0 and (t[-2] + t[-1] + t[0] + s[-1]).count('x') % 2 == 0:
    ans = []
    for c in t:
      if c == 'o':
        ans.append('S')
      else:
        ans.append('W')
    print(*ans, sep='')
    break
else:
  print(-1)

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

def check(s, i, j, k):
    if j and s == "o" and i != k:
        return True
    elif j and s == "x" and i == k:
        return True
    elif not j and s == "o" and i == k:
        return True
    elif not j and s == "x" and i != k:
        return True
    return False

def func(f, s):
    l = [-1]*N
    l[0] = f
    l[1] = s
    for i in range(1, len(l) - 1):
        if l[i] and S[i] == "o" or not l[i] and S[i] == "x":
            l[i + 1] = l[i - 1] ^ 1
        else:
            l[i + 1] = l[i - 1]
    if check(S[-1], l[-2], l[-1], l[0]):
        if check(S[0], l[-1], l[0], l[1]):
            return l
    return False

for i, j in [(0, 0), (0, 1), (1, 1), (1, 0)]:
    l = func(i, j)
    if l:
        for v in l:
            print("SW"[v], end="")
        print()
        exit()
print(-1)

Solution (Python):
def next_animal(before, current, claim):
    if (before == current and claim == 'x') or \
        (before != current and claim == 'o'):
        return 'W'
    else:
        return 'S'


def search(S):
    assert len(S) > 2
    init_twos = ['SS', 'SW', 'WS', 'WW']
    ret = ''
    for init_two in init_twos:
        animals = init_two
        for i in range(1, len(S) - 1):
            a = next_animal(animals[i - 1], animals[i], S[i])
            animals += a
        
        if animals[1] != next_animal(animals[-1], animals[0], S[0]):
            continue
        if animals[0] != next_animal(animals[-2], animals[-1], S[-1]):
            continue
        ret = animals
        break
    return ret


def main():
    N = int(input())
    S = input()
    ret = search(S)
    if len(ret) > 0:
        print(ret)
    else:
        print(-1)


if __name__ == '__main__':
    main()

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

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

Solution (Python):

import sys
input = sys.stdin.readline





def check(a0, a1):
    b0,b1 = a0,a1
    Ans = a1
    for i in range(N):
        
        if a1 == "S":
            
            if S[i] == "o":
                a2 = a0
            else:
                a2 = B[a0]
        
        else:
            
            if S[i] == "o":
                a2 = B[a0]
            else:
                a2 = a0
        Ans += a2
        a0,a1 = a1,a2
    if Ans[0] == Ans[N] and Ans[0] == b1 and Ans[N-1] == b0:
        return Ans[0:N]
    else:
        return -1




N = int(input())
S = input().rstrip()

B = {"S":"W", "W":"S"}
S0S1 = [("S","S"), ("S","W"), ("W","S"), ("W","W")]

for s0,s1 in S0S1:
    Ans = check(s0,s1)
    if Ans != -1:
        print(Ans)
        sys.exit()

print(-1)

Solution (Python):
import bisect
import collections
import copy
import functools
import heapq
import math
import sys
from collections import deque
from collections import defaultdict
input = sys.stdin.readline
MOD = 10**9+7

N = int(input())
s = list(input().rstrip())
s.append(s[0])
a = [-1]*(N+2) 

def d(self,f,ans):
    if ans == "o":
        return (self + f)%2
    else:
        return (self + f +1)%2

flag = 0
for p in [(0,0),(0,1),(1,0),(1,1)]:
    a[0],a[1] = p
    for i in range(1,N+1):
        a[i+1] = d(a[i],a[i-1],s[i])
    if a[0] == a[N] and a[1] == a[N+1]:
        break
else:
    flag = -1

if flag == -1:
    print(-1)
else:
    ans = [None]*N
    for i in range(N):
        if a[i] == 0:
            ans[i] = "S"
        else:
            ans[i] = "W"
    output = "".join(ans)
    print(output)

Solution (Python):
from itertools import product

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

swap = {'S': 'W', 'W': 'S'}
for a, b in product('SW', repeat=2):
    t = [None] * N
    t[0] = a
    t[1] = b
    for i in range(1, N - 1):
        if t[i] == 'S':
            if s[i] == 'o':
                t[i + 1] = t[i - 1]
            elif s[i] == 'x':
                t[i + 1] = swap[t[i - 1]]
        elif t[i] == 'W':
            if s[i] == 'o':
                t[i + 1] = swap[t[i - 1]]
            elif s[i] == 'x':
                t[i + 1] = t[i - 1]
    if t[N - 1] == 'S':
        if s[N - 1] == 'o' and t[N - 2] != t[0]:
            continue
        elif s[N - 1] == 'x' and t[N - 2] == t[0]:
            continue
    elif t[N - 1] == 'W':
        if s[N - 1] == 'o' and t[N - 2] == t[0]:
            continue
        elif s[N - 1] == 'x' and t[N - 2] != t[0]:
            continue
    if t[0] == 'S':
        if s[0] == 'o' and t[N - 1] != t[1]:
            continue
        elif s[0] == 'x' and t[N - 1] == t[1]:
            continue
    elif t[0] == 'W':
        if s[0] == 'o' and t[N - 1] == t[1]:
            continue
        elif s[0] == 'x' and t[N - 1] != t[1]:
            continue
    print(''.join(t))
    exit()
print(-1)

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

for j in pat:
    now = j
    flag = True
    for i in range(1,n+1):
        if (now[i] == "S" and s[i] == "o") or (now[i] == "W" and s[i] == "x"):
            now += now[i-1]
        else:
            if now[i-1] == "S":
                now += "W"
            else:
                now += "S"
    if now[0] == now[-2] and now[1] == now[-1]:
        print(now[:-2])
        exit()

print(-1)

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

for j in pat:
    now = j
    flag = True
    for i in range(1,n+1):
        if (now[i] == "S" and s[i] == "o") or (now[i] == "W" and s[i] == "x"):
            now += now[i-1]
        else:
            if now[i-1] == "S":
                now += "W"
            else:
                now += "S"
    if now[0] == now[-2] and now[1] == now[-1]:
        print(now[:-2])
        exit()

print(-1)

Solution (Python):
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt, ceil
from functools import lru_cache, reduce
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True




def warshall_floyd(d, n):
    
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d



def dijkstra_heap(s, edge, n):
    
    d = [10**20] * n
    used = [True] * n 
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr


def lcm(x, y):
    return (x * y) // gcd(x, y)


def lcm_list(numbers):
    return reduce(lcm, numbers, 1)


def gcd_list(numbers):
    return reduce(gcd, numbers)






def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P


def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret



n = int(input())
s = input()
impossible = True
for i in ["S", "W"]:
    for j in ["S", "W"]:
        x = i + j
        
        for k in range(1, n - 1):
            if s[k] == "o" and x[-1] == "S":
                if x[-2] == "S":
                    x += "S"
                else:
                    x += "W"
            elif s[k] == "o" and x[-1] == "W":
                if x[-2] == "S":
                    x += "W"
                else:
                    x += "S"
            elif s[k] == "x" and x[-1] == "S":
                if x[-2] == "S":
                    x += "W"
                else:
                    x += "S"
            elif s[k] == "x" and x[-1] == "W":
                if x[-2] == "S":
                    x += "S"
                else:
                    x += "W"
            
                
        
        ok = True
        if (s[-1] == "o" and x[-1] == "S") or (s[-1] == "x" and x[-1] == "W"):
            if x[-2] != x[0]:
                ok = False
        elif x[-2] == x[0]: 
            ok = False
        if (s[0] == "o" and x[0] == "S") or (s[0] == "x" and x[0] == "W"):
            if x[-1] != x[1]:
                ok = False
        elif x[-1] == x[1]:
            ok = False
        if ok and impossible:
            print(x)
            impossible = False
if impossible:
    print(-1)

Solution (Python):


import sys






















from itertools import product, permutations  







def main():
    mod = 1000000007                
    inf = float('inf')              
    
    sys.setrecursionlimit(10**6)    
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    def check_no_contradict(n, new_s, pattern):
        animals = [None] * (n + 2)
        animals[1], animals[2] = pattern
        animals[0] = animals[2] if (animals[1] and new_s[1] == 'o') or (not animals[1] and new_s[1] == 'x') else not animals[2]
        for i in range(2, n + 1):
            animals[i+1] = animals[i-1] if (animals[i] and new_s[i] == 'o') or (not animals[i] and new_s[i] == 'x') else not animals[i-1]
        if animals[0] == animals[n] and animals[1] == animals[n + 1]:
            return animals[1:n+1]
        else:
            return []


    
    n = ii()
    s = input()
    new_s = s[-1] + s + s[0]    
    for pattern in product([True, False], repeat=2):
        result = check_no_contradict(n, new_s, pattern)
        if result:
            print(''.join(list(map(lambda x: 'S' if x else 'W', result))))
            exit()
    print(-1)





if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
s = input()
s += s[0]
d = {'S':'W', 'W':'S'}
flag = True
for sw in ['SS', 'WW', 'SW', 'WS']:
    l = sw
    for i in range(1, n+1):
        if l[i] == 'S' and s[i] == 'o' or l[i] == 'W' and s[i] == 'x':
            l += l[i-1]
        else:
            l += d[l[i-1]]
    if l[0] == l[-2] and l[1] == l[-1] :
        print(l[:-2])
        flag = False
        break
if flag:
    print(-1)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    s = input()
    L = ["S", "W"]

    for first in L:
        for second in L:
            res = ["" for _ in range(n)]
            res[0] = first
            res[1] = second
            for i in range(1, n - 1):
                if s[i] == "o":
                    if res[i] == "S" and res[i - 1] == "S":
                        res[i + 1] = "S"
                    elif res[i] == "S" and res[i - 1] == "W":
                        res[i + 1] = "W"
                    elif res[i] == "W" and res[i - 1] == "W":
                        res[i + 1] = "S"
                    else:
                        res[i + 1] = "W"
                else:
                    if res[i] == "S" and res[i - 1] == "S":
                        res[i + 1] = "W"
                    elif res[i] == "S" and res[i - 1] == "W":
                        res[i + 1] = "S"
                    elif res[i] == "W" and res[i - 1] == "W":
                        res[i + 1] = "W"
                    else:
                        res[i + 1] = "S"

            if s[-1] == "o":
                if (res[-1] == "S" and res[-2] != res[0]) or (res[-1] == "W" and res[-2] == res[0]):
                    continue
            else:
                if (res[-1] == "S" and res[-2] == res[0]) or (res[-1] == "W" and res[-2] != res[0]):
                    continue

            if s[0] == "o":
                if (res[0] == "S" and res[-1] != res[1]) or (res[0] == "W" and res[-1] == res[1]):
                    continue
            else:
                if (res[0] == "S" and res[-1] == res[1]) or (res[0] == "W" and res[-1] != res[1]):
                    continue

            print("".join(res))
            break
        else:
            continue
        break
    else:
        print(-1)


if __name__ == '__main__':
    resolve()

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

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

def wolfsheep(xy):
    global n,s
    result=[xy[0],xy[1]]

    for i in range(1,n+1):
        s+=s[0]
        if result[i]=="S":
            if s[i]=="o":
                result.append(result[i-1])
            else:
                result.append(rev(result[i-1]))
        else:
            if s[i]=="o":
                result.append(rev(result[i-1]))
            else:
                result.append(result[i-1])

    if result[0]==result[n] and result[1]==result[n+1]:
        return result
    else:
        return 0


tmp= wolfsheep("SW")
if tmp!=0:
    print("".join(tmp[:-2]))
    exit()


tmp= wolfsheep("SS")
if tmp!=0:
    print("".join(tmp[:-2]))
    exit()

tmp= wolfsheep("WW")
if tmp!=0:
    print("".join(tmp[:-2]))
    exit()

tmp= wolfsheep("WS")
if tmp!=0:
    print("".join(tmp[:-2]))
    exit()

print(-1)

Solution (Python):

import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N=int(input())
    s=input()
    s=s+s[0]
    for j in range(4):
        l=[-1]*(N+2)
        for k in range(2):
            l[k]=(j>>k)&1
        for i in range(1,N+1):
            if l[i]==0:
                if s[i-1]=='o':
                    l[i+1]=l[i-1]
                else:
                    l[i+1]=int(not l[i-1])
            else:
                if s[i-1]=='o':
                    l[i+1]=int(not l[i-1])
                else:
                    l[i+1]=l[i-1]
        if l[0]==l[-2] and l[1]==l[-1]:
            for x in l[1:N+1]:
                if x==0:
                    print('S',end='')
                else:
                    print('W',end='')
            print('')
            exit()
    print(-1)

if __name__ == '__main__':
    main()

Solution (Python):
def convert(s):
    if s == 'S' or s == 'o':
        return 1
    else:
        return -1


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

cands = [['S', 'S'], ['S', 'W'], ['W', 'S'], ['W', 'W']]

for cand in cands:
    for i in range(1, len(s)-1):
        if cand[-1] == 'S':
            if s[i] == 'o' and cand[-2] == 'S':
                cand.append('S')
            elif s[i] == 'x' and cand[-2] == 'S':
                cand.append('W')
            elif s[i] == 'o' and cand[-2] == 'W':
                cand.append('W')
            else:
                cand.append('S')
        else:
            if s[i] == 'o' and cand[-2] == 'S':
                cand.append('W')
            elif s[i] == 'x' and cand[-2] == 'S':
                cand.append('S')
            elif s[i] == 'o' and cand[-2] == 'W':
                cand.append('S')
            else:
                cand.append('W')
    if (convert(cand[0]) * convert(cand[-1]) * convert(cand[1]) * convert(s[0]) == 1) and \
            (convert(cand[0]) * convert(cand[-1]) * convert(cand[-2]) * convert(s[-1]) == 1):
        print(''.join(cand))
        exit()

print(-1)

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

s = input()


def fnc(x1, x2):
    pre = x1  
    curr = x2  
    ans = []
    for i in range(N):
        if curr == 1:  
            if s[i] == 'o':
                nv = pre
            else:
                nv = (pre + 1) % 2
        else:  
            if s[i] == 'x':
                nv = pre
            else:
                nv = (pre + 1) % 2
        pre = curr
        curr = nv
        ans.append(pre)

    if pre == x1 and curr == x2:
        return ans
    else:
        return None


def solve():
    for i in [1, 0]:
        for j in [1, 0]:
            ans = fnc(i, j)
            if ans:
                return ans
    return None


if __name__ == '__main__':
    ans = solve()
    if not ans:
        print(-1)
        exit()

    for a in ans:
        print('S' if a else 'W', end='')
    print()

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

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

sl = list(s)
dp =[0]*n
dp[0]="S"
dp[1]="S"
sw(sl,dp)
if sl[0] =="o":
    if dp[n-1] =="W":
        pass
    elif sl[n-1] =="x":
        if dp[n-2] =="S":
            pass
        else:
            res = ''.join(dp)
            print(res)
            exit()
    elif sl[n-1] =="o":
        if dp[n-2] =="S":
            res = ''.join(dp)
            print(res)
            exit()
        else:
            pass
else:
    if dp[n-1] =="S":
        pass
    elif sl[n-1] =="x":
        if dp[n-2] =="W":
            pass
        else:
            res = ''.join(dp)
            print(res)
            exit()
    elif sl[n-1] =="o":
        if dp[n-2] =="W":
            res = ''.join(dp)
            print(res)
            exit()
        else:
            pass

dp =[0]*n
dp[0]="S"
dp[1]="W"
sw(sl,dp)
if sl[0] =="o":
    if dp[n-1] =="S":
        pass
    elif sl[n-1] =="x":
        if dp[n-2] =="W":
            pass
        else:
            res = ''.join(dp)
            print(res)
            exit()
    elif sl[n-1] =="o":
        if dp[n-2] =="W":
            res = ''.join(dp)
            print(res)
            exit()
        else:
            pass
else:
    if dp[n-1] =="W":
        pass
    elif sl[n-1] =="x":
        if dp[n-2] =="S":
            pass
        else:
            res = ''.join(dp)
            print(res)
            exit()
    elif sl[n-1] =="o":
        if dp[n-2] =="S":
            res = ''.join(dp)
            print(res)
            exit()
        else:
            pass
    
dp =[0]*n
dp[0]="W"
dp[1]="S"
sw(sl,dp)
if sl[0] =="o":
    if dp[n-1] =="S":
        pass
    elif sl[n-1] =="x":
        if dp[n-2] =="S":
            pass
        else:
            res = ''.join(dp)
            print(res)
            exit()
    elif sl[n-1] =="o":
        if dp[n-2] =="S":
            res = ''.join(dp)
            print(res)
            exit()
        else:
            pass
else:
    if dp[n-1] =="W":
        pass
    elif sl[n-1] =="x":
        if dp[n-2] =="W":
            pass
        else:
            res = ''.join(dp)
            print(res)
            exit()
    elif sl[n-1] =="o":
        if dp[n-2] =="W":
            res = ''.join(dp)
            print(res)
            exit()
        else:
            pass
        
dp =[0]*n
dp[0]="W"
dp[1]="W"
sw(sl,dp)
if sl[0] =="o":
    if dp[n-1] =="W":
        pass
    elif sl[n-1] =="x":
        if dp[n-2] =="W":
            pass
        else:
            res = ''.join(dp)
            print(res)
            exit()
    elif sl[n-1] =="o":
        if dp[n-2] =="W":
            res = ''.join(dp)
            print(res)
            exit()
        else:
            pass
else:
    if dp[n-1] =="S":
        pass
    elif sl[n-1] =="x":
        if dp[n-2] =="S":
            pass
        else:
            res = ''.join(dp)
            print(res)
            exit()
    elif sl[n-1] =="o":
        if dp[n-2] =="S":
            res = ''.join(dp)
            print(res)
            exit()
        else:
            pass

print(-1)

Solution (Python):
import itertools
N=int(input())
slist=[x=="o" for x in input()]


answer_list=[None]*N

ok=False
for p1,p2 in itertools.product([True,False],repeat=2):
  answer_list[0]=p1
  answer_list[1]=p2
  
  for i in range(2,N):
    if answer_list[i-1]==slist[i-1]:
      answer_list[i]=answer_list[i-2]
    else:
      answer_list[i]=not answer_list[i-2]
        
  contra=False
  for i in range(N):
    l=(i-1)%N
    r=(i+1)%N
    if (answer_list[i]==slist[i])^(answer_list[l]==answer_list[r]):
      contra=True
  if not contra:
    ok=True
    break
    
if ok:
  sw_list=[]
  for ans in answer_list:
    if ans:
      sw_list.append("S")
    else:
      sw_list.append("W")
  print("".join(sw_list))
else:
  print(-1)

Solution (Python):
N=int(input())
slist=[x=="o" for x in input()]


answer_list=[0]*N

ok=False
for p1,p2 in [(1,1),(1,-1),(-1,1),(-1,-1)]:
  answer_list[0]=p1
  answer_list[1]=p2
  
  for i in range(2,N):
    if answer_list[i-1]==1:
      if slist[i-1]:
        answer_list[i]=answer_list[i-2]
      else:
        answer_list[i]=-answer_list[i-2]
    else:
      if slist[i-1]:
        answer_list[i]=-answer_list[i-2]
      else:
        answer_list[i]=answer_list[i-2]
        
  contra=False
  for i in range(N):
    l=(i-1)%N
    r=(i+1)%N
    if answer_list[i]==1:
      if slist[i]:
        if answer_list[l]!=answer_list[r]:
          contra=True
      else:
        if answer_list[l]==answer_list[r]:
          contra=True
    else:
      if slist[i]:
        if answer_list[l]==answer_list[r]:          
          contra=True
      else:
        if answer_list[l]!=answer_list[r]:
          contra=True

  if not contra:
    ok=True
    break
    
if ok:
  sw_list=[]
  for ans in answer_list:
    if ans==1:
      sw_list.append("S")
    else:
      sw_list.append("W")
  print("".join(sw_list))
else:
  print(-1)

Solution (Python):
import copy

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

flag = False
begin_list = [["S", "S"], ["W", "S"], ["S", "W"], ["W", "W"]]

for i in range(4):
  sub = copy.deepcopy(begin_list[i])
  judge = True
  for j in range(2, n):
    if s[j-1] == "o":
      if sub[j-1] == "S":
        if sub[j-2] == "S":
          sub.append("S")
        else:
          sub.append("W")
      else:
        if sub[j-2] == "S":
          sub.append("W")
        else:
          sub.append("S")
    else:
      if sub[j-1] == "S":
        if sub[j-2] == "S":
          sub.append("W")
        else:
          sub.append("S")
      else:
        if sub[j-2] == "S":
          sub.append("S")
        else:
          sub.append("W")
  if s[-1] == "o":
    if (sub[-1] == "S" and sub[-2] != sub[0]) or (sub[-1] == "W" and sub[-2] == sub[0]):
      continue
  else:
    if (sub[-1] == "S" and sub[-2] == sub[0]) or (sub[-1] == "W" and sub[-2] != sub[0]):
      continue
  if s[0] == "o":
    if (sub[0] == "S" and sub[-1] != sub[1]) or (sub[0] == "W" and sub[-1] == sub[1]):
      continue
  else:
    if (sub[0] == "S" and sub[-1] == sub[1]) or (sub[0] == "W" and sub[-1] != sub[1]):
      continue
  flag = True
  break

if flag:
  print("".join(sub))
else:
  print(-1)