Problem p02721 (python)

Fixed submission:
k,y,c = map( int, input().split(" "))
ss = input()

asc = []
dsc = []

cnt = 0
err_flg = 0
while( True ):
  if(len(ss) <= cnt):
    err_flg = 1
    break
  if( ss[cnt] == "o"):
    asc.append( cnt )
    cnt += c+1
  else:
    cnt += 1
    
  if( len(asc)==y ):
    break

cnt = 0
ss = ss[::-1]
while( True ):
  if(len(ss) <= cnt):
    err_flg = 1
    break
  if( ss[cnt] == "o"):
    dsc.append( cnt )
    cnt += c+1
  else:
    cnt += 1
    
  if( len(dsc)==y ):
    break
    
for i in range(len(dsc)):
  dsc[i] = len(ss) - dsc[i] - 1
  
dsc.reverse()
#print(asc)
#print(dsc)

if( err_flg == 0 ):
  for i in range(len(asc)):
    if( asc[i] == dsc[i] ):
      print(asc[i]+1)

Buggy submission (verdict: Runtime Error):
def getlist_pattern( offset, rstr, N, step ):
  aap = []
  if(N<=0):
    return aap
  
  for i,ch in enumerate(rstr):
    if( ch == "o" ):
      ap = []
      if( len(rstr) >i+step+1 ):
      	ap = getlist_pattern( offset+i+step+1, rstr[i+step+1:], N-1,step )
      
      if( ap==[] ):
        ap = [[offset+i]]
      else:
      	for j in range(len(ap)):
          ap[j].append(offset+i)
      aap.extend(ap)
  return aap    

n,k,c = map(int, input().split(" "))

vstr = input()

pp = getlist_pattern( 0, vstr, k, c )

#print(pp)
base = []
for p in pp:
  if(len(p) == k):
    base = p
    break

base.sort()

for ind in base:
  err_flag = 0
  for p in pp:
    if(len(p) == k):
      if( not( ind in p )):
        err_flag = 1
        break
  if( err_flag==0):
  	print( ind+1 )

Buggy submission (verdict: Runtime Error):
def getlist_pattern( offset, rstr, N, step ):
  aap = []
  if(N<=0):
    return aap
  
  for i,ch in enumerate(rstr):
    if( ch == "o" ):
      ap = []
      if( len(rstr) >=i+step+1 ):
      	ap = getlist_pattern( offset+i+step+1, rstr[i+step+1:], N-1,step )
      
      if( ap==[] ):
        ap = [[offset+i]]
      else:
      	for j in range(len(ap)):
          ap[j].append(offset+i)
      aap.extend(ap)
  return aap    

n,k,c = map(int, input().split(" "))

vstr = input()

pp = getlist_pattern( 0, vstr, k, c )

#print(pp)
base = []
for p in pp:
  if(len(p) == k):
    base = p
    break

base.sort()

for ind in base:
  err_flag = 0
  for p in pp:
    if(len(p) == k):
      if( not( ind in p )):
        err_flag = 1
        break
  if( err_flag==0):
  	print( ind+1 )

Buggy submission (verdict: Runtime Error):
def getlist_pattern( offset, rstr, N, step ):
  aap = []
  if(N<=0):
    return aap
  
  for i,ch in enumerate(rstr):
    if( ch == "o" ):
      ap = getlist_pattern( offset+i+step+1, rstr[i+step+1:], N-1,step )
      
      if( ap==[] ):
        ap = [[offset+i]]
      else:
      	for j in range(len(ap)):
          ap[j].append(offset+i)
      aap.extend(ap)
  return aap    

n,k,c = map(int, input().split(" "))

vstr = input()

pp = getlist_pattern( 0, vstr, k, c )

#print(pp)
base = []
for p in pp:
  if(len(p) == k):
    base = p
    break

base.sort()

for ind in base:
  err_flag = 0
  for p in pp:
    if(len(p) == k):
      if( not( ind in p )):
        err_flag = 1
        break
  if( err_flag==0):
  	print( ind+1 )

Buggy submission (verdict: Runtime Error):
def getlist_pattern( offset, rstr, N, step ):
  aap = []
  if(N<=0):
    return aap
  
  for i,ch in enumerate(rstr):
    if( ch == "o" ):
      ap = getlist_pattern( offset+i+step+1, rstr[i+step+1:], N-1,step )
      
      if( ap==[] ):
        ap = [[offset+i]]
      else:
      	for j in range(len(ap)):
          ap[j].append(offset+i)
      aap.extend(ap)
  return aap    

n,k,c = map(int, input().split(" "))

vstr = input()

pp = getlist_pattern( 0, vstr, k, c )

#print(pp)

for p in pp:
  if(len(p) == k):
    base = p
    break

base.sort()

for ind in base:
  err_flag = 0
  for p in pp:
    if(len(p) == k):
      if( not( ind in p )):
        err_flag = 1
        break
  if( err_flag==0):
  	print( ind+1 )

Buggy submission (verdict: Runtime Error):
def getlist_pattern( offset, rstr, N, step ):
  aap = []
  if(N<=0):
    return aap
  
  for i,ch in enumerate(rstr):
    if( ch == "o" ):
      ap = getlist_pattern( offset+i+step, rstr[i+step:], N-1,step )
      
      if( ap==[] ):
        ap = [[offset+i]]
      else:
      	for j in range(len(ap)):
          ap[j].append(offset+i)
      aap.extend(ap)
  return aap    

n,k,c = map(int, input().split(" "))

vstr = input()

pp = getlist_pattern( 0, vstr, k, 2 )


for p in pp:
  if(len(p) == k):
    base = p
    break

base.sort()

for ind in base:
  err_flag = 0
  for p in pp:
    if(len(p) == k):
      if( not( ind in p )):
        err_flag = 1
        break
  if( err_flag==0):
  	print( ind+1 )