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

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

for st in start:
    ans = st
    for i in range(1, n):
        if s[i] == "o" and ans[i] == "S":
            if ans[i-1] == "S":
                ans += "S"
            else:
                ans += "W"
        elif s[i] == "x" and ans[i] == "S":
            if ans[i-1] == "S":
                ans += "W"
            else:
                ans += "S"
        elif s[i] == "o" and ans[i] == "W":
            if ans[i-1] == "S":
                ans += "W"
            else:
                ans += "S"
        elif s[i] == "x" and ans[i] == "W":
            if ans[i-1] == "S":
                ans += "S"
            else:
                ans += "W"

    if ans[0] == ans[-1]:
        ans = ans[:n]
        ok = False
        if s[0] == "o" and ans[0] == "S":
            if ans[-1] == ans[1]:
                ok = True
        elif s[0] == "x" and ans[0] == "S":
            if ans[-1] != ans[1]:
                ok = True
        elif s[0] == "o" and ans[0] == "W":
            if ans[-1] != ans[1]:
                ok = True
        elif s[0] == "x" and ans[0] == "W":
            if ans[-1] == ans[1]:
                ok = True
        if ok:
            print(ans[:n])
            exit()
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])
    break
else:
  print(-1)

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


T = [[1, 1], [1, -1], [-1, 1], [-1, -1]]
for t in T:
    for i in range(n-1):
        if t[i+1] == 1:
            if s[i+1] == "o":
                t.append(t[i])
            else:
                t.append(-1*t[i])
        else:
            if s[i+1] == "o":
                t.append(-1*t[i])
            else:
                t.append(t[i])

for t in T:
    if t[0] == t[-1]:
        if t[0] == 1:
            if s[0] == "o" and t[-2] == t[1]:
                ans = t
                break
            elif s[0] == "x" and t[-2] != t[1]:
                ans = t
                break
        elif t[0] == -1:
            if s[0] == "o" and t[-2] != t[1]:
                ans = t
                break
            elif s[0] == "x" and t[-2] == t[1]:
                ans = t
                break
else:
    print(-1)
    exit()


str_ans = ""
for i in range(n):
    if ans[i] == 1:
        str_ans += "S"
    elif ans[i] == -1:
        str_ans += "W"
print(str_ans)

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



from itertools import product
for tf in product([True, False], repeat=2):
    tf = list(tf)
    for i in range(1, n):
        if s[i] == 'o':
            if tf[i]:
                tf.append(tf[i-1])
            else:
                tf.append(not tf[i-1])
        else:
            if tf[i]:
                tf.append(not tf[i-1])
            else:
                tf.append(tf[i-1])

    if tf[0] == tf[-1]:
        tf.pop(-1)
        flag = False
        if s[0] == 'o':
            if tf[0]:
                if tf[-1] == tf[1]:
                    flag = True
            else:
                if tf[-1] != tf[1]:
                    flag = True
        else:
            if tf[0]:
                if tf[-1] != tf[1]:
                    flag = True
            else:
                if tf[-1] == tf[1]:
                    flag = True

        if flag:
            for i in range(n):
                if tf[i]:
                    tf[i] = 'S'
                else:
                    tf[i] = 'W'
            print(''.join(tf))
            exit()

print(-1)

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()

def main():
    N = int(input())
    S = input()
    """
    0, 1番目を決定すればそこから先は一意に確定するのでO(4N)で愚直にチェック可能
    """
    ans = [0] * N
    for i in range(4):
        ans[0] = i % 2
        ans[1] = i // 2
        for j in range(1, N - 1):
            if S[j] == 'o' and ans[j] == 1:
                ans[j + 1] = ans[j - 1]
            elif S[j] == 'o' and ans[j] == 0:
                ans[j + 1] = 1 - ans[j - 1]
            elif S[j] == 'x' and ans[j] == 1:
                ans[j + 1] = 1 - ans[j - 1]
            else:
                ans[j + 1] = ans[j - 1]
        if S[-1] == 'o' and ans[-1] == 1 and ans[-2] != ans[0]: continue
        if S[-1] == 'o' and ans[-1] == 0 and ans[-2] == ans[0]: continue
        if S[-1] == 'x' and ans[-1] == 1 and ans[-2] == ans[0]: continue
        if S[-1] == 'x' and ans[-1] == 0 and ans[-2] != ans[0]: continue
        if S[0] == 'o' and ans[0] == 1 and ans[-1] != ans[1]: continue
        if S[0] == 'o' and ans[0] == 0 and ans[-1] == ans[1]: continue
        if S[0] == 'x' and ans[0] == 1 and ans[-1] == ans[1]: continue
        if S[0] == 'x' and ans[0] == 0 and ans[-1] != ans[1]: continue
        t = ''
        for a in ans: 
            if a == 0:
                t += 'W'
            else:
                t += 'S'
        print(t)
        return
    print(-1)

if __name__ == "__main__":
    main()

Solution (Python):
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]

def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  N=I()
  s=S()
  a=['S','W']
  aa=(['S','S'],['S','W'],['W','S'],['W','W'])

  for ans in aa:
    for i in range(1,N-1):
      if ans[i]=='S':
        if s[i]=='o':
          ans.append(ans[i-1])
        else:
          ind=a.index(ans[i-1])
          ans.append(a[1-ind])
      else:
        if s[i]=='o':
          ind=a.index(ans[i-1])
          ans.append(a[1-ind])
        else:
          ans.append(ans[i-1])
    stress=''.join(str(x) for x in ans)
    f=True
    for i in range(N):
      if stress[i]=='S':
        if i==0:
          if s[i]=='o':
            if not (stress[-1]==stress[i+1]):
              
              f=False
          else:
            if not (stress[-1]!=stress[i+1]):
              
              f=False
        elif i==N-1:
          if s[i]=='o':
            if not (stress[i-1]==stress[0]):
              
              f=False
          else:
            if not (stress[i-1]!=stress[0]):
              
              f=False
        else:
          if s[i]=='o':
            if not (stress[i-1]==stress[i+1]):
              
              f=False
          else:
            if not (stress[i-1]!=stress[i+1]):
              
              f=False
      else:
        if i==0:
          if s[i]=='o':
            if not (stress[-1]!=stress[i+1]):
              
              f=False
          else:
            if not (stress[-1]==stress[i+1]):
              
              f=False
        elif i==N-1:
          if s[i]=='o':
            if not (stress[i-1]!=stress[0]):
              
              f=False
          else:
            if not (stress[i-1]==stress[0]):
              
              f=False
        else:
          if s[i]=='o':
            if not (stress[i-1]!=stress[i+1]):
              
              f=False
          else:
            if not (stress[i-1]==stress[i+1]):
              
              f=False

    if f:
      return ''.join(str(x) for x in ans)

  return -1


print(main())

Solution (Python):

import sys 
from collections import defaultdict
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
S = readline().decode()

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


d = defaultdict(int)
d['SSo'] = 'S'
d['SSx'] = 'W'
d['SWo'] = 'W'
d['SWx'] = 'S'
d['WSo'] = 'W'
d['WSx'] = 'S'
d['WWo'] = 'S'
d['WWx'] = 'W'
 


ans = []
for s in st:
    t = s  
    for i in range(1,N-1):
        tmp = t[-2:]
        ss = tmp + S[i]
        t += d[ss]
    ans.append(t)


for a in ans:
    b = a[N-2]+a[N-1]+S[N-1]
    if d[b] != a[0]:
        continue
    b = a[N-1]+a[0]+S[0]
    if d[b] != a[1]:
        continue
    print(a)
    sys.exit()

print(-1)

Solution (Python):

import sys 
from collections import defaultdict
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
S = readline().decode()

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


d = defaultdict(int)
d['SSo'] = 'S'
d['SSx'] = 'W'
d['SWo'] = 'W'
d['SWx'] = 'S'
d['WSo'] = 'W'
d['WSx'] = 'S'
d['WWo'] = 'S'
d['WWx'] = 'W'
 


ans = []
for s in st:
    t = s  
    for i in range(1,N-1):
        tmp = t[-2:]
        ss = tmp + S[i]
        t += d[ss]
    ans.append(t)


for a in ans:
    b = a[N-2]+a[N-1]+S[N-1]
    if d[b] != a[0]:
        continue
    b = a[N-1]+a[0]+S[0]
    if d[b] != a[1]:
        continue
    print(a)
    sys.exit()

print(-1)

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

init = ["SS", "SW", "WS", "WW"]
next_animal = { ("S","o","S"):"S",
                ("S","o","W"):"W",
                ("S","x","S"):"W",
                ("S","x","W"):"S",
                ("W","o","S"):"W",
                ("W","o","W"):"S",
                ("W","x","S"):"S",
                ("W","x","W"):"W"}
for X in init:
    SW = X
    for i in range(1,N):
        SW += next_animal[SW[i],s[i],SW[i-1]]
    ls = len(SW)
    if SW[0] == SW[ls-1] and next_animal[SW[0],s[0],SW[ls-2]] == SW[1]:
        print(SW[:ls-1])
        break
else:
    print(-1)

Solution (Python):
def check(before, center, after, saying):
    return ([center, saying] in [["S", "o"], ["W", "x"]] and before == after)\
           or ([center, saying] in [["S", "x"], ["W", "o"]] and before != after)


def main():
    n = int(input())
    s = list(input())
    ans = "-1"
    for init in ["S", "W"]:
        if ans != "-1":
            break
        for next in ["S", "W"]:
            now_ans = ["" for _ in range(n)]
            now_ans[0] = init
            now_ans[1] = next
            for i in range(1, n - 1):
                if [now_ans[i], s[i]] in [["S", "o"], ["W", "x"]]:
                    now_ans[i + 1] = now_ans[i - 1]
                else:
                    now_ans[i + 1] = "W" if now_ans[i - 1] == "S" else "S"
            if check(now_ans[-2], now_ans[-1], now_ans[0], s[-1]) and check(now_ans[-1], now_ans[0], now_ans[1], s[0]):
                ans = "".join(now_ans)
                break
    print(ans)


if __name__ == '__main__':
    main()

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

def f(SW,ox,prev):
  if SW=='S':
    if ox == 'o':
      if prev=='S': return 'S'
      else: return 'W'
    else:
      if prev=='S': return 'W'
      else: return 'S'
  else:
    if ox == 'o':
      if prev=='S': return 'W'
      else: return 'S'
    else:
      if prev=='S': return 'S'
      else: return 'W'

combination=[('S','S'),('S','W'),('W','S'),('W','W')]
ok=0
for j in range(4):
  if ok==1:break
  ans=[]
  for i in range(N):
    if i == 0:
      first,last = combination[j]
      ans.append(first)
      now = first
      next_ = f(now,S[i],last)
      continue
    if i == N-1:
      if last == next_ and first==f(next_,S[i],ans[-1]):
        ok=1
        ans.append(next_)
        break
      else:break
    ans.append(next_)
    next_ = f(next_,S[i],ans[-2])
    
if ok==1:
  print(''.join(ans))
else:
  print(-1)

Solution (Python):
import sys
N = int(input())
s = input()
not_sw = {'S':'W', 'W':'S'}

for sw1 in ['S', 'W']:
    for sw2 in ['S', 'W']:
        flag = True
        ans = [''] * (N+1)
        ans[0] = sw1
        ans[-1] = sw1
        if (s[0] == 'o' and ans[0] == 'S')  or (s[0] == 'x' and ans[0] == 'W'):
            ans[1] = sw2
            ans[-2] = sw2
        elif (s[0] == 'x' and ans[0] == 'S')  or (s[0] == 'o' and ans[0] == 'W'):
            ans[1] = not_sw[sw2]
            ans[-2] = sw2
        for i in range(1, N-2):
            if (s[i] == 'o' and ans[i] == 'S')  or (s[i] == 'x' and ans[i] == 'W'):
                ans[i+1] = ans[i-1]
            elif (s[i] == 'x' and ans[i] == 'S')  or (s[i] == 'o' and ans[i] == 'W'):
                ans[i+1] = not_sw[ans[i-1]]
        for i in range(N-2, N):
            if (s[i] == 'o' and ans[i] == 'S')  or (s[i] == 'x' and ans[i] == 'W'):
                if ans[i+1] != ans[i-1]:
                    flag = False
            elif (s[i] == 'x' and ans[i] == 'S')  or (s[i] == 'o' and ans[i] == 'W'):
                if ans[i+1] != not_sw[ans[i-1]]:
                    flag = False
        if flag:
            print(''.join(ans[:-1]))
            sys.exit()
print(-1)

Solution (Python):
def abc055_d():
    n = int(input())
    s = str(input())
    ss = s[-1] + s + s[0]

    def solve(ini1, ini0):
        res = [None] * (n+2)
        res[1] = ini1
        res[0] = ini0
        for i in range(1, n+1):
            if ss[i] == 'o':
                if res[i] == 'S' and res[i-1] == 'S': res[i+1] = 'S'
                if res[i] == 'S' and res[i-1] == 'W': res[i+1] = 'W'
                if res[i] == 'W' and res[i-1] == 'S': res[i+1] = 'W'
                if res[i] == 'W' and res[i-1] == 'W': res[i+1] = 'S'
            else:
                if res[i] == 'S' and res[i-1] == 'S': res[i+1] = 'W'
                if res[i] == 'S' and res[i-1] == 'W': res[i+1] = 'S'
                if res[i] == 'W' and res[i-1] == 'S': res[i+1] = 'S'
                if res[i] == 'W' and res[i-1] == 'W': res[i+1] = 'W'
        return res

    ans = '-1'
    ini = [('S','S'), ('S','W'), ('W','S'), ('W','W')]
    for ini1, ini0 in ini:
        res = solve(ini1, ini0)
        if res[0] == res[n] and res[1] == res[n+1]:
            ans = ''.join(res[1:n+1])
            break
    print(ans)

if __name__ == '__main__':
    abc055_d()

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

res = 'W'
if s[0] == 'o':
    res += 'S'
    for i in range(2,n+1):
        if s[i-1] == 'o':
            if res[i-1] == 'S':
                t = res[i-2]
            else:
                if res[i-2] == 'S':
                    t = 'W'
                else:
                    t = 'S'
        else:
            if res[i - 1] == 'S':
                if res[i-2] == 'S':
                    t = 'W'
                else:
                    t = 'S'
            else:
                t = res[i - 2]
        res += t
    if res[-1] == 'W' and res[-2] == 'W':
        print(res[:-1])
        exit()
res = 'W'
if s[0] == 'o':
    res += 'W'
    for i in range(2,n+1):
        if s[i-1] == 'o':
            if res[i-1] == 'S':
                t = res[i-2]
            else:
                if res[i-2] == 'S':
                    t = 'W'
                else:
                    t = 'S'
        else:
            if res[i - 1] == 'S':
                if res[i-2] == 'S':
                    t = 'W'
                else:
                    t = 'S'
            else:
                t = res[i - 2]
        res += t
    if res[-1] == 'W' and res[-2] == 'S':
        print(res[:-1])
        exit()
res = 'W'
if s[0] == 'x':
    res += 'S'
    for i in range(2,n+1):
        if s[i-1] == 'o':
            if res[i-1] == 'S':
                t = res[i-2]
            else:
                if res[i-2] == 'S':
                    t = 'W'
                else:
                    t = 'S'
        else:
            if res[i - 1] == 'S':
                if res[i-2] == 'S':
                    t = 'W'
                else:
                    t = 'S'
            else:
                t = res[i - 2]
        res += t
    if res[-1] == 'W' and res[-2] == 'S':
        print(res[:-1])
        exit()
res = 'W'
if s[0] == 'x':
    res += 'W'
    for i in range(2,n+1):
        if s[i-1] == 'o':
            if res[i-1] == 'S':
                t = res[i-2]
            else:
                if res[i-2] == 'S':
                    t = 'W'
                else:
                    t = 'S'
        else:
            if res[i - 1] == 'S':
                if res[i-2] == 'S':
                    t = 'W'
                else:
                    t = 'S'
            else:
                t = res[i - 2]
        res += t
    if res[-1] == 'W' and res[-2] == 'W':
        print(res[:-1])
        exit()

res = 'S'
if s[0] == 'o':
    res += 'S'
    for i in range(2,n+1):
        if s[i-1] == 'o':
            if res[i-1] == 'S':
                t = res[i-2]
            else:
                if res[i-2] == 'S':
                    t = 'W'
                else:
                    t = 'S'
        else:
            if res[i - 1] == 'S':
                if res[i-2] == 'S':
                    t = 'W'
                else:
                    t = 'S'
            else:
                t = res[i - 2]
        res += t
    if res[-1] == 'S' and res[-2] == 'S':
        print(res[:-1])
        exit()
res = 'S'
if s[0] == 'o':
    res += 'W'
    for i in range(2,n+1):
        if s[i-1] == 'o':
            if res[i-1] == 'S':
                t = res[i-2]
            else:
                if res[i-2] == 'S':
                    t = 'W'
                else:
                    t = 'S'
        else:
            if res[i - 1] == 'S':
                if res[i-2] == 'S':
                    t = 'W'
                else:
                    t = 'S'
            else:
                t = res[i - 2]
        res += t
    if res[-1] == 'S' and res[-2] == 'W':
        print(res[:-1])
        exit()
res = 'S'
if s[0] == 'x':
    res += 'S'
    for i in range(2,n+1):
        if s[i-1] == 'o':
            if res[i-1] == 'S':
                t = res[i-2]
            else:
                if res[i-2] == 'S':
                    t = 'W'
                else:
                    t = 'S'
        else:
            if res[i - 1] == 'S':
                if res[i-2] == 'S':
                    t = 'W'
                else:
                    t = 'S'
            else:
                t = res[i - 2]
        res += t
    if res[-1] == 'S' and res[-2] == 'W':
        print(res[:-1])
        exit()
res = 'S'
if s[0] == 'x':
    res += 'W'
    for i in range(2,n+1):
        if s[i-1] == 'o':
            if res[i-1] == 'S':
                t = res[i-2]
            else:
                if res[i-2] == 'S':
                    t = 'W'
                else:
                    t = 'S'
        else:
            if res[i - 1] == 'S':
                if res[i-2] == 'S':
                    t = 'W'
                else:
                    t = 'S'
            else:
                t = res[i - 2]
        res += t
    if res[-1] == 'S' and res[-2] == 'S':
        print(res[:-1])
        exit()

print(-1)

Solution (Python):
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LS2(): return list(sys.stdin.readline().rstrip())  

N = I()
s = LS2()
for i in range(N):
    if s[i] == 'o':
        s[i] = 0
    else:
        s[i] = 1

for a,b in [(0,0),(0,1),(1,0),(1,1)]:  
    A = [0]*N
    A[0] = a
    A[1] = b
    for i in range(2,N):
        A[i] = A[i-2] ^ A[i-1] ^ s[i-1]
    if A[0] == A[-2] ^ A[-1] ^ s[-1] and A[1] == A[-1] ^ A[0] ^ s[0]:
        A = ['S' if A[i] == 0 else 'W' for i in range(N)]
        print(''.join(A))
        exit()

print(-1)

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


for s in ['SS', 'SW', 'WS', 'WW']:
    ss = s
    jdg = False
    for i in range(1, N):
        if S[i] == 'o':
            if ss[i] == 'S':
                ss += ss[i - 1]
            else:
                if ss[i - 1] == 'W': ss += 'S'
                else: ss += 'W'
        else:
            if ss[i] == 'S':
                if ss[i - 1] == 'W': ss += 'S'
                else: ss += 'W'
            else:
                ss += ss[i - 1]
    if ss[N] == ss[0]:
        if S[0] == 'o':
            if (ss[0] == 'S' and ss[N-1] == ss[1]) or (ss[0] == 'W' and ss[N-1] != ss[1]):
                jdg = True
                break
        else:
            if (ss[0] == 'S' and ss[N-1] != ss[1]) or (ss[0] == 'W' and ss[N-1] == ss[1]):
                jdg = True
                break
print(ss[:-1] if jdg else -1)

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())
    S = readline().strip()

    ans = -1
    for last, first in ((0, 0), (0, 1), (1, 0), (1, 1)):
        vec = [0] * N
        vec[-1] = last
        vec[0] = first
        for i in range(N):
            if vec[i] == 0:
                if S[i] == 'o':
                    vec[(i + 1) % N] = vec[i - 1]
                else:
                    vec[(i + 1) % N] = 1 - vec[i - 1]
            else:
                if S[i] == 'o':
                    vec[(i + 1) % N] = 1 - vec[i - 1]
                else:
                    vec[(i + 1) % N] = vec[i - 1]

        if vec[-1] == last and vec[0] == first:
            ans = ''.join('S' if a == 0 else 'W' for a in vec)
            break

    print(ans)
    return


if __name__ == '__main__':
    main()

Solution (Python):
N=int(input())
S=input()
for t in ["SS", "SW", "WS", "WW"]:
  for i in S[1:-1]:
    if t[-1] == "S":
      if i == "o": t+=t[-2]
      else: t += "S" if t[-2] == "W" else "W"
    else:
      if i == "x": t += t[-2]
      else: t += "S" if t[-2] == "W" else "W"

    if t[0] == "S":
      if S[0] == "o": f = t[-1] == t[1]
      else: f = t[-1] != t[1]
    else:
      if S[0] == "x": f = t[-1] == t[1]
      else: f = t[-1] != t[1]
 
    if t[-1] == "S":
      if S[-1] == "o": g = t[-2] == t[0]
      else: g = t[-2] != t[0]
    else:
      if S[-1] == "x": g = t[-2] == t[0]
      else: g = t[-2] != t[0]
 
  if f and g:
    print(t)
    exit()

print(-1)

Solution (Python):
import sys
from collections import deque

dic={'o':lambda s:1-(s[1]^s[0]), 'x':lambda s:s[1]^s[0]}
def mknseq(ox,ld):
    for x in ld:
        x.append(dic[ox]((x[-2],x[-1])))
def main():
    N=int(sys.stdin.readline().strip())
    s=list(sys.stdin.readline().strip())
    
    ans=[[x,y] for x in range(2) for y in range(2)]
    for x in range(N):
        mknseq(s[x],ans)
    
    for x in ans:
        if x[0]==x[-2] and x[1]==x[-1]:
            return print(''.join([['W','S'][i] for i in x])[1:-1])
    print(-1)

if __name__=='__main__':
    main()

Solution (Python):
import sys
from collections import deque

dic={'o':lambda s:1-(s[1]^s[0]), 'x':lambda s:s[1]^s[0]}
def mknseq(ox,ld):
    for x in ld:
        x.append(dic[ox]((x[-2],x[-1])))
def main():
    N=int(sys.stdin.readline().strip())
    s=list(sys.stdin.readline().strip())
    ans=[deque([x,y]) for x in range(2) for y in range(2)]
    for x in range(N):
        mknseq(s[x],ans)
    
    for x in ans:
        if x[0]==x[-2] and x[1]==x[-1]:
            return print(''.join([['W','S'][i] for i in x])[1:-1])
    print(-1)

if __name__=='__main__':
    main()

Solution (Python):
import sys
from collections import deque

dic={'o':lambda s:1-(s[1]^s[0]), 'x':lambda s:s[1]^s[0]}
def mknseq(ox,ld):
    for x in ld:
        x.append(dic[ox]([x[-2],x[-1]]))
def main():
    N=int(sys.stdin.readline().strip())
    s=list(sys.stdin.readline().strip())
    ans=[deque([x,y]) for x in range(2) for y in range(2)]
    for x in range(N):
        mknseq(s[x],ans)
    ans=[list(x) for x in ans]
    
    for x in ans:
        if x[:2]==x[-2:]:
            return print(''.join([['W','S'][i] for i in x[1:-1]]))
    print(-1)

if __name__=='__main__':
    main()

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

animal = ["S", "W"]

start = [[0, 0], [0, 1], [1, 0], [1, 1]]

for i, j in start:
  ans = [-1] * N
  ans[0] = i
  ans[1] = j
  p = 0
  for k in range(N - 1):
    
    if p == 0:
      if k == 0:
        if S[k] == "o":
          if ans[k] == 0:
            ans[-1] = ans[1]
          else:
            ans[-1] = 1 - ans[1]
        else:
          if ans[k] == 0:
            ans[-1] = 1 - ans[1]
          else:
            ans[-1] = ans[1]
      else:
        if S[k] == "o":
          if ans[k] == 0:
            now = ans[k - 1]
            if ans[k + 1] == 1 - now:
              p = 1
            else:
              ans[k + 1] = now
          else:
            now = 1 - ans[k - 1]
            if ans[k + 1] == 1 - now:
              p = 1
            else:
              ans[k + 1] = now            
        else:
          if ans[k] == 0:
            now = 1 - ans[k - 1]
            if ans[k + 1] == 1 - now:
              p = 1
            else:
              ans[k + 1] = now
          else:
            now = ans[k - 1]
            if ans[k + 1] == 1 - now:
              p = 1
            else:
              ans[k + 1] = now
  
  
  if ans[-1] == 0:
    if S[-1] == "o":
      if ans[-2] != ans[0]:
        p = 1
    else:
      if ans[-2] == ans[0]:
        p = 1
  else:
    if S[-1] == "o":
      if ans[-2] == ans[0]:
        p = 1
    else:
      if ans[-2] != ans[0]:
        p = 1
  
  if p == 0:
    
    for i in range(N):
      if ans[i] == 0:
        print("S", end = "")
      else:
        print("W", end = "")
    quit()
    
print(-1)

Solution (Python):
n=int(input())
s=input()
ch=['S','W']


for c1 in range(2):
    for c0 in range(2):
        if (ch[c1]=='S' and s[1]=='o') or (ch[c1]=='W' and s[1]=='x'):
            ans=ch[c0]+ch[c1]+ch[c0]
        else:
            ans=ch[c0]+ch[c1]+ch[(c0+1)%2]
        
        i=2

        while i<n-1:
            if (ans[-1]=='S' and s[i]=='o') or (ans[-1]=='W' and s[i]=='x'):
                ans+=ans[-2]
            else:
                ans+='W' if ans[-2]=='S' else 'S'
            i+=1
        
        for i in range(n):
            bc=ans[(i-1+n)%n]
            ac=ans[(i+1)%n]

            if (ans[i]=='S' and s[i]=='o') or (ans[i]=='W' and s[i]=='x'):
                if bc!=ac:
                    break
            else:
                if bc==ac:
                    break
        else:
            print(ans)
            exit(0)

print(-1)

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

lst = ["SW", "WS", "SS", "WW"]
ans = []

for tmp in lst:
    for i in range(1, N-1):
        if(s[i] == "o"):
            if(tmp[i] == "S"):
                tmp += tmp[i-1]
            else:
                if(tmp[i-1] == "S"):
                    tmp += "W"
                else:
                    tmp += "S"
        else:
            if(tmp[i] == "W"):
                tmp += tmp[i-1]
            else:
                if(tmp[i-1] == "S"):
                    tmp += "W"
                else:
                    tmp += "S"

    ans.append(tmp)

for st in ans:
    flg = True
    if(s[0] == "o"):
        if(st[0] == "S"):
            if(st[-1] != st[1]):
                flg = False
        else:
            if(st[-1] == st[1]):
                flg = False
    else:
        if(st[0] == "S"):
            if(st[-1] == st[1]):
                flg = False
        else:
            if(st[-1] != st[1]):
                flg = False
    if(s[N-1] == "o"):
        if(st[N-1] == "S"):
            if(st[N-2] != st[0]):
                flg = False
        else:
            if(st[N-2] == st[0]):
                flg = False
    else:
        if(st[N-1] == "S"):
            if(st[N-2] == st[0]):
                flg = False
        else:
            if(st[N-2] != st[0]):
                flg = False
    if(flg):
        print(st)
        sys.exit()
print(-1)

Solution (Python):
N = int(input())
s = list(input())
s = s * 2
q = [[True,True],[True,False],[False,True],[False,False]]
p = []
ans = []
for k in range(4):
    p = q[k]
    for i in range(N*2-2):
        if p[i + 1]:
            if s[i + 1] == "o":
                p.append(p[i])
            else:
                p.append(not p[i])
        else:
            if s[i + 1] == "o":
                p.append(not p[i])
            else:
                p.append(p[i])
    if p[0:N-1] == p[N:N*2-1]:
        for i in range(N):
            if p[i]:
                ans.append("S")
            else:
                ans.append("W")
        print("".join(ans))
        break
    if k == 3:
        print(-1)