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):
"""
sheep oXo xXx ⇨ True
wolf  oXx xXo ⇨ True 
２点決める

s[i] == "o" and a[i] == "W"  a[i+1] != a[i-1]
s[i] == "o" and a[i] == "S"  a[i+1] == a[i-1]
s[i] == "x" and a[i] == "W"  a[i+1] == a[i-1]
s[i] == "x" and a[i] == "S"  a[i+1] != a[i-1]
"""
n = int(input())
s = input()

ds = [(0,0),(0,1),(1,0),(1,1)]

for d0,d1 in ds:
    a = [d0,d1]
    for i in range(1,n):
        if s[i] == "o" and a[i] == 0:
            a.append(a[i-1])
        elif s[i] == "x" and a[i] == 0:
            a.append(a[i-1]^1)
        elif s[i] == "o" and a[i] == 1:
            a.append(a[i-1]^1)
        else:
            a.append(a[i-1])
    
    X = ["S","W"]
    
    if a[0] != a[-1]:continue
    a = a[:-1]
    if a[0] == 0 and s[0] == "x":
        if a[1] != a[-1]:
            a = "".join([X[i] for i in a])
            print(a)
            exit()
    if a[0] == 0 and s[0] == "o":
        if a[1] == a[-1]:
            a = "".join([X[i] for i in a])
            print(a)
            exit()
    if a[0] == 1 and s[0] == "x":
        if a[1] == a[-1]:
            a = "".join([X[i] for i in a])
            print(a)
            exit()
    if a[-0] == 1 and s[0] == "o":
        if a[1] != a[-1]:
            a = "".join([X[i] for i in a])
            print(a)
            exit()
print(-1)

Solution (Python):



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



candidate = [("S", "S"), ("S", "W"), ("W", "S"), ("W", "W")]
for a,b in candidate:
    ans = [""] * (N+2)

    ans[0], ans[1] = a, b
    for i in range(N):
        if ans[i+1] == "S":
            if S[i] == "o":
                ans[i+2] = ans[i]
            else:
                if ans[i] == "S":
                    ans[i+2] = "W"
                else:
                    ans[i+2] = "S"
        else:
            if S[i] == "o":
                if ans[i] == "S":
                    ans[i+2] = "W"
                else:
                    ans[i+2] = "S"
            else:
                ans[i+2] = ans[i]
    
    if ans[0] == ans[N] and ans[1] == ans[N+1]:
        print("".join(ans[1:N+1]))
        exit()

print(-1)

Solution (Python):


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

o = "o"
x = "x"

sheep = "S"
wolf = "W"

ans = [None] * n

ans[0] = sheep 
ans[1] = sheep 
for i, c in enumerate(s[1:-1]):
  if ((c == o) == (ans[i+1] == sheep)) == (ans[i] == sheep):
    ans[i+2] = sheep
  else:
    ans[i+2] = wolf

if ((s[0] == o) == (ans[0] == sheep)) == (ans[1] == ans[-1]):
  if ((s[-1] == o) == (ans[-1] == sheep)) == (ans[0] == ans[-2]):
    print("".join(ans))
    exit()

ans[0] = sheep 
ans[1] = wolf
for i, c in enumerate(s[1:-1]):
  if ((c == o) == (ans[i+1] == sheep)) == (ans[i] == sheep):
    ans[i+2] = sheep
  else:
    ans[i+2] = wolf

if ((s[0] == o) == (ans[0] == sheep)) == (ans[1] == ans[-1]):
  if ((s[-1] == o) == (ans[-1] == sheep)) == (ans[0] == ans[-2]):
    print("".join(ans))
    exit()

ans[0] = wolf
ans[1] = sheep 
for i, c in enumerate(s[1:-1]):
  if ((c == o) == (ans[i+1] == sheep)) == (ans[i] == sheep):
    ans[i+2] = sheep
  else:
    ans[i+2] = wolf

if ((s[0] == o) == (ans[0] == sheep)) == (ans[1] == ans[-1]):
  if ((s[-1] == o) == (ans[-1] == sheep)) == (ans[0] == ans[-2]):
    print("".join(ans))
    exit()

ans[0] = wolf
ans[1] = wolf
for i, c in enumerate(s[1:-1]):
  if ((c == o) == (ans[i+1] == sheep)) == (ans[i] == sheep):
    ans[i+2] = sheep
  else:
    ans[i+2] = wolf

if ((s[0] == o) == (ans[0] == sheep)) == (ans[1] == ans[-1]):
  if ((s[-1] == o) == (ans[-1] == sheep)) == (ans[0] == ans[-2]):
    print("".join(ans))
    exit()

print(-1)

Solution (Python):
N=int(input())
s=input()
ans='SS'
for i in range(1,N):
    if s[i]=='o' and ans[-1]=='S' and ans[-2]=='S':
        ans+='S'
    elif s[i]=='o' and ans[-1]=='S' and ans[-2]=='W':
        ans+='W'
    elif s[i]=='o' and ans[-1]=='W' and ans[-2]=='S':
        ans+='W'
    elif s[i]=='o' and ans[-1]=='W' and ans[-2]=='W':
        ans+='S'
    if s[i]=='x' and ans[-1]=='S' and ans[-2]=='S':
        ans+='W'
    elif s[i]=='x' and ans[-1]=='S' and ans[-2]=='W':
        ans+='S'
    elif s[i]=='x' and ans[-1]=='W' and ans[-2]=='S':
        ans+='S'
    elif s[i]=='x' and ans[-1]=='W' and ans[-2]=='W':
        ans+='W'

if ans[0]==ans[-1]:
    ans=ans[:N]
    if s[0]=='o' and ans[-1]==ans[1]:
        print(ans)
        exit()
    elif s[0]=='x' and ans[-1]!=ans[1]:
        print(ans)
        exit()
    

ans='SW'
for i in range(1,N):
    if s[i]=='o' and ans[-1]=='S' and ans[-2]=='S':
        ans+='S'
    elif s[i]=='o' and ans[-1]=='S' and ans[-2]=='W':
        ans+='W'
    elif s[i]=='o' and ans[-1]=='W' and ans[-2]=='S':
        ans+='W'
    elif s[i]=='o' and ans[-1]=='W' and ans[-2]=='W':
        ans+='S'
    if s[i]=='x' and ans[-1]=='S' and ans[-2]=='S':
        ans+='W'
    elif s[i]=='x' and ans[-1]=='S' and ans[-2]=='W':
        ans+='S'
    elif s[i]=='x' and ans[-1]=='W' and ans[-2]=='S':
        ans+='S'
    elif s[i]=='x' and ans[-1]=='W' and ans[-2]=='W':
        ans+='W'

if ans[0]==ans[-1]:
    ans=ans[:N]
    if s[0]=='o' and ans[-1]==ans[1]:
        print(ans)
        exit()
    elif s[0]=='x' and ans[-1]!=ans[1]:
        print(ans)
        exit()

ans='WS'
for i in range(1,N):
    if s[i]=='o' and ans[-1]=='S' and ans[-2]=='S':
        ans+='S'
    elif s[i]=='o' and ans[-1]=='S' and ans[-2]=='W':
        ans+='W'
    elif s[i]=='o' and ans[-1]=='W' and ans[-2]=='S':
        ans+='W'
    elif s[i]=='o' and ans[-1]=='W' and ans[-2]=='W':
        ans+='S'
    if s[i]=='x' and ans[-1]=='S' and ans[-2]=='S':
        ans+='W'
    elif s[i]=='x' and ans[-1]=='S' and ans[-2]=='W':
        ans+='S'
    elif s[i]=='x' and ans[-1]=='W' and ans[-2]=='S':
        ans+='S'
    elif s[i]=='x' and ans[-1]=='W' and ans[-2]=='W':
        ans+='W'

if ans[0]==ans[-1]:
    ans=ans[:N]
    if s[0]=='x' and ans[-1]==ans[1]:
        print(ans)
        exit()
    elif s[0]=='o' and ans[-1]!=ans[1]:
        print(ans)
        exit()

ans='WW'
for i in range(1,N):
    if s[i]=='o' and ans[-1]=='S' and ans[-2]=='S':
        ans+='S'
    elif s[i]=='o' and ans[-1]=='S' and ans[-2]=='W':
        ans+='W'
    elif s[i]=='o' and ans[-1]=='W' and ans[-2]=='S':
        ans+='W'
    elif s[i]=='o' and ans[-1]=='W' and ans[-2]=='W':
        ans+='S'
    if s[i]=='x' and ans[-1]=='S' and ans[-2]=='S':
        ans+='W'
    elif s[i]=='x' and ans[-1]=='S' and ans[-2]=='W':
        ans+='S'
    elif s[i]=='x' and ans[-1]=='W' and ans[-2]=='S':
        ans+='S'
    elif s[i]=='x' and ans[-1]=='W' and ans[-2]=='W':
        ans+='W'

if ans[0]==ans[-1]:
    ans=ans[:N]
    if s[0]=='x' and ans[-1]==ans[1]:
        print(ans)
        exit()
    elif s[0]=='o' and ans[-1]!=ans[1]:
        print(ans)
        exit()

print(-1)

Solution (Python):



import sys
N = int(input())
S = [1 if s == 'o' else 0 for s in input()]

tostr = ('W', 'S')


def f(a, b):
    last = prev = a
    first = current = b
    ans = []
    for s in S:
        ans.append(tostr[current])
        prev, current = current, prev ^ current ^ s
    if current == first and prev == last:
        print(''.join(ans))
        sys.exit()

f(1, 1)
f(1, 0)
f(0, 1)
f(0, 0)

print('-1')

Solution (Python):
import sys
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
s = ns()
a = [['S','S'],['S','W'],['W','S'],['W','W']]

for b in a:
    for i in range(1,n):
        c = 0 if b[i] == 'S' else 1
        d = 0 if s[i] == 'o' else 1
        e = b[i-1] if not c^d else 'W' if b[i-1] == 'S' else 'S'
        b.append(e)
    c = 0 if b[0] == 'S' else 1
    d = 0 if s[0] == 'o' else 1
    e = 0 if b[-2] == b[1] else 1
    if b[0] == b[-1] and c^d == e:
        print(''.join(b[:-1]))
        exit()

print(-1)

Solution (Python):
n = int(input())
s = tuple(input())
ans = ['SS','SW','WS','WW']

for i in range(1,n-1):
    for j in range(4):
        if (s[i] == 'o') ^ (ans[j][-1] == 'S'):
            ans[j] += 'SW'.strip(ans[j][-2])
        else:
            ans[j] += ans[j][-2]
for i in range(4):
    if (s[0] == 'o') ^ (ans[i][0] == 'S'):
        if ans[i][1] == ans[i][n-1]:
            continue
    else:
        if ans[i][1] != ans[i][n-1]:
            continue
    if (s[n-1] == 'o') ^ (ans[i][n-1] == 'S'):
        if ans[i][0] == ans[i][n-2]:
            continue
    else:
        if ans[i][0] != ans[i][n-2]:
            continue
    print(ans[i])
    exit(0)
print(-1)

Solution (Python):
N = int(input())
s = input()
animals = ["S", "W"]
for s1 in animals:
    for s2 in animals:
        t = [s1, s2]
        for i in range(1, N-1):
            if s[i] == "o":
                if t[i] == "S":
                    if t[i-1] == "S":
                        t.append("S")
                    else:
                        t.append("W")
                else:
                    if t[i-1] == "S":
                        t.append("W")
                    else:
                        t.append("S")
            else:
                if t[i] == "S":
                    if t[i-1] == "S":
                        t.append("W")
                    else:
                        t.append("S")
                else:
                    if t[i-1] == "S":
                        t.append("S")
                    else:
                        t.append("W")
        ans = ""
        for i in range(N):
            prev = i - 1 if 0 <= i - 1 else N - 1
            next = i + 1 if i + 1 < N else 0
            if t[i] == "S":
                if t[prev] == t[next]:
                    ans += "o"
                else:
                    ans += "x"
            else:
                if t[prev] == t[next]:
                    ans += "x"
                else:
                    ans += "o"
        if ans == s:
            print("".join(t))
            exit()
print(-1)

Solution (Python):
n = int(input())
s = input()
a = "SS"
ct=1
while ct<7:    
    for i in range(n-1):
        p=a[i]
        q="A"
        if a[i]=="S":
            q="W"
        else:
            q="S"
        if a[i+1]=="S":
            if s[i+1] == "o":
                a=a+a[i]
            else:
                a=a+q
        else:
            if s[i+1] == "o":
                 a=a+q
            else:
                a=a+a[i]
    if a[0]==a[n]:
        if a[0]=="S" and s[0]=="o" and a[n-1]==a[1]:
            print(a[0:n])
            break
        elif a[0]=="S" and s[0] !="o" and a[n-1]!=a[1]:         
            print(a[0:n])
            break
        elif a[0]=="W" and s[0] =="o" and a[n-1]!=a[1]: 
            print(a[0:n])
            break
        elif a[0]=="W" and s[0] !="o" and a[n-1]==a[1]: 
            print(a[0:n])
            break
        else:
            ct=ct+1
            if ct==2:
                a="SW"
            elif ct==3:
                a="WS"
            elif ct==4:
                a="WW"
            else:
                print(-1)
                break
    else:
        ct=ct+1
        if ct==2:
            a="SW"
        elif ct==3:
            a="WS"
        elif ct==4:
            a="WW"
        else:
            print(-1)
            break

Solution (Python):
n = int(input())
s = input()
flag = False
for i in range(4):
    if i == 0:
        ans = 'SS'
        past = 'S'
        cur = 'S'
        for j in range(1,n-1):
            if cur == 'S':
                if s[j] == 'o':
                    if past == 'S':
                        ans += 'S'
                    else:
                        ans += 'W'
                        past = 'S'
                        cur = 'W'
                else:
                    if past == 'S':
                        ans += 'W'
                        cur = 'W'
                    else:
                        ans += 'S'
                        past = 'S'
            else:
                if cur == 'W':
                    if s[j] == 'o':
                        if past == 'S':
                            ans += 'W'
                            past = 'W'
                        else:
                            ans += 'S'
                            cur = 'S'
                    else:
                        if past == 'S':
                            ans += 'S'
                            past = 'W'
                            cur = 'S'
                        else:
                            ans += 'W'
        if ans[len(ans)-1] == 'S':
            if s[n-1] == 'o':
                if ans[0] == ans[len(ans)-2]:
                    if s[0] == 'o':
                        if ans[1] == ans[len(ans)-1]:
                            flag = True
                            break
                    else:
                        if ans[1] != ans[len(ans)-1]:
                            flag = True
                            break
            else:
                if ans[0] != ans[len(ans)-2]:
                    if s[0] == 'o':
                        if ans[1] == ans[len(ans)-1]:
                            flag = True
                            break
                    else:
                        if ans[1] != ans[len(ans)-1]:
                            flag = True
                            break
        else:
            if s[n-1] == 'o':
                if ans[0] != ans[len(ans)-2]:
                    if s[0] == 'o':
                        if ans[1] == ans[len(ans)-1]:
                            flag = True
                            break
                    else:
                        if ans[1] != ans[len(ans)-1]:
                            flag = True
                            break
            else:
                if ans[0] == ans[len(ans)-2]:
                    if s[0] == 'o':
                        if ans[1] == ans[len(ans)-1]:
                            flag = True
                            break
                    else:
                        if ans[1] != ans[len(ans)-1]:
                            flag = True
                            break
    elif i == 1:
        ans = 'SW'
        past = 'S'
        cur = 'W'
        for j in range(1,n-1):
            if cur == 'S':
                if s[j] == 'o':
                    if past == 'S':
                        ans += 'S'
                    else:
                        ans += 'W'
                        past = 'S'
                        cur = 'W'
                else:
                    if past == 'S':
                        ans += 'W'
                        cur = 'W'
                    else:
                        ans += 'S'
                        past = 'S'
            else:
                if cur == 'W':
                    if s[j] == 'o':
                        if past == 'S':
                            ans += 'W'
                            past = 'W'
                        else:
                            ans += 'S'
                            cur = 'S'
                    else:
                        if past == 'S':
                            ans += 'S'
                            past = 'W'
                            cur = 'S'
                        else:
                            ans += 'W'
        if ans[len(ans)-1] == 'S':
            if s[n-1] == 'o':
                if ans[0] == ans[len(ans)-2]:
                    if s[0] == 'o':
                        if ans[1] == ans[len(ans)-1]:
                            flag = True
                            break
                    else:
                        if ans[1] != ans[len(ans)-1]:
                            flag = True
                            break
            else:
                if ans[0] != ans[len(ans)-2]:
                    if s[0] == 'o':
                        if ans[1] == ans[len(ans)-1]:
                            flag = True
                            break
                    else:
                        if ans[1] != ans[len(ans)-1]:
                            flag = True
                            break
        else:
            if s[n-1] == 'o':
                if ans[0] != ans[len(ans)-2]:
                    if s[0] == 'o':
                        if ans[1] == ans[len(ans)-1]:
                            flag = True
                            break
                    else:
                        if ans[1] != ans[len(ans)-1]:
                            flag = True
                            break
            else:
                if ans[0] == ans[len(ans)-2]:
                    if s[0] == 'o':
                        if ans[1] == ans[len(ans)-1]:
                            flag = True
                            break
                    else:
                        if ans[1] != ans[len(ans)-1]:
                            flag = True
                            break
    elif i == 2:
        ans = 'WS'
        past = 'W'
        cur = 'S'
        for j in range(1,n-1):
            if cur == 'S':
                if s[j] == 'o':
                    if past == 'S':
                        ans += 'S'
                    else:
                        ans += 'W'
                        past = 'S'
                        cur = 'W'
                else:
                    if past == 'S':
                        ans += 'W'
                        cur = 'W'
                    else:
                        ans += 'S'
                        past = 'S'
            else:
                if cur == 'W':
                    if s[j] == 'o':
                        if past == 'S':
                            ans += 'W'
                            past = 'W'
                        else:
                            ans += 'S'
                            cur = 'S'
                    else:
                        if past == 'S':
                            ans += 'S'
                            past = 'W'
                            cur = 'S'
                        else:
                            ans += 'W'
        if ans[len(ans)-1] == 'S':
            if s[n-1] == 'o':
                if ans[0] == ans[len(ans)-2]:
                    if s[0] == 'o':
                        if ans[1] != ans[len(ans)-1]:
                            flag = True
                            break
                    else:
                        if ans[1] == ans[len(ans)-1]:
                            flag = True
                            break
            else:
                if ans[0] != ans[len(ans)-2]:
                    if s[0] == 'o':
                        if ans[1] != ans[len(ans)-1]:
                            flag = True
                            break
                    else:
                        if ans[1] == ans[len(ans)-1]:
                            flag = True
                            break
        else:
            if s[n-1] == 'o':
                if ans[0] != ans[len(ans)-2]:
                    if s[0] == 'o':
                        if ans[1] != ans[len(ans)-1]:
                            flag = True
                            break
                    else:
                        if ans[1] == ans[len(ans)-1]:
                            flag = True
                            break
            else:
                if ans[0] == ans[len(ans)-2]:
                    if s[0] == 'o':
                        if ans[1] != ans[len(ans)-1]:
                            flag = True
                            break
                    else:
                        if ans[1] == ans[len(ans)-1]:
                            flag = True
                            break
    else:
        ans = 'WW'
        past = 'W'
        cur = 'W'
        for j in range(1,n-1):
            if cur == 'S':
                if s[j] == 'o':
                    if past == 'S':
                        ans += 'S'
                    else:
                        ans += 'W'
                        past = 'S'
                        cur = 'W'
                else:
                    if past == 'S':
                        ans += 'W'
                        cur = 'W'
                    else:
                        ans += 'S'
                        past = 'S'
            else:
                if cur == 'W':
                    if s[j] == 'o':
                        if past == 'S':
                            ans += 'W'
                            past = 'W'
                        else:
                            ans += 'S'
                            cur = 'S'
                    else:
                        if past == 'S':
                            ans += 'S'
                            past = 'W'
                            cur = 'S'
                        else:
                            ans += 'W'
        if ans[len(ans)-1] == 'S':
            if s[n-1] == 'o':
                if ans[0] == ans[len(ans)-2]:
                    if s[0] == 'o':
                        if ans[1] != ans[len(ans)-1]:
                            flag = True
                            break
                    else:
                        if ans[1] == ans[len(ans)-1]:
                            flag = True
                            break
            else:
                if ans[0] != ans[len(ans)-2]:
                    if s[0] == 'o':
                        if ans[1] != ans[len(ans)-1]:
                            flag = True
                            break
                    else:
                        if ans[1] == ans[len(ans)-1]:
                            flag = True
                            break
        else:
            if s[n-1] == 'o':
                if ans[0] != ans[len(ans)-2]:
                    if s[0] == 'o':
                        if ans[1] != ans[len(ans)-1]:
                            flag = True
                            break
                    else:
                        if ans[1] == ans[len(ans)-1]:
                            flag = True
                            break
            else:
                if ans[0] == ans[len(ans)-2]:
                    if s[0] == 'o':
                        if ans[1] != ans[len(ans)-1]:
                            flag = True
                            break
                    else:
                        if ans[1] == ans[len(ans)-1]:
                            flag = True
                            break
if flag:
    print(ans)
else:
    print(-1)

Solution (Python):
n = int(input())
s = input()
l = [[0,0],[0,1],[1,0],[1,1]]
for i in range(4):
  for j in range(1,n-1):
    if s[j] == 'o':
      if l[i][-1] == 0:
        l[i].append(l[i][-2])
      else:
        l[i].append(1-l[i][-2])
    else:
      if l[i][-1] == 0:
        l[i].append(1-l[i][-2])
      else:
        l[i].append(l[i][-2])
  if (s[0]=='o' and l[i][0]==0 and l[i][1]!=l[i][-1]) or (s[0]=='o' and l[i][0]==1 and l[i][1]==l[i][-1]) or (s[0]=='x' and l[i][0]==0 and l[i][1]==l[i][-1]) or (s[0]=='x' and l[i][0]==1 and l[i][1]!=l[i][-1]):
    continue
  if (s[-1]=='o' and l[i][-1]==0 and l[i][0]!=l[i][-2]) or (s[-1]=='o' and l[i][-1]==1 and l[i][0]==l[i][-2]) or (s[-1]=='x' and l[i][-1]==0 and l[i][0]==l[i][-2]) or (s[-1]=='x' and l[i][-1]==1 and l[i][0]!=l[i][-2]):
    continue
  for j in l[i]:
    print('SW'[j],end='')
  exit()
print(-1)

Solution (Python):
def calc(s,ans1,ans2):
  if s=="o":
    if ans1=="S":
      if ans2=="S":
        return "S"
      else:
        return "W"
    else:
      if ans2=="S":
        return "W"
      else:
        return "S"
  else:
    if ans1=="S":
      if ans2=="S":
        return "W"
      else:
        return "S"
    else:
      if ans2=="S":
        return "S"
      else:
        return "W"

def check(ans0,ans1):
  ans=[""]*n
  ans[0]=ans0
  ans[1]=ans1
  ans[-1]=calc(s[0],ans[0],ans[1])
  for i in range(2,n):ans[i]=calc(s[i-1],ans[i-1],ans[i-2])
  if ans[-1]==calc(s[0],ans[0],ans[1]) and ans[0]==calc(s[-1],ans[-1],ans[-2]):
    print("".join(ans))
    exit()
  else:
    return 0
n=int(input())
s=input()
check("S","S")
check("S","W")
check("W","S")
check("W","W")
print(-1)

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

Solution (Python):
from itertools import product
N = int(input())
s = input()
s += s[0]

def isOK(x, y):
    lst = [-1] * (N+2)
    lst[0] = x
    lst[1] = y
    for i in range(1, N+1):
        if (s[i] == 'o') ^ (lst[i]):    
            lst[i+1] = 1 - lst[i-1]
        else:                       
            lst[i+1] = lst[i-1]
    if lst[0] == lst[-2] and lst[1] == lst[-1]:     
        return lst[:-2]
    else:
        return []

for x, y in product([1,0], repeat=2):
    chk = isOK(x, y)
    if len(chk) > 0:
        break

if len(chk) == 0:
    ans = -1
else:
    ans = ''
    for x in chk:
        if x:
            ans += 'S'
        else:
            ans += 'W'
print(ans)

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

def solve(first,second):
    sheep=[]

    sheep.append(first)
    sheep.append(second)

    for i in range(1,n):
        rep= s[i] == "o"
        if not rep ^ sheep[i]:
            sheep.append(sheep[i-1])
        else:
            sheep.append(not sheep[i-1])

    if sheep[0] == sheep[-1]:
        rep= s[0] == "o"
        same = sheep[-2] == sheep[1]
        if sheep[0] ^ rep != same:
            for a in sheep[:-1]:
                if a:
                    print("S",end="")
                else:
                    print("W",end="")
            exit()

fir=[True,False]
sec=[True,False]

for i in fir:
    for j in sec:
        solve(i,j)
print(-1)

Solution (Python):
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))



N = I()
s = str(input())


a = [-1]*N
A1,A2,A3,A4 = a[:],a[:],a[:],a[:]

def check(A):
    for i in range(1,N):
        now = 0 if s[i] == 'o' else 1
        temp = A[i-1] ^ A[i] ^ now
        if 1 <= i <= N-2:
            A[i+1] = temp
        else:
            if temp != A[0]:
                return
    now = 0 if s[0] == 'o' else 1
    if A[N-1] ^ A[0] ^ A[1] ^ now:
        return
    return A

A1[0],A1[1] = 0,0
A2[0],A2[1] = 0,1
A3[0],A3[1] = 1,0
A4[0],A4[1] = 1,1

ans = []
ans.extend([check(A1),check(A2),check(A3),check(A4)])
for x in ans:
    if x is not None:
        x = map(str,x)
        print(''.join(x).replace('0','S').replace('1','W'))
        exit()

print(-1)

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

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

Solution (Python):



N = int(input())
s = [x=="o" for x in input()]

def is_true(L1:bool, L2:bool):
    L = [None] * N

    L[0] = L1
    L[1] = L2
    for i in range(1,N):
        if i == N-1:
            if s[i]: 
                tmp = L[i-1] if L[i] else (not L[i-1])
            else: 
                tmp = L[i-1] if not L[i] else (not L[i-1])
            if tmp == L[0]:
                continue
            else:
                return (False, L)

        if s[i]: 
            L[i+1] = L[i-1] if L[i] else (not L[i-1])
        else: 
            L[i+1] = L[i-1] if not L[i] else (not L[i-1])
    
    if s[0]: 
        if L[0]: 
            return (True, L) if L[-1] == L[1] else (False, L)
        else: 
            return (True, L) if L[-1] != L[1] else (False, L)
    else: 
        if L[0]: 
            return (True, L) if L[-1] != L[1] else (False, L)
        else: 
            return (True, L) if L[-1] == L[1] else (False, L)

def main():
    for L1 in (True, False):
        for L2 in (True, False):
            flag, tmp = is_true(L1, L2)
            if not flag:
                continue
            else:
                ans = ""
                for x in tmp:
                    ans += "S" if x else "W"
                print(ans)
                exit()
    
    print(-1)

if __name__ == "__main__":
    main()