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: Accepted

Solution code:
#  coding:utf-8

def _func(n, s):
    res = ["S", "S"]
    for x in s[1:-1]:
        if x == "o":
            if ((res[-2] == "S" and res[-1] == "S") or
                (res[-2] == "W" and res[-1] == "W")):
                res.append("S")
            else:
                res.append("W")
        elif x == "x":
            if ((res[-2] == "S" and res[-1] == "S") or
                (res[-2] == "W" and res[-1] == "W")):
                res.append("W")
            else:
                res.append("S")
    else:
        if (s[0], s[-1]) == ("o", "o"):
            if (res[-2], res[-1]) == ("S", "S"):
                return "".join(res)
        elif (s[0], s[-1]) == ("o", "x"):
            if (res[-2], res[-1]) == ("W", "S"):
                return "".join(res)
        elif (s[0], s[-1]) == ("x", "o"):
            if (res[-2], res[-1]) == ("W", "W"):
                return "".join(res)
        elif (s[0], s[-1]) == ("x", "x"):
            if (res[-2], res[-1]) == ("S", "W"):
                return "".join(res)
        
    res = ["S", "W"]
    for x in s[1:-1]:
        if x == "o":
            if ((res[-2] == "S" and res[-1] == "S") or
                (res[-2] == "W" and res[-1] == "W")):
                res.append("S")
            else:
                res.append("W")
        elif x == "x":
            if ((res[-2] == "S" and res[-1] == "S") or
                (res[-2] == "W" and res[-1] == "W")):
                res.append("W")
            else:
                res.append("S")
    else:
        if (s[0], s[-1]) == ("o", "o"):
            if (res[-2], res[-1]) == ("W", "W"):
                return "".join(res)
        elif (s[0], s[-1]) == ("o", "x"):
            if (res[-2], res[-1]) == ("S", "W"):
                return "".join(res)
        elif (s[0], s[-1]) == ("x", "o"):
            if (res[-2], res[-1]) == ("S", "S"):
                return "".join(res)
        elif (s[0], s[-1]) == ("x", "x"):
            if (res[-2], res[-1]) == ("W", "S"):
                return "".join(res)

    res = ["W", "S"]
    for x in s[1:-1]:
        if x == "o":
            if ((res[-2] == "S" and res[-1] == "S") or
                (res[-2] == "W" and res[-1] == "W")):
                res.append("S")
            else:
                res.append("W")
        elif x == "x":
            if ((res[-2] == "S" and res[-1] == "S") or
                (res[-2] == "W" and res[-1] == "W")):
                res.append("W")
            else:
                res.append("S")
    else:
        if (s[0], s[-1]) == ("o", "o"):
            if (res[-2], res[-1]) == ("S", "W"):
                return "".join(res)
        elif (s[0], s[-1]) == ("o", "x"):
            if (res[-2], res[-1]) == ("W", "W"):
                return "".join(res)
        elif (s[0], s[-1]) == ("x", "o"):
            if (res[-2], res[-1]) == ("S", "S"):
                return "".join(res)
        elif (s[0], s[-1]) == ("x", "x"):
            if (res[-2], res[-1]) == ("W", "S"):
                return "".join(res)

    res = ["W", "W"]
    for x in s[1:-1]:
        if x == "o":
            if ((res[-2] == "S" and res[-1] == "S") or
                (res[-2] == "W" and res[-1] == "W")):
                res.append("S")
            else:
                res.append("W")
        elif x == "x":
            if ((res[-2] == "S" and res[-1] == "S") or
                (res[-2] == "W" and res[-1] == "W")):
                res.append("W")
            else:
                res.append("S")
    else:
        if (s[0], s[-1]) == ("o", "o"):
            if (res[-2], res[-1]) == ("W", "S"):
                return "".join(res)
        elif (s[0], s[-1]) == ("o", "x"):
            if (res[-2], res[-1]) == ("S", "S"):
                return "".join(res)
        elif (s[0], s[-1]) == ("x", "o"):
            if (res[-2], res[-1]) == ("S", "W"):
                return "".join(res)
        elif (s[0], s[-1]) == ("x", "x"):
            if (res[-2], res[-1]) == ("W", "W"):
                return "".join(res)

    return -1


if __name__ == "__main__":
    n = int(raw_input())
    S = raw_input()
    print _func(n, S)

Submission status: Accepted

Solution code:
a = int(input())
b = list(input())
frag = 0
parks = [list("SS"),list("SW"),list("WS"),list("WW")]
for park in parks:
    for i in range(len(b)-2):
        if b[i+1] == "o":
            if park[i]=="S" and park[i+1]=="S":
                park.append("S")
            elif park[i]=="S" and park[i+1]=="W":
                park.append("W")
            elif park[i]=="W" and park[i+1]=="S":
                park.append("W")
            elif park[i]=="W" and park[i+1]=="W":
                park.append("S")
        elif b[i+1] == "x":
            if park[i]=="S" and park[i+1]=="S":
                park.append("W")
            elif park[i]=="S" and park[i+1]=="W":
                park.append("S")
            elif park[i]=="W" and park[i+1]=="S":
                park.append("S")
            elif park[i]=="W" and park[i+1]=="W":
                park.append("W")
    
    frag2 = 0
    if b[0]=="o":
        if park[0] == "S":
            if park[-1]==park[1]:
                frag2 = 1 
        if park[0] == "W":
            if park[-1]!=park[1]:
                frag2 = 1
    if b[0]=="x":
        if park[0] == "S":
            if park[-1]!=park[1]:
                frag2 = 1
        if park[0] == "W":
            if park[-1]==park[1]:
                frag2 = 1
                
    if frag2 == 1:
        if b[-1]=="o":
            if park[-1] == "S":
                if park[0]==park[-2]:
                    print (''.join(park))
                    frag = 1
                    break
            if park[-1] == "W":
                if park[0]!=park[-2]:
                    print (''.join(park))
                    frag = 1
                    break
        if b[-1]=="x":
            if park[-1] == "S":
                if park[0]!=park[-2]:
                    print (''.join(park))
                    frag = 1
                    break
            if park[-1] == "W":
                if park[0]==park[-2]:
                    print (''.join(park))
                    frag = 1
                    break
if frag == 0:
    print(-1)

Submission status: Accepted

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

types = ["S", "W"]

res = ""

def check(a, b, c, s):
    if s == 'o':
        if b == 'W':
            return a != c
        else:
            return a == c
    else:
        if b == 'W':
            return a == c
        else:
            return a != c

for t in types:
    circle = ""
    for tt in types:
        circle = t+tt
        for i in range(1, N-1):
            pre_a = circle[i-1]
            now_a = circle[i]
            if s[i] == 'o':
                if pre_a == now_a:
                    circle += "S"
                else:
                    circle += "W"
            else:
                if pre_a == now_a:
                  circle += "W"
                else:
                  circle += "S"
        is_ok = True
        is_ok *= check(circle[-1], circle[0], circle[1], s[0])
        is_ok *= check(circle[-2], circle[-1], circle[0], s[-1])

        if is_ok:
            print(circle)
            exit()

print(-1)

Submission status: Accepted

Solution code:
def input_parser():
    N=int(input())
    s=input()
    return N, s
N, s=input_parser()
s_bool=[_s is 'o' for _s in s]
ans=-1
for flag in range(0,4):
    if flag==0:
        animals=[True,True]
    elif flag==1:
        animals = [True, False]
    elif flag==2:
        animals=[False,True]
    else:
        animals=[False,False]
    for animal_index in range(1,N-1,1):
        animals.append((animals[animal_index] is animals[animal_index-1])is s_bool[animal_index])

    def last_check(s_bool,animals):
        global N
        # first animal witness
        if (((animals[N-2]==animals[0]) is s_bool[N-1]) is animals[N-1]) and ((((animals[N-1]==animals[1]) is s_bool[0]))is animals[0]):
            return True
        else:
            return False
    if last_check(s_bool,animals):
        ans=""
        for itr in range(0,N,1):
            if animals[itr]:
                ans += 'S'
            else:
                ans += 'W'
        break

def output_parser(output):
    print(output)

output_parser(ans)

Submission status: Accepted

Solution code:
_ = input()
s = input()

cands = ['SSS', 'SWW', 'WWS', 'WSW'] if s[0] == 'o' else ['WSS', 'SSW', 'SWS', 'WWW']

d = {
    'o':{'SS': 'S', 'SW': 'W', 'WW': 'S', 'WS': 'W'},
    'x':{'SS': 'W', 'SW': 'S', 'WW': 'W', 'WS': 'S'}
}

for char in s[1:]:
    for i in range(len(cands)):
        cands[i] += d[char][cands[i][-2:]]

for cand in cands:
    if cand[:2] == cand[-2:]:
        print(cand[1:-1])
        break
else:
    print(-1)

Submission status: Accepted

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

def calc(x, y):
    S = [0]*n
    S[0] = x; S[1] = y
    for i in xrange(2, n):
        if (S[i-1] and s[i-1] == 'o') or (not S[i-1] and s[i-1] == 'x'):
            S[i] = S[i-2]
        else:
            S[i] = S[i-2] ^ 1
    if (S[n-1] and s[n-1] == 'o') or (not S[n-1] and s[n-1] == 'x'):
        if S[n-2] != S[0]:
            return ''
    else:
        if S[n-2] == S[0]:
            return ''
    if (S[0] and s[0] == 'o') or (not S[0] and s[0] == 'x'):
        if S[n-1] != S[1]:
            return ''
    else:
        if S[n-1] == S[1]:
            return ''
    return "".join(map("WS".__getitem__, S))

for i in xrange(4):
    res = calc(i & 1, (i>>1)&1)
    if res:
        print res
        break
else:
    print "-1"

Submission status: Accepted

Solution code:
d={"o":1,"x":-1}
w={"S":1,"W":-1}
n={1:"S",-1:"W"}
N=int(raw_input())
s=raw_input()
s+=s[0]
def ans(a):
    for i in range(1,N+1):
        a+=n[w[a[i]]*w[a[i-1]]*d[s[i]]]
    if a[:2]==a[-2:]:
        return a[:-2]
    else:
        return []
for ini in ["SS","SW","WS","WW"]:
    a=ans(ini)
    if a:
        print a
        break
else:
    print "-1"

Submission status: Accepted

Solution code:
n = int(input())
ox = str(input())
ans = -1
ss = [1, 1]
sw = [1, -1]
ws = [-1, 1]
ww = [-1, -1]
line = [ss, sw, ws, ww]

for c in ox[1:]:
    for s in line:
        if c == "o":
            if s[-1] == 1:
                s.append(s[-2])
            else:
                s.append(s[-2] * -1)
        else:
            if s[-1] == -1:
                s.append(s[-2])
            else:
                s.append(s[-2] * -1)

for s in line:
    if s[0] == s[-1]:
        if ox[0] == "o":
            if (s[0] == 1 and s[1] == s[-2]) or (s[0] == -1 and s[1] != s[-2]):
                ans = ""
                for i in s[:-1]:
                    if i == 1:
                        ans += "S"
                    else:
                        ans += "W"
        else:
            if (s[0] == -1 and s[1] == s[-2]) or (s[0] == 1 and s[1] != s[-2]):
                ans = ""
                for i in s[:-1]:
                    if i == 1:
                        ans += "S"
                    else:
                        ans += "W"
print(ans)

Submission status: Accepted

Solution code:
from logging import getLogger, StreamHandler, DEBUG
logger = getLogger(__name__)
handler = StreamHandler()
handler.setLevel(DEBUG)
logger.setLevel(DEBUG)
logger.addHandler(handler)

import sys

def saySame(s, sw, index):
    return (sw[index] == 'S' and s[index] == 'o') or (sw[index] == 'W' and s[index] == 'x')
    
def match(s, sw, index, N):
    if saySame(s,sw,index):
        return sw[(index - 1 + N) % N] == sw[(index + 1 + N) % N]
    else:
        return sw[(index - 1 + N) % N] != sw[(index + 1 + N) % N]

N = int(input())
s = input()

for j in range(4):
    sw = ""
    if j%2==0:
        sw+= 'S'
    else:
        sw+= 'W'

    if (int(j/2))%2==0:
        sw+= 'S'
    else:
        sw+= 'W'
#    logger.debug(sw)


    for i in range(N-2):
        if saySame(s,sw,i+1):
            sw+=sw[i]
        else:
            if sw[i] == 'S':
                sw+='W'
            else:
                sw+='S'

#        logger.debug(sw)

    if match(s,sw,0,N) and match(s,sw,N-1,N):
        print(sw)
        sys.exit()

print(-1)

Submission status: Accepted

Solution code:
from logging import getLogger, StreamHandler, DEBUG
logger = getLogger(__name__)
handler = StreamHandler()
handler.setLevel(DEBUG)
logger.setLevel(DEBUG)
logger.addHandler(handler)

import sys

def match(s, sw, index, N):
    if s[index]=='o':
        if sw[index]=='S':
            return sw[(index - 1 + N) % N] == sw[(index + 1 + N) % N]
        else:
            return sw[(index - 1 + N) % N] != sw[(index + 1 + N) % N]
    else:
        if sw[index]=='W':
            return sw[(index - 1 + N) % N] == sw[(index + 1 + N) % N]
        else:
            return sw[(index - 1 + N) % N] != sw[(index + 1 + N) % N]


N = int(input())
s = input()


	 
    

for j in range(4):
    sw = ""
    if j%2==0:
        sw+= 'S'
    else:
        sw+= 'W'

    if (int(j/2))%2==0:
        sw+= 'S'
    else:
        sw+= 'W'
#    logger.debug(sw)


    for i in range(N-2):
        if (sw[i+1] == 'S' and s[i+1] == 'o') or (sw[i+1] == 'W' and s[i+1] == 'x'):
            sw+=sw[i]
        else:
            if sw[i] == 'S':
                sw+='W'
            else:
                sw+='S'

#        logger.debug(sw)

    if match(s,sw,0,N) and match(s,sw,N-1,N):
        print(sw)
        sys.exit()

print(-1)

Submission status: Accepted

Solution code:
import sys

def SorW(i):
    if i == 0:
        j = N - 1
    else:
        j = i - 1
    if t[i] == 'S' and t[j] == 'S':
        if s[i] == 'o':
            a = 'S'
        else:
            a = 'W'
    elif t[i] == 'S' and t[j] == 'W':
        if s[i] == 'o':
            a = 'W'
        else:
            a = 'S'
    elif t[i] == 'W' and t[j] == 'W':
        if s[i] == 'o':
            a = 'S'
        else:
            a = 'W'
    else:
        if s[i] == 'o':
            a = 'W'
        else:
            a = 'S'
    return a

N = int(input())
s = str(input())

for t in [['S', 'S'], ['S', 'W'], ['W', 'W'], ['W', 'S']]:
    for i in range(1, N):
        t.append(SorW(i))
    if t[0] == t[N] and t[1] == SorW(0):
        del t[N]
        print(''.join(t))
        sys.exit()
print('-1')

Submission status: Accepted

Solution code:
N = input()
str_animal = raw_input()
mat = list(str_animal)
pat = (('S', 'S'), ('S', 'W'), ('W', 'S'), ('W', 'W'))

def judge(listSW, listox):
    matSW = listSW[-2:] + listSW[:2]
    matox = listox[-2:] + listox[:2]
    for i in xrange(1,3):
        if matSW[i] == 'S':
            if matox[i] == 'o' and matSW[i-1] != matSW[i+1]: break
            if matox[i] == 'x' and matSW[i-1] == matSW[i+1]: break
        else:
            if matox[i] == 'o' and matSW[i-1] == matSW[i+1]: break
            if matox[i] == 'x' and matSW[i-1] != matSW[i+1]: break
    else:
        return 0
    return -1

for i in pat:
    animal = list(i)
    for j in xrange(1, N-1):
        if animal[j] == 'S':
            if mat[j] == 'o':
                animal.append(animal[j-1])
            else:
                if animal[j-1] == 'S':
                    animal.append('W')
                else:
                    animal.append('S')
        else:
            if mat[j] == 'o':
                if animal[j-1] == 'S':
                    animal.append('W')
                else:
                    animal.append('S')
            else:
                animal.append(animal[j-1])
    foo = judge(animal, mat)
    if foo == 0:
        print ''.join(animal)
        break
else:
    print -1

Submission status: Accepted

Solution code:
N = int(input())
c = 0
S = list()
for i in input():
    if(i == 'o'): S.append(0)
    else: S.append(1)

for i in [0, 1]:
    if(c == 1): break
    for j in [0, 1]:
        t = list()
        t.append(i)
        t.append(j)

        for k in range(1, N-1):
            t.append(S[k] ^ t[k] ^ t[k-1])

        if(((S[0] ^ t[0] ^ t[-1]) == t[1]) & ((S[-1] ^ t[-1] ^ t[-2]) == t[0])):
            c = 1
            break

if(c == 1):
    ans = ""
    for i in t:
        if(i == 0): ans = ans + 'S'
        else: ans = ans + 'W'
    print(ans)
else:
    print('-1')

Submission status: Accepted

Solution code:
MOD = 1000000007

N = int(input())
S = list(input())

s = 'S'
w = 'W'
c = 0
c1 = 0
c2 = 0

for i in [s, w]:
    if(c == 1): break
    for j in [s, w]:
        if (c == 1): break
        t = list()
        t.append(i)
        t.append(j)

        for k in range(1, N-1):
            if(S[k] == 'o'):
               if(t[k] == s):
                   t.append(t[k-1])
               else:
                    if(t[k-1] == s): t.append(w)
                    else: t.append(s)

            else:
                if (t[k] == w):
                    t.append(t[k - 1])
                else:
                    if (t[k - 1] == s):
                        t.append(w)
                    else:
                        t.append(s)

        c1 = 0
        if(t[0] == s):
            if(S[0] == 'o'):
                if(t[1] == t[N-1]):
                    c1 = 1
            else:
                if (t[1] != t[N - 1]):
                    c1 = 1
        else:
            if (S[0] == 'x'):
                if (t[1] == t[N - 1]):
                    c1 = 1
            else:
                if (t[1] != t[N - 1]):
                    c1 = 1
        c2 = 0
        if (t[N-1] == s):
            if (S[N-1] == 'o'):
                if (t[0] == t[N - 2]):
                    c2 = 1
            else:
                if (t[0] != t[N - 2]):
                    c2 = 1
        else:
            if (S[N-1] == 'x'):
                if (t[0] == t[N - 2]):
                    c2 = 1
            else:
                if (t[0] != t[N - 2]):
                    c2 = 1
        if(c1 == 1 & c2 == 1): c = 1

if(c == 1):
    print(''.join(t))
else:
    print('-1')

Submission status: Accepted

Solution code:
import itertools
length = int(input())
target = input()
target = [n == "o" for n in target]
for before,after in itertools.product([True,False],repeat = 2):
    tmp_answer = [0 for n in range(length)]
    tmp_answer[0] = before
    tmp_answer[1] = after
    for i in range(1,length-1):
        tmp_answer[i+1] = before ^ after ^ target[i]
        before,after = after,tmp_answer[i+1]

    if tmp_answer[length - 2] ^ tmp_answer [length - 1] ^ target[length - 1]  == tmp_answer[0] and \
    tmp_answer[length - 1] ^ tmp_answer [0] ^ target[0]  == tmp_answer[1]:
        print("".join(["S" if n else "W" for n in tmp_answer]))
        break
else:
    print(-1)

Submission status: Accepted

Solution code:
from itertools import product

N = int(raw_input())
ox = [1 if c == 'o' else 0 for c in raw_input()]

SHEEP, WOLF = 0, 1
a = [None] * N

for s1, s2 in product([SHEEP, WOLF], repeat=2):
    a[0], a[1] = s1, s2
    for i in xrange(2, N):
        a[i] = 1 - ((ox[i - 1] ^ a[i - 1]) ^ a[i - 2])

    ok = True
    for i in xrange(N):
        same = 1 if a[i - 1] == a[i + 1 - N] else 0
        if ox[i] + a[i] + same in (1, 3):
            ok = False
            break
    if ok:
        print ''.join('SW'[a[i]] for i in xrange(N))
        break
else:
    print -1

Submission status: Accepted

Solution code:
input()
s = input()
pair = ["SS", "SW", "WS", "WW"]
replace = {"S": "W", "W": "S"}
hasFound = False
for i in pair:
    for j in s[1:]:
        if j is 'o':
            if i[-1] is 'S':
                i += i[-2]
            else:
                i += replace[i[-2]]
        else:
            if i[-1] is 'S':
                i += replace[i[-2]]
            else:
                i += i[-2]
    if i[0] is i[-1]:
        if s[0] == 'o':
            hasFound = i[0] is 'S' and i[-2] is i[1] or i[0] is 'W' and i[-2] is not i[1]
        else:
            hasFound = i[0] is 'S' and i[-2] is not i[1] or i[0] is 'W' and i[-2] is i[1]
    if hasFound:
        print(i[:-1])
        break
if not hasFound:
    print(-1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
s=input()
a=['SS','WS','SW','WW']
def f(a,b,w):
    if w=='o':
        if a=='S' and b=='S':return 'S'
        elif a=='W' and b=='S':return 'W'
        elif a=='S' and b=='W':return 'W'
        else:return 'S'
    else:
        if a=='S' and b=='S':return 'W'
        elif a=='W' and b=='S':return 'S'
        elif a=='S' and b=='W':return 'S'
        else:return 'W'

for i in range(n):
    for j in range(4):a[j]+=f(a[j][i],a[j][i+1],s[i])
for i in range(4):
    if a[i][1]==a[i][n+1] and a[i][0] == a[i][n]:print(a[i][1:n+1]);exit()
print(-1)

Submission status: Accepted

Solution code:
two = ["SS", "SW", "WS", "WW"]
n = int(input())
s = input()
flip = {"S":"W", "W":"S"}
flag = False

for i in two:
    for j in s[1:]:
        if j == 'o':
            if i[-1] == 'S':
                i += i[-2]
            else:
                i += flip[i[-2]]
        else:
            if i[-1] == 'S':
                i += flip[i[-2]]
            else:
                i += i[-2]
    if i[0] == i[-1]:
        if s[0] == 'o':
            if i[0] == 'S' and i[-2] == i[1] or i[0] == 'W' and i[-2] != i[1]:
                flag = True
        else:
            if i[0] == 'S' and i[-2] != i[1] or i[0] == 'W' and i[-2] == i[1]:
                flag = True
    if flag:
        print(i[:-1])
        break
if not flag:
    print(-1)

Submission status: Accepted

Solution code:
#coding: UTF-8
import sys
N=int(input())
Say=input()
A1='SS'
A2='WS'
A3='SW'
A4='WW'
def Nextone(a,b,w):
    if w=='o':
        if a=='S' and b=='S':
            return 'S'
        elif a=='W' and b=='S':
            return 'W'
        elif a=='S' and b=='W':
            return 'W'
        else:
            return 'S'
    else:
        if a=='S' and b=='S':
            return 'W'
        elif a=='W' and b=='S':
            return 'S'
        elif a=='S' and b=='W':
            return 'S'
        else:
            return 'W'

for i in range(0,N):
    A1+=Nextone(A1[i],A1[i+1],Say[i])
    A2+=Nextone(A2[i],A2[i+1],Say[i])
    A3+=Nextone(A3[i],A3[i+1],Say[i])
    A4+=Nextone(A4[i],A4[i+1],Say[i])
if A1[1]==A1[N+1] and A1[0]==A1[N]:
    print(A1[1:N+1])
elif A2[1]==A2[N+1] and A2[0]==A2[N]:
    print(A2[1:N+1])
elif A3[1]==A3[N+1] and A3[0]==A3[N]:
    print(A3[1:N+1])
elif A4[1]==A4[N+1] and A4[0]==A4[N]:
    print(A4[1:N+1])
else:
    print(-1)

Submission status: Accepted

Solution code:
def flip(c):
    if c=='S':
        return 'W'
    else:
        return 'S'

def judge():
    found=False
    ret = -1
    for i in xrange(N):
        #print r
        if r[i]=='S':
            if s[i]=='o':
                if i==0:
                    r[i-1]=r[i+1]
                elif i==N-1:
                    if r[0]==r[i-1]:
                        found=True
                elif i==N-2:
                    if r[i+1]!=r[i-1]:
                        break;                    
                else:
                    r[i+1]=r[i-1]
            else:
                if i==0:
                    r[i-1]=flip(r[i+1])
                elif i==N-2:
                    if r[i+1]!=flip(r[i-1]):
                        break;                    
                elif i==N-1:
                    if r[0]==flip(r[i-1]):
                        found=True
                else:
                    r[i+1]=flip(r[i-1])
        else: # W
            if s[i]=='x':
                if i==0:
                    r[i-1]=r[i+1]
                elif i==N-1:
                    if r[0]==r[i-1]:
                        found=True
                elif i==N-2:
                    if r[i+1]!=r[i-1]:
                        break;                    
                else:
                    r[i+1]=r[i-1]
            else:
                if i==0:
                    r[i-1]=flip(r[i+1])
                elif i==N-1:
                    if r[0]==flip(r[i-1]):
                        found=True
                elif i==N-2:
                    if r[i+1]!=flip(r[i-1]):
                        break;                    
                else:
                    r[i+1]=flip(r[i-1])
                
        if found:
            ret = ''.join(r)

    return ret
    
N=input()
s=list(raw_input())


ptn=[['S','S'],['S','W'],['W','S'],['W','W']]

ret = None
for p in ptn:
    r = [None]*N
    r[0]=p[0]
    r[1]=p[1]
    ret = judge()
    if ret != -1:
        break
print ret

Submission status: Accepted

Solution code:
from collections import defaultdict


def solve(s, l):
    for now in range(1, len(s) + 1):
        now %= len(s)
        pre = now - 1
        nex = (now + 1) % len(s)

        # 整合性のチェック
        if l[pre] is not None and l[nex] is not None:
            if l[now] == 1:
                if s[now] == "o":
                    if l[nex] != l[pre]:
                        return False
                else:
                    if l[nex] == l[pre]:
                        return False
            else:
                if s[now] == "o":
                    if l[nex] == l[pre]:
                        return False
                else:
                    if l[nex] != l[pre]:
                        return False

        # nextを決める
        if l[pre] is not None and l[nex] is None:
            # ひつじ
            if l[now] == 1:
                # 両隣が同じはず
                if s[now] == "o":
                    l[nex] = l[pre]

                # 両隣が違うはず
                else:
                    l[nex] = -1 * l[pre]
            # おおかみ
            else:
                # 両隣が違うはず
                if s[now] == "o":
                    l[nex] = -1 * l[pre]
                # 両隣が同じはず
                else:
                    l[nex] = l[pre]

    return True


def main():
    N = int(input())
    S = input()

    for a, b in [(1, 1), (1, -1), (-1, 1), (-1, -1)]:
        ans = [None] * N
        ans[0], ans[1] = a, b

        if solve(S, ans):
            print(*["S" if x == 1 else "W" for x in ans], sep="")
            return

    print(-1)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n =int(input())
s = input()
s = list(s)
for i in range(len(s)):
    if s[i] =='o':
        s[i] = int(1)
    else:
        s[i] = int(-1)

syoki_list = [[1,1],[1,-1],[-1,1],[-1,-1]]
a = "-1"
for i in range(len(syoki_list)):
    t = []
    t.append(syoki_list[i][0])
    t.append(syoki_list[i][1])
    for j in range(2,n+1):
        t.append(t[j-2] * t[j-1] * s[j-1])
    if t[0] == t[n] and t[1] == t[n-1] * t[n]*s[0]:
        for i in range(n+1):
            if t[i] == 1:
                t[i] = "S"
            else:
                t[i] = "W"
        a= "".join(t[:n])
        break

print(a)

Submission status: Accepted

Solution code:
import itertools
N = int(input())
s = list(map(lambda x: True if x == "o" else False, list(input())))

f = lambda x,y: not(x^y)

def hantei(N,s):
    for onetwo in itertools.product((True, False), (True, False)):
        res = {}
        for n in range(N):
            if n == 0:
                res[n] = onetwo[0]
            elif n == 1:
                res[n] = onetwo[1]
            else:
                res[n] = f(res[n-2], f(res[n-1], s[n-1]))
        # check s[0]
        if not ((res[1] == res[N-1]) ^ res[0]) == s[0]:
            if not ((res[0] == res[N-2]) ^ res[N-1]) == s[N-1]:
                print(''.join(map(lambda x: "S" if x == True else "W", res.values())))
                return True

    return False

if not hantei(N, s):
    print(-1)

Submission status: Accepted

Solution code:
# coding: utf-8
# Here your code !
import sys
N = int(input())
ipt = list(input())
stR = ["S" for i in range(N)]

def sheep(stg):
     return stg
def wolf(stg):
    if stg == "S":
        return "W"
    else:
        return "S"
def modN (i):
    return i%N
def check ( num1,num2 ):
    stR[0]=num1
    stR[1]=num2
    for i in range(N+2):
        if stR[modN(i+1)] == "S" and ipt[modN(i+1)]=="o"  :
            stR[modN(i+2)]=sheep(stR[modN(i)])
        elif stR[modN(i+1)] == "W" and ipt[modN(i+1)]=="x":
            stR[modN(i+2)]=sheep(stR[modN(i)])
        else:
            stR[modN(i+2)]=wolf(stR[modN(i)])
    
    if stR[0]==num1 and stR[1]==num2:
        print("".join(stR))
        return True
    else:
        return False

if check("S","W"):
    sys.exit()
else:
    
    if check("W","W"):
        sys.exit()
    else:
        
        if check("W","S"):
            sys.exit()
        else:
            
            if check("S","S"):
                sys.exit()
            else:
                print(-1)