Problem p03795 (python)

Fixed submission:
N = int(input())
print(N*800-(N//15)*200)

Buggy submission (verdict: Runtime Error):
N = int(input())
s = input()

def lier_check(aa):
    lier = 1
    if aa==0:
        mae=N-1
    else:
        mae=aa-1
    if aa == N-1:
        ato = 0
    else:
        ato = aa+1
    
    if ans[aa] == 'S' and s[aa] == 'o':
        if ans[mae] != ans[ato]:
            lier = -1
    if ans[aa] == 'S' and s[aa] == 'x':
        if ans[mae] == ans[ato]:
            lier = -1
    if ans[aa] == 'W' and s[aa] == 'o':
        if ans[mae] == ans[ato]:
            lier = -1
    if ans[aa] == 'W' and s[aa] == 'x':
        if ans[mae] != ans[ato]:
            lier = -1 
    return(lier)


ans = ['X']*N
ans[0] = 'S'
if s[0] == 'o':
    ans[N-1] = 'S'
    ans[1] = 'S'
else:
    ans[N-1] = 'W'
    ans[1] = 'S'
for aa in range(1,N-1):
    if ans[aa] == 'S' and s[aa] == 'o' and ans[aa-1]=='S':
        ans[aa+1] = 'S'
    elif ans[aa] == 'S' and s[aa] == 'o' and ans[aa-1]=='W':
        ans[aa+1] = 'W'
    elif ans[aa] == 'S' and s[aa] == 'x' and ans[aa-1]=='S':
        ans[aa+1] = 'W'
    elif ans[aa] == 'S' and s[aa] == 'x' and ans[aa-1]=='W':
        ans[aa+1] = 'S'
    elif ans[aa] == 'W' and s[aa] == 'o' and ans[aa-1]=='S':
        ans[aa+1] = 'W'
    elif ans[aa] == 'W' and s[aa] == 'o' and ans[aa-1]=='W':
        ans[aa+1] = 'S'
    elif ans[aa] == 'W' and s[aa] == 'x' and ans[aa-1]=='S':
        ans[aa+1] = 'S'
    elif ans[aa] == 'W' and s[aa] == 'x' and ans[aa-1]=='W':
        ans[aa+1] = 'W'

kekka = 1
for aa in range(0,len(ans)):
    if(lier_check(aa) == -1):
        kekka = -1
        break
if kekka == 1:
    print("".join(ans))

    
######## 

ans = ['X']*N
ans[0] = 'S'
if s[0] == 'o':
    ans[N-1] = 'W'
    ans[1] = 'W'
else:
    ans[N-1] = 'W'
    ans[1] = 'S'
for aa in range(1,N-1):
    if ans[aa] == 'S' and s[aa] == 'o' and ans[aa-1]=='S':
        ans[aa+1] = 'S'
    elif ans[aa] == 'S' and s[aa] == 'o' and ans[aa-1]=='W':
        ans[aa+1] = 'W'
    elif ans[aa] == 'S' and s[aa] == 'x' and ans[aa-1]=='S':
        ans[aa+1] = 'W'
    elif ans[aa] == 'S' and s[aa] == 'x' and ans[aa-1]=='W':
        ans[aa+1] = 'S'
    elif ans[aa] == 'W' and s[aa] == 'o' and ans[aa-1]=='S':
        ans[aa+1] = 'W'
    elif ans[aa] == 'W' and s[aa] == 'o' and ans[aa-1]=='W':
        ans[aa+1] = 'S'
    elif ans[aa] == 'W' and s[aa] == 'x' and ans[aa-1]=='S':
        ans[aa+1] = 'S'
    elif ans[aa] == 'W' and s[aa] == 'x' and ans[aa-1]=='W':
        ans[aa+1] = 'W'

kekka = 1
for aa in range(0,len(ans)):
    if(lier_check(aa) == -1):
        kekka = -1
        break
if kekka == 1:
    print("".join(ans))
else:
    ############
    ans = ['X']*N
    ans[0] = 'S'
    if s[0] == 'o':
        ans[N-1] = 'S'
        ans[1] = 'S'
    else:
        ans[N-1] = 'S'
        ans[1] = 'W'
    for aa in range(1,N-1):
        if ans[aa] == 'S' and s[aa] == 'o' and ans[aa-1]=='S':
            ans[aa+1] = 'S'
        elif ans[aa] == 'S' and s[aa] == 'o' and ans[aa-1]=='W':
            ans[aa+1] = 'W'
        elif ans[aa] == 'S' and s[aa] == 'x' and ans[aa-1]=='S':
            ans[aa+1] = 'W'
        elif ans[aa] == 'S' and s[aa] == 'x' and ans[aa-1]=='W':
            ans[aa+1] = 'S'
        elif ans[aa] == 'W' and s[aa] == 'o' and ans[aa-1]=='S':
            ans[aa+1] = 'W'
        elif ans[aa] == 'W' and s[aa] == 'o' and ans[aa-1]=='W':
            ans[aa+1] = 'S'
        elif ans[aa] == 'W' and s[aa] == 'x' and ans[aa-1]=='S':
            ans[aa+1] = 'S'
        elif ans[aa] == 'W' and s[aa] == 'x' and ans[aa-1]=='W':
            ans[aa+1] = 'W'

    kekka = 1
    for aa in range(0,len(ans)):
        if(lier_check(aa) == -1):
            kekka = -1
            break
    if kekka == 1:
        print("".join(ans))
    else:

        #######
        ans = ['X']*N
        ans[0] = 'S'
        if s[0] == 'o':
            ans[N-1] = 'W'
            ans[1] = 'W'
        else:
            ans[N-1] = 'S'
            ans[1] = 'W'
        for aa in range(1,N-1):
            if ans[aa] == 'S' and s[aa] == 'o' and ans[aa-1]=='S':
                ans[aa+1] = 'S'
            elif ans[aa] == 'S' and s[aa] == 'o' and ans[aa-1]=='W':
                ans[aa+1] = 'W'
            elif ans[aa] == 'S' and s[aa] == 'x' and ans[aa-1]=='S':
                ans[aa+1] = 'W'
            elif ans[aa] == 'S' and s[aa] == 'x' and ans[aa-1]=='W':
                ans[aa+1] = 'S'
            elif ans[aa] == 'W' and s[aa] == 'o' and ans[aa-1]=='S':
                ans[aa+1] = 'W'
            elif ans[aa] == 'W' and s[aa] == 'o' and ans[aa-1]=='W':
                ans[aa+1] = 'S'
            elif ans[aa] == 'W' and s[aa] == 'x' and ans[aa-1]=='S':
                ans[aa+1] = 'S'
            elif ans[aa] == 'W' and s[aa] == 'x' and ans[aa-1]=='W':
                ans[aa+1] = 'W'

        kekka = 1
        for aa in range(0,len(ans)):
            if(lier_check(aa) == -1):
                kekka = -1
                break
        if kekka == 1:
            print("".join(ans))
        else:
            print(kekka)