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

def loop():
    for i in range(1, n-1):
        if ans[i] == 'S':
            if s[i] == 'x':
                if ans[i-1] == 'S':         
                    ans[i+1] = 'W'
                else:
                    ans[i+1] = 'S'
            else:
                if ans[i-1] == 'W':
                    ans[i+1] = 'W'
                else:
                    ans[i+1] = 'S'
        else:
            if s[i] == 'o':
                if ans[i-1] == 'S':
                    ans[i+1] = 'W'
                else:
                    ans[i+1] = 'S'
            else:
                if ans[i-1] == 'W':
                    ans[i+1] = 'W'
                else:
                    ans[i+1] = 'S'

ans = ['S'] * n
if s[0]  == 'x':
    ans[1] = 'W'
else:
    ans[1] = 'S'
loop()
if ans[n-1] == 'S':
    if (s[n-1] == 'o' and ans[n-2] == 'S') or (s[n-1] == 'x' and ans[n-2] == 'W'):
        print(''.join(ans))
        exit()

ans = ['W'] * n
if s[0]  == 'x':
    ans[1] = 'W'
else:
    ans[1] = 'S'
loop()
if ans[n-1] == 'W':
    if (s[n-1] == 'x' and ans[n-2] == 'W') or (s[n-1] == 'o' and ans[n-2] == 'S'):
        print(''.join(ans))
        exit()

ans = ['W'] * (n-1) + ['S']
if s[0]  == 'x':
    ans[1] = 'S'
else:
    ans[1] = 'W'
loop()
if ans[n-1] == 'S':
    if (s[n-1] == 'x' and ans[n-2] == 'S') or (s[n-1] == 'o' and ans[n-2] == 'W'):
        print(''.join(ans))
        exit()

ans = ['S'] * (n-1) + ['W']
if s[0]  == 'x':
    ans[1] = 'S'
else:
    ans[1] = 'W'
loop()
if ans[n-1] == 'W':
    if (s[n-1] == 'x' and ans[n-2] == 'S') or (s[n-1] == 'o' and ans[n-2] == 'W'):
        print(''.join(ans))
        exit()

print(-1)

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

def loop():
    for i in range(1, n-1):
        if ans[i] == 'S':
            if s[i] == 'x':
                if ans[i-1] == 'S':         
                    ans[i+1] = 'W'
                else:
                    ans[i+1] = 'S'
            else:
                if ans[i-1] == 'W':
                    ans[i+1] = 'W'
                else:
                    ans[i+1] = 'S'
        else:
            if s[i] == 'o':
                if ans[i-1] == 'S':
                    ans[i+1] = 'W'
                else:
                    ans[i+1] = 'S'
            else:
                if ans[i-1] == 'W':
                    ans[i+1] = 'W'
                else:
                    ans[i+1] = 'S'

ans = ['S'] + ['Unknown'] * (n-2) + ['S']
if s[0]  == 'x':
    ans[1] = 'W'
else:
    ans[1] = 'S'
loop()
if ans[n-1] == 'S':
    if (s[n-1] == 'o' and ans[n-2] == 'S') or (s[n-1] == 'x' and ans[n-2] == 'W'):
        print(''.join(ans))
        exit()

ans = ['W'] + ['Unknown'] * (n-2) + ['S']
if s[0]  == 'x':
    ans[1] = 'S'
else:
    ans[1] = 'W'
loop()
if ans[n-1] == 'S':
    if (s[n-1] == 'x' and ans[n-2] == 'S') or (s[n-1] == 'o' and ans[n-2] == 'W'):
        print(''.join(ans))
        exit()

ans = ['W'] + ['Unknown'] * (n-2) + ['W']
if s[0]  == 'x':
    ans[1] = 'W'
else:
    ans[1] = 'S'
loop()
if ans[n-1] == 'W':
    if (s[n-1] == 'x' and ans[n-2] == 'W') or (s[n-1] == 'o' and ans[n-2] == 'S'):
        print(''.join(ans))
        exit()

ans = ['S'] + ['Unknown'] * (n-2) + ['W']
if s[0]  == 'x':
    ans[1] = 'S'
else:
    ans[1] = 'W'
loop()
if ans[n-1] == 'W':
    if (s[n-1] == 'x' and ans[n-2] == 'S') or (s[n-1] == 'o' and ans[n-2] == 'W'):
        print(''.join(ans))
        exit()

print(-1)

Solution (Python):




 
from collections import* 
from fractions import gcd
from functools import* 
from itertools import* 
from operator import mul,itemgetter
from bisect import* 
from heapq import* 
from math import factorial,pi
from copy import deepcopy
import sys
sys.setrecursionlimit(10**8)

 
def main():
    n=int(input())
    s=input()
    
    
    doubutu1=["W","W"]
    doubutu2=["S","W"]
    doubutu3=["W","S"]
    doubutu4=["S","S"]
    def doubutuappender(doubutu):
        for i in range(1,n):
            if doubutu[i]=="S":
                doubutu.append( ["SW"["S"==doubutu[i-1]] ,doubutu[i-1]][s[i]=="o"])
            else:
                doubutu.append( [doubutu[i-1] ,"SW"["S"==doubutu[i-1]]][s[i]=="o"])
        return doubutu
    for i in [doubutuappender(doubutu1),doubutuappender(doubutu2),doubutuappender(doubutu3),doubutuappender(doubutu4)]:
        if i[0]==i[-1]:
            if s[0]=="o" and i[0]=="S" and i[1]==i[-2]:
                print("".join(i[:-1]))
                exit()
            elif s[0]=="x" and i[0]=="S" and i[1]!=i[-2]:
                print("".join(i[:-1]))
                exit()
            elif s[0]=="o" and i[0]=="W" and i[1]!=i[-2]:
                print("".join(i[:-1]))
                exit()
            elif s[0]=="x" and i[0]=="W" and i[1]==i[-2]:
                print("".join(i[:-1]))
                exit()
    print(-1)
if __name__ == '__main__':
    main()

Solution (Python):

def reset(n):
    a = [0 for i in range(n+2)]
    return a
    
n = int(input())
s = list(input())
s.append(s[0])

dt = [[1,1],[-1,1],[1,-1],[-1,-1]] 

ans = False
for i in range(4):
    li = reset(n)
    li[0] = dt[i][0]
    li[1] = dt[i][1]

    for j in range(1,len(s)):
        if s[j] =='o':
            li[j+1] = li[j]*li[j-1]
        elif s[j] =='x':
            li[j+1] = li[j]*li[j-1]*(-1)
    if li[0]==li[n] and li[1]==li[n+1]:
        ans = True
        break

if (ans):
    for i in range(n):
        if li[i] == 1:
            print('S',end="")
        else:
            print('W',end="")
    print('')

else:
    print(-1)

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

Solution (Python):
N = int(input())
s = input()
SW_list = ["SS", "SW", "WS", "WW"]
check = False
for sw in SW_list:
    ans = [""] * N
    ans[0] = sw[0]
    ans[1] = sw[1]
    for i in range(1, N-1):
        if (ans[i] == "S" and s[i] == "o") or (ans[i] == "W" and s[i] == "x"):
            ans[i+1] = ans[i-1]
        else:
            ans[i+1] = "S" if ans[i-1] == "W" else "W"
    if (ans[0] == "S" and s[0] == "o") or (ans[0] == "W" and s[0] == "x"):
        if ans[1] == ans[-1]:
            check = True
    else:
        if ans[1] != ans[-1]:
            check = True
    if (ans[-1] == "S" and s[-1] == "o") or (ans[-1] == "W" and s[-1] == "x"):
        if ans[0] != ans[-2]:
            check = False
    else:
        if ans[0] == ans[-2]:
            check = False
    if check:
        print(*ans, sep="")
        break

if check == False:
    print(-1)

Solution (Python):



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

    
    
    
    for pair in ['SS', 'SW', 'WW', 'WS']:
        ans = ['' for _ in range(n + 1)]

        for index, p in enumerate(pair):
            ans[index] = p

            for j in range(1, n):
                if s[j] == 'o':
                    if ans[j] == 'S':
                        ans[j + 1] = ans[j - 1]
                    else:
                        if ans[j - 1] == 'S':
                            ans[j + 1] = 'W'
                        else:
                            ans[j + 1] = 'S'
                else:
                    if ans[j] == 'S':
                        if ans[j - 1] == 'S':
                            ans[j + 1] = 'W'
                        else:
                            ans[j + 1] = 'S'
                    else:
                        ans[j + 1] = ans[j - 1]

        if ans[0] == ans[-1]:
            
            
            if ans[n - 1] == ans[1] and ((s[0] == 'o' and ans[0] == 'S') or (s[0] == 'x' and ans[0] == 'W')):
                print(''.join(ans[:-1]))
                break
            elif ans[n - 1] != ans[1] and ((s[0] == 'o' and ans[0] == 'W') or (s[0] == 'x' and ans[0] == 'S')):
                print(''.join(ans[:-1]))
                break
    else:
        print(-1)


if __name__ == '__main__':
    main()

Solution (Python):



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

    
    
    
    for pair in ['SS', 'SW', 'WW', 'WS']:
        ans = ['' for _ in range(n + 1)]

        for index, p in enumerate(pair):
            ans[index] = p

            for j in range(1, n):
                if s[j] == 'o':
                    if ans[j] == 'S':
                        ans[j + 1] = ans[j - 1]
                    else:
                        if ans[j - 1] == 'S':
                            ans[j + 1] = 'W'
                        else:
                            ans[j + 1] = 'S'
                else:
                    if ans[j] == 'S':
                        if ans[j - 1] == 'S':
                            ans[j + 1] = 'W'
                        else:
                            ans[j + 1] = 'S'
                    else:
                        ans[j + 1] = ans[j - 1]

        if ans[0] == ans[-1]:
            if ans[n - 1] == ans[1] and ((s[0] == 'o' and ans[0] == 'S') or (s[0] == 'x' and ans[0] == 'W')):
                print(''.join(ans[:-1]))
                break
            elif ans[n - 1] != ans[1] and ((s[0] == 'o' and ans[0] == 'W') or (s[0] == 'x' and ans[0] == 'S')):
                print(''.join(ans[:-1]))
                break
    else:
        print(-1)


if __name__ == '__main__':
    main()

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

for ans in ['SS','SW','WS','WW']:
    for i in range(1,N+1):
        if (ans[-1] == 'S' and S[i] == 'o') or (ans[-1] == 'W' and S[i] == 'x'):
            ans += ans[-2]
        else:
            ans += ('S' if ans[-2] == 'W' else 'W')
    if ans[:2] == ans[N:]:
        print(ans[:N])
        exit()
print(-1)

Solution (Python):
n = int(input())
s = input()
list_pat = [["S", "S"], ["S", "W"], ["W", "S"], ["W", "W"]]
for one_s in s[1:]:
  if one_s == "o":
    for i, one_pat in enumerate(list_pat):
      if one_pat[-1] == "S":
        if one_pat[-2] == "S":
          list_pat[i].append("S")
        else:
          list_pat[i].append("W")
      else:
        if one_pat[-2] == "S":
          list_pat[i].append("W")
        else:
          list_pat[i].append("S")
  else:
    for i, one_pat in enumerate(list_pat):
      if one_pat[-1] == "S":
        if one_pat[-2] == "S":
          list_pat[i].append("W")
        else:
          list_pat[i].append("S")
      else:
        if one_pat[-2] == "S":
          list_pat[i].append("S")
        else:
          list_pat[i].append("W")

for one_pat in list_pat:
  if one_pat[0] == one_pat[-1]:
    if one_pat[0] == "S":
      if s[0] == "o" and one_pat[-2] == one_pat[1]:
        print("".join(one_pat[:-1]))
        exit()
      elif s[0] == "x" and one_pat[-2] != one_pat[1]:
        print("".join(one_pat[:-1]))
        exit()
    else:
      if s[0] == "o" and one_pat[-2] != one_pat[1]:
        print("".join(one_pat[:-1]))
        exit()
      elif s[0] == "x" and one_pat[-2] == one_pat[1]:
        print("".join(one_pat[:-1]))
        exit()
print("-1")

Solution (Python):



N = int(input())
s = list(input().replace("o", "1").replace("x", "0"))
s = list(map(int, s))


def next_animal(animal1, animal2, answer2):
    if (animal2 == 1 and answer2 == 1) or (animal2==0 and answer2==0):
        return animal1
    else:
        return 1^animal1


for first_two_animals in [[1,1],[1,0],[0,1],[0,0]]:
    animal_list = []
    animal_list.append(first_two_animals[0])
    animal_list.append(first_two_animals[1])

    for idx in range(2,N):
        animal_list.append(next_animal(animal_list[idx-2], animal_list[idx-1], s[idx-1]))

    
    if (s[0]==1 and animal_list[0]==1) or (s[0]==0 and animal_list[0]==0):
        last_animal = animal_list[1]
    else:
        last_animal = 1^animal_list[1]

    if (last_animal==1 and (animal_list[-2] == animal_list[0])) or (last_animal==0 and (animal_list[-2] != animal_list[0])):
        last_answer = 1
    else:
        last_answer = 0

    if last_animal == animal_list[-1] and last_answer == s[-1]:
        animal_list = list(map(str, animal_list))
        animal_list = [x.replace("1", "S").replace("0", "W") for x in animal_list]
        print("".join(animal_list))
        exit()

print(-1)

Solution (Python):
import sys
def input():
    return sys.stdin.readline()[:-1]

n=int(input())
s=input()
tmp=["SS","WW","SW","WS"]
for j in range(4):
    ans=tmp[j]
    for i in range(n-1):
        if ans[i+1]=="S":
            if s[i+1]=="o":
                if ans[i]=="S":
                    ans+="S"
                else:
                    ans+="W"
            else:
                if ans[i]=="S":
                    ans+="W"
                else:
                    ans+="S"
        else:
            if s[i+1]=="o":
                if ans[i]=="S":
                    ans+="W"
                else:
                    ans+="S"
            else:
                if ans[i]=="S":
                    ans+="S"
                else:
                    ans+="W"
    if ans[0]==ans[-1]:
        if s[0]=="o":
            if ans[0]=="S" and ans[1]==ans[-2]:
                print(ans[:-1])
                quit()
            if ans[0]=="W" and ans[1]!=ans[-2]:
                print(ans[:-1])
                quit()
        else:
            if ans[0]=="S" and ans[1]!=ans[-2]:
                print(ans[:-1])
                quit()
            if ans[0]=="W" and ans[1]==ans[-2]:
                print(ans[:-1])
                quit()
print(-1)

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


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

for j in range(4) :
    t = A[j]
    for i in range(1,N) :
        if S[i] == "o" :
            if t[i] == "S" :
                if t[i-1] == "S" :
                    t += "S"
                else :
                    t += "W"
            else :
                if t[i-1] == "S" :
                    t += "W"
                else :
                    t += "S"
        else :
            if t[i] == "S" :
                if t[i-1] == "S" :
                    t += "W"
                else :
                    t += "S"
            else :
                if t[i-1] == "S" :
                    t += "S"
                else :
                    t += "W"
    
    if t[0] == t[-1] :
        if S[0] == "o" and t[0] == "S" and (t[-2] == t[1]) :
            print(t[:-1])
            break
        elif S[0] == "o" and (t[0] == "W") and (t[-2] != t[1]) :
            print(t[:-1])
            break
        if S[0] == "x" and t[0] == "S" and (t[-2] != t[1]) :
            print(t[:-1])
            break
        elif S[0] == "x" and (t[0] == "W") and (t[-2] == t[1]) :
            print(t[:-1])
            break
else :
    print(-1)

Solution (Python):
n = int(input())
s_list = list(input())
def main():
  animal_list = [None] * n
  sonzai = False
  
  if not sonzai:
    animal_list[0] = True
    animal_list[1] = True
    animal_list = create_animal_list(animal_list)
    sonzai = is_valid_list(animal_list)
  if not sonzai:
    animal_list[0] = True
    animal_list[1] = False
    animal_list = create_animal_list(animal_list)
    sonzai = is_valid_list(animal_list)
  if not sonzai:
    animal_list[0] = False
    animal_list[1] = False
    animal_list = create_animal_list(animal_list)
    sonzai = is_valid_list(animal_list)
  if not sonzai:
    animal_list[0] = False
    animal_list[1] = True
    animal_list = create_animal_list(animal_list)
    sonzai = is_valid_list(animal_list)
  if not sonzai:
    print(-1)
  else:
    animal_list2 = []
    for animal in animal_list:
      if animal:
        animal_list2.append("S")
      else:
        animal_list2.append("W")
    animal_list2 = "".join(animal_list2)
    print(animal_list2)
def is_valid_list(animal_list):
  return is_ok(animal_list, 0) and is_ok(animal_list,-1)
  
def is_ok(animal_list, index):
  if animal_list[index%n]:
    if s_list[index%n] == "o":
      return animal_list[(index+1)%n] == animal_list[index-1]
    else:
      return not (animal_list[(index+1)%n] == animal_list[index-1])
  else:
    if s_list[index%n] == "o":
      return not (animal_list[(index+1)%n] == animal_list[index-1])
    else:
      return (animal_list[(index+1)%n] == animal_list[index-1])
def create_animal_list(animal_list):
  for index in range(2, len(animal_list)):
    if animal_list[index-1]:
      if s_list[index-1] == "o":
        animal_list[index] = animal_list[index-2]
      else:
        animal_list[index] = not animal_list[index-2]
    else:
      if s_list[index-1] == "o":
        animal_list[index] = not animal_list[index-2]
      else:
        animal_list[index] = animal_list[index-2]
  return animal_list
main()

Solution (Python):
n = int(input())
s = input()
ans = -1

for i in ['SS', 'SW', 'WW', 'WS']:
    narabi = ''
    narabi += i
    for k in range(n - 2):
        if narabi[-1] == 'S':
            if s[k + 1] == 'o':
                narabi += narabi[-2]
            else:
                if narabi[-2] == 'S':
                    narabi += 'W'
                else:
                    narabi += 'S'
        else:
            if s[k + 1] == 'o':
                if narabi[-2] == 'S':
                    narabi += 'W'
                else:
                    narabi += 'S'
            else:
                narabi += narabi[-2]
    kenshou = narabi[-2:]
    kenshou2 = kenshou + narabi[:2]
    kenshou_s = s[-1] + s[-0]
    for k in range(2):
        if kenshou[-1] == 'S':
            if kenshou_s[k] == 'o':
                kenshou += kenshou[-2]
            else:
                if kenshou[-2] == 'S':
                    kenshou += 'W'
                else:
                    kenshou += 'S'
        else:
            if kenshou_s[k] == 'o':
                if kenshou[-2] == 'S':
                    kenshou += 'W'
                else:
                    kenshou += 'S'
            else:
                kenshou += kenshou[-2]
    if kenshou == kenshou2:
        ans = narabi
        break
    
    
    
print(ans)

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

cs = 'SW'
for ss in [[0, 0], [0, 1], [1, 0], [1, 1]]:
    for i in range(1, n + 1):
        if (ss[i % n] == 0 and s[i % n] == 'o') or (ss[i % n] == 1
                                                    and s[i % n] == 'x'):
            ss.append(ss[i - 1])
        else:
            ss.append(1 - ss[i - 1])
    if ss[-2] == ss[0] and ss[-1] == ss[1]:
        res = ''.join([cs[i] for i in ss[:-2]])
        print(res)
        break
else:
    print(-1)

Solution (Python):
N = int(input())
s = list(input())
if s[1] == 'o':
    ans = [['S', 'S', 'S'], ['W', 'S', 'W'], ['S', 'W', 'W'], ['W', 'W', 'S']]
else:
    ans = [['S', 'S', 'W'], ['W', 'S', 'S'], ['S', 'W', 'S'], ['W', 'W', 'W']]

for i in range(4):
    for j in range(2, N-1):
        if s[j] == 'o':
            n0, n1 = 'S', 'W'
        else:
            n0, n1 = 'W', 'S'
        if ans[i][j-1] == 'S':
            if ans[i][j] == 'S':
                ans[i].append(n0)
            else:
                ans[i].append(n1)
        else:
            if ans[i][j] == 'S':
                ans[i].append(n1)
            else:
                ans[i].append(n0)
    
    Realize = True
    for j in [-1, 0]:
        if s[j] == 'o':
            if ans[i][j] == 'S':
                if ans[i][j-1] != ans[i][j+1]:
                    Realize = False
                    break
            else:
                if ans[i][j-1] == ans[i][j+1]:
                    Realize = False
                    break
        else:
            if ans[i][j] == 'S':
                if ans[i][j-1] == ans[i][j+1]:
                    Realize = False
                    break
            else:
                if ans[i][j-1] != ans[i][j+1]:
                    Realize = False
                    break
    if Realize:
        print(''.join(ans[i]))
        exit()
print(-1)

Solution (Python):
n=int(input())
s=input()
def e(c):
    if c=="S":
        return "W"
    else:
        return "S"

def f(s1,sn,s2):
    ans=[""]*n
    ans[0]=s1
    ans[1]=s2
    for i in range(1,n-1):
        if s[i]=="o":
            if ans[i]=="S":
                ans[i+1]=ans[i-1]
            else:
                ans[i+1]=e(ans[i-1])
        else:
            if ans[i]=="W":
                ans[i+1]=ans[i-1]
            else:
                ans[i+1]=e(ans[i-1])
    if ans[-1]!=sn:
        return False
    elif s[-1]=="o":
        if ans[-1]=="S":
            if ans[-2]==ans[0]:
                return ans
        else:
            if ans[0]==e(ans[-2]):
                return ans
    else:
        if ans[-1]=="W":
            if ans[-2]==ans[0]:
                return ans
        else:
            if ans[0]==e(ans[-2]):
                return ans
    return False

if s[0]=="o":
    if f("S","S","S"):
        print(*f("S","S","S"),sep="")
    elif f("W","S","W"):
        print(*f("W","S","W"),sep="")
    elif f("W","W","S"):
        print(*f("W","W","S"),sep="")
    elif f("S","W","W"):
        print(*f("S","W","W"),sep="")
    else:
        print(-1)
else:
    if f("W","W","W"):
        print(*f("W","W","W"),sep="")
    elif f("W","S","S"):
        print(*f("W","S","S"),sep="")
    elif f("S","S","W"):
        print(*f("S","S","W"),sep="")
    elif f("S","W","S"):
        print(*f("S","W","S"),sep="")
    else:
        print(-1)

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

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

for i in range(4):
  ans = l[i]
  for j in range(1, n):
    if ans[j] == 'S' and s[j] == 'o':
      if ans[j-1] == 'S':
        ans += 'S'
      else:
        ans += 'W'
    elif ans[j] == 'S' and s[j] == 'x':
      if ans[j-1] == 'S':
        ans += 'W'
      else:
        ans += 'S'
    elif ans[j] == 'W' and s[j] == 'o':
      if ans[j-1] == 'S':
        ans += 'W'
      else:
        ans += 'S'
    else:
      if ans[j-1] == 'S':
        ans += 'S'
      else:
        ans += 'W' 
  flag = 0
  if ans[-1] == ans[0]:
    if ans[0] == 'S' and s[0] == 'o':
      if ans[-2] == ans[1]:
        flag = 1
    elif ans[0] == 'W' and s[0] == 'o':
      if ans[-2] != ans[1]:
        flag = 1
    elif ans[0] == 'S' and s[0] == 'x':
      if ans[-2] != ans[1]:
        flag = 1
    else:
      if ans[-2] == ans[1]:
        flag = 1
  if flag == 1:
    print(ans[:-1])
    exit()
else:
  print('-1')

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

ok = 0

for ii in [[0,0], [0,1], [1,0], [1,1]]:
    A = [ii[0], ii[1]]
    
    for i in range(1, n-1):
        A.append(int((A[-1] == 1) ^ (A[-2] == 1) ^ (s[i] == "x")))
    
    if (A[-2] == 1) ^ (A[-1] == 1) ^ (A[0] == 1) ^ (s[-1] == "o") and \
        (A[-1] == 1) ^ (A[0] == 1) ^ (A[1] == 1) ^ (s[0] == "o"):
        ok = 1
        break

if ok == 0:
    print(-1)
else:
    ans = []
    for i in range(n):
        if A[i] == 0:
            ans.append("S")
        else:
            ans.append("W")
    print("".join(ans))

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


def check_truth(a_0, a_1):
    a = [True for i in range(N)]  
    a[0] = a_0
    a[-1] = a_1
    for i in range(N):
        if a[i]:
            if s[i] == 'o':
                a[(i+1)%N] = a[i-1]
            else:
                a[(i+1)%N] = not a[i-1]
        else:
            if s[i] == 'o':
                a[(i+1)%N] = not a[i-1]
            else:
                a[(i+1)%N] = a[i-1]
    if a[0] != a_0 or a[-1] != a_1:
        return -1
    else:
        return a


p = [True, False]
for i in range(2):
    for j in range(2):
        ans = check_truth(p[i], p[j])
        if ans != -1:
            for k in range(N):
                if ans[k]:
                    print('S', end='')
                else:
                    print('W', end='')
            print()
            exit()
print(-1)

Solution (Python):
def solve():
	n=int(input())
	s=[c=="o"for c in input()]
	for a,b in ([0,0],[0,1],[1,0],[1,1]):
		r=[a,b]
		for i in range(n):a,b=b,s[-~i%n]==(a==b);r+=[b]
		if r[:2]==r[-2:]:print("".join("WS"[i]for i in r[:-2]),sep="");exit()
	print(-1)
	
if __name__=="__main__":
	solve()

Solution (Python):
n,s=open(0);n=int(n)
for a,b in ([0,0],[0,1],[1,0],[1,1]):
	r=[a,b]
	for i in range(n):a,b=b,s[-~i%n]=="xo"[a==b];r+=[b]
	if r[:2]==r[-2:]:print(*("WS"[i]for i in r[:-2]),sep="");exit()
print(-1)

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

def main():
    N = int(input())
    s = input().strip()

    next_o = {"SS": "S", "SW": "W","WS": "W", "WW": "S"}
    next_x = {"SS": "W", "SW": "S","WS": "S", "WW": "W"}

    for ans in ["SS", "SW", "WS", "WW"]:
        for i in range(1, N):
            if s[i] == "o":
                ans += next_o[ans[-2:]]
            else:
                ans += next_x[ans[-2:]]
        
        if ans[0] == ans[-1]:
            if s[0] == "o":
                if ans[1] == next_o[ans[-2:]]:
                    print(ans[:-1])
                    return
            else:
                if ans[1] == next_x[ans[-2:]]:
                    print(ans[:-1])
                    return
    
    print(-1)

if __name__ == "__main__":
    main()

Solution (Python):
n=int(input())
s=[0+(m=="o") for m in input()]



def nxt(a,b,m):
	if a==b:
		return m
	else:
		return 1-m

for a,b in ((1,1),(0,1),(1,0),(0,0)):
	c,d = a,b
	ans = [a,b]
	for i in range(n-2):
		a,b = b,nxt(a,b,s[i+1])
		ans.append(b)
	if nxt(a,b,s[-1])==c and nxt(b,c,s[0])==d:
		for x in ans:
			if x:
				print("S",end="")
			else:
				print("W",end="")
		exit()
print(-1)

Solution (Python):
N = int(input())
s = input()
def calcnext(a, b, c):
  if b == "W":
    c = "x" if c == "o" else "o"
  n = a if c == "o" else "S" if a == "W" else "W"
  return n
for ab in ["SS", "SW", "WS", "WW"]:
  l = list(ab)
  for i in range(2, N+2):
    n = calcnext(l[i-2], l[i-1], s[(i-1)%N])
    l.append(n)
  
  if l[N:N+2] == l[0:2]:
    print("".join(l[:N]))
    exit()
print(-1)

Solution (Python):
input();s=input();A=["SS","SW","WS","WW"]
for c in s:A=[t+"SW"[(t[-1]==t[-2])-(c=="o")]for t in A]
A=[t[1:-1]for t in A if t[:2]==t[-2:]];print(A[0]if A else-1)

Solution (Python):


N=int(input())
s=input()
A=["SS","SW","WS","WW"]
for i,c in enumerate(s):
    for j in range(4):
        if A[j][-2:]=="SS":
            if c=="o":A[j]+="S"
            else:A[j]+="W"
        elif A[j][-2:]=="SW":
            if c=="o":A[j]+="W"
            else:A[j]+="S"
        elif A[j][-2:]=="WS":
            if c=="o":A[j]+="W"
            else:A[j]+="S"
        else:
            if c=="o":A[j]+="S"
            else:A[j]+="W"
A=[t[1:-1]for t in A if t[:2]==t[-2:]]
print(A[0]if A else-1)

Solution (Python):
N = int(input())
S = input()
T = [int(s == "o") for s in S]

def solve():
    for A in [[0, 0], [0, 1], [1, 0], [1, 1]]:
        for i in range(2, N):
            A.append(A[-2] ^ A[-1] ^ T[i - 1])
        if (T[-1] == (A[-2] ^ A[-1] ^ A[0]) and
            T[0] == (A[-1] ^ A[0] ^ A[1])):
            return A
    return []

ans = solve()
if ans:
    print("".join("S" if a else "W" for a in ans))
else:
    print(-1)