qyliang/CodeNanoFix huggingface dataset:
Buggy code:
n = int(input())
p = 1
for i in range(1, n+1):
    p *= i
print(p % 10**9 + 7)

Fixed code:
n = int(input())
p, d =1, 10**9+7
for i in range(1,n+1):
  p = (p*i) % d
print(p)
Buggy code:
n = int(input)

p = 1
for i in range(2, n+1):
  p = p*i%(10**9+7)
print(p)

Fixed code:
n = int(input())
 
p = 1
for i in range(2, n+1):
  p = p*i%(10**9+7)
print(p)
Buggy code:


import numpy as np
import math
MOD=10**9+7

n=int(input())
ans=1
for i in range(n+1):
    ans=(ans*i)%MOD
print(ans)

Fixed code:


import numpy as np
import math
MOD=10**9+7

n=int(input())
ans=1
for i in range(1,n+1):
    ans=(ans*i)%MOD
print(ans)
Buggy code:
import math
print(math.factorial(int(input()))%(10**7+7))

Fixed code:
import math

print((math.factorial(int(input()))) % (10**9+7))
Buggy code:
from sys import stdin


def main() -> int:
    n = next_int()
    m = 10 ** 9 + 7

    ans = 1
    for i in range(n):
        j = i % m
        ans = (ans * j) % m

    print(ans)
    return 0


def next_int() -> int:
    return int(next_str())


def next_str() -> str:
    result = ""
    while True:
        tmp = stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()

Fixed code:
from sys import stdin


def main() -> int:
    n = next_int()
    m = 10 ** 9 + 7

    ans = 1

    for i in range(1, n + 1):
        j = i % m
        ans = (ans * j) % m

    print(ans)
    return 0


def next_int() -> int:
    return int(next_str())


def next_str() -> str:
    result = ""
    while True:
        tmp = stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()
Buggy code:
N  = int(input())
#N = 10**5
p = 1
#x = [p*i for i in range(1,N+1)]
for i in range(1,N+1):
  p =i*p%(10**9+7)
  print(p)
  
  
  
print(p)

Fixed code:
N  = int(input())
#N = 10**5
p = 1
#x = [p*i for i in range(1,N+1)]
for i in range(1,N+1):
  p =i*p%(10**9+7)
#  print(p)
  
  
  
print(p)
Buggy code:
N = int(input())

P = 1

for i in range(1,N):
    P = P*i

print(P % (10**9+7))


Fixed code:
N = int(input())

P = 1

for i in range(2,N+1):
    P = P*i
    P = P % (10 ** 9 + 7)

print(P)
Buggy code:
#ABC055

n = int(input())
p = 10 ** 9 + 7
x = 1
for i in range(1,n):
    x *= (i + 1) % p
print(x)

Fixed code:
#ABC055

n = int(input())
p = 10 ** 9 + 7
x = 1
for i in range(1,n):
    x *= (i + 1) % p
    x %= p
print(x % p)
Buggy code:
n = int(input())
k = 1
for i in range(1,n+1):
  k = k**i
print(k%(10**9+7))

Fixed code:
n = int(input())
k = 1
for i in range(1,n+1):
  k = k*i%(10**9+7)
print(k)
Buggy code:
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    answer=1
    n=int(input())
    for i in range(1,n+1):
        answer*=i
        answer%=10**9+7
    print(answer)
#resolve()

Fixed code:
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    answer=1
    n=int(input())
    for i in range(1,n+1):
        answer*=i
        answer%=10**9+7
    print(answer)
resolve()
Buggy code:
n=int(input())
s=list(input())
s=s+s
x=[["S","S"],["S","W"],["W","S"],["W","W"]]

for temp1 in x:
    if s[0]=="o":
        c=temp1[1]
    else:
        if temp1[1]=="S":
            c="W"
        else:
            c="S"
    for i in range(1,2*n-1):
        if s[i]=="o":
            if temp1[i]=="S":
                temp1.append(temp1[i-1])
                
            else:
                if temp1[i-1]=="S":
                    temp1.append("W")
                else:
                    temp1.append("S")
        else:
            if s[i]=="W":
                temp1.append(temp1[i-1])
            else:
                if temp1[i-1]=="W":
                    temp1.append("S")
                else:
                    temp1.append("W")
    
    
    if temp1[:n]==temp1[n:]:
        print("".join(temp1[:n]))
        exit()
print(-1)

Fixed code:
n=int(input())
s=list(input())
s=s+s
x=[["S","S"],["S","W"],["W","S"],["W","W"]]

for temp1 in x:
    if s[0]=="o":
        c=temp1[1]
    else:
        if temp1[1]=="S":
            c="W"
        else:
            c="S"
    for i in range(1,n+1):
        if s[i]=="o":
            if temp1[i]=="S":
                temp1.append(temp1[i-1])
                
            else:
                if temp1[i-1]=="S":
                    temp1.append("W")
                else:
                    temp1.append("S")
        else:
            if temp1[i]=="W":
                temp1.append(temp1[i-1])
            else:
                if temp1[i-1]=="W":
                    temp1.append("S")
                else:
                    temp1.append("W")
    
    
    if temp1[0]==temp1[-2] and temp1[1]==temp1[-1]:
        print("".join(temp1[:n]))
        exit()
print(-1)
Buggy code:
n = int(input())
s = input()

# S:1 W:-1
T = [[1, 1], [1, -1], [-1, 1], [-1, -1]]
for t in T:
    for i in range(n-2):
        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])
#print(T)
for t in T:
    if t[0] == 1:
        if s[0] == "o" and t[-1] == t[1]:
            ans = t
            break
        elif s[0] == "x" and t[-1] != t[1]:
            ans = t
            break
    elif t[0] == -1:
        if s[0] == "o" and t[-1] != t[1]:
            ans = t
            break
        elif s[0] == "x" and t[-1] == 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)




Fixed code:
n = int(input())
s = input()

# S:1 W:-1
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])
#print(T)
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)
Buggy code:
N = int(input())
s = list(input())
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):
        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] == p[-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)

Fixed code:
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)
Buggy code:
n=int(input())
s=list(input())
def func(a,b):
  ans=[a,b] #True:S, False:W
  for i in range(1,n):
    if s[i]=='o':
      if ans[-1]:
        ans.append(ans[-2])
      else:
        ans.append(not ans[-2])
    else:
      if ans[-1]:
        ans.append(not ans[-2])
      else:
        ans.append(ans[-2])
  if s[0]=='o' and a and ans[0]==ans[-1]:
    print(''.join(['S' if ansi else 'W' for ansi in ans[:-1]]))
    exit()
  elif s[0]=='o' and not a and ans[0]!=ans[-1]:
    print(''.join(['S' if ansi else 'W' for ansi in ans[:-1]]))
    exit()
  elif s[0]=='x' and a and ans[0]!=ans[-1]:
    print(''.join(['S' if ansi else 'W' for ansi in ans[:-1]]))
    exit()
  elif s[0]=='x' and not a and ans[0]==ans[-1]:
    print(''.join(['S' if ansi else 'W' for ansi in ans[:-1]]))
    exit()
func(True,True)
func(True,False)
func(False,True)
func(False,False)
print(-1)


Fixed code:
n=int(input())
s=list(input())
def func(a,b):
  ans=[a,b] #True:S, False:W
  for i in range(1,n):
    if s[i]=='o':
      if ans[-1]:
        ans.append(ans[-2])
      else:
        ans.append(not ans[-2])
    else:
      if ans[-1]:
        ans.append(not ans[-2])
      else:
        ans.append(ans[-2])
  if ans[0]==ans[-1]:
    flg=False
    if s[0]=='o' and a and ans[1]==ans[-2]:
      flg=True
    elif s[0]=='o' and not a and ans[1]!=ans[-2]:
      flg=True
    elif s[0]=='x' and a and ans[1]!=ans[-2]:
      flg=True
    elif s[0]=='x' and not a and ans[1]==ans[-2]:
      flg=True
    if flg:
      print(''.join(['S' if ansi else 'W' for ansi in ans[:-1]]))
      exit()
func(True,True)
func(True,False)
func(False,True)
func(False,False)
print(-1)
Buggy code:
n = int(input())
s = input()
seed1 = ["S","W"]
ans = ["SS","SW","WS","WW"]
for i in s[1:]:
    for k,v in enumerate(ans):
        now = 0 if i == "o" else 1
        now = (now + seed1.index(v[-1]) + seed1.index(v[-2])) % 2
        if now:
            ans[k] += "W"
        else:
            ans[k] += "S"
now = 0 if s[0] == "o" else 1
for i in ans:
    if (i[0] == i[-1]) and ((i[2] == i[-2]) ^ now):
        print(i[:-1])
        exit()
print(-1)

Fixed code:
n = int(input())
s = input()
seed1 = ["S","W"]
ans = ["SS","SW","WS","WW"]
for i in s[1:]:
    for k,v in enumerate(ans):
        now = 0 if i == "o" else 1
        now = (now + seed1.index(v[-1]) + seed1.index(v[-2])) % 2
        if now:
            ans[k] += "W"
        else:
            ans[k] += "S"
now = 0 if s[0] == "x" else 1
for i in ans:  
    now2 = (now + seed1.index(i[-2]) + seed1.index(i[1]) + seed1.index(i[0])) % 2
    if (i[0] == i[-1]) and now2:
        print(i[:-1])
        exit()
print(-1)
Buggy code:
N=int(input())
S=list(input().rstrip())
for i in range(N):
  if S[i]=='o': S[i]=True
  else: S[i]=False
S.append(S[0])
A=[True]*(N+2)
for a in [[True,True],[True,False],[False,True],[False,False]]:
  A[0],A[1]=a[0],a[1]
  for j in range(1,N+1):
    if A[j] ^ S[j]:
      A[j+1]=not A[j-1]
    else:
      A[j+1]=A[j-1]
  if A[0]==A[-1]:
    for k in range(N):
      if A[k]: A[k]='S'
      else: A[k]='W'
    print("".join(A[:N]))
    exit()
print(-1)

Fixed code:
N=int(input())
S=list(input().rstrip())
for i in range(N):
  if S[i]=='o': S[i]=True
  else: S[i]=False
S.append(S[0])
A=[True]*(N+2)
for a in [[True,True],[True,False],[False,True],[False,False]]:
  A[0],A[1]=a[0],a[1]
  for j in range(1,N+1):
    if A[j] ^ S[j]:
      A[j+1]=not A[j-1]
    else:
      A[j+1]=A[j-1]
  if A[0]==A[-2] and A[1]==A[-1]:
    for k in range(N):
      if A[k]: A[k]='S'
      else: A[k]='W'
    print("".join(A[:N]))
    exit()
print(-1)
Buggy code:
import sys

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

array = [[True, True], [True, False], [False, False], [False, True]]

for i in range(1, n):
  for v in array:
    flag = not((s[i] == 'o') ^ v[i])
    v.append(not(flag ^ v[i-1]))
    
for v in array:
  flag1 = (array[1] == array[-2])
  flag2 = not((s[0] == 'o') ^ v[0])
  flag = not(flag1 ^ flag2)
  
  if v[0] == v[-1] and flag:
    for c in v[0:len(v)-1]:
      if c:
        print('S', end='')
      else:
        print('W', end='')
        
    print()
    sys.exit(0)
    
print(-1)

Fixed code:
import sys

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

array = [[True, True], [True, False], [False, False], [False, True]]

for i in range(1, n):
  for v in array:
    flag = ((s[i] == 'o') == v[i])
    v.append((flag == v[i-1]))
    
for v in array:
  flag1 = (v[1] == v[-2])
  flag2 = ((s[0] == 'o') == v[0])
  flag = (flag1 == flag2)
  
  if v[0] == v[-1] and flag:
    for c in v[0:len(v)-1]:
      if c:
        print('S', end='')
      else:
        print('W', end='')
        
    print()
    
    sys.exit(0)
    
print(-1)
Buggy code:
import sys
input = sys.stdin.readline
n=int(input())
s=input()
def solve():
    for i in range(1,n):
        if (ans[i]=="S" and s[i]=="o") or (ans[i]=="W" and s[i]=="x"):
            ans[i+1]=ans[i-1]
        else:
            if ans[i-1]=="S":
                ans[i+1]="W"
            else:
                ans[i+1]="S"

        if (ans[0]=="S" and s[0]=="o") or (ans[0]=="W" and s[0]=="x"):
            sl=ans[1]
        else:
            if a[1]=="S":
                sl="W"
            else:
                sl="S"
    if ans[0]==ans[-1] and sl==ans[n-1]:
        return True
    else:
        return False

ans=[0]*(n+1)

for i in ["S","W"]:
    for j in ["S","W"]:
        ans[0]=i
        ans[1]=j
        if solve():
            print("".join(ans[:-1]))
            exit()
print(-1)


Fixed code:
import sys
input = sys.stdin.readline
n=int(input())
s=input()
def solve():
    for i in range(1,n):
        if (ans[i]=="S" and s[i]=="o") or (ans[i]=="W" and s[i]=="x"):
            ans[i+1]=ans[i-1]
        else:
            if ans[i-1]=="S":
                ans[i+1]="W"
            else:
                ans[i+1]="S"

        if (ans[0]=="S" and s[0]=="o") or (ans[0]=="W" and s[0]=="x"):
            sl=ans[1]
        else:
            if ans[1]=="S":
                sl="W"
            else:
                sl="S"
    if ans[0]==ans[-1] and sl==ans[n-1]:
        return True
    else:
        return False

ans=[0]*(n+1)

for i in ["S","W"]:
    for j in ["S","W"]:
        ans[0]=i
        ans[1]=j
        if solve():
            print("".join(ans[:-1]))
            exit()
print(-1)
Buggy code:

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

dt = [[1,1],[-1,1],[1,-1],[-1,-1]] #1→sheep,-1→wlf

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)



Fixed code:

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]] #1→sheep,-1→wlf

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)
Buggy code:
n=int(input())
s=[0+(m=="o") for m in input()]

#o:1,x:0
#Sheep:1,wolf:0
def nxt(a,b,m):
	if a==b:
		return m
	else:
		return 1-m

for a,b in ((0,0),(0,1),(1,0),(1,1)):
	check = a
	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]) == check:
		for x in ans:
			if x:
				print("S",end="")
			else:
				print("W",end="")
		exit()
print(-1)

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

#o:1,x:0
#Sheep:1,wolf:0
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)
Buggy code:
n = int(input())
s = input()
s += s[:2]

for ans in ["SS", "SW", "WW", "WS"]:
    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[0] == ans[n]:
        print(ans)
        exit()

print(-1)

Fixed code:
n = int(input())
s = input()
s += s[:2]

for ans in ["SS", "SW", "WW", "WS"]:
    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)
Buggy code:
n = int(input())
s = [c == 'o' for c in input()]
def next_s(s, flag):
  d = {'S' : 'W', 'W' : 'S'}
  if flag:
    return s
  else:
    return d[s]

def sim(s0):
  ans = ['.' for _ in range(n)]
  ans[0] = s0[0]
  ans[1] = s0[1]
  for i in range(2, n):
    if ans[i-1] == 'S':
      ans[i] = next_s(ans[i-2], s[i-1])
    else:
      ans[i] = next_s(ans[i-2], not s[i-1])
  res = ans[1] == ans[-1]
  if s0[0] == 'S':
    if res == s[0]:
      return ans
  else:
    if res != s[0]:
      return ans
  return False

def solve():
  for item in ["SS", "SW", "WS", "WW"]:
    ans = sim(item)
    if ans:
      return print(''.join(ans))
  return print(-1)

Fixed code:
n = int(input())
s = [c == 'o' for c in input()]
def next_s(s, flag):
  d = {'S' : 'W', 'W' : 'S'}
  if flag:
    return s
  else:
    return d[s]

def sim(s0):
  ans = ['.' for _ in range(n+1)]
  ans[0] = s0[0]
  ans[1] = s0[1]
  for i in range(2, n+1):
    if ans[i-1] == 'S':
      ans[i] = next_s(ans[i-2], s[i-1])
    else:
      ans[i] = next_s(ans[i-2], not s[i-1])
  res = ans[1] == ans[-2]
  if s0[0] == 'S':
    if res == s[0] and ans[-1] == ans[0]:
      return ans[:-1]
  else:
    if res != s[0] and ans[-1] == ans[0]:
      return ans[:-1]
  return False

def solve():
  for item in ["SS", "SW", "WS", "WW"]:
    ans = sim(item)
    if ans:
      return print(''.join(ans))
  return print(-1)

solve()
Buggy code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def neg(i):
    if i == 'S':
        return 'W'
    else:
        return 'S'

s  = ''
n = 0

def check(build):
    poss = [0, n-1]
    for pos in poss:
        if build[pos] == 'S':
            if s[pos] == 'o' and build[(pos-1+n)%n] == build[(pos+1+n)%n]:
                return True
            if s[pos] == 'x' and build[(pos-1+n)%n] != build[(pos+1+n)%n]:
                print(build)
                return True
        else:
            if s[pos] == 'o' and build[(pos-1+n)%n] != build[(pos+1+n)%n]:
                return True
            if s[pos] == 'x' and build[(pos-1+n)%n] == build[(pos+1+n)%n]:
                return True

def solve():
    global s, n
    n = f()[0]
    s = input()

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

            if check(build):
                print(build)
                return

    print(-1)

            
                



solve()


Fixed code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def neg(i):
    if i == 'S':
        return 'W'
    else:
        return 'S'

s  = ''
n = 0

def check(build):
    poss = [0, n-1]
    for pos in poss:
        if build[pos] == 'S':
            if s[pos] == 'o' and build[(pos-1+n)%n] != build[(pos+1+n)%n]:
                return False
            if s[pos] == 'x' and build[(pos-1+n)%n] == build[(pos+1+n)%n]:
                return False
        else:
            if s[pos] == 'o' and build[(pos-1+n)%n] == build[(pos+1+n)%n]:
                return False
            if s[pos] == 'x' and build[(pos-1+n)%n] != build[(pos+1+n)%n]:
                return False
    
    return True

def solve():
    global s, n
    n = f()[0]
    s = input()

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

            if check(build):
                print(build)
                return

    print(-1)


solve()
Buggy code:
N = int(input())
s = input()

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

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

    if ans[i][0] == ans[i][-1]:
        print(ans[i][:-1])
        exit()
print(-1)

Fixed code:
N = int(input())
s = input()

ans = ['SS', 'SW', 'WS', 'WW']
s += s[0]
for i in range(4):
    for j in range(1, N+1):
        if ans[i][j] == 'S':
            if s[j] == 'o':
                ans[i] += ans[i][j-1]
            else:
                if ans[i][j-1] == 'S':
                    ans[i] += 'W'
                else:
                    ans[i] += 'S'
        else:
            if s[j] == 'x':
                ans[i] += ans[i][j-1]
            else:
                if ans[i][j-1] == 'S':
                    ans[i] += 'W'
                else:
                    ans[i] += 'S'

    if ans[i][0] == ans[i][-2] and ans[i][1] == ans[i][-1]:
        print(ans[i][:-2])
        exit()

print(-1)