Problem:
 Score : 500 points    Problem Statement Snuke, who loves animals, built a zoo.  There are N animals in this zoo. They are conveniently numbered 1 through N , and arranged in a circle.
The animal numbered i (2≤i≤N-1) is adjacent to the animals numbered i-1 and i+1 . Also, the animal numbered 1 is adjacent to the animals numbered 2 and N , and the animal numbered N is adjacent to the animals numbered N-1 and 1 .  There are two kinds of animals in this zoo: honest sheep that only speak the truth, and lying wolves that only tell lies.  Snuke cannot tell the difference between these two species, and asked each animal the following question: "Are your neighbors of the same species?" The animal numbered i answered s_i . Here, if s_i is o , the animal said that the two neighboring animals are of the same species, and if s_i is x , the animal said that the two neighboring animals are of different species.  More formally, a sheep answered o if the two neighboring animals are both sheep or both wolves, and answered x otherwise.
Similarly, a wolf answered x if the two neighboring animals are both sheep or both wolves, and answered o otherwise.  Snuke is wondering whether there is a valid assignment of species to the animals that is consistent with these responses. If there is such an assignment, show one such assignment. Otherwise, print -1 .      Constraints  3 ≤ N ≤ 10^{5}  s is a string of length N consisting of o and x .         Input The input is given from Standard Input in the following format:  N  s       Output If there does not exist an valid assignment that is consistent with s , print -1 .
Otherwise, print an string t in the following format. The output is considered correct if the assignment described by t is consistent with s .   t is a string of length N consisting of S and W .  If t_i is S , it indicates that the animal numbered i is a sheep. If t_i is W , it indicates that the animal numbered i is a wolf.         Sample Input 1 6
ooxoox      Sample Output 1 SSSWWS  For example, if the animals numbered 1 , 2 , 3 , 4 , 5 and 6 are respectively a sheep, sheep, sheep, wolf, wolf, and sheep, it is consistent with their responses. Besides, there is another valid assignment of species: a wolf, sheep, wolf, sheep, wolf and wolf.  Let us remind you: if the neiboring animals are of the same species, a sheep answers o and a wolf answers x . If the neiboring animals are of different species, a sheep answers x and a wolf answers o .          Sample Input 2 3
oox      Sample Output 2 -1  Print -1 if there is no valid assignment of species.       Sample Input 3 10
oxooxoxoox      Sample Output 3 SSWWSSSWWS

Solution (Python):
init_ts = ["SS", "SW", "WS", "WW"]

def notanim(t):
    if t=="S":
        return "W"
    else:
        return "S"

def nextAnimal(ts, s):
    if ts[1]=="S":
        if s=="o":
            return ts[0]
        else:
            return notanim(ts[0])
    elif ts[1]=="W":
        if s=="o":
            return notanim(ts[0])
        else:
            return ts[0]

def maket(n, s, init_t):
    t = init_t
    new_s = s[1:] + s[0]
    for i in range(n):
        t += nextAnimal(t[-2:], new_s[i])
    return t

n = int(input())
s = input()
flag = True
for init_t in init_ts:
    tmp_t = maket(n, s, init_t)
    if tmp_t[-2:]==init_t:
        print(tmp_t[:-2])
        flag = False
        break
    else:
        pass

if flag:
    print(-1)

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

b = [0 if si == 'o' else 1 for si in s]
sw = [0] * N

for i in range(4):
    sw[0] = i & 1
    sw[1] = (i >> 1) & 1

    for k in range(2, N):
        sw[k] = b[k - 1] ^ sw[k - 1] ^ sw[k - 2]

    if b[N - 1] != (sw[N - 2] ^ sw[N - 1] ^ sw[0]):
        continue
    if b[0] != (sw[N - 1] ^ sw[0] ^ sw[1]):
        continue

    ans = ['W' if si else 'S' for si in sw]
    print(''.join(ans))
    quit()

print(-1)

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

b = [0 if si == 'o' else 1 for si in s]

for i in range(4):
    sw = [i & 1] + [(i >> 1) & 1] + [0] * (N - 2)

    for k in range(2, N):
        sw[k] = b[k - 1] ^ sw[k - 1] ^ sw[k - 2]

    if b[N - 1] != (sw[N - 2] ^ sw[N - 1] ^ sw[0]):
        continue
    if b[0] != (sw[N - 1] ^ sw[0] ^ sw[1]):
        continue

    ans = ['W' if si else 'S' for si in sw]
    print(''.join(ans))
    quit()

print(-1)

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

b = [0 if si == 'o' else 1 for si in s]

for i in range(2):
    for j in range(2):
        sw = [i] + [j] + [0] * (N - 2)

        for k in range(2, N):
            sw[k] = b[k - 1] ^ sw[k - 1] ^ sw[k - 2]

        if b[N - 1] != (sw[N - 2] ^ sw[N - 1] ^ sw[0]):
            continue
        if b[0] != (sw[N - 1] ^ sw[0] ^ sw[1]):
            continue

        ans = ['W' if si else 'S' for si in sw]
        print(''.join(ans))
        quit()

print(-1)

Solution (Python):
N = int(input())
s = list(input())
S = [0]*N
for i in range(N):
    if s[i]=='o':
        S[i]=1
    else:
        S[i]=-1

P = [[1]*N,[1]*N,[-1]*N,[-1]*N]

if S[0]==1:
    P[0][1]=1
    P[0][N-1]=1
    P[1][1] = -1
    P[1][N - 1] = -1
    P[2][1] = 1
    P[2][N - 1] = -1
    P[3][1] = -1
    P[3][N - 1] = 1
else:
    P[0][1] = 1
    P[0][N - 1] = -1
    P[1][1] = -1
    P[1][N - 1] = 1
    P[2][1] = 1
    P[2][N - 1] = 1
    P[3][1] = -1
    P[3][N - 1] = -1

result = -1
for i in range(1,N-1):
    if i == N-2:
        for j in range(4):
            if S[i] * P[j][i] == 1:
                if P[j][i + 1] == P[j][i - 1]:
                    if S[i+1] * P[j][i+1] == 1:
                        if P[j][0] == P[j][i]:
                            result = j
                            break
                    else:
                        if P[j][0] == - P[j][i]:
                            result = j
                            break
            else:
                if P[j][i + 1] == - P[j][i - 1]:
                    if S[i+1] * P[j][i+1] == 1:
                        if P[j][0] == P[j][i]:
                            result = j
                            break
                    else:
                        if P[j][0] == - P[j][i]:
                            result = j
                            break
    for j in range(4):
        if S[i]*P[j][i]==1:
            P[j][i+1]=P[j][i-1]
        else:
            P[j][i + 1] = - P[j][i - 1]

if result == -1:
    print(result)
else:
    for i in range(N):
        if P[result][i]==1:
            print('S',end="")
        else:
            print('W',end="")

Solution (Python):
options = [(0, 0), (0, 1), (1, 0), (1, 1)]


def judge(n, s):
    res = [None] * n
    for op in options:
        res[-1], res[0] = op
        s_num = list(map(lambda a: 0 if a == 'o' else 1, s))
        for i in range(n):
            res[(i + 1) % n] = res[i] ^ s_num[i] ^ res[i - 1]
        if (res[-1], res[0]) == op:
            print(''.join(map(lambda a: 'S' if a == 0 else 'W', res)))
            exit()

n = int(input())
s = input()
judge(n, s)
print(-1)

Solution (Python):


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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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
        
        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)

Solution (Python):
_ = 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)

Solution (Python):
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"

Solution (Python):
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"

Solution (Python):
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)

Solution (Python):
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'



    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'



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

print(-1)

Solution (Python):
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'



    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'



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

print(-1)

Solution (Python):
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')

Solution (Python):
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

Solution (Python):
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')

Solution (Python):
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')

Solution (Python):
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)

Solution (Python):
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

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):

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)

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

def judge():
    found=False
    ret = -1
    for i in xrange(N):
        
        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: 
            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