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



Sample input:
6
ooxoox


Sample output:
SSSWWS

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
flag=True
lists=["WWW","SWS","WSS","SSW","SWW","WWS","SSS"]
if s[0]=="x":
    for j in range(4):
        strings=lists[j]
        for i in range(n-1):
            if strings[-2]=="W" and strings[-1]=="W" and s[i+1]=="o":
                strings+="S"
            elif strings[-2]=="W" and strings[-1]=="W" and s[i+1]=="x": 
                strings+="W"
                
            elif strings[-2]=="W" and strings[-1]=="S" and s[i+1]=="o":
                break
            elif strings[-2]=="W" and strings[-1]=="S" and s[i+1]=="x":
                strings+="S"
                
            elif strings[-2]=="S" and strings[-1]=="S" and s[i+1]=="o":
                strings+="S"
            elif strings[-2]=="S" and strings[-1]=="S" and s[i+1]=="x": 
                strings+="W"
                
            elif strings[-2]=="S" and strings[-1]=="W" and s[i+1]=="o":
                strings+="W"
            elif strings[-2]=="S" and strings[-1]=="W" and s[i+1]=="x":    
                strings+="S"

        if strings[0]==strings[-2] and strings[1]==strings[-1]:
            flag=False
            print(strings[1:-1])
            break
        else:
            continue
elif s[0]=="o":
    for j in range(4,7):
        strings=lists[j]
        for i in range(n-1):
            if strings[-2]=="W" and strings[-1]=="W" and s[i+1]=="o":
                strings+="S"
            elif strings[-2]=="W" and strings[-1]=="W" and s[i+1]=="x": 
                strings+="W" 
            elif strings[-2]=="W" and strings[-1]=="S" and s[i+1]=="o":
                break
            elif strings[-2]=="W" and strings[-1]=="S" and s[i+1]=="x":
                strings+="S"
            elif strings[-2]=="S" and strings[-1]=="S" and s[i+1]=="o":
                strings+="S"
            elif strings[-2]=="S" and strings[-1]=="S" and s[i+1]=="x": 
                strings+="W"
                
            elif strings[-2]=="S" and strings[-1]=="W" and s[i+1]=="o":
                strings+="W"
            elif strings[-2]=="S" and strings[-1]=="W" and s[i+1]=="x":    
                strings+="S"

        if  len(strings)==n+2 and strings[0]==strings[-2] and strings[1]==strings[-1]:
            flag=False
            print(strings[1:-1])
            break
        else:
            continue
        
if flag:
    print("-1")

Submission status: Wrong Answer

Solution code:
#%%
n = int(input())
s = list(input())

t = [2] * n

def change(x):
    if x == 0:
        return 1
    else:
        return 0

# 0 = hituzi
# 1 = ookami
l = [[0, 0], [0, 1], [1, 0], [1, 1]]
flag = False

for i in l:
    l0 = i[0]
    l1 = i[1]
    t[0] = l0
    t[1] = l1
    if s[0] == 'o':
        tmp = l1
    else:
        tmp = change(l1)
    for j in range(1, n-1):
        if s[j] == 'o' and t[j] == 0:
            t[j+1] = t[j-1]
        elif s[j] == 'x' and t[j] == 0:
            t[j+1] = change(t[j-1])
        elif s[j] == 'o' and t[j] == 1:
            t[j+1] = change(t[j-1])
        else:
            t[j+1] = t[j-1]
    #print(tmp, t)
    if tmp == t[-1] :
        if (s[-1] == 'o' and t[-1] == 0) or(s[-1] == 'x' and t[-1] == 1):
            if t[0] == t[-2]:
                flag = True
                break
            else:
                pass
        elif (s[-1] == 'x' and t[-1] == 0) or ((s[-1] == 'o' and t[-1] == 1)):
            if t[0] != t[-2]:
                flag = True
                break
            else:
                pass  


ans_list = []
for i in range(n):
    if t[i] == 0:
        ans_list.append('S')
    else:
        ans_list.append('W')

if flag:
    ans = ''.join(ans_list)
    print(ans)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
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[-1] == t[1]) :
            print(t[:-1])
            break
        elif S[0] == "o" and (t[0] == "W") and (t[-1] != t[1]) :
            print(t[:-1])
            break
        if S[0] == "x" and t[0] == "S" and (t[-1] != t[1]) :
            print(t[:-1])
            break
        elif S[0] == "x" and (t[0] == "W") and (t[-1] == t[1]) :
            print(t[:-1])
            break
else :
    print(-1)

Submission status: Wrong Answer

Solution code:
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[-1] == t[1]) :
            print(t)
            break
        elif S[0] == "o" and (t[0] == "W") and (t[-1] != t[1]) :
            print(t)
            break
        if S[0] == "x" and t[0] == "S" and (t[-1] != t[1]) :
            print(t)
            break
        elif S[0] == "x" and (t[0] == "W") and (t[-1] == t[1]) :
            print(t)
            break
else :
    print(-1)

Submission status: Wrong Answer

Solution code:
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] :
        print(t[:-1])
        break
else :
    print(-1)

Submission status: Wrong Answer

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


def check(t):
    # print('check', t)
    t = t[-1] + t + t[0]
    for i in range(1, n + 1):
        j = i - 1
        # if (t[i] == 'S') ^ (s[j] == 'o') ^ (t[i - 1] != t[i + 1]): continue
        if t[i] == 'S':
            consumed = 'o' if t[i - 1] == t[i + 1] else 'x'
        else:
            consumed = 'o' if t[i - 1] != t[i + 1] else 'x'

        if consumed == s[j]: continue

        # print('ng i=',i,t[i-1:i+2],s[j])
        return
    # print('ok')
    import sys
    sys.exit()

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

    # if ans[0] == ans[-1]:
    #     print("".join(ans)[:-1])
    #     import sys
    #     sys.exit()
    check("".join(ans)[:-1])


getans('WW' + '.' * (n - 1))
getans('WS' + '.' * (n - 1))
getans('SW' + '.' * (n - 1))
getans('SS' + '.' * (n - 1))

print(-1)

Submission status: Wrong Answer

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


def check(t):
    print('check',t)
    t = t[-1] + t + t[0]
    for i in range(1, n + 1):
        if t[i] == 'S':
            if t[i - 1] != t[i + 1]:
                print('no')
                return
        else:
            if t[i - 1] == t[i + 1]:
                print('no')
                return
    print('ok')

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

    if ans[0] == ans[-1]:
        print("".join(ans)[:-1])
        import sys
        sys.exit()
    # check("".join(ans))


getans('WW' + '.' * (n - 1))
getans('WS' + '.' * (n - 1))
getans('SW' + '.' * (n - 1))
getans('SS' + '.' * (n - 1))

print(-1)

Submission status: Wrong Answer

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


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


        # else:
        #     ans[i + 1] = 'S' if (s[i] == 'o') ^ (ans[i - 1] == 'S') else 'W'


        # ans[i + 1] = 'W' if (ans[i] == 'S') ^ (s[i] == 'o') ^ (ans[i - 1] == 'S') else 'S'


    if ans[0] == ans[-1]:
        print("".join(ans)[:-1])
        import sys
        sys.exit()


getans('WW' + '.' * (n - 1))
getans('WS' + '.' * (n - 1))
getans('SW' + '.' * (n - 1))
getans('SS' + '.' * (n - 1))

print(-1)

Submission status: Wrong Answer

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


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


        ans[i + 1] = 'W' if (ans[i] == 'S') ^ (s[i] == 'o') ^ (ans[i - 1] == 'S') else 'S'


    if ans[0] == ans[-1]:
        print("".join(ans)[:-1])
        import sys
        sys.exit()


getans('WW' + '.' * (n - 1))
getans('WS' + '.' * (n - 1))
getans('SW' + '.' * (n - 1))
getans('SS' + '.' * (n - 1))

print(-1)

Submission status: Wrong Answer

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


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

        #     if s[i]=='o':
        #         ans[i+1]= 'S' if ans[i-1]=='S' else 'W'
        #     else:
        #         ans[i+1]= 'W' if ans[i-1]=='S' else 'S'
        # else:
        #     if s[i]=='o':
        #         ans[i+1]= 'S' if ans[i-1]=='S' else 'W'
        #     else:
        #         ans[i+1]= 'W' if ans[i-1]=='S' else 'S'
    if ans[0] == ans[-1]:
        print("".join(ans)[:-1])
        import sys
        sys.exit()



getans('WW' + '.' * (n - 1))
getans('WS' + '.' * (n - 1))
getans('SW' + '.' * (n - 1))
getans('SS' + '.' * (n - 1))

print(-1)

Submission status: Wrong Answer

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

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

        #     if s[i]=='o':
        #         ans[i+1]= 'S' if ans[i-1]=='S' else 'W'
        #     else:
        #         ans[i+1]= 'W' if ans[i-1]=='S' else 'S'
        # else:
        #     if s[i]=='o':
        #         ans[i+1]= 'S' if ans[i-1]=='S' else 'W'
        #     else:
        #         ans[i+1]= 'W' if ans[i-1]=='S' else 'S'
    if ans[0] == ans[-1]:
        print("".join(ans)[:-1])
        import sys
        sys.exit()


getans('WW' + '.' * (n - 1))
getans('WS' + '.' * (n - 1))
getans('SW' + '.' * (n - 1))
getans('SS' + '.' * (n - 1))

print(-1)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = [1 if a == 'o' else 0 for a in list(input())]

def check(a0, a1):
    dp = [None]*(N+1) #TrueならSheep, FalseならWolf
    dp[0] = a0
    dp[1] = a1
    for i in range(2, N+1):
        if dp[i-2] and dp[i-1]:
            dp[i] = True if S[i-1] == 1 else False
        if dp[i-2] and not dp[i-1]:
            dp[i] = True if S[i-1] == 0 else False
        if not dp[i-2] and dp[i-1]:
            dp[i] = True if S[i-1] == 0 else False
        if not dp[i-2] and not dp[i-1]:
            dp[i] = True if S[i-1] == 1 else False
    return dp


def main():
    ok = False
    for a0 in [True, False]:
        for a1 in [True, False]:
            dp = check(a0, a1)
            if dp[N] == a0:
                ok = True
                break
        if ok:
            break
    if not ok:
        print(-1)
    else:
        ans = ['S' if dp[i] else 'W' for i in range(N)]
        print(''.join(ans))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
n = int(input())
s = input()

L = ["000","001","010","011"
,"100","101","110","111"]
l= len(s)

for t in L:
    u = [int(t[0]),int(t[1]),int(t[2])]
    for i in range(1,l+1):
        if s[(i+l)%l]==s[(i+1+l)%l]:
            u.append(u[-2])
        else:
            u.append(1-u[-2])
    if u[0:3]==u[-3:]:
        for i in range(len(s)):
            if u[i]==0:
                print("S",end = "")
            else:
                print("W",end = "")
        sys.exit()
print(-1)

Submission status: Wrong Answer

Solution code:
N = int(input())
s = input()
ans1 = [0]*N
ans1[0] = 'S'
ls = ['SS', 'SW', 'WS', 'WW']
flag = True
for l in ls:
  ans = []
  m = [0]*N
  m[0] = l[0]
  m[1] = l[1]
  for i in range(1,N):
    if m[i]=='S':
      flag = True
    else:
      flag = False
      
    if i==N-1:
      if flag:
        if s[i]=='o':
          if m[0]==m[N-2]:
            ans = m
            break
        else:
          if m[0]!=m[N-2]:
            ans = m
            break
      else:
        if s[i]=='o':
          if m[0]!=m[N-2]:
            ans = m
            break
        else:
          if m[0]==m[N-2]:
            ans = m
            break
      break
          
    if flag:
      if s[i]=='o':
        m[i+1] = m[i-1]
      else:
        if m[i-1]=='S':
          m[i+1] = 'W'
        else:
          m[i+1] = 'S'
    else:
      if s[i]=='o':
        if m[i-1]=='S':
          m[i+1] = 'W'
        else:
          m[i+1] = 'S'
      else:
        m[i+1] = m[i-1]
  if ans:
    if m[0]=='S':
      flag = True
    else:
      flag = False
    i = 0
    if flag:
      if s[i]=='o':
        if ans[1]==ans[N-1]:
          break
        else:
          continue
      else:
        if ans[1]!=ans[N-1]:
          break
        else:
          continue
    else:
      if s[i]=='o':
        if ans[1]!=m[N-1]:
          break
        else:
          continue
      else:
        if m[1]==ans[N-1]:
          break
        else:
          continue
if ans:
  print(''.join(ans))
else:
  print(-1)

Submission status: Wrong Answer

Solution code:
N = int(input())
s = input()
ans1 = [0]*N
ans1[0] = 'S'
ls = ['SS', 'SW', 'WS', 'WW']
flag = True
for l in ls:
  ans = []
  m = [0]*N
  m[0] = l[0]
  m[1] = l[1]
  for i in range(1,N):
    if m[i]=='S':
      flag = True
    else:
      flag = False
      
    if i==N-1:
      if flag:
        if s[i]=='o':
          if m[0]==m[N-2]:
            ans = m
            break
        else:
          if m[0]!=m[N-2]:
            ans = m
            break
      else:
        if s[i]=='o':
          if m[0]!=m[N-2]:
            ans = m
            break
        else:
          if m[0]==m[N-2]:
            ans = m
            break
      break
          
    if flag:
      if s[i]=='o':
        m[i+1] = m[i-1]
      else:
        if m[i-1]=='S':
          m[i+1] = 'W'
        else:
          m[i+1] = 'S'
    else:
      if s[i]=='o':
        if m[i-1]=='S':
          m[i+1] = 'W'
        else:
          m[i+1] = 'S'
      else:
        m[i+1] = m[i-1]
  if ans:
    break
if ans:
  print(''.join(ans))
else:
  print(-1)

Submission status: Wrong Answer

Solution code:
N = int(input())
s = input()
s += s[0]

T = ['' for _ in range(N+2)]
for T[0],T[1] in [['S','S'],['S','W'],['W','S'],['W','W']]:
  for i in range(2,N+2):
    if (T[i-1] == 'S' and s[i-1] == 'o') or (T[i-1] == 'W' and s[i-1] == 'x'):
      T[i] = T[i-2]
    else:
      if T[i-2] == 'S':
        T[i] = 'W'
      else:
        T[i] = 'S'
  #print(T)
  if T[0:1] == T[-2:-1]:
    print(''.join(T[:N]))
    exit()
print(-1)

Submission status: Wrong Answer

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

T = ['' for _ in range(N+1)]
for T[0],T[1] in [['S','S'],['S','W'],['W','S'],['W','W']]:
  for i in range(2,N+1):
    if (T[i-1] == 'S' and s[i-1] == 'o') or (T[i-1] == 'W' and s[i-1] == 'x'):
      T[i] = T[i-2]
    else:
      if T[i-2] == 'S':
        T[i] = 'W'
      else:
        T[i] = 'S'
  #print(T)
  if (T[0] == T[N]) and ((T[0] == 'S' and s[0] == 'o' and T[1] == T[N]) or (T[0] == 'S' and s[0] == 'x' and T[1] != T[N]) or (T[0] == 'W' and s[0] == 'o' and T[1] != T[N]) or (T[0] == 'W' and s[0] == 'x' and T[1] == T[N])):
    print(''.join(T[:N]))
    exit()
print(-1)

Submission status: Wrong Answer

Solution code:
import itertools
n = int(input())
s = input()
a = [""] * (n+1)
r = ["S", "W"]
for i in list(itertools.product(r, r)): 
  a[0] = i[0]
  a[1] = i[1]
  for j in range(1, n): 
    if s[j] == "o":
      if a[j] == "S":
        if a[j-1] == "S":
          a[j+1] = "S"
        else:
          a[j+1] = "W"
      else:
        if a[j-1] == "S":
          a[j+1] = "W"
        else:
          a[j+1] = "S"
    else:
      if a[j] == "S":
        if a[j-1] == "S":
          a[j+1] = "W"
        else:
          a[j+1] = "S"
      else:
        if a[j-1] == "S":
          a[j+1] = "S"
        else:
          a[j+1] = "W"
  if a[0] != a[-1]:
    break
  if s[0] == "o":
    if a[0] == "S":
      if a[1] == a[-2]:
        print("".join(a[:-1]))
        exit()
    else:
      if a[1] != a[-2]:
        print("".join(a[:-1]))
        exit()
  else:
    if a[0] == "S":
      if a[1] != a[-2]:
        print("".join(a[:-1]))
        exit()
    else:
      if a[1] == a[-2]:
        print("".join(a[:-1]))
        exit()
print(-1)

Submission status: Wrong Answer

Solution code:
import itertools
n = int(input())
s = input()
a = [""] * (n+1)
r = ["S", "W"]
for i in list(itertools.combinations_with_replacement(r, 2)): 
  a[0] = i[0]
  a[1] = i[1]
  for j in range(1, n): 
    if s[j] == "o":
      if a[j] == "S":
        if a[j-1] == "S":
          a[j+1] = "S"
        else:
          a[j+1] = "W"
      else:
        if a[j-1] == "S":
          a[j+1] = "W"
        else:
          a[j+1] = "S"
    else:
      if a[j] == "S":
        if a[j-1] == "S":
          a[j+1] = "W"
        else:
          a[j+1] = "S"
      else:
        if a[j-1] == "S":
          a[j+1] = "S"
        else:
          a[j+1] = "W"
  if a[0] != a[-1]:
    break
  if s[0] == "o":
    if a[0] == "S":
      if a[1] == a[-2]:
        print("".join(a[:-1]))
        exit()
    else:
      if a[1] != a[-2]:
        print("".join(a[:-1]))
        exit()
  else:
    if a[0] == "S":
      if a[1] != a[-2]:
        print("".join(a[:-1]))
        exit()
    else:
      if a[1] == a[-2]:
        print("".join(a[:-1]))
        exit()
print(-1)

Submission status: Wrong Answer

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

def check(a:list):
    for i in range(1,n):
        if a[i] == "S":
            if s[i] == "o":
                a.append(a[i-1])
            else:
                if a[i-1] == "S":
                    a.append("W")
                else:
                    a.append("S")
        if a[i] == "W":
            if s[i] == "o":
                if a[i-1] == "S":
                    a.append("W")
                else:
                    a.append("S")
            else:
                a.append(a[i-1])
    if a[1] != a[-1]:
        return 0
    else:
        a.pop()
        if a[1] == a[-1]:
            return "".join(a) if (a[0] == "S" and s[0] == "o") or (a[0] == "W" and s[0] == "x") else 0
        else:
            return "".join(a) if (a[0] == "S" and s[0] == "x") or (a[0] == "W" and s[0] == "o") else 0 

if check(["S","S"]):
    print(check(["S","S"]))
    exit()

if check(["S","W"]):
    print(check(["S","W"]))
    exit()

if check(["W","S"]):
    print(check(["W","S"]))
    exit()

if check(["W","W"]):
    print(check(["W","W"]))
    exit()

print(-1)

Submission status: Wrong Answer

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

def check(a:list):
    for i in range(1,n+1):
        i %= n
        if i == 0:
            if a[0] != a[-1]:
                return 0
            else:
                a.pop()
        if a[i] == "S":
            if s[i] == "o":
                a.append(a[i-1])
            else:
                if a[i-1] == "S":
                    a.append("W")
                else:
                    a.append("S")
        if a[i] == "W":
            if s[i] == "o":
                if a[i-1] == "S":
                    a.append("W")
                else:
                    a.append("S")
            else:
                a.append(a[i-1])

    if a[-1] == a[-2]:
        a.pop()
        return "".join(a)
    else:
        return 0

if check(["S","S"]):
    print(check(["S","S"]))
    exit()

if check(["S","W"]):
    print(check(["S","W"]))
    exit()

if check(["W","S"]):
    print(check(["W","S"]))
    exit()

if check(["W","W"]):
    print(check(["W","W"]))
    exit()

print(-1)

Submission status: Wrong Answer

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

def check(a:list):
    for i in range(1,n):
      if a[i] == "S":
          if s[i] == "o":
              a.append(a[i-1])
          else:
              if a[i-1] == "S":
                  a.append("W")
              else:
                  a.append("S")
      if a[i] == "W":
          if s[i] == "o":
              if a[i-1] == "S":
                  a.append("W")
              else:
                  a.append("S")
          else:
              a.append(a[i-1])
    if a[0] == a[-1]:
        a.pop()
        return "".join(a)
    else:
        return 0

if check(["S","S"]):
    print(check(["S","S"]))
    exit()

if check(["S","W"]):
    print(check(["S","W"]))
    exit()

if check(["W","S"]):
    print(check(["W","S"]))
    exit()

if check(["W","W"]):
    print(check(["W","W"]))
    exit()

print(-1)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=[1 if c=='o' else 0 for c in input()]
S+=S[:2]
from itertools import product
f=0
for a,b in product(range(2),repeat=2):
    r=[0]*(N+2)
    for i in range(N):
        r[i+2]=r[i] if r[i+1]^S[i+1] else r[i]^1
    if r[:2]==r[N:]:
        f=1
        break
print(''.join(['S' if x==0 else 'W' for x in r[:N]]) if f else -1)

Submission status: Wrong Answer

Solution code:
from collections import Counter,defaultdict
import sys,heapq,bisect,math,itertools,string,queue
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

def check(x):
    res[0] = x[0]
    res[1] = x[1]
    for i in range(1,n-1):
        if (res[i] == 'S' and s[i] == 'o') or (res[i] == 'W' and s[i] == 'x'):
            if res[i-1] == 'S':
                res[i+1] = 'S'
            else:
                res[i+1] = 'W'
        else:
            if res[i-1] == 'S':
                res[i+1] = 'W'
            else:
                res[i+1] = 'S'
    # print(res)
    if (res[n-1] == 'S' and s[n-1] == 'o') or (res[n-1] == 'W' and s[n-1] == 'x'):
        if res[n-2] != res[0]:
            return False
    else:
        if res[n-2] == res[0]:
            return False
    if (res[0] == 'S' and s[0] == 'o') or (res[0] == 'W' and s[0] == 'x'):
        if res[n-1] != res[1]:
            return False
    else:
        if res[n-1] == res[1]:
            return False
    return res

n = inp()
s = input()
a = [['S','S'],['S','W'],['W','S'],['W','W']]
res = [''] * n
# print(a)
for i in range(4):
    if check(a[i]):
        print(''.join(res))
        quit()
print(-1,-1)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    s = input()
    # c = ["WS", "SW", "SS", "WW"]
    c = ["SW", "WS", "SS", "WW"]
    ok = False
    for tmp in c:
        ans = tmp
        for i in range(1, N):
            if s[i] == "o":# oの時
                if ans[i-1] == "S" and ans[i] == "S":
                    ans += "S"
                elif ans[i-1] == "W" and ans[i] == "S":
                    ans += "W"
                elif ans[i-1] == "S" and ans[i] == "W":
                    ans += "W"
                elif ans[i-1] == "W" and ans[i] == "W":
                    ans += "S"
            else:# xの時
                if ans[i-1] == "S" and ans[i] == "S":
                    ans += "W"
                elif ans[i-1] == "W" and ans[i] == "S":
                    ans += "S"
                elif ans[i-1] == "S" and ans[i] == "W":
                    ans += "S"
                elif ans[i-1] == "W" and ans[i] == "W":
                    ans += "W"
    
        if ans[0] == ans[-1]:
            ok = True
            print(ans[:-1])
            # print(len(ans))
            break
    if not ok:
        print(-1)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    s = input()
    # c = ["WS", "SW", "SS", "WW"]
    c = ["SW", "WS", "SS", "WW"]
    ok = False
    for tmp in c:
        ans = tmp
        for i in range(1, N):
            if s[i] == "o":# oの時
                if ans[i-1] == "S" and ans[i] == "S":
                    ans += "S"
                elif ans[i-1] == "W" and ans[i] == "S":
                    ans += "W"
                elif ans[i-1] == "S" and ans[i] == "W":
                    ans += "W"
                elif ans[i-1] == "W" and ans[i] == "W":
                    ans += "S"
            else:# xの時
                if ans[i-1] == "S" and ans[i] == "S":
                    ans += "W"
                elif ans[i-1] == "W" and ans[i] == "S":
                    ans += "S"
                elif ans[i-1] == "S" and ans[i] == "W":
                    ans += "S"
                elif ans[i-1] == "W" and ans[i] == "W":
                    ans += "W"
    
        if ans[0] == ans[-1]:
            ok = True
            print(ans[:-1])
            print(len(ans))
            break
    if not ok:
        print(-1)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    s = input()

    ok = False
    for ans in ["SS", "WS", "WW", "SW"]:
        for i in range(1, N):
            if s[i] == "o":# oの時
                if ans[i-1] == "S" and ans[i] == "S":
                    ans += "S"
                elif ans[i-1] == "W" and ans[i] == "S":
                    ans += "W"
                elif ans[i-1] == "S" and ans[i] == "W":
                    ans += "W"
                elif ans[i-1] == "W" and ans[i] == "W":
                    ans += "S"
            else:# xの時
                if ans[i-1] == "S" and ans[i] == "S":
                    ans += "W"
                elif ans[i-1] == "W" and ans[i] == "S":
                    ans += "S"
                elif ans[i-1] == "S" and ans[i] == "W":
                    ans += "S"
                elif ans[i-1] == "W" and ans[i] == "W":
                    ans += "W"
    
        if ans[0] == ans[-1]:
            ok = True
            print(ans[:-1])
            break
    if not ok:
        print(-1)

if __name__ == "__main__":
    main()