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:
#!/usr/bin/env python

n = int(raw_input())
s = raw_input()

def solver(a, b):
	r = [a, b]
	for _ in xrange(n-2):
		r.append(None)

	for i in xrange(1, n-1):
		last = r[i-1]
		if r[i] == 'S':
			if s[i] == 'o':
				r[i+1] = last
			else:
				r[i+1] = 'S' if last == 'W' else 'W'
		else:
			if s[i] == 'o':
				r[i+1] = 'S' if last == 'W' else 'W'
			else:
				r[i+1] = last
	if r[-1] == 'S':
		if s[-1] == 'o':
			return r[0] == r[-2], r
		else:
			return r[0] != r[-2], r
	else:
		if s[-1] == 'o':
			return r[0] != r[-2], r
		else:
			return r[0] == r[-2], r

flag = False
d = [
	('S', 'S'),
	('W', 'S'),
	('W', 'W'),
	('S', 'W'),
]

for a, b in d:
	flag, r = solver(a, b)
	if flag:
		print ''.join(r)
		break
if not flag:
	print -1

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
s = raw_input()
r = []
for i in range(n):
	r.append("S")
for i in xrange(1, len(s)-1):
	left = r[i-1]
	if r[i] == 'S':
		if s[i] == 'o':
			r[i+1] = left
		else:
			r[i+1] = 'S' if left == 'W' else 'W'
	else:
		if s[i] == 'o':
			r[i + 1] = 'S' if left == 'W' else 'W'
		else:
			r[i+1] = left

flag = True
if r[-1] == 'S':
	if s[-1] == 'o':
		flag = r[0] == r[-2]
	else:
		flag = r[0] != r[-2]
else:
	if s[-1] == 'o':
		flag = r[0] != r[-2]
	else:
		flag = r[0] == r[-2]
if flag:
	print "".join(r)
else:
	print -1

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python
# -*- coding: utf-8 -*-



def gen(start, s):
	for i in xrange(1, len(s)+1):
		c = start[i]
		h = s[i] if i < len(s) else s[0]
		if h == 'o':
			if c == 'S':
				start += start[i-1]
			else:
				start += 'S' if start[i-1] == 'W' else 'W'
		else:
			if c == 'S':
				start += 'S' if start[i-1] == 'W' else 'W'
			else:
				start += start[i-1]

	if start[:2] == start[-2:]:
		return start[:-1]
	return ''


def main():
	n = int(raw_input())
	s = raw_input()

	for x in ('SS', 'SW', 'WW', 'WS'):
		ans = gen(x, s)
		if ans:
			print ans
			return
	print -1

if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python
# -*- coding: utf-8 -*-



def gen(start, s):
	for i in xrange(1, len(s)):
		c = start[i]
		if s[i] == 'o':
			if c == 'S':
				start += start[i-1]
			else:
				start += 'S' if start[i-1] == 'W' else 'W'
		else:
			if c == 'S':
				start += 'S' if start[i-1] == 'W' else 'W'
			else:
				start += start[i-1]

	if start[0] == start[-1]:
		return start[:-1]
	return ''


def main():
	n = int(raw_input())
	s = raw_input()

	for x in ('SS', 'SW', 'WW', 'WS'):
		ans = gen(x, s)
		if ans:
			print ans
			return
	print -1

if __name__ == '__main__':
	main()

Submission status: Wrong Answer

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

is_zoo = False
start = 'SS'
for _s in s[1:-1]:
  if start[-1] == 'S':
    if _s == 'o':
      start += start[-2]
    else:
      start += 'S' if start[-2] == 'W' else 'W'
  else:
    if _s == 'x':
      start += start[-2]
    else:
      start += 'S' if start[-2] == 'W' else 'W'
if (start[-1] == 'S' and s[-1] == 'o' and start[-2] == 'S' and s[0] == 'o') or \
  (start[-1] == 'S' and s[-1] == 'x' and start[-2] == 'W' and s[0] == 'o') or \
  (start[-1] == 'W' and s[-1] == 'o' and start[-2] == 'W' and s[0] == 'x') or \
  (start[-1] == 'W' and s[-1] == 'x' and start[-2] == 'S' and s[0] == 'x'):
  print(start)
  is_zoo = True

start = 'SW'
if not is_zoo:
  for _s in s[1:-1]:
    if start[-1] == 'S':
      if _s == 'o':
        start += start[-2]
      else:
        start += 'S' if start[-2] == 'W' else 'W'
    else:
      if _s == 'x':
        start += start[-2]
      else:
        start += 'S' if start[-2] == 'W' else 'W'
  if (start[-1] == 'S' and s[-1] == 'o' and start[-2] == 'S' and s[0] == 'o') or \
    (start[-1] == 'S' and s[-1] == 'x' and start[-2] == 'W' and s[0] == 'o') or \
    (start[-1] == 'W' and s[-1] == 'o' and start[-2] == 'W' and s[0] == 'x') or \
    (start[-1] == 'W' and s[-1] == 'x' and start[-2] == 'S' and s[0] == 'x'):
    print(start)
    is_zoo = True

start = 'WS'
if not is_zoo:
  for _s in s[1:-1]:
    if start[-1] == 'S':
      if _s == 'o':
        start += start[-2]
      else:
        start += 'S' if start[-2] == 'W' else 'W'
    else:
      if _s == 'x':
        start += start[-2]
      else:
        start += 'S' if start[-2] == 'W' else 'W'
  if (start[-1] == 'S' and s[-1] == 'o' and start[-2] == 'W' and s[0] == 'x') or \
    (start[-1] == 'S' and s[-1] == 'x' and start[-2] == 'S' and s[0] == 'x') or \
    (start[-1] == 'W' and s[-1] == 'o' and start[-2] == 'S' and s[0] == 'o') or \
    (start[-1] == 'W' and s[-1] == 'x' and start[-2] == 'W' and s[0] == 'o'):
    print(start)
    is_zoo = True

start = 'WW'
if not is_zoo:
  for _s in s[1:-1]:
    if start[-1] == 'S':
      if _s == 'o':
        start += start[-2]
      else:
        start += 'S' if start[-2] == 'W' else 'W'
    else:
      if _s == 'x':
        start += start[-2]
      else:
        start += 'S' if start[-2] == 'W' else 'W'
  if (start[-1] == 'S' and s[-1] == 'o' and start[-2] == 'W' and s[0] == 'o') or \
    (start[-1] == 'S' and s[-1] == 'x' and start[-2] == 'S' and s[0] == 'o') or \
    (start[-1] == 'W' and s[-1] == 'o' and start[-2] == 'S' and s[0] == 'x') or \
    (start[-1] == 'W' and s[-1] == 'x' and start[-2] == 'W' and s[0] == 'x'):
    print(start)
    is_zoo = True

if not is_zoo:
  print(-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
s = list(map(lambda x:1 if x=="o" else -1,list(s)))
flag = False
for start in [[1,1], [1,-1], [-1, 1], [-1, -1]]:
    circle = start + [0]*(n-2)
    for i in range(1,n-1):
        circle[i+1] = circle[i]*s[i]*circle[i-1]
    # 最後があっているかどうかの確認
    if circle[-2] == circle[-1]*s[-1]*circle[0]:
        flag = True
        break
if flag:
    ans = ""
    for i in circle:
        if i == 1:
            ans += "S"
        else:
            ans += "W"
    print(ans)
else:
    print(-1)

Submission status: Wrong Answer

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

is_zoo = False
start = 'SS'
for _s in s[1:-1]:
  if start[-1] == 'S':
    if _s == 'o':
      start += start[-2]
    else:
      start += 'S' if start[-2] == 'W' else 'W'
  else:
    if _s == 'x':
      start += start[-2]
    else:
      start += 'S' if start[-2] == 'W' else 'W'
if (start[-1] == 'S' and s[-1] == 'o' and start[-2] == 'S') or \
  (start[-1] == 'S' and s[-1] == 'x' and start[-2] == 'W') or \
  (start[-1] == 'W' and s[-1] == 'o' and start[-2] == 'W') or \
  (start[-1] == 'W' and s[-1] == 'x' and start[-2] == 'S'):
  print(start)
  is_zoo = True

start = 'SW'
if not is_zoo:
  for _s in s[1:-1]:
    if start[-1] == 'S':
      if _s == 'o':
        start += start[-2]
      else:
        start += 'S' if start[-2] == 'W' else 'W'
    else:
      if _s == 'x':
        start += start[-2]
      else:
        start += 'S' if start[-2] == 'W' else 'W'
  if (start[-1] == 'S' and s[-1] == 'o' and start[-2] == 'S') or \
    (start[-1] == 'S' and s[-1] == 'x' and start[-2] == 'W') or \
    (start[-1] == 'W' and s[-1] == 'o' and start[-2] == 'W') or \
    (start[-1] == 'W' and s[-1] == 'x' and start[-2] == 'S'):
    print(start)
    is_zoo = True

start = 'WS'
if not is_zoo:
  for _s in s[1:-1]:
    if start[-1] == 'S':
      if _s == 'o':
        start += start[-2]
      else:
        start += 'S' if start[-2] == 'W' else 'W'
    else:
      if _s == 'x':
        start += start[-2]
      else:
        start += 'S' if start[-2] == 'W' else 'W'
  if (start[-1] == 'S' and s[-1] == 'o' and start[-2] == 'W') or \
    (start[-1] == 'S' and s[-1] == 'x' and start[-2] == 'S') or \
    (start[-1] == 'W' and s[-1] == 'o' and start[-2] == 'S') or \
    (start[-1] == 'W' and s[-1] == 'x' and start[-2] == 'W'):
    print(start)
    is_zoo = True

start = 'WW'
if not is_zoo:
  for _s in s[1:-1]:
    if start[-1] == 'S':
      if _s == 'o':
        start += start[-2]
      else:
        start += 'S' if start[-2] == 'W' else 'W'
    else:
      if _s == 'x':
        start += start[-2]
      else:
        start += 'S' if start[-2] == 'W' else 'W'
  if (start[-1] == 'S' and s[-1] == 'o' and start[-2] == 'W') or \
    (start[-1] == 'S' and s[-1] == 'x' and start[-2] == 'S') or \
    (start[-1] == 'W' and s[-1] == 'o' and start[-2] == 'S') or \
    (start[-1] == 'W' and s[-1] == 'x' and start[-2] == 'W'):
    print(start)
    is_zoo = True

if not is_zoo:
  print(-1)

Submission status: Wrong Answer

Solution code:
#ARC069D
N=int(input())
S=input()
def NoSW(a):
	if a=='S':
		return 'W'
	else: #a=='W'
		return 'S'
def NoOX(a):
	if a=='o':
		return 'x'
	else: #a=='x'
		return 'o'
C=['' for i in range(N)]
for a in ['S','W']: #assumption1
	for b in ['S','W']:#assumption2
		C[0]=a
		C[1]=b
		for i in range(1,N-1):
			if C[i]=='W':
				S=S[:i]+NoOX(S[i])+S[i+1:]
			if S[i]=='o':
				C[i+1]=C[i-1]
			else:
				C[i+1]=NoSW(C[i-1])
		#final check
		for i in [0,N-1]: 
			if C[i]=='W':
				S=S[:i]+NoOX(S[i])+S[i+1:]
		if S[0]=='o':
			boo=1
		else: #S[0]=='x'
			boo=0
		if boo != (C[N-1]==C[1]):
			continue
		if S[N-1]=='o':
			boo=1
		else: #S[N-1]=='x'
			boo=0
		if boo != (C[N-2]==C[0]):
			continue
		print(''.join(C))
		exit()
print(-1)

Submission status: Wrong Answer

Solution code:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
s = input()[:-1]
ans = [1]*(N+2)


def print_ans(l: list):
    ret = ""
    for a in l[1:-1]:
        ret += "S" if a else "W"
    print(ret)


def next(ind: int, isSame: bool, isSheep: bool)->bool:
    # if isSame:
    #    if isSheep:
    #        return ans[ind-1]
    #    else:
    #        return not ans[ind-1]
    # else:
    #    if isSheep:
    #        return not ans[ind-1]
    #    else:
            #        return ans[ind-1]

    return not(isSame ^ isSheep) ^ ans[ind-1]


def check(first: bool, last: bool)->list:
    ans[0] = last
    ans[1] = first
    for i in range(1, N+1):
        ans[i+1] = next(i, s[i-1] == "o", ans[i])

    return ans[0] == ans[N] and ans[1] == ans[N+1]


for first in [True, False]:
    for last in [True, False]:
        if check(first, last):
            print_ans(ans)
            exit()
print("-1")

Submission status: Wrong Answer

Solution code:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
s = input()[:-1]
ans = [1]*(N+2)


def print_ans(l: list):
    ret = ""
    for a in l[1:-1]:
        ret += "S" if a else "W"
    print(ret)


def next(ind: int, isSame: bool, isSheep: bool)->bool:
    # if isSame:
    #    if isSheep:
    #        return ans[ind-1]
    #    else:
    #        return not ans[ind-1]
    # else:
    #    if isSheep:
    #        return not ans[ind-1]
    #    else:
            #        return ans[ind-1]

    return (isSame == isSheep) ^ ans[ind-1]


def check(first: bool, last: bool)->list:
    ans[0] = last
    ans[1] = first
    for i in range(1, N+1):
        ans[i+1] = next(i, s[i-1] == "o", ans[i])

    return ans[0] == ans[N] and ans[1] == ans[N+1]


for first in [True, False]:
    for last in [True, False]:
        if check(first, last):
            print_ans(ans)
            exit()
print("-1")

Submission status: Wrong Answer

Solution code:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
s = input()[:-1]
ans = [1]*(N+2)


def print_ans(l: list):
    ret = ""
    for a in l[1:-1]:
        ret += "S" if a else "W"
    print(ret)


def next(ind: int, isSame: bool, isSheep: bool)->bool:
    # if isSame:
    #    if isSheep:
    #        return ans[ind-1]
    #    else:
    #        return not ans[ind-1]
    # else:
    #    if isSheep:
    #        return not ans[ind-1]
    #    else:
            #        return ans[ind-1]

    return isSame == isSheep ^ ans[ind-1]


def check(first: bool, last: bool)->list:
    ans[0] = last
    ans[1] = first
    for i in range(1, N+1):
        ans[i+1] = next(i, s[i-1] == "o", ans[i])

    return ans[0] == ans[N] and ans[1] == ans[N+1]


for first in [True, False]:
    for last in [True, False]:
        if check(first, last):
            print_ans(ans)
            exit()
print("-1")

Submission status: Wrong Answer

Solution code:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
s = input()[:-1]
ans = [1]*(N+2)


def print_ans(l: list):
    """
    T,Fからなる配列を受け取る
    T->S
    F->Wに変えて出力する
    """
    ret = ""
    for a in l[1:-1]:
        ret += "S" if a else "W"
    print(ret)


def next(ind: int, isSame: bool, isSheep: bool)->bool:
    """
    ind+1の動物を決める
    """
    if isSame:
        if isSheep:
            return ans[ind-1]
        else:
            return not ans[ind-1]
    else:
        if isSheep:
            return not ans[ind-1]
        else:
            return ans[ind-1]


def check(first: bool, last: bool)->list:
    """
    Lは動物の並び
    True;羊
    False:狼
    L=[L[-1],L[0],...]として、sの情報に従って隣を決めていく。
    最後まで行ったときに、最後の値がlastと一致するならok
    番兵的な
    """
    ans[0] = last
    ans[1] = first
    for i in range(1, N+1):
        ans[i+1] = next(i, s[i-1] == "o", ans[i])

    return ans[N+1] == ans[0]


for first in [True, False]:
    for last in [True, False]:
        if check(first, last):
            print_ans(ans)
            exit()
print("-1")

Submission status: Wrong Answer

Solution code:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
s = input()[:-1]
ans = [1]*(N+1)


def print_ans(l: list):
    """
    T,Fからなる配列を受け取る
    T->S
    F->Wに変えて出力する
    """
    ret = ""
    for a in l[1:]:
        ret += "S" if a else "W"
    print(ret)


def next(ind: int, isSame: bool, isSheep: bool)->bool:
    """
    ind+1の動物を決める
    """
    if isSame:
        if isSheep:
            return ans[ind-1]
        else:
            return not ans[ind-1]
    else:
        if isSheep:
            return not ans[ind-1]
        else:
            return ans[ind-1]


def check(start: bool, last: bool)->list:
    """
    Lは動物の並び
    True;羊
    False:狼
    L=[L[-1],L[0],...]として、sの情報に従って隣を決めていく。
    最後まで行ったときに、最後の値がlastと一致するならok
    番兵的な
    """
    ans[0] = last
    ans[1] = start
    for i in range(1, N):
        ans[i+1] = next(i, s[i-1] == "o", ans[i])

    # print("ans")
    # print_ans(ans)
    # print(s)
    if s[N-1] == "o":
        if ans[N]:
            return ans[1] == ans[N-1]
        else:
            return not ans[1] == ans[N-1]
    else:
        if ans[N]:
            return not ans[1] == ans[N-1]
        else:
            return ans[1] == ans[N-1]


for start in [True, False]:
    for last in [True, False]:
        #print("c->", start, last)
        if check(start, last):
            print_ans(ans)
            exit()
print("-1")

Submission status: Wrong Answer

Solution code:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
s = input()[:-1]
ans = [1]*(N+1)


def print_ans(l: list):
    """
    T,Fからなる配列を受け取る
    T->S
    F->Wに変えて出力する
    """
    ret = ""
    for a in l[1:]:
        ret += "S" if a else "W"
    print(ret)


def next(ind: int, isSame: bool, isSheep: bool)->bool:
    """
    ind+1の動物を決める
    """
    if isSame:
        if isSheep:
            return ans[ind-1]
        else:
            return not ans[ind-1]
    else:
        if isSheep:
            return not ans[ind-1]
        else:
            return ans[ind-1]


def check(start: bool, last: bool)->list:
    """
    Lは動物の並び
    True;羊
    False:狼
    L=[L[-1],L[0],...]として、sの情報に従って隣を決めていく。
    最後まで行ったときに、最後の値がlastと一致するならok
    番兵的な
    """
    ans[0] = last
    ans[1] = start
    for i in range(1, N):
        ans[i+1] = next(i, s[i-1] == "o", ans[i])

    #print("ans->", ans)
    if s[N-1] == "o":
        if ans[N]:
            return ans[N-1] == last
        else:
            return not ans[N-1] == last
    else:
        if ans[N]:
            return not ans[N-1] == last
        else:
            return ans[N-1] == last


for start in [True, False]:
    for last in [True, False]:
        #print("c->", start, last)
        if check(start, last):
            print_ans(ans)
            exit()
print("-1")

Submission status: Wrong Answer

Solution code:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
s = input()[:-1]
ans = [False]*(N+1)


def print_ans(l: list):
    """
    T,Fからなる配列を受け取る
    T->S
    F->Wに変えて出力する
    """
    ret = ""
    for a in l[1:]:
        ret += "S" if a else "W"
    print(ret)


def next(ind: int, isSame: bool, isSheep: bool)->bool:
    """
    ind+1の動物を決める
    """
    if isSame:
        if isSheep:
            return ans[ind-1]
        else:
            return not ans[ind-1]
    else:
        if isSheep:
            return not ans[ind-1]
        else:
            return ans[ind-1]


def check(start: bool, last: bool)->list:
    """
    Lは動物の並び
    True;羊
    False:狼
    L=[L[-1],L[0],...]として、sの情報に従って隣を決めていく。
    最後まで行ったときに、最後の値がlastと一致するならok
    番兵的な
    """
    ans[0] = last
    ans[1] = start
    for i in range(1, N):
        ans[i+1] = next(i, s[i-1] == "o", ans[i])

    if s[N-1] == "o":
        return ans[N] == last
    else:
        return ans[N] == last


for start in [True, False]:
    for last in [True, False]:
        if check(start, last):
            print_ans(ans)
            exit()
print("-1")

Submission status: Wrong Answer

Solution code:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
s = input()[:-1]
ans = [False]*(N+1)


def print_ans(l: list):
    """
    T,Fからなる配列を受け取る
    T->S
    F->Wに変えて出力する
    """
    ret = ""
    for a in l[1:]:
        ret += "S" if a else "W"
    print(ret)


def next(ind: int, isSame: bool, isSheep: bool)->bool:
    """
    ind+1の動物を決める
    """
    if isSame:
        if isSheep:
            return ans[ind-1]
        else:
            return not ans[ind-1]
    else:
        if isSheep:
            return not ans[ind-1]
        else:
            return ans[ind-1]


def check(start: bool, last: bool)->list:
    """
    Lは動物の並び
    True;羊
    False:狼
    L=[L[-1],L[0],...]として、sの情報に従って隣を決めていく。
    最後まで行ったときに、最後の値がlastと一致するならok
    番兵的な
    """
    ans[0] = last
    ans[1] = start
    for i in range(1, N):
        ans[i+1] = next(i, s[i] == "o", ans[i])

    return ans[N] == ans[0]


for start in [True, False]:
    for last in [True, False]:
        if check(start, last):
            print_ans(ans)
            exit()
print("-1")

Submission status: Wrong Answer

Solution code:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
s = input()[:-1]
ans = [False]*(N+1)


def print_ans(l: list):
    """
    T,Fからなる配列を受け取る
    T->S
    F->Wに変えて出力する
    """
    ret = ""
    for a in l[:-1]:
        ret += "S" if a else "W"
    print(ret)


def next(ind: int, isSame: bool, isSheep: bool)->bool:
    """
    ind+1の動物を決める
    """
    if isSame:
        if isSheep:
            return ans[ind-1]
        else:
            return not ans[ind-1]
    else:
        if isSheep:
            return not ans[ind-1]
        else:
            return ans[ind-1]


def check(start: bool, last: bool)->list:
    """
    Lは動物の並び
    True;羊
    False:狼
    L=[L[-1],L[0],...]として、sの情報に従って隣を決めていく。
    最後まで行ったときに、最後の値がlastと一致するならok
    """
    ans[0] = last
    ans[1] = start
    for i in range(1, N):
        ans[i+1] = next(i, s[i] == "o", ans[i])

    return ans[N] == ans[0]


for start in [True, False]:
    for last in [True, False]:
        if check(start, last):
            print_ans(ans)
            exit()
print("-1")

Submission status: Wrong Answer

Solution code:
N=eval(input())
s=input()
l=[]
for i in range(N):
     l.append(0)
l[0]='S'
if s[0]=='o':
     l[1]='S'
     l[-1]='S'
     k=l[-1]
else:
     l[1]='S'
     l[-1]='W'
     k=l[-1]
for i in range(1,N-2):
     if s[i]=='o':
          if l[i]=='S':
               if l[i-1]=='S':  
                    l[i+1]='S'
               else:
                    l[i+1]='W'
          else:
               if l[i-1]=='S':
                    l[i+1]='W'
               else:
                    l[i+1]='S'
     elif s[i]=='x':
          if l[i]=='S':
               if l[i-1]=='S':
                    l[i+1]='W'
               else:
                    l[i+1]='S'
          else:
               if l[i-1]=='S':
                    l[i+1]='S'
               else:
                    l[i+1]='W'
if s[-1]=='o':
     if l[-1]=='S':
          if l[-2]=='W':
               if l[0]!='W':
                    k=1
          else:
               if l[0]!='S':
                    k=1
     else:
          if l[-2]=='W':
               if l[0]!='S':
                    k=1
          else:
               if l[0]!='W':
                    k=1
else:
     if l[-1]=='S':
          if l[-2]=='W':
               if l[0]!='S':
                    k=1
          else:
               if l[0]!='W':
                    k=1
     else:
          if l[-2]=='W':
               if l[0]!='W':
                    k=1
          else:
               if l[0]!='S':
                    k=1
          
               
if k==l[-1]:
     for i in l:
          print(i,end='')
else:
     print(-1)

Submission status: Wrong Answer

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



def f(k):
    if s[k] == 'o' and a[k] == 1:
        a[k+1] = a[k-1]
    elif s[k] == 'o' and a[k] == -1:
        a[k+1] = a[k-1]*(-1)
    elif s[k] == 'x' and a[k] == 1:
        a[k+1] = a[k-1]*(-1)
    else:
        a[k+1] = a[k-1]
judge = -1
for e in [[1,1],[1,-1],[-1,1],[-1,-1]]:
    if judge == -1:
        a = [0]*n
        a[0] = e[0]
        a[1] = e[1]
        for j in range(1,n-1):
            f(j)
        if s[0] == 'o' and a[0] == 1:
            if a[1] ==  a[-1]:
                judge = 1
        elif s[0] == 'o' and a[0] == -1:
            if a[1] == a[-1]*(-1):
                judge = 1
        elif s[0] == 'x' and a[0] == 1:
            if a[+1] == a[-1]*(-1):
                judge = 1
        else:
            if a[1] == a[-1]:
                judge = 1
        if judge == 1:
            if s[n-1] == 'o' and a[n-1] == 1:
                if a[0] != a[n-2]:
                    judge == -1
            elif s[n-1] == 'o' and a[n-1] == -1:
                if a[0] != a[n-2]*(-1):
                    judge = -1
            elif s[n-1] == 'x' and a[n-1] == 1:
                if a[0] != a[n-2]*(-1):
                    judge = -1
            else:
                if a[0] != a[n-2]:
                    judge = -1
if judge == -1:
    print(-1)
else:
    ans = ''
    for i in range(n):
        if a[i] == 1:
            ans += 'S'
        else:
            ans += 'W'
    print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

def main():
    n = int(input())
    s = input()
    for d0 in ["S", "W"]:
        for d1 in ["S", "W"]:
            pat = wrap(n, s, d0, d1)
            if pat[0] == pat[n]:
                res = "".join(pat[:n])
                assert len(res) == n
                assert len(set(list(res))) <= 2
                print(res)
                return
    print("-1")

def wrap(n, s, d0, d1):
    ds = [d0, d1]
    for i in range(2, n + 1):
        d = get_dnext(ds[i - 2], ds[i - 1], s[i - 1])
        ds.append(d)
    assert len(ds) == n + 1
    return ds

def get_dnext(dpre, di, si):
    if di == "S" and si == "o":
        dnext = dpre
    elif di == "S" and si == "x":
        dnext = inv(dpre)
    elif di == "W" and si == "o":
        dnext = inv(dpre)
    elif di == "W" and si == "x":
        dnext = dpre
    else:
        raise Exception
    return dnext

def inv(d):
    return "W" if d == "S" else "S"

main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

def main():
    n = int(input())
    s = input()
    for d0 in ["S", "W"]:
        for d1 in ["S", "W"]:
            pat = wrap(n, s, d0, d1)
            if pat[0] == pat[n]:
                print("".join(pat[:n]))
                return
    print("-1")

def wrap(n, s, d0, d1):
    ds = [d0, d1]
    for i in range(2, n + 1):
        d = get_dnext(ds[i - 2], ds[i - 1], s[i - 1])
        ds.append(d)
    assert len(ds) == n + 1
    return ds

def get_dnext(dpre, di, si):
    if di == "S" and si == "o":
        dnext = dpre
    elif di == "S" and si == "x":
        dnext = inv(dpre)
    elif di == "W" and si == "o":
        dnext = inv(dpre)
    elif di == "W" and si == "x":
        dnext = dpre
    else:
        raise Exception
    return dnext

def inv(d):
    return "W" if d == "S" else "S"

main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

def main():
    n = int(input())
    s = input()
    for d0 in ["S", "W"]:
        for d1 in ["S", "W"]:
            pat = is_possible(n, s, d0, d1)
            if pat:
                print("".join(pat))
                return
    print("-1")

def is_possible(n, s, d0, d1):
    ds = [d0, d1]
    for i in range(2, n + 1):
        d = get_dnext(ds[i - 2], ds[i - 1], s[i - 1])
        ds.append(d)
    if ds[0] == ds[-1]:
        return ds[:-1]
    else:
        return []

def get_dnext(dpre, di, si):
    if di == "S" and si == "o":
        dnext = dpre
    elif di == "S" and si == "x":
        dnext = inv(dpre)
    elif di == "W" and si == "o":
        dnext = inv(dpre)
    elif di == "W" and si == "x":
        dnext = dpre
    else:
        raise Exception
    return dnext

def inv(d):
    return "W" if d == "S" else "S"

main()

Submission status: Wrong Answer

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

bool_list = [[True,True],[True,False],[False,True],[False,False]]

flag=False
for boo in bool_list:
    ans_list = list(boo)
    for i in range(1,N):

        if S[i]=="o":
            if ans_list[i]:
                if ans_list[i-1]:
                    ans_list.append(True)
                else:
                    ans_list.append(False)
            else:
                if ans_list[i-1]:
                    ans_list.append(False)
                else:
                    ans_list.append(True)
        else:
            if not ans_list[i]:
                if ans_list[i-1]:
                    ans_list.append(True)
                else:
                    ans_list.append(False)
            else:
                if ans_list[i-1]:
                    ans_list.append(False)
                else:
                    ans_list.append(True)
    
    if ans_list[0]==ans_list[N]:
        flag=True
        break

if flag:
    ans=""
    for a in ans_list[:-1]:
        if a:
            ans+="S"
        else:
            ans+="W"
    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):
    for i in range(1,n):
        if s[i]=='o':
            if a[j][i]=='S':
                if a[j][i-1]=='S':
                    a[j]+='S'
                else:
                    a[j]+='W'
            else:
                if a[j][i-1]=='S':
                    a[j]+='W'
                else:
                    a[j]+='S'
        else:
            if a[j][i]=='S':
                if a[j][i-1]=='S':
                    a[j]+='W'
                else:
                    a[j]+='S'
            else:
                if a[j][i-1]=='S':
                    a[j]+='S'
                else:
                    a[j]+='W'
ans='-1'
for j in range(4):
    if a[j][0]==a[j][-1]:
        if s[0]=='o' and a[j][-2]==a[j][1]:
            ans=a[j][:-1]
            break
        if s[0]=='x' and a[j][-2]!=a[j][1]:
            ans=a[j][:-1]
            break
print(ans)

Submission status: Wrong Answer

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