Problem p03798 (python)

Fixed submission:
n = int(input())
s = input()

def kakunin(animal):
    for i in range(2,n):
        if s[i-1]=='o':
            if (animal[i-1]==0) and (animal[i-2]==0 ):
                animal[i]=0
            elif (animal[i-1]==1) and (animal[i-2]==0 ):
                animal[i]+=1
            elif (animal[i-1]==0) and (animal[i-2]==1 ):
                animal[i]+=1
            elif (animal[i-1]==1) and (animal[i-2]==1 ):
                animal[i]=0
        else:
            if (animal[i-1]==0) and (animal[i-2]==0 ):
                animal[i]+=1
            elif (animal[i-1]==1) and (animal[i-2]==0 ):
                animal[i]=0
            elif (animal[i-1]==0) and (animal[i-2]==1 ):
                animal[i]=0
            elif (animal[i-1]==1) and (animal[i-2]==1 ):
                animal[i]+=1
    if s[0]=='o':
        if (animal[0]==0):
            if (animal[1]==0) and (animal[-1]==0 ):
                if ((s[-1]=='o')and(animal[-2]==0))or((s[-1]=='x')and(animal[-2]==1)):
                    return True
            elif (animal[1]==1) and (animal[-1]==1):
                if ((s[-1]=='o')and(animal[-2]==1))or((s[-1]=='x')and(animal[-2]==0)):
                    return True
        else:
            if (animal[1]==1) and (animal[-1]==0 ):
                if ((s[-1]=='o')and(animal[-2]==1))or((s[-1]=='x')and(animal[-2]==0)):
                    return True
            elif (animal[1]==0) and (animal[-1]==1):
                if ((s[-1]=='o')and(animal[-2]==0))or((s[-1]=='x')and(animal[-2]==1)):
                    return True
            
            
    else:
        if (animal[0]==0):
            if (animal[1]==1) and (animal[-1]==0 ):
                if ((s[-1]=='o')and(animal[-2]==0))or((s[-1]=='x')and(animal[-2]==1)):
                    return True
            elif (animal[1]==0) and (animal[-1]==1):
                if ((s[-1]=='o')and(animal[-2]==1))or((s[-1]=='x')and(animal[-2]==0)):
                    return True
        else:
            if (animal[1]==1) and (animal[-1]==1):
                if ((s[-1]=='o')and(animal[-2]==0))or((s[-1]=='x')and(animal[-2]==1)):
                    return True
            elif (animal[1]==0) and (animal[-1]==0):
                if ((s[-1]=='o')and(animal[-2]==0))or((s[-1]=='x')and(animal[-2]==1)):
                    return True
    return False
f = [False]     
for i in range(0,4):
    animal = [0]*n
    if i == 1:
        animal[0]+=1
    elif i==2:
        animal[1]+=1
    elif i==3:
        animal[0]+=1
        animal[1]+=1
    f[0]= kakunin(animal) 
    if f[0]==True:
        u = ''
        for j in range(0,n):
            if animal[j]==0:
                u = u+'S'
            else:
                u = u + 'W'
        print(u)
        break

if f[0] == False:
    print(-1)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()
animal = [0]*n #0が羊、1が狼
f = [False]
def dfs(v,animal):    
    if f[0]== True:
        return 
    if v == n-1:
        if s[v]=='o':
            if animal[v]==0:
                if ((animal[v-1]==0)and(animal[0]==0))or((animal[v-1]==1)and(animal[0]==1)):
                    # print("True!")
                    f[0]= True
                    return 
            else:
                if ((animal[v-1]==0)and(animal[0]==1))or((animal[v-1]==1)and(animal[0]==0)):
                    # print("True!")
                    f[0]= True
                    return 
        else:
            if animal[v]==0:
                if ((animal[v-1]==0)and(animal[0]==1))or((animal[v-1]==1)and(animal[0]==0)):
                    # print("True!")
                    f[0]= True
                    return 
                
            else:
                if ((animal[v-1]==0)and(animal[0]==0))or((animal[v-1]==1)and(animal[0]==1)):
                    # print("True!")
                    f[0]= True
                    return 
        if f[0]==False:
            # print("False!")
            return
        
        
    if s[v]=='o':
        if animal[v]==0:
            if animal[v-1]==0:
                animal[v+1]=0
                dfs(v+1,animal)
            else:
                animal[v+1]+=1
                dfs(v+1,animal)
            
        else:
            if animal[v-1]==0:
                animal[v+1]+=1
                dfs(v+1,animal)
            else:
                animal[v+1]=0
                dfs(v+1,animal)
            

    else:
        if animal[v]==0:
            if animal[v-1]==0:
                animal[v+1]+=1
                dfs(v+1,animal)
            else:
                animal[v+1]=0
                dfs(v+1,animal)
            
        else:
            if animal[v-1]==0:
                animal[v+1]=0
                dfs(v+1,animal)
            else:
                animal[v+1]+=1
                dfs(v+1,animal)
            

dfs(0,animal)
animal1 = animal
f1 = f[0]

animal = [0]*n #0が羊、1が狼
f = [False]

dfs(1,animal)
animal2 = animal
f2 = f[0]

if (f1==False) and (f2==False):
    print(-1)
if f1 == True:
    u = ''
    for i in range(0,n):
        if animal1[i]==0:
            u = u+'S'
        else:
            u = u + 'W'
    print(u)

if (f1 != True) and (f2 ==True):
    u = ''
    for i in range(0,n):
        if animal2[i]==0:
            u = u+'S'
        else:
            u = u + 'W'
    print(u)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()
animal = [0]*n #0が羊、1が狼
f = [False]
def dfs(v,animal):
    if v == 0:
        dfs(1,animal)
        animal[0]+=1
        dfs(1,animal)
        
        
    if f[0]== True:
        return 
    if v == n-1:
        if s[v]=='o':
            if animal[v]==0:
                if ((animal[v-1]==0)and(animal[0]==0))or((animal[v-1]==1)and(animal[0]==1)):
                    # print("True!")
                    f[0]= True
                    return 
            else:
                if ((animal[v-1]==0)and(animal[0]==1))or((animal[v-1]==1)and(animal[0]==0)):
                    # print("True!")
                    f[0]= True
                    return 
        else:
            if animal[v]==0:
                if ((animal[v-1]==0)and(animal[0]==1))or((animal[v-1]==1)and(animal[0]==0)):
                    # print("True!")
                    f[0]= True
                    return 
                
            else:
                if ((animal[v-1]==0)and(animal[0]==0))or((animal[v-1]==1)and(animal[0]==1)):
                    # print("True!")
                    f[0]= True
                    return 
        if f[0]==False:
            # print("False!")
            return
        
        
    if s[v]=='o':
        if animal[v]==0:
            if animal[v-1]==0:
                animal[v+1]=0
                dfs(v+1,animal)
            else:
                animal[v+1]+=1
                dfs(v+1,animal)
            
        else:
            if animal[v-1]==0:
                animal[v+1]+=1
                dfs(v+1,animal)
            else:
                animal[v+1]=0
                dfs(v+1,animal)
            

    else:
        if animal[v]==0:
            if animal[v-1]==0:
                animal[v+1]+=1
                dfs(v+1,animal)
            else:
                animal[v+1]=0
                dfs(v+1,animal)
            
        else:
            if animal[v-1]==0:
                animal[v+1]=0
                dfs(v+1,animal)
            else:
                animal[v+1]+=1
                dfs(v+1,animal)
            

dfs(0,animal)
if f[0]==False:
    print(-1)
if f[0]==True:
    u = ''
    for i in range(0,n):
        if animal[i]==0:
            u = u+'S'
        else:
            u = u + 'W'
    print(u)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()
animal = [0]*n #0が羊、1が狼
f = [False]
def dfs(v,animal):
    if v == 0:
        dfs(1,animal)
        animal[0]+=1
        dfs(1,animal)
        
        
    if f[0]== True:
        return animal
    if v == n-1:
        if s[v]=='o':
            if animal[v]==0:
                if ((animal[v-1]==0)and(animal[0]==0))or((animal[v-1]==1)and(animal[0]==1)):
                    # print("True!")
                    f[0]= True
                    return 
            else:
                if ((animal[v-1]==0)and(animal[0]==1))or((animal[v-1]==1)and(animal[0]==0)):
                    # print("True!")
                    f[0]= True
                    return 
        else:
            if animal[v]==0:
                if ((animal[v-1]==0)and(animal[0]==1))or((animal[v-1]==1)and(animal[0]==0)):
                    # print("True!")
                    f[0]= True
                    return 
                
            else:
                if ((animal[v-1]==0)and(animal[0]==0))or((animal[v-1]==1)and(animal[0]==1)):
                    # print("True!")
                    f[0]= True
                    return 
        if f[0]==False:
            # print("False!")
            return
        
        
    if s[v]=='o':
        if animal[v]==0:
            if animal[v-1]==0:
                animal[v+1]=0
                dfs(v+1,animal)
            else:
                animal[v+1]+=1
                dfs(v+1,animal)
            
        else:
            if animal[v-1]==0:
                animal[v+1]+=1
                dfs(v+1,animal)
            else:
                animal[v+1]=0
                dfs(v+1,animal)
            

    else:
        if animal[v]==0:
            if animal[v-1]==0:
                animal[v+1]+=1
                dfs(v+1,animal)
            else:
                animal[v+1]=0
                dfs(v+1,animal)
            
        else:
            if animal[v-1]==0:
                animal[v+1]=0
                dfs(v+1,animal)
            else:
                animal[v+1]+=1
                dfs(v+1,animal)
            

dfs(0,animal)
if f[0]==False:
    print(-1)
if f[0]==True:
    u = ''
    for i in range(0,n):
        if animal[i]==0:
            u = u+'S'
        else:
            u = u + 'W'
    print(u)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()
animal = [0]*n #0が羊、1が狼
f = [False]
def dfs(v,animal):
    if v == 0:
        dfs(1,animal)
        animal[0]+=1
        dfs(1,animal)
        
        
    if f[0]== True:
        return animal
    if v == n-1:
        if s[v]=='o':
            if animal[v]==0:
                if ((animal[v-1]==0)and(animal[0]==0))or((animal[v-1]==1)and(animal[0]==1)):
                    # print("True!")
                    f[0]= True
                    return animal
            else:
                if ((animal[v-1]==0)and(animal[0]==1))or((animal[v-1]==1)and(animal[0]==0)):
                    # print("True!")
                    f[0]= True
                    return animal
        else:
            if animal[v]==0:
                if ((animal[v-1]==0)and(animal[0]==1))or((animal[v-1]==1)and(animal[0]==0)):
                    # print("True!")
                    f[0]= True
                    return animal
                
            else:
                if ((animal[v-1]==0)and(animal[0]==0))or((animal[v-1]==1)and(animal[0]==1)):
                    # print("True!")
                    f[0]= True
                    return animal
        if f[0]==False:
            # print("False!")
            return
        
        
    if s[v]=='o':
        if animal[v]==0:
            if animal[v-1]==0:
                animal[v+1]=0
                dfs(v+1,animal)
            else:
                animal[v+1]+=1
                dfs(v+1,animal)
            
        else:
            if animal[v-1]==0:
                animal[v+1]+=1
                dfs(v+1,animal)
            else:
                animal[v+1]=0
                dfs(v+1,animal)
            

    else:
        if animal[v]==0:
            if animal[v-1]==0:
                animal[v+1]+=1
                dfs(v+1,animal)
            else:
                animal[v+1]=0
                dfs(v+1,animal)
            
        else:
            if animal[v-1]==0:
                animal[v+1]=0
                dfs(v+1,animal)
            else:
                animal[v+1]+=1
                dfs(v+1,animal)
            

dfs(0,animal)
if f[0]==False:
    print(-1)
if f[0]==True:
    u = ''
    for i in range(0,n):
        if animal[i]==0:
            u = u+'S'
        else:
            u = u + 'W'
    print(u)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()
animal = [0]*n #0が羊、1が狼
f = [False]
def dfs(v,animal):
    if f[0]== True:
        return animal
    if v == n-1:
        if s[v]=='o':
            if animal[v]==0:
                if ((animal[v-1]==0)and(animal[0]==0))or((animal[v-1]==1)and(animal[0]==1)):
                    # print("True!")
                    f[0]= True
                    return animal
            else:
                if ((animal[v-1]==0)and(animal[0]==1))or((animal[v-1]==1)and(animal[0]==0)):
                    # print("True!")
                    f[0]= True
                    return animal
        else:
            if animal[v]==0:
                if ((animal[v-1]==0)and(animal[0]==1))or((animal[v-1]==1)and(animal[0]==0)):
                    # print("True!")
                    f[0]= True
                    return animal
                
            else:
                if ((animal[v-1]==0)and(animal[0]==0))or((animal[v-1]==1)and(animal[0]==1)):
                    # print("True!")
                    f[0]= True
                    return animal
        if f[0]==False:
            # print("False!")
            return
        
        
    if s[v]=='o':
        if animal[v]==0:
            if animal[v-1]==0:
                animal[v+1]=0
                dfs(v+1,animal)
            else:
                animal[v+1]+=1
                dfs(v+1,animal)
            
        else:
            if animal[v-1]==0:
                animal[v+1]+=1
                dfs(v+1,animal)
            else:
                animal[v+1]=0
                dfs(v+1,animal)
            

    else:
        if animal[v]==0:
            if animal[v-1]==0:
                animal[v+1]+=1
                dfs(v+1,animal)
            else:
                animal[v+1]=0
                dfs(v+1,animal)
            
        else:
            if animal[v-1]==0:
                animal[v+1]=0
                dfs(v+1,animal)
            else:
                animal[v+1]+=1
                dfs(v+1,animal)
            

dfs(0,animal)
if f[0]==False:
    print(-1)
if f[0]==True:
    u = ''
    for i in range(0,n):
        if animal[i]==0:
            u = u+'S'
        else:
            u = u + 'W'
    print(u)