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


d = [0]*N

def check(a, b):
    d[-1] = a
    d[0] = b
    for i in range(N-2):
        if S[i] == "o":
            if d[i] == 1:
                d[i+1] = d[i-1]
            else:
                d[i+1] = d[i-1]*-1
        else:
            if d[i] == 1:
                d[i+1] = d[i-1]*-1
            else:
                d[i+1] = d[i-1]
        
    for i in range(N-1):
        if d[i] == 1:
            if S[i] == "o":
                if d[i-1] != d[i+1]:
                    return False
            else:
                if d[i-1] == d[i+1]:
                    return False
        else:
            if S[i] == "o":
                if d[i-1] == d[i+1]:
                    return False
            else:
                if d[i-1] != d[i+1]:
                    return False
    if d[N-1] == 1:
        if S[N-1] == "o":
            if d[N-2] != d[0]:
                return False
        else:
            if d[N-2] == d[0]:
                return False
    else:
        if S[N-1] == "o":
            if d[N-2] == d[0]:
                return False
        else:
            if d[N-2] != d[0]:
                return False
    return True

if check(1, 1):
    pass
elif check(1, -1):
    pass
elif check(-1, -1):
    pass
elif check(-1, 1):
    pass
else:
    print(-1)
    exit()

ans = ""
for i in range(N):
    if d[i] == 1:
        ans += "S"
    else:
        ans += "W"
print(ans)

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

def sheep(a,b):
    l=[0]*(n+1)
    l[0]=a
    l[1]=b
    m=[]
    for i in range(1,n):
        if s[i]=="o":
            if l[i]==0:
                l[i+1]=l[i-1]
            else:
                l[i+1]=(l[i-1]+1)%2
        else:
            if l[i]==0:
                l[i+1]=(l[i-1]+1)%2
            else:
                l[i+1]=l[i-1]
    x=0
    if s[0]=="o":
        if l[0]==0:
            x=l[1]
        else:
            x=(l[1]+1)%2
    else:
        if l[0]==0:
            x=(l[1]+1)%2
        else:
            x=l[1]
    if l[n]==l[0] and x==l[n-1]:
        for i in range(n):
            if l[i]==0:
                m.append("S")
            else:
                m.append("W")
        print("".join(m))
        exit()

sheep(0,0)
sheep(0,1)
sheep(1,0)
sheep(1,1)
print("-1")

Solution (Python):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


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

out = None
for a0, a1 in (("W", "S"), ("S", "W"), ("S","S"), ("W", "W")):
    ans = [None]*n
    ans[0] = a0
    ans[-1] = a1
    for i in range(n-1):
        v = int(s[i]=="o") + int(ans[i-1]=="S") + int(ans[i]=="S")
        if v%2==1:
            ans[i+1] = "S"
        else:
            ans[i+1] = "W"
    v = int(s[n-1]=="o") + int(ans[n-2]=="S") + int(ans[0]=="S") + int(ans[n-1]=="S")
    if ans[-1]==a1 and v%2==0:
        out = ans
if out is not None:
    write("".join(out))
else:
    print(-1)

Solution (Python):
import sys
read = sys.stdin.buffer.read
input = sys.stdin.readline
input = sys.stdin.buffer.readline





def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))



from itertools import combinations

def main():
	n=II()
	s=input().decode()


	def check(a,b,c):
		A=[None]*(n+1)
		A[0]=a
		A[1]=b
		A[n-1]=c
		A[n]=a

		for i in range(1,n):
			if (s[i]=="o" and A[i]=="S") or (s[i]=="x" and A[i]=="W"):
				if A[i+1]==None:
					A[i+1]=A[i-1]
				else:
					if A[i+1]!=A[i-1]:
						return
			
			else:
				if A[i+1]==None:
					if A[i-1]=="S":
						A[i+1]="W"
					else:
						A[i+1]="S"
				else:
					if A[i+1]==A[i-1]:
						return

		print(*A[:-1],sep="")
		exit(0)

	if s[0]=="o":
		check("S","S","S")
		check("S","W","W")
		check("W","W","S")
		check("W","S","W")

	else:
		check("S","S","W")
		check("S","W","S")
		check("W","S","S")
		check("W","W","W")

	print(-1)













if __name__ == "__main__":
	main()

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

C = ('SS', 'SW', 'WS', 'WW')
for i in range(4):
    ans = list(C[i])
    for j in range(1, N):
        if (ans[-1] == 'S' and S[j] == 'o') or(ans[-1] == 'W' and S[j] == 'x'):
            ans.append(ans[-2])
        else:
            ans.append('S' if ans[-2] == 'W' else 'W')
    if ans[0] == ans[-1]:
        ans.pop()
        if (ans[0] == 'S' and S[0] == 'o' and ans[-1] == ans[1]) or \
            (ans[0] == 'S' and S[0] == 'x' and ans[-1] != ans[1]) or \
                (ans[0] == 'W' and S[0] == 'o' and ans[-1] != ans[1]) or \
                (ans[0] == 'W' and S[0] == 'x' and ans[-1] == ans[1]):
            print(''.join(ans))
            exit()
print(-1)

Solution (Python):
from collections import deque

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

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

for pat in patterns:
    q = deque(list(pat))
    bef = q[0]
    cur = q[1]
    for i in range(1,N+1):
        aft = ""
        if (cur == "S" and S[i%N] == "o") or (cur == "W" and S[i%N] == "x"):
            aft = "S" if bef == "S" else "W"
        else:
            aft = "S" if bef == "W" else "W"
        q.append(aft)
        bef = cur
        cur = aft

    if q[0] == q[-2] and q[1]==q[-1]:
        for i in range(N):
            print(q.popleft(), end="")
        print()
        exit()

print(-1)

Solution (Python):
import math



def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    
    return divisors

def ValueToBits(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res

def BitsToValue(arr):
    n = len(arr)
    ans = 0
    for i in range(n):
        ans+= arr[i] * 2**i
    return ans

def ZipArray(a):
    aa = [[a[i],i]for i in range(n)]

    aa.sort(key = lambda x : x[0])
    for i in range(n):
        aa[i][0]=i+1
    aa.sort(key = lambda x : x[1])
    b=[aa[i][0] for i in range(len(a))]
    return b

def ValueToArray10(x, digit):
    ans = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        ans[digit-i-1] = now%10
        now = now //10
    return ans

def Zeros(a,b):
    if(b<=-1):
        return [0 for i in range(a)]
    else:
        return [[0 for i in range(b)] for i in range(a)]

def AddV2(v,w):
    return [v[0]+w[0],v[1]+w[1]]

dir4 = [[1,0],[0,1],[-1,0],[0,-1]]


def clamp(x,y,z):
    return max(y,min(z,x))

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
            

def Zaatsu(a):
    a.sort()
    now = a[0][0]
    od = 0
    for i in range(n):
        if(now==a[i][0]):
            a[i][0]=od
        else:
            now = a[i][0]
            od+=1
            a[i][0] = od
    
    a.sort(key = lambda x : x[1])
    return a

class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)

    
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

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


'''
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 2
N = 10 ** 6 + 2
fact = [1, 1]  
factinv = [1, 1]  
inv = [0, 1]  

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

'''

def rl(x):
    return range(len(x))













n = int(input())

s = input()

ani = [0 for i in range(n)]



def calc():
    for i in range(1,n-1):
        if((ani[i]==0 and s[i]=='o') or (ani[i]==1 and s[i]=='x')):
            ani[i+1] = ani[i-1]
        else:
            ani[i+1] = 1 - ani[i-1]
    if(ani[0]==0):
        if((s[0]=='o' and ani[1]!=ani[-1])or(s[0]=='x' and ani[1]==ani[-1])):
            
            return
    else:
        if((s[0]=='x' and ani[1]!=ani[-1])or(s[0]=='o' and ani[1]==ani[-1])):
            
            return
    if(ani[-1]==0):
        if((s[-1]=='o' and ani[0]!=ani[-2])or(s[-1]=='x' and ani[0]==ani[-2])):
            
            return
    else:
        if((s[-1]=='x' and ani[0]!=ani[-2])or(s[-1]=='o' and ani[0]==ani[-2])):
            
            return
    anss=[]
    for j in range(n):
        anss.append('S' if ani[j]==0 else 'W')
    print(''.join(anss))
    exit()

ani[0] = 0
ani[1] = 0
calc()

ani[0] = 1
ani[1] = 0
calc()

ani[0] = 0
ani[1] = 1
calc()

ani[0] = 1
ani[1] = 1
calc()

print(-1)

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n=int(input())
    s=input()
    for ans in ("SS","SW","WS","WW"):
        for c in s[1:]:
            if ans[-1]=="S":
                ans+="W" if (ans[-2]=="W")^(c=="x") else "S"
            else:
                ans+="S" if (ans[-2]=="W")^(c=="x") else "W"
        if ans[0]==ans[-1] and (((ans[0]=="W")^(s[0]=="x"))^(ans[-2]==ans[1])):
            print(ans[:-1])
            sys.exit()
    print(-1)


if __name__=='__main__':
    main()

Solution (Python):
import sys
readline = sys.stdin.readline

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






ANI = "WS"
for n in range(4):
  pat = [None] * N
  pat[0] = n & 1
  pat[1] = (n >> 1) & 1
  for i in range(1, N - 1):
    if pat[i]:
      
      if S[i] == "o":
        pat[i + 1] = pat[i - 1]
      else:
        pat[i + 1] = pat[i - 1] ^ 1
    else:
      
      if S[i] == "o":
        pat[i + 1] = pat[i - 1] ^ 1
      else:
        pat[i + 1] = pat[i - 1]
  
  
  ok = True
  if (pat[0] == 1 and S[0] == "o") or (pat[0] == 0 and S[0] == "x"):
    if pat[N - 1] != pat[1]:
      ok = False
  elif (pat[0] == 1 and S[0] == "x") or (pat[0] == 0 and S[0] == "o"):
    if pat[N - 1] == pat[1]:
      ok = False
  if (pat[N - 1] == 1 and S[N - 1] == "o") or (pat[N - 1] == 0 and S[N - 1] == "x"):
    if pat[N - 2] != pat[0]:
      ok = False
  elif (pat[N - 1] == 1 and S[N - 1] == "x") or (pat[N - 1] == 0 and S[N - 1] == "o"):
    if pat[N - 2] == pat[0]:
      ok = False
  if ok:
    ans = ""
    for p in pat:
      ans += ANI[p]
    print(ans)
    break
else:
  print(-1)

Solution (Python):
def main():
    from itertools import product

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

    def is_ok(t):
        
        for i, c in enumerate(s[1:-1], start=1):
            if t[i]:  
                if c == 'o':
                    t[i + 1] = t[i - 1]
                else:
                    t[i + 1] = t[i - 1] ^ 1
            else:
                if c == 'o':
                    t[i + 1] = t[i - 1] ^ 1
                else:
                    t[i + 1] = t[i - 1]

        ret = True
        if t[0]:
            if s[0] == 'o':
                ret &= t[-1] == t[1]
            else:
                ret &= t[-1] != t[1]
        else:
            if s[0] == 'o':
                ret &= t[-1] != t[1]
            else:
                ret &= t[-1] == t[1]

        if t[-1]:
            if s[-1] == 'o':
                ret &= t[-2] == t[0]
            else:
                ret &= t[-2] != t[0]
        else:
            if s[-1] == 'o':
                ret &= t[-2] != t[0]
            else:
                ret &= t[-2] == t[0]
        return ret

    for prd in product([0, 1], repeat=2):
        
        t = [''] * N
        t[:2] = prd
        if is_ok(t):
            print(*map(lambda x: 'WS'[x], t), sep='')
            return

    print(-1)


if __name__ == '__main__':
    main()

Solution (Python):
import sys

def check(b0, b1):
    is_sheep[0] = b0
    is_sheep[1] = b1
    
    for i in range(1, N):
        if s[i] == 'o':
            if is_sheep[i]:
                is_sheep[(i+1)%N] = is_sheep[i-1]
            else:
                is_sheep[(i+1)%N] = not is_sheep[i-1]
        else:
            if is_sheep[i]:
                is_sheep[(i+1)%N] = not is_sheep[i-1]
            else:
                is_sheep[(i+1)%N] = is_sheep[i-1]
    
    if b0 == is_sheep[0]:
        if s[0] == 'o':
            if b0:
                return is_sheep[N-1]==is_sheep[1]
            else:
                return is_sheep[N-1]!=is_sheep[1]
        else:
            if b0:
                return is_sheep[N-1]!=is_sheep[1]
            else:
                return is_sheep[N-1]==is_sheep[1]
    else:
        return False
 
N = int(sys.stdin.readline().strip())
s = sys.stdin.readline().strip()

is_sheep = [False] * N
 
for b0, b1 in [(False, False), (False, True), (True, False), (True, True)]:
    if check(b0, b1):
        ans = ['S' if is_sheep[i] else 'W' for i in range(N)]
        print(''.join(ans))
        break
else:
    print(-1)

Solution (Python):
n=int(input())
s=input()
ans=""
for f,t in [["S","S"],["S","W"],["W","S"],["W","W"]]:
  ss=f+(n-2)*"X"+t
  ss=list(ss)
  ok=True
  for i in range(n-1):
    if s[i]=="o":
      if ss[i]=="S":
        if ss[i-1]=="S":
          ss[i+1]="S"
        else:
          ss[i+1]="W"
      elif ss[i]=="W":
        if ss[i-1]=="S":
          ss[i+1]="W"
        else:
          ss[i+1]="S"
    elif s[i]=="x":
      if ss[i]=="S":
        if ss[i-1]=="S":
          ss[i+1]="W"
        else:
          ss[i+1]="S"
      elif ss[i]=="W":
        if ss[i-1]=="S":
          ss[i+1]="S"
        else:
          ss[i+1]="W"
  for i in range(n):
    if i==n-1:
      if s[i]=="o":
        if ss[i]=="S":
          if ss[i-1]==ss[0]:
            pass
          else:
            ok=False
            break
        elif ss[i]=="W":
          if ss[i-1]!=ss[0]:
            pass
          else:
            ok=False
            break
      elif s[i]=="x":
        if ss[i]=="S":
          if ss[i-1]!=ss[0]:
            pass
          else:
            ok=False
            break
        elif ss[i]=="W":
          if ss[i-1]==ss[0]:
            pass
          else:
            ok=False
            break
      continue
    if s[i]=="o":
      if ss[i]=="S":
        if ss[i-1]==ss[i+1]:
          pass
        else:
          ok=False
          break
      elif ss[i]=="W":
        if ss[i-1]!=ss[i+1]:
          pass
        else:
          ok=False
          break
    elif s[i]=="x":
      if ss[i]=="S":
        if ss[i-1]!=ss[i+1]:
          pass
        else:
          ok=False
          break
      elif ss[i]=="W":
        if ss[i-1]==ss[i+1]:
          pass
        else:
          ok=False
          break
      
  if ok:
    for si in ss:
      ans+=si
    print(ans)
    exit(0)
print(-1)

Solution (Python):
import sys

import math
from fractions import Fraction
import itertools

input=sys.stdin.readline

n=int(input())
s=input()
a=[0]*(n+1)
a[0]="S"
a[1]="S"
for i in range(1,n):
    if (a[i]=="S" and s[i]=="o") or (a[i]=="W" and s[i]=="x"):
        a[i+1]=a[i-1]
    else:
        if a[i-1]=="W":
            a[i+1]="S"
        else:
            a[i+1]="W"
if a[n]==a[0] and ((s[0]=="o" and a[1]==a[n-1] or s[0]=="x" and a[1]!=a[n-1])) :
    print("".join(a[:n]))
    exit()
a=[None]*(n+1)
a[0]="S"
a[1]="W"
for i in range(1,n):
    if (a[i]=="S" and s[i]=="o") or (a[i]=="W" and s[i]=="x"):
        a[i+1]=a[i-1]
    else:
        if a[i-1]=="W":
            a[i+1]="S"
        else:
            a[i+1]="W"
if a[n]==a[0] and ((s[0]=="o" and a[1]==a[n-1] or s[0]=="x" and a[1]!=a[n-1])):
    print("".join(a[:n]))
    exit()
    
a=[0]*(n+1)
a[0]="W"
a[1]="S"
for i in range(1,n):
    if (a[i]=="S" and s[i]=="o") or (a[i]=="W" and s[i]=="x"):
        a[i+1]=a[i-1]
    else:
        if a[i-1]=="W":
            a[i+1]="S"
        else:
            a[i+1]="W"
if a[n]==a[0] and ((s[0]=="o" and a[1]!=a[n-1] or s[0]=="x" and a[1]==a[n-1])):
    print("".join(a[:n]))
    exit()
a=[None]*(n+1)
a[0]="W"
a[1]="W"
for i in range(1,n):
    if (a[i]=="S" and s[i]=="o") or (a[i]=="W" and s[i]=="x"):
        a[i+1]=a[i-1]
    else:
        if a[i-1]=="W":
            a[i+1]="S"
        else:
            a[i+1]="W"

if a[n]==a[0] and ((s[0]=="o" and a[1]!=a[n-1] or s[0]=="x" and a[1]==a[n-1])):
    print("".join(a[:n]))
    exit()
print(-1)

Solution (Python):
import sys

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

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



lst = [None] * (N + 2)
lst[0] = 'S'
if S[0] == 'o':
    lst[1] = 'S'
    lst[-1] = 'S'
else:
    lst[1] = 'S'
    lst[-1] = 'W'
for i in range(1, N):
    if S[i] == 'o':
        if lst[i] == 'S':
            lst[i + 1] = lst[i - 1]
        else:
            lst[i + 1] = 'S' if lst[i - 1] == 'W' else 'W'
    else: 
        if lst[i] == 'S':
            lst[i + 1] = 'S' if lst[i - 1] == 'W' else 'W'
        else:
            lst[i + 1] = lst[i - 1]

if lst[N - 1] == lst[N + 1] and lst[0] == lst[N]:
    print (*lst[:-2], sep = '')
    
    exit()


lst = [None] * (N + 2)
lst[0] = 'S'
if S[0] == 'o':
    lst[1] = 'W'
    lst[-1] = 'W'
else:
    lst[1] = 'W'
    lst[-1] = 'S'
for i in range(1, N):
    if S[i] == 'o':
        if lst[i] == 'S':
            lst[i + 1] = lst[i - 1]
        else:
            lst[i + 1] = 'S' if lst[i - 1] == 'W' else 'W'
    else: 
        if lst[i] == 'S':
            lst[i + 1] = 'S' if lst[i - 1] == 'W' else 'W'
        else:
            lst[i + 1] = lst[i - 1]

if lst[N - 1] == lst[N + 1] and lst[0] == lst[N]:
    print (*lst[:-2], sep = '')
    
    exit()


lst = [None] * (N + 2)
lst[0] = 'W'
if S[0] == 'o':
    lst[1] = 'W'
    lst[-1] = 'S'
else:
    lst[1] = 'W'
    lst[-1] = 'W'
for i in range(1, N):
    if S[i] == 'o':
        if lst[i] == 'S':
            lst[i + 1] = lst[i - 1]
        else:
            lst[i + 1] = 'S' if lst[i - 1] == 'W' else 'W'
    else: 
        if lst[i] == 'S':
            lst[i + 1] = 'S' if lst[i - 1] == 'W' else 'W'
        else:
            lst[i + 1] = lst[i - 1]

if lst[N - 1] == lst[N + 1] and lst[0] == lst[N]:
    print (*lst[:-2], sep = '')
    
    exit()


lst = [None] * (N + 2)
lst[0] = 'W'
if S[0] == 'o':
    lst[1] = 'S'
    lst[-1] = 'W'
else:
    lst[1] = 'S'
    lst[-1] = 'S'
for i in range(1, N):
    if S[i] == 'o':
        if lst[i] == 'S':
            lst[i + 1] = lst[i - 1]
        else:
            lst[i + 1] = 'S' if lst[i - 1] == 'W' else 'W'
    else: 
        if lst[i] == 'S':
            lst[i + 1] = 'S' if lst[i - 1] == 'W' else 'W'
        else:
            lst[i + 1] = lst[i - 1]

if lst[N - 1] == lst[N + 1] and lst[0] == lst[N]:
    print (*lst[:-2], sep = '')
    
    exit()

print (-1)

Solution (Python):
def resolve():
    n = int(input())
    s = input()
    
    def next(before, now, answer):
        if now == True and answer == "o":
            return before
        elif now == True and answer == "x":
            return not before
        elif now == False and answer == "o":
            return not before
        elif now == False and answer == "x":
            return before
    for i in range(2**2):
        mena = [0]*n
        for j in range(2):
            mena[j] = (i >> j) & 1
        for j in range(1, n-1):
            mena[j+1] = next(mena[j-1], mena[j], s[j])
        if (next(mena[n-2], mena[n-1], s[n-1]) == mena[0]) and (next(mena[n-1], mena[0], s[0]) == mena[1]):
            OK = True
        else:
            OK = False
        if OK:
            ans = []
            for k in range(len(mena)):
                if mena[k]:
                    ans.append("S")
                else:
                    ans.append("W")
            print("".join(ans))
            exit()
    print(-1)
resolve()

Solution (Python):

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


def check(a1, a2):
    ans = [a1, a2]
    for i, s in enumerate(S + [S[0]]):
        if i == 0:
            continue

        if ans[i] == 0:
            if s == "o":
                ans.append(ans[i - 1])
            else:
                ans.append(ans[i - 1] ^ 1)
        else:
            if s == "x":
                ans.append(ans[i - 1])
            else:
                ans.append(ans[i - 1] ^ 1)

    if ans[:2] != ans[-2:]:
        return None
    else:
        return ans[:-2]



for a1 in range(2):
    for a2 in range(2):
        ans = check(a1, a2)
        if ans is not None:
            print("".join(map(lambda x: "S" if x == 0 else "W", ans)))
            exit()


print(-1)

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

for a in ('SS','SW','WS','WW'):
    for c in S[1:]:
        if a[-1]=='S':
            a += 'W' if (a[-2]=='W') ^ (c=='x') else 'S'
        else:
            a += 'S' if (a[-2]=='W') ^ (c=='x') else 'W'
    if a[0] != a[-1]: continue
    if (a[0]=='W') ^ (S[0]=='x'):
        if a[-2]==a[1]: continue
    else:
        if a[-2]!=a[1]: continue
    print(a[:-1])
    exit()
print(-1)

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

def isOk(first, second):
    prev, now = first, second
    ret = [prev]

    for s in S[1:] + S[0]:
        ret.append(now)
        isSame = (s == 'o')

        if isSame == now:
            prev, now = now, prev
        else:
            prev, now = now, not prev

    return ret if (first == prev and second == now) else []

for first in [True, False]:
    for second in [True, False]:
        ans = isOk(first, second)
        if ans:
            print(''.join(['S' if a else 'W' for a in ans[:-1]]))
            exit()

print('-1')

Solution (Python):
import sys
input = sys.stdin.readline

N = int(input())
s = input().rstrip()
for t in ['SS', 'SW', 'WS', 'WW']:
    for i in range(1, N-1):
        if (t[-1] == 'W') ^ (s[i] == 'o') ^ (t[-2] == 'S'):
            t += 'W'
        else:
            t += 'S'
    if (t[-1] == 'W') ^ (s[-1] == 'o') ^ (t[-2] == t[0]):
        continue
    if (t[0] == 'W') ^ (s[0] == 'o') ^ (t[-1] == t[1]):
        continue
    print(t)
    exit()
print(-1)

Solution (Python):
def check(a, b, S):
    animal = [a, b]
    for s in S[1:]:
        if s == "o" and animal[-1]:
            animal.append(animal[-2])
        elif s == "o" and not animal[-1]:
            animal.append(animal[-2] ^ 1)
        elif s == "x" and animal[-1]:
            animal.append(animal[-2] ^ 1)
        else:
            animal.append(animal[-2])

    if animal[:2] != animal[-2:]:
        return False

    ans = ""
    for x in animal[:-2]:
        if x:
            ans += "S"
        else:
            ans += "W"
    print(ans)
    return True


if __name__ == "__main__":
    N = int(input())
    S = input()
    S += S[0]
    for i in range(2):
        for j in range(2):
            if check(i, j, S):
                exit()
    print(-1)

Solution (Python):
N=int(input())
s=input()
a,b,c,d='SS','SW','WW','WS'
def f(a,N):
  for i in range(N-2):
    if a[-1]=='S' and s[i+1]=='o':
      if a[-2]=='S':
        a=a+'S'
      else:
        a=a+'W'
    elif a[-1]=='S' and s[i+1]=='x':
      if a[-2]=='S':
        a=a+'W'
      else:
        a=a+'S'
    elif a[-1]=='W' and s[i+1]=='o':
      if a[-2]=='S':
        a=a+'W'
      else:
        a=a+'S'
    else:
      if a[-2]=='S':
        a=a+'S'
      else:
        a=a+'W'
  return a

A,B,C,D=f(a,N),f(b,N),f(c,N),f(d,N)    
def g(s,A):
  a=True
  if A[-1]=='S'and s[-1]=='o':
    if A[-2]!=A[0]:
      a=False
  elif A[-1]=='S'and s[-1]=='x':
    if A[-2]==A[0]:
      a=False
  elif A[-1]=='W'and s[-1]=='o':
    if A[-2]==A[0]:
      a=False    
  elif A[-1]=='W'and s[-1]=='x':
    if A[-2]!=A[0]:
      a=False  
  
  if A[0]=='S'and s[0]=='o':
    if A[-1]!=A[1]:
      a=False
  elif A[0]=='S'and s[0]=='x':
    if A[-1]==A[1]:
      a=False
  elif A[0]=='W'and s[0]=='o':
    if A[-1]==A[1]:
      a=False    
  elif A[0]=='W'and s[0]=='x':
    if A[-1]!=A[1]:
      a=False
  return a
      
if g(s,A):
  print(A)
  exit()
if g(s,B):
  print(B)
  exit()      
if g(s,C):
  print(C)
  exit()
if g(s,D):
  print(D)
  exit() 
print(-1)

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

ans = ['X']*(n+2)

ans[0] = 'S'
ans[1] = 'S'

for zero, one in ['SS','SW','WS','WW']:
    ans[0] = zero
    ans[1] = one
    for i in range(1,n+1):
        if (s[i] == 'o' and ans[i]=='S') or (s[i] == 'x' and ans[i]=='W'):
            ans[i+1] = ans[i-1]
        else:
            ans[i+1] = 'S' if ans[i-1]=='W' else 'W'

    if ans[0:2] == ans[n:]:
        print(*ans[:n],sep='')
        exit()

print(-1)

Solution (Python):
n,s=int(input()),input()
s+=s[:2]

for i in range(2):
    for j in range(2):
        a=[0]*(n+2)
        a[0]=i
        a[1]=j
        for k in range(1,n+1):
            if a[k]==0:
                if s[k]=="o":
                    a[k+1]=a[k-1]
                else:
                    a[k+1]=not a[k-1]
            else:
                if s[k]=="o":
                    a[k+1]=not a[k-1]
                else:
                    a[k+1]=a[k-1]
        if a[0]==a[n] and a[1]==a[n+1]:
            print(*["W" if k else "S" for k in a[:n]],sep="")
            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()
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)**int(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):
    first=p//2
    second=p%2
    l=[first,second]+[0]*(n-2)
    for i in range(1,n):
        l[(i+1)%n]=[l[i-1],1-l[i-1]][::(-1)**int(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):
    first=p//2
    second=p%2
    l=[first,second]+[0]*(n-2)
    for i in range(1,n):
        if s[i]=="o":
            l[(i+1)%n]=l[i-1] if l[i] else 1-l[i-1]
        else:l[(i+1)%n]=1-l[i-1] if l[i] else l[i-1]
    d=""
    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):
def f(a0,a1, N,s, A):
    A[0] = a0
    A[1] = a1
    WOLF = -1
    SHEEP = 1
    for i in range(2,N):
        if s[i-1] == "o" and A[i-1] == WOLF:
            A[i] = -A[i-2]
        elif s[i-1] == "o" and A[i-1] == SHEEP:
            A[i] = A[i-2]
        elif s[i-1] == "x" and A[i-1] == SHEEP:
            A[i] = -A[i-2]
        elif s[i-1] == "x" and A[i-1] == WOLF:
            A[i] = A[i-2]
    for i in range(N):
        same = A[(i-1)%N] == A[(i+1)%N]
        if A[i] == WOLF:
            if  s[i] == "o" and same or s[i] == "x" and not same:
                return False
        if A[i] == SHEEP:
            if  s[i] == "x" and same or s[i] == "o" and not same:
                return False
    return True
                
        

def main():
    N = int(input())
    s = input()
    A = [0]*N
    if f(1,1,N,s,A):
        print("".join(["S" if A[i] == 1 else "W" for i in range(N)]))

    elif f(-1,1,N,s,A):
        print("".join(["S" if A[i] == 1 else "W" for i in range(N)]))

    elif f(1,-1,N,s,A):
        print("".join(["S" if A[i] == 1 else "W" for i in range(N)]))

    elif f(-1,-1,N,s,A):
        print("".join(["S" if A[i] == 1 else "W" for i in range(N)]))
    else:
        print(-1)


main()

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


ANS=[list("SS"+"?"*(n)),list("WS"+"?"*(n)),list("SW"+"?"*(n)),list("WW"+"?"*(n))]
for ans in ANS:
    for i in range(2, n+2):
        if (ans[i - 2] == 'S' and s[i - 1] == 'o' and ans[i - 1] == 'S') or (
                ans[i - 2] == 'W' and s[i - 1] == 'o' and ans[i - 1] == 'W') \
                or (ans[i - 2] == 'S' and ans[i - 1] == 'W' and s[i - 1] == 'x') or (
                ans[i - 2] == 'W' and ans[i - 1] == 'S' and s[i - 1] == 'x'):
            ans[i] = 'S'
        else:
            ans[i] = 'W'
    if ans[:2]==ans[-2:]:
        print(''.join(ans[:-2]))
        exit()


print(-1)