Problem p03800 (python)

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

if __name__ == "__main__":
    main()

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

if __name__ == "__main__":
    main()